35 lines
881 B
Go
35 lines
881 B
Go
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)
|
|
}
|