3
0
- codegen includes rbac since it's used everywhere,
- update permissions structure naming for title/subtitle
This commit is contained in:
Tit Petric
2018-12-04 13:31:53 +01:00
parent 687cd0b2e0
commit f2dfffbab2
9 changed files with 180 additions and 169 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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 (

View File

@@ -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: "",
},
},
},

View File

@@ -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",
},
},
},

View File

@@ -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"
}

View File

@@ -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
}
]

View File

@@ -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
}
]

View File

@@ -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: "",
},
},
},