2022-01-26 10:16:33 +01:00
|
|
|
package domain
|
|
|
|
|
2023-05-05 17:34:53 +02:00
|
|
|
import "context"
|
|
|
|
|
2022-01-26 10:16:33 +01: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 17:34:53 +02:00
|
|
|
|
|
|
|
type PermissionCheck func(ctx context.Context, permission, orgID, resourceID string) (err error)
|
|
|
|
|
|
|
|
const (
|
|
|
|
PermissionUserWrite = "user.write"
|
2023-06-20 18:23:28 +02:00
|
|
|
PermissionUserRead = "user.read"
|
2023-12-21 10:03:37 +01:00
|
|
|
PermissionUserDelete = "user.delete"
|
2023-05-05 17:34:53 +02:00
|
|
|
PermissionSessionWrite = "session.write"
|
|
|
|
PermissionSessionDelete = "session.delete"
|
|
|
|
)
|