File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ package rolestore
2
+
3
+ import (
4
+ "encoding/json"
5
+
6
+ "golang.org/x/xerrors"
7
+
8
+ "github.com/coder/coder/v2/coderd/database"
9
+ "github.com/coder/coder/v2/coderd/rbac"
10
+ )
11
+
12
+ func ConvertDBRole (dbRole database.CustomRole ) (rbac.Role , error ) {
13
+ role := rbac.Role {
14
+ Name : dbRole .Name ,
15
+ DisplayName : dbRole .DisplayName ,
16
+ Site : nil ,
17
+ Org : nil ,
18
+ User : nil ,
19
+ }
20
+
21
+ err := json .Unmarshal (dbRole .SitePermissions , & role .Site )
22
+ if err != nil {
23
+ return role , xerrors .Errorf ("unmarshal site permissions: %w" , err )
24
+ }
25
+
26
+ err = json .Unmarshal (dbRole .OrgPermissions , & role .Org )
27
+ if err != nil {
28
+ return role , xerrors .Errorf ("unmarshal org permissions: %w" , err )
29
+ }
30
+
31
+ err = json .Unmarshal (dbRole .UserPermissions , & role .User )
32
+ if err != nil {
33
+ return role , xerrors .Errorf ("unmarshal user permissions: %w" , err )
34
+ }
35
+
36
+ return role , nil
37
+ }
You can’t perform that action at this time.
0 commit comments