diff --git a/sam/types/channel.go b/sam/types/channel.go index 38e9bbd66..d599a5570 100644 --- a/sam/types/channel.go +++ b/sam/types/channel.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "fmt" "time" ) @@ -53,6 +54,21 @@ type ( ChannelMemberSet []*ChannelMember ) +// Scope returns permissions group that for this type +func (r *Channel) Scope() string { + return "channel" +} + +// Resource returns a RBAC resource ID for this type +func (r *Channel) Resource() string { + return fmt.Sprintf("%s:%d", r.Scope(), r.ID) +} + +// Operation returns a RBAC resource-scoped role name for an operation +func (r *Channel) Operation(name string) string { + return fmt.Sprintf("%s/%s", r.Resource(), name) +} + func (cc ChannelSet) Walk(w func(*Channel) error) (err error) { for i := range cc { if err = w(cc[i]); err != nil { diff --git a/sam/types/message.go b/sam/types/message.go index a6ff65011..131a62a3d 100644 --- a/sam/types/message.go +++ b/sam/types/message.go @@ -37,9 +37,9 @@ type ( const ( MessageTypeSimpleMessage MessageType = "" - MessageTypeChannelEvent MessageType = "channelEvent" - MessageTypeInlineImage MessageType = "inlineImage" - MessageTypeAttachment MessageType = "attachment" + MessageTypeChannelEvent = "channelEvent" + MessageTypeInlineImage = "inlineImage" + MessageTypeAttachment = "attachment" ) func (mm MessageSet) Walk(w func(*Message) error) (err error) { diff --git a/sam/types/organisation.go b/sam/types/organisation.go index 7ac7dc32d..d8de1fc08 100644 --- a/sam/types/organisation.go +++ b/sam/types/organisation.go @@ -1,6 +1,7 @@ package types import ( + "fmt" "time" ) @@ -20,3 +21,18 @@ type ( Query string } ) + +// 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) +} diff --git a/sam/types/team.go b/sam/types/team.go index 3d6e4aa20..adba7e027 100644 --- a/sam/types/team.go +++ b/sam/types/team.go @@ -1,6 +1,7 @@ package types import ( + "fmt" "time" ) @@ -20,3 +21,18 @@ type ( Query string } ) + +// 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) +}