Skip to content

Commit 27386d4

Browse files
authored
fix: No org admins until organizations are in the UI (coder#5414)
* fix: No org admins until organizations are in the UI Until organizations have management UI, we should not set any org admins. This goes around the site wide perms transparently and is confusing to users. Default user is no longer an org admin, so the demotion test makes no sense
1 parent 012a9e7 commit 27386d4

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

coderd/database/migrations/000086_no_org_admins.down.sql

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
UPDATE
2+
organization_members
3+
SET
4+
roles = ARRAY [] :: text[]
5+
WHERE
6+
'organization-admin:'||organization_id = ANY(roles);

coderd/organizations.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ func (api *API) postOrganizations(rw http.ResponseWriter, r *http.Request) {
7676
CreatedAt: database.Now(),
7777
UpdatedAt: database.Now(),
7878
Roles: []string{
79-
rbac.RoleOrgAdmin(organization.ID),
79+
// TODO: When organizations are allowed to be created, we should
80+
// come back to determining the default role of the person who
81+
// creates the org. Until that happens, all users in an organization
82+
// should be just regular members.
83+
rbac.RoleOrgMember(organization.ID),
8084
},
8185
})
8286
if err != nil {

coderd/users.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,11 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create
10711071
return xerrors.Errorf("create organization: %w", err)
10721072
}
10731073
req.OrganizationID = organization.ID
1074-
orgRoles = append(orgRoles, rbac.RoleOrgAdmin(req.OrganizationID))
1074+
// TODO: When organizations are allowed to be created, we should
1075+
// come back to determining the default role of the person who
1076+
// creates the org. Until that happens, all users in an organization
1077+
// should be just regular members.
1078+
orgRoles = append(orgRoles, rbac.RoleOrgMember(req.OrganizationID))
10751079

10761080
_, err = tx.InsertAllUsersGroup(ctx, organization.ID)
10771081
if err != nil {

coderd/users_test.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,6 @@ func TestGrantSiteRoles(t *testing.T) {
817817
Error: true,
818818
StatusCode: http.StatusForbidden,
819819
},
820-
{
821-
Name: "MemberAssignMember",
822-
Client: member,
823-
OrgID: first.OrganizationID,
824-
AssignToUser: first.UserID.String(),
825-
Roles: []string{},
826-
Error: true,
827-
StatusCode: http.StatusForbidden,
828-
},
829820
{
830821
Name: "AdminUpdateOrgSelf",
831822
Client: admin,
@@ -921,7 +912,7 @@ func TestInitialRoles(t *testing.T) {
921912
}, "should be a member and admin")
922913

923914
require.ElementsMatch(t, roles.OrganizationRoles[first.OrganizationID], []string{
924-
rbac.RoleOrgAdmin(first.OrganizationID),
915+
rbac.RoleOrgMember(first.OrganizationID),
925916
}, "should be a member and admin")
926917
}
927918

0 commit comments

Comments
 (0)