upd(crm): add resources and scopes to system types
This commit is contained in:
+11
-15
@@ -1,9 +1,11 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -53,19 +55,13 @@ type (
|
||||
ChannelType string
|
||||
)
|
||||
|
||||
// Scope returns permissions group that for this type
|
||||
func (c *Channel) Scope() string {
|
||||
return "channel"
|
||||
}
|
||||
|
||||
// Resource returns a RBAC resource ID for this type
|
||||
func (c *Channel) Resource() string {
|
||||
return fmt.Sprintf("%s:%d", c.Scope(), c.ID)
|
||||
}
|
||||
|
||||
// Operation returns a RBAC resource-scoped role name for an operation
|
||||
func (c *Channel) Operation(name string) string {
|
||||
return fmt.Sprintf("%s/%s", c.Resource(), name)
|
||||
// Resource returns a system resource ID for this type
|
||||
func (r *Channel) Resource() types.Resource {
|
||||
return types.Resource{
|
||||
ID: r.ID,
|
||||
Name: r.Name,
|
||||
Scope: "channel",
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Channel) IsValid() bool {
|
||||
|
||||
@@ -1,27 +1,13 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
// Organisations - Organisations represent a top-level grouping entity. There may be many organisations defined in a single deployment.
|
||||
Organisation types.Organisation
|
||||
// Organisations - Organisations represent a top-level grouping entity.
|
||||
// There may be many organisations defined in a single deployment.
|
||||
Organisation struct {
|
||||
types.Organisation
|
||||
}
|
||||
)
|
||||
|
||||
// Scope returns permissions group that for this type
|
||||
func (r *Organisation) Scope() string {
|
||||
return "organisation"
|
||||
}
|
||||
|
||||
// Resource returns a RBAC resource ID for this type
|
||||
func (r *Organisation) Resource() string {
|
||||
return fmt.Sprintf("%s:%d", r.Scope(), r.ID)
|
||||
}
|
||||
|
||||
// Operation returns a RBAC resource-scoped role name for an operation
|
||||
func (r *Organisation) Operation(name string) string {
|
||||
return fmt.Sprintf("%s/%s", r.Resource(), name)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/crusttech/crust/internal/rules"
|
||||
"github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
ResourceProvider interface {
|
||||
Scope() string
|
||||
Resource() string
|
||||
Operation(name string) string
|
||||
Permissions() []rules.OperationGroup
|
||||
Resource() types.Resource
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
+3
-18
@@ -1,26 +1,11 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
Team types.Team
|
||||
Team struct {
|
||||
types.Team
|
||||
}
|
||||
)
|
||||
|
||||
// Scope returns permissions group that for this type
|
||||
func (r *Team) Scope() string {
|
||||
return "team"
|
||||
}
|
||||
|
||||
// Resource returns a RBAC resource ID for this type
|
||||
func (r *Team) Resource() string {
|
||||
return fmt.Sprintf("%s:%d", r.Scope(), r.ID)
|
||||
}
|
||||
|
||||
// Operation returns a RBAC resource-scoped role name for an operation
|
||||
func (r *Team) Operation(name string) string {
|
||||
return fmt.Sprintf("%s/%s", r.Resource(), name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user