refac: debt on role backend
This commit is contained in:
1 parent
de142f6c5f
commit
a043f7f41a
130 files changed
+3591
-512
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"RenewCMS/internal/domain/builtintype"
|
||||
"RenewCMS/internal/domain/role"
|
||||
)
|
||||
|
||||
type ContentCaller struct {
|
||||
UserID uint32
|
||||
Grants role.GrantSet
|
||||
}
|
||||
|
||||
func (c ContentCaller) requireHolding(key string, typeKey string) error {
|
||||
if !c.Grants.HoldsFor(key, typeKey) {
|
||||
return role.MissingPermissionError{Key: key}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c ContentCaller) authorize(key string, typeKey string, createdBy uint32) error {
|
||||
if !c.Grants.Permits(key, typeKey, c.UserID, createdBy) {
|
||||
return role.MissingPermissionError{Key: key}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c ContentCaller) reads(typeKey string, createdBy uint32) bool {
|
||||
return c.Grants.Permits(role.KeyContentRead, typeKey, c.UserID, createdBy)
|
||||
}
|
||||
|
||||
func (c ContentCaller) seesArticle(art article.Article) bool {
|
||||
return art.IsOnline || c.reads(builtintype.KeyArticle, art.CreatedBy)
|
||||
}
|
||||
Reference in new issue
Block a user