3
0

add(sam): resource hints for org/chan/team

This commit is contained in:
Tit Petric
2018-10-01 15:00:04 +02:00
parent 66229f6a40
commit 8d84f8ec03
4 changed files with 51 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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