2022-01-26 09:16:33 +00:00
|
|
|
package domain
|
|
|
|
|
2023-05-05 15:34:53 +00:00
|
|
|
import "context"
|
|
|
|
|
2022-01-26 09:16:33 +00:00
|
|
|
type Permissions struct {
|
|
|
|
Permissions []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Permissions) AppendPermissions(ctxID string, permissions ...string) {
|
|
|
|
for _, permission := range permissions {
|
|
|
|
p.appendPermission(ctxID, permission)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Permissions) appendPermission(ctxID, permission string) {
|
|
|
|
if ctxID != "" {
|
|
|
|
permission = permission + ":" + ctxID
|
|
|
|
}
|
|
|
|
for _, existingPermission := range p.Permissions {
|
|
|
|
if existingPermission == permission {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.Permissions = append(p.Permissions, permission)
|
|
|
|
}
|
2023-05-05 15:34:53 +00:00
|
|
|
|
|
|
|
type PermissionCheck func(ctx context.Context, permission, orgID, resourceID string) (err error)
|
|
|
|
|
|
|
|
const (
|
|
|
|
PermissionUserWrite = "user.write"
|
2023-06-20 16:23:28 +00:00
|
|
|
PermissionUserRead = "user.read"
|
2023-05-05 15:34:53 +00:00
|
|
|
PermissionSessionWrite = "session.write"
|
|
|
|
PermissionSessionDelete = "session.delete"
|
|
|
|
)
|