37 lines
872 B
Go
37 lines
872 B
Go
package domain
|
|
|
|
import (
|
|
"errors"
|
|
"git.cin.su/m/Assistant/contracts/identity"
|
|
)
|
|
|
|
var ErrInvalidRealm = errors.New("invalid principal data realm")
|
|
|
|
func ValidatePrincipalDataRealm(value identity.PrincipalDataRealm) error {
|
|
if !value.Valid() {
|
|
return ErrInvalidRealm
|
|
}
|
|
if value.Kind == identity.DataRealmPersonal && len(value.MemberPrincipalIDs) != 0 {
|
|
return ErrInvalidRealm
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func CanReadRealm(value identity.PrincipalDataRealm, principalID identity.PrincipalID) bool {
|
|
if ValidatePrincipalDataRealm(value) != nil || principalID == "" {
|
|
return false
|
|
}
|
|
if value.Kind == identity.DataRealmPublic {
|
|
return true
|
|
}
|
|
if principalID == value.OwnerPrincipalID {
|
|
return true
|
|
}
|
|
for _, member := range value.MemberPrincipalIDs {
|
|
if member == principalID {
|
|
return value.Kind == identity.DataRealmShared && value.Shared
|
|
}
|
|
}
|
|
return false
|
|
}
|