Skip to content

Commit 9305177

Browse files
committed
include converter function for roles
1 parent 07f31ba commit 9305177

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

coderd/rbac/rolestore/rolestore.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy