forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usergroup.go
42 lines (38 loc) · 913 Bytes
/
usergroup.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
40
41
42
package uadmin
// UserGroup !
type UserGroup struct {
Model
GroupName string `uadmin:"filter"`
}
func (u UserGroup) String() string {
return u.GroupName
}
// HasAccess !
func (u *UserGroup) HasAccess(modelName string) GroupPermission {
Trail(WARNING, "UserGroup.HasAccess will be deprecated in version 0.6.0. Use User.GetAccess instead.")
return u.hasAccess(modelName)
}
// hasAccess !
func (u *UserGroup) hasAccess(modelName string) GroupPermission {
up := GroupPermission{}
dm := DashboardMenu{}
if CachePermissions {
modelID := uint(0)
for _, m := range cachedModels {
if m.URL == modelName {
modelID = m.ID
break
}
}
for _, g := range cacheGroupPerms {
if g.UserGroupID == u.ID && g.DashboardMenuID == modelID {
up = g
break
}
}
} else {
Get(&dm, "url = ?", modelName)
Get(&up, "user_group_id = ? AND dashboard_menu_id = ?", u.ID, dm.ID)
}
return up
}