8000 fix(api): clone perm (#4637) · ovh/cds@c2748f5 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit c2748f5

Browse files
yesnaultfsamin
authored andcommitted
fix(api): clone perm (#4637)
1 parent b95c3d8 commit c2748f5

File tree

3 files changed

+29
-41
lines changed

3 files changed

+29
-41
lines changed

engine/api/router_permission.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ func loadPermissionsByGroupID(db gorp.SqlExecutor, store cache.Store, groupID in
111111
store.SetWithTTL(ku, u.Permissions, 120)
112112
}
113113

114-
return g, u.Permissions, nil
114+
return g, u.Permissions.Clone(), nil
115115
}

sdk/user.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,28 @@ type Favorite struct {
2626
type UserPermissions struct {
2727
Groups []string `json:"Groups,omitempty"` // json key are capitalized to ensure exising data in cache are still valid
2828
GroupsAdmin []string `json:"GroupsAdmin,omitempty"`
29-
ProjectsPerm map[string]int `json:"ProjectsPerm,omitempty"`
29+
ProjectsPerm UserPermissionsMap `json:"ProjectsPerm,omitempty"`
3030
WorkflowsPerm UserPermissionsMap `json:"WorkflowsPerm,omitempty"`
3131
}
3232

33+
func (u UserPermissions) Clone() UserPermissions {
34+
up := UserPermissions{}
35+
up.Groups = make([]string, len(u.Groups))
36+
up.GroupsAdmin = make([]string, len(u.GroupsAdmin))
37+
up.ProjectsPerm = make(UserPermissionsMap, len(u.ProjectsPerm))
38+
up.WorkflowsPerm = make(UserPermissionsMap, len(u.WorkflowsPerm))
39+
copy(up.Groups, u.Groups)
40+
copy(up.GroupsAdmin, u.GroupsAdmin)
41+
42+
for i, v := range u.ProjectsPerm {
43+
up.ProjectsPerm[i] = v
44+
}
45+
for i, v := range u.WorkflowsPerm {
46+
up.WorkflowsPerm[i] = v
47+
}
48+
return up
49+
}
50+
3351
// UserPermissionsMap is a type of map. The in key the key and name of the object and value is the level of permissions
3452
//easyjson:json
3553
type UserPermissionsMap map[string]int

sdk/user_easyjson.go

Lines changed: 9 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0