package model import ( "context" "forge.cadoles.com/Cadoles/daddy/internal/voter" ) type WorkgroupVoter struct { } func (v *WorkgroupVoter) Vote(ctx context.Context, subject interface{}, obj interface{}, act interface{}) (voter.Decision, error) { user, ok := subject.(*User) if !ok { return voter.Abstain, nil } workgroup, ok := obj.(*Workgroup) if !ok { return voter.Abstain, nil } action, ok := act.(Action) if !ok { return voter.Abstain, nil } switch action { case ActionCreate: return voter.Allow, nil case ActionRead: return voter.Allow, nil case ActionJoin: return voter.Allow, nil case ActionLeave: fallthrough case ActionUpdate: fallthrough case ActionClose: if inWorkgroup(user, workgroup) { return voter.Allow, nil } else { return voter.Deny, nil } case ActionDelete: return voter.Deny, nil } return voter.Abstain, nil } func NewWorkgroupVoter() *WorkgroupVoter { return &WorkgroupVoter{} }