Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87c474b

Browse files
committed
Move convertRole(s) to coderd
1 parentb1bb55f commit87c474b

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

‎coderd/roles.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (*api) assignableSiteRoles(rw http.ResponseWriter, _ *http.Request) {
1515
// TODO: @emyrk in the future, allow granular subsets of roles to be returned based on the
1616
// role of the user.
1717
roles:=rbac.SiteRoles()
18-
httpapi.Write(rw,http.StatusOK,codersdk.ConvertRoles(roles))
18+
httpapi.Write(rw,http.StatusOK,ConvertRoles(roles))
1919
}
2020

2121
// assignableSiteRoles returns all site wide roles that can be assigned.
@@ -24,5 +24,20 @@ func (*api) assignableOrgRoles(rw http.ResponseWriter, r *http.Request) {
2424
// role of the user.
2525
organization:=httpmw.OrganizationParam(r)
2626
roles:=rbac.OrganizationRoles(organization.ID)
27-
httpapi.Write(rw,http.StatusOK,codersdk.ConvertRoles(roles))
27+
httpapi.Write(rw,http.StatusOK,ConvertRoles(roles))
28+
}
29+
30+
funcConvertRole(role rbac.Role) codersdk.Role {
31+
return codersdk.Role{
32+
DisplayName:role.DisplayName,
33+
Name:role.Name,
34+
}
35+
}
36+
37+
funcConvertRoles(roles []rbac.Role) []codersdk.Role {
38+
converted:=make([]codersdk.Role,0,len(roles))
39+
for_,role:=rangeroles {
40+
converted=append(converted,ConvertRole(role))
41+
}
42+
returnconverted
2843
}

‎coderd/roles_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/stretchr/testify/require"
99

10+
"github.com/coder/coder/coderd"
1011
"github.com/coder/coder/coderd/coderdtest"
1112
"github.com/coder/coder/coderd/rbac"
1213
"github.com/coder/coder/codersdk"
@@ -84,7 +85,7 @@ func TestListRoles(t *testing.T) {
8485
APICall:func() ([]codersdk.Role,error) {
8586
returnorgAdmin.ListOrganizationRoles(ctx,admin.OrganizationID)
8687
},
87-
ExpectedRoles:codersdk.ConvertRoles(rbac.OrganizationRoles(admin.OrganizationID)),
88+
ExpectedRoles:coderd.ConvertRoles(rbac.OrganizationRoles(admin.OrganizationID)),
8889
},
8990
{
9091
Name:"OrgAdminListOtherOrg",
@@ -99,14 +100,14 @@ func TestListRoles(t *testing.T) {
99100
APICall:func() ([]codersdk.Role,error) {
100101
returnclient.ListSiteRoles(ctx)
101102
},
102-
ExpectedRoles:codersdk.ConvertRoles(rbac.SiteRoles()),
103+
ExpectedRoles:coderd.ConvertRoles(rbac.SiteRoles()),
103104
},
104105
{
105106
Name:"AdminListOrg",
106107
APICall:func() ([]codersdk.Role,error) {
107108
returnclient.ListOrganizationRoles(ctx,admin.OrganizationID)
108109
},
109-
ExpectedRoles:codersdk.ConvertRoles(rbac.OrganizationRoles(admin.OrganizationID)),
110+
ExpectedRoles:coderd.ConvertRoles(rbac.OrganizationRoles(admin.OrganizationID)),
110111
},
111112
}
112113

‎codersdk/roles.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"net/http"
88

9-
"github.com/coder/coder/coderd/rbac"
109
"github.com/google/uuid"
1110
)
1211

@@ -44,18 +43,3 @@ func (c *Client) ListOrganizationRoles(ctx context.Context, org uuid.UUID) ([]Ro
4443
varroles []Role
4544
returnroles,json.NewDecoder(res.Body).Decode(&roles)
4645
}
47-
48-
funcConvertRole(role rbac.Role)Role {
49-
returnRole{
50-
DisplayName:role.DisplayName,
51-
Name:role.Name,
52-
}
53-
}
54-
55-
funcConvertRoles(roles []rbac.Role) []Role {
56-
converted:=make([]Role,0,len(roles))
57-
for_,role:=rangeroles {
58-
converted=append(converted,ConvertRole(role))
59-
}
60-
returnconverted
61-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp