From f2dfffbab2db767015e7edb6bec133622bcfb3a7 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Tue, 4 Dec 2018 13:31:53 +0100 Subject: [PATCH] update: - codegen includes rbac since it's used everywhere, - update permissions structure naming for title/subtitle --- codegen/templates/http_request_inline.tpl | 2 + codegen/v2/permissions.go | 2 +- internal/rbac/operations.go | 23 +++-- sam/types/channel.perms.go | 66 ++++++------ sam/types/organisation.perms.go | 116 +++++++++++----------- sam/types/permissions/1-organisation.json | 38 +++---- sam/types/permissions/2-team.json | 18 ++-- sam/types/permissions/3-channel.json | 18 ++-- sam/types/team.perms.go | 66 ++++++------ 9 files changed, 180 insertions(+), 169 deletions(-) diff --git a/codegen/templates/http_request_inline.tpl b/codegen/templates/http_request_inline.tpl index dd1c5d5b2..b8823ba8d 100644 --- a/codegen/templates/http_request_inline.tpl +++ b/codegen/templates/http_request_inline.tpl @@ -9,6 +9,7 @@ import ( "github.com/go-chi/chi" "github.com/pkg/errors" "github.com/jmoiron/sqlx/types" + "github.com/crusttech/crust/internal/rbac" "mime/multipart" "strings" ) @@ -16,6 +17,7 @@ import ( var _ = chi.URLParam var _ = types.JSONText{} var _ = multipart.FileHeader{} +var _ = rbac.Operation {foreach $calls as $call} // {name} {call.name} request parameters diff --git a/codegen/v2/permissions.go b/codegen/v2/permissions.go index fb4180d9a..3263735f9 100644 --- a/codegen/v2/permissions.go +++ b/codegen/v2/permissions.go @@ -37,7 +37,7 @@ func main() { fmt.Fprintln(&w) fmt.Fprintln(&w, "import \"github.com/crusttech/crust/internal/rbac\"") fmt.Fprintln(&w) - fmt.Fprintln(&w, "/* File is generated from", *input, "& main.go */") + fmt.Fprintln(&w, "/* File is generated from", *input, "with permissions.go */") fmt.Fprintln(&w) fmt.Fprintln(&w, *fname, "{") fmt.Fprintln(&w, "\treturn", s) diff --git a/internal/rbac/operations.go b/internal/rbac/operations.go index 79fbca3b9..eec180d35 100644 --- a/internal/rbac/operations.go +++ b/internal/rbac/operations.go @@ -2,17 +2,17 @@ package rbac type ( OperationGroup struct { - Name string - Operations []Operation + Title string `json:"title"` + Operations []Operation `json:"operations"` } Operation struct { - Key string - Name string - Title string + Key string `json:"key"` + Title string `json:"title"` + Subtitle string `json:"subtitle"` // Enabled will show/hide the operation in administration - Enabled bool + Enabled bool `json:"enabled"` // The default value for managing operations on a role // @@ -20,10 +20,19 @@ type ( // true = checked (allow), // false = unchecked (deny) - Default OperationState + Default OperationState `json:"default"` } OperationState string + + Permission struct { + // Resource (organisation, team, channel) + Resource string `json:"resource"` + // Operation name (Operation.Key) + Operation string `json:"operation"` + // Operation state (inherit, allow, deny) + Value OperationState `json:"value"` + } ) const ( diff --git a/sam/types/channel.perms.go b/sam/types/channel.perms.go index 9ca5370d2..c09d6e821 100644 --- a/sam/types/channel.perms.go +++ b/sam/types/channel.perms.go @@ -2,54 +2,54 @@ package types import "github.com/crusttech/crust/internal/rbac" -/* File is generated from sam/types/permissions/3-channel.json & main.go */ +/* File is generated from sam/types/permissions/3-channel.json with permissions.go */ func (c *Channel) Permissions() []rbac.OperationGroup { return []rbac.OperationGroup{ rbac.OperationGroup{ - Name: "", + Title: "General permissions", Operations: []rbac.Operation{ rbac.Operation{ - Key: "manage.webhooks", - Name: "Manage webhooks (@todo: implement webhooks)", - Title: "Members with this permission can create, edit and delete webhooks", - Enabled: false, - Default: "", + Key: "manage.webhooks", + Title: "Manage webhooks (@todo: implement webhooks)", + Subtitle: "Members with this permission can create, edit and delete webhooks", + Enabled: false, + Default: "", }, }, }, rbac.OperationGroup{ - Name: "", + Title: "Text Permissions", Operations: []rbac.Operation{ rbac.Operation{ - Key: "send", - Name: "Send Messages", - Title: "", - Enabled: true, - Default: "", + Key: "send", + Title: "Send Messages", + Subtitle: "", + Enabled: true, + Default: "", }, rbac.Operation{ - Key: "embed", - Name: "Embed Links", - Title: "", - Enabled: true, - Default: "", + Key: "embed", + Title: "Embed Links", + Subtitle: "", + Enabled: true, + Default: "", }, rbac.Operation{ - Key: "attach", - Name: "Attach Files", - Title: "", - Enabled: true, - Default: "", + Key: "attach", + Title: "Attach Files", + Subtitle: "", + Enabled: true, + Default: "", }, rbac.Operation{ - Key: "manage.messages", - Name: "Manage messages", - Title: "Members with this permission can edit/delete messages inside this channel", - Enabled: true, - Default: "", + Key: "manage.messages", + Title: "Manage messages", + Subtitle: "Members with this permission can edit/delete messages inside this channel", + Enabled: true, + Default: "", }, rbac.Operation{ - Key: "react", - Name: "Manage reactions", - Title: "Members with this permission can add new reactions to a message", - Enabled: true, - Default: "", + Key: "react", + Title: "Manage reactions", + Subtitle: "Members with this permission can add new reactions to a message", + Enabled: true, + Default: "", }, }, }, diff --git a/sam/types/organisation.perms.go b/sam/types/organisation.perms.go index 331cf6708..5549b5440 100644 --- a/sam/types/organisation.perms.go +++ b/sam/types/organisation.perms.go @@ -2,84 +2,84 @@ package types import "github.com/crusttech/crust/internal/rbac" -/* File is generated from sam/types/permissions/1-organisation.json & main.go */ +/* File is generated from sam/types/permissions/1-organisation.json with permissions.go */ func (c *Organisation) Permissions() []rbac.OperationGroup { return []rbac.OperationGroup{ rbac.OperationGroup{ - Name: "", + Title: "General permissions", Operations: []rbac.Operation{ rbac.Operation{ - Key: "admin", - Name: "Administrator", - Title: "Members with this permission have every permission and also bypass channel specific permissions. Granting this permission is dangerous", - Enabled: true, - Default: "deny", + Key: "admin", + Title: "Administrator", + Subtitle: "Members with this permission have every permission and also bypass channel specific permissions. Granting this permission is dangerous", + Enabled: true, + Default: "deny", }, rbac.Operation{ - Key: "audit", - Name: "View Audit Log (@todo: add audit logs)", - Title: "Members with this permission have access to view the servers audit logs", - Enabled: false, - Default: "deny", + Key: "audit", + Title: "View Audit Log (@todo: add audit logs)", + Subtitle: "Members with this permission have access to view the servers audit logs", + Enabled: false, + Default: "deny", }, rbac.Operation{ - Key: "manage.organisation", - Name: "Manage Organisation", - Title: "Members with this permission can change the organisation name and other organisation details", - Enabled: true, - Default: "deny", + Key: "manage.organisation", + Title: "Manage Organisation", + Subtitle: "Members with this permission can change the organisation name and other organisation details", + Enabled: true, + Default: "deny", }, rbac.Operation{ - Key: "manage.roles", - Name: "Manage Roles", - Title: "Members with this permission can create/edit/delete roles inside this organisation", - Enabled: true, - Default: "deny", + Key: "manage.roles", + Title: "Manage Roles", + Subtitle: "Members with this permission can create/edit/delete roles inside this organisation", + Enabled: true, + Default: "deny", }, rbac.Operation{ - Key: "manage.channels", - Name: "Manage channels", - Title: "Members with this permission can create/edit/delete channels inside this organisation", - Enabled: true, - Default: "deny", + Key: "manage.channels", + Title: "Manage channels", + Subtitle: "Members with this permission can create/edit/delete channels inside this organisation", + Enabled: true, + Default: "deny", }, rbac.Operation{ - Key: "manage.webhooks", - Name: "Manage webhooks (@todo: implement webhooks)", - Title: "Members with this permission can create, edit and delete webhooks", - Enabled: false, - Default: "deny", + Key: "manage.webhooks", + Title: "Manage webhooks (@todo: implement webhooks)", + Subtitle: "Members with this permission can create, edit and delete webhooks", + Enabled: false, + Default: "deny", }, }, }, rbac.OperationGroup{ - Name: "", + Title: "Text Permissions", Operations: []rbac.Operation{ rbac.Operation{ - Key: "send", - Name: "Send Messages", - Title: "", - Enabled: true, - Default: "allow", + Key: "send", + Title: "Send Messages", + Subtitle: "", + Enabled: true, + Default: "allow", }, rbac.Operation{ - Key: "embed", - Name: "Embed Links", - Title: "", - Enabled: true, - Default: "allow", + Key: "embed", + Title: "Embed Links", + Subtitle: "", + Enabled: true, + Default: "allow", }, rbac.Operation{ - Key: "attach", - Name: "Attach Files", - Title: "", - Enabled: true, - Default: "allow", + Key: "attach", + Title: "Attach Files", + Subtitle: "", + Enabled: true, + Default: "allow", }, rbac.Operation{ - Key: "manage.messages", - Name: "Manage messages", - Title: "Members with this permission can edit/delete messages inside channels", - Enabled: true, - Default: "deny", + Key: "manage.messages", + Title: "Manage messages", + Subtitle: "Members with this permission can edit/delete messages inside channels", + Enabled: true, + Default: "deny", }, rbac.Operation{ - Key: "react", - Name: "Manage reactions", - Title: "Members with this permission can add new reactions to a message", - Enabled: true, - Default: "allow", + Key: "react", + Title: "Manage reactions", + Subtitle: "Members with this permission can add new reactions to a message", + Enabled: true, + Default: "allow", }, }, }, diff --git a/sam/types/permissions/1-organisation.json b/sam/types/permissions/1-organisation.json index cc3fb98fc..4cd9ab8d3 100644 --- a/sam/types/permissions/1-organisation.json +++ b/sam/types/permissions/1-organisation.json @@ -4,43 +4,43 @@ "operations": [ { "key": "admin", - "name": "Administrator", - "title": "Members with this permission have every permission and also bypass channel specific permissions. Granting this permission is dangerous", + "title": "Administrator", + "subtitle": "Members with this permission have every permission and also bypass channel specific permissions. Granting this permission is dangerous", "enabled": true, "default": "deny" }, { "key": "audit", - "name": "View Audit Log (@todo: add audit logs)", - "title": "Members with this permission have access to view the servers audit logs", + "title": "View Audit Log (@todo: add audit logs)", + "subtitle": "Members with this permission have access to view the servers audit logs", "enabled": false, "default": "deny" }, { "key": "manage.organisation", - "name": "Manage Organisation", - "title": "Members with this permission can change the organisation name and other organisation details", + "title": "Manage Organisation", + "subtitle": "Members with this permission can change the organisation name and other organisation details", "enabled": true, "default": "deny" }, { "key": "manage.roles", - "name": "Manage Roles", - "title": "Members with this permission can create/edit/delete roles inside this organisation", + "title": "Manage Roles", + "subtitle": "Members with this permission can create/edit/delete roles inside this organisation", "enabled": true, "default": "deny" }, { "key": "manage.channels", - "name": "Manage channels", - "title": "Members with this permission can create/edit/delete channels inside this organisation", + "title": "Manage channels", + "subtitle": "Members with this permission can create/edit/delete channels inside this organisation", "enabled": true, "default": "deny" }, { "key": "manage.webhooks", - "name": "Manage webhooks (@todo: implement webhooks)", - "title": "Members with this permission can create, edit and delete webhooks", + "title": "Manage webhooks (@todo: implement webhooks)", + "subtitle": "Members with this permission can create, edit and delete webhooks", "enabled": false, "default": "deny" } @@ -51,33 +51,33 @@ "operations": [ { "key": "send", - "name": "Send Messages", + "title": "Send Messages", "enabled": true, "default": "allow" }, { "key": "embed", - "name": "Embed Links", + "title": "Embed Links", "enabled": true, "default": "allow" }, { "key": "attach", - "name": "Attach Files", + "title": "Attach Files", "enabled": true, "default": "allow" }, { "key": "manage.messages", - "name": "Manage messages", - "title": "Members with this permission can edit/delete messages inside channels", + "title": "Manage messages", + "subtitle": "Members with this permission can edit/delete messages inside channels", "enabled": true, "default": "deny" }, { "key": "react", - "name": "Manage reactions", - "title": "Members with this permission can add new reactions to a message", + "title": "Manage reactions", + "subtitle": "Members with this permission can add new reactions to a message", "enabled": true, "default": "allow" } diff --git a/sam/types/permissions/2-team.json b/sam/types/permissions/2-team.json index d43e3dcb0..2351959e4 100644 --- a/sam/types/permissions/2-team.json +++ b/sam/types/permissions/2-team.json @@ -4,8 +4,8 @@ "operations": [ { "key": "manage.webhooks", - "name": "Manage webhooks (@todo: implement webhooks)", - "title": "Members with this permission can create, edit and delete webhooks", + "title": "Manage webhooks (@todo: implement webhooks)", + "subtitle": "Members with this permission can create, edit and delete webhooks", "enabled": false } ] @@ -15,29 +15,29 @@ "operations": [ { "key": "send", - "name": "Send Messages", + "title": "Send Messages", "enabled": true }, { "key": "embed", - "name": "Embed Links", + "title": "Embed Links", "enabled": true }, { "key": "attach", - "name": "Attach Files", + "title": "Attach Files", "enabled": true }, { "key": "manage.messages", - "name": "Manage messages", - "title": "Members with this permission can edit/delete messages inside channels", + "title": "Manage messages", + "subtitle": "Members with this permission can edit/delete messages inside channels", "enabled": true }, { "key": "react", - "name": "Manage reactions", - "title": "Members with this permission can add new reactions to a message", + "title": "Manage reactions", + "subtitle": "Members with this permission can add new reactions to a message", "enabled": true } ] diff --git a/sam/types/permissions/3-channel.json b/sam/types/permissions/3-channel.json index 3a118b2fd..5e066ca58 100644 --- a/sam/types/permissions/3-channel.json +++ b/sam/types/permissions/3-channel.json @@ -4,8 +4,8 @@ "operations": [ { "key": "manage.webhooks", - "name": "Manage webhooks (@todo: implement webhooks)", - "title": "Members with this permission can create, edit and delete webhooks", + "title": "Manage webhooks (@todo: implement webhooks)", + "subtitle": "Members with this permission can create, edit and delete webhooks", "enabled": false } ] @@ -15,29 +15,29 @@ "operations": [ { "key": "send", - "name": "Send Messages", + "title": "Send Messages", "enabled": true }, { "key": "embed", - "name": "Embed Links", + "title": "Embed Links", "enabled": true }, { "key": "attach", - "name": "Attach Files", + "title": "Attach Files", "enabled": true }, { "key": "manage.messages", - "name": "Manage messages", - "title": "Members with this permission can edit/delete messages inside this channel", + "title": "Manage messages", + "subtitle": "Members with this permission can edit/delete messages inside this channel", "enabled": true }, { "key": "react", - "name": "Manage reactions", - "title": "Members with this permission can add new reactions to a message", + "title": "Manage reactions", + "subtitle": "Members with this permission can add new reactions to a message", "enabled": true } ] diff --git a/sam/types/team.perms.go b/sam/types/team.perms.go index 65495e726..04fad75f7 100644 --- a/sam/types/team.perms.go +++ b/sam/types/team.perms.go @@ -2,54 +2,54 @@ package types import "github.com/crusttech/crust/internal/rbac" -/* File is generated from sam/types/permissions/2-team.json & main.go */ +/* File is generated from sam/types/permissions/2-team.json with permissions.go */ func (c *Team) Permissions() []rbac.OperationGroup { return []rbac.OperationGroup{ rbac.OperationGroup{ - Name: "", + Title: "General permissions", Operations: []rbac.Operation{ rbac.Operation{ - Key: "manage.webhooks", - Name: "Manage webhooks (@todo: implement webhooks)", - Title: "Members with this permission can create, edit and delete webhooks", - Enabled: false, - Default: "", + Key: "manage.webhooks", + Title: "Manage webhooks (@todo: implement webhooks)", + Subtitle: "Members with this permission can create, edit and delete webhooks", + Enabled: false, + Default: "", }, }, }, rbac.OperationGroup{ - Name: "", + Title: "Text Permissions", Operations: []rbac.Operation{ rbac.Operation{ - Key: "send", - Name: "Send Messages", - Title: "", - Enabled: true, - Default: "", + Key: "send", + Title: "Send Messages", + Subtitle: "", + Enabled: true, + Default: "", }, rbac.Operation{ - Key: "embed", - Name: "Embed Links", - Title: "", - Enabled: true, - Default: "", + Key: "embed", + Title: "Embed Links", + Subtitle: "", + Enabled: true, + Default: "", }, rbac.Operation{ - Key: "attach", - Name: "Attach Files", - Title: "", - Enabled: true, - Default: "", + Key: "attach", + Title: "Attach Files", + Subtitle: "", + Enabled: true, + Default: "", }, rbac.Operation{ - Key: "manage.messages", - Name: "Manage messages", - Title: "Members with this permission can edit/delete messages inside channels", - Enabled: true, - Default: "", + Key: "manage.messages", + Title: "Manage messages", + Subtitle: "Members with this permission can edit/delete messages inside channels", + Enabled: true, + Default: "", }, rbac.Operation{ - Key: "react", - Name: "Manage reactions", - Title: "Members with this permission can add new reactions to a message", - Enabled: true, - Default: "", + Key: "react", + Title: "Manage reactions", + Subtitle: "Members with this permission can add new reactions to a message", + Enabled: true, + Default: "", }, }, },