-
Notifications
You must be signed in to change notification settings - Fork 2
/
server_user_domain.go
39 lines (35 loc) · 1017 Bytes
/
server_user_domain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package caskin
import "github.com/ahmetb/go-linq/v3"
// GetUserByDomain
// get all user in domain
// 1. no permission checking
func (s *server) GetUserByDomain(domain Domain) ([]User, error) {
us := s.Enforcer.GetUsersInDomain(domain)
uid := ID(us)
linq.From(uid).Distinct().ToSlice(&uid)
return s.DB.GetUserByID(uid)
}
// GetDomainByUser
// get user's all domain
// 1. no permission checking
func (s *server) GetDomainByUser(user User) ([]Domain, error) {
if domain, err := s.getDomainBySuperadmin(user); err == nil {
return domain, nil
}
ds := s.Enforcer.GetDomainsIncludeUser(user)
did := ID(ds)
linq.From(did).Distinct().ToSlice(&did)
return s.DB.GetDomainByID(did)
}
func (s *server) getDomainBySuperadmin(user User) ([]Domain, error) {
// TODO don't use SuperadminCheck
if ok, _ := s.Enforcer.IsSuperadmin(user); !ok {
return nil, ErrIsNotSuperadmin
}
domain, err := s.GetDomain()
if err != nil {
return nil, err
}
domain = append(domain, GetSuperadminDomain())
return domain, nil
}