@@ -21,7 +21,15 @@ type enterpriseCustomRoleHandler struct {
21
21
func (h enterpriseCustomRoleHandler ) PatchOrganizationRole (ctx context.Context , db database.Store , rw http.ResponseWriter , orgID uuid.UUID , role codersdk.Role ) (codersdk.Role , bool ) {
22
22
if ! h .Enabled {
23
23
httpapi .Write (ctx , rw , http .StatusForbidden , codersdk.Response {
24
- Message : "Custom roles is not enabled" ,
24
+ Message : "Custom roles are not enabled" ,
25
+ })
26
+ return codersdk.Role {}, false
27
+ }
28
+
29
+ if err := httpapi .NameValid (role .Name ); err != nil {
30
+ httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
31
+ Message : "Invalid role name" ,
32
+ Detail : err .Error (),
25
33
})
26
34
return codersdk.Role {}, false
27
35
}
@@ -43,25 +51,14 @@ func (h enterpriseCustomRoleHandler) PatchOrganizationRole(ctx context.Context,
43
51
return codersdk.Role {}, false
44
52
}
45
53
46
- if len ( role .OrganizationPermissions ) > 1 {
54
+ if role .OrganizationID != orgID . String () {
47
55
httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
48
- Message : "Invalid request, Only 1 organization can be assigned permissions " ,
49
- Detail : "roles can only contain 1 organization" ,
56
+ Message : "Invalid request, organization in role and url must match " ,
57
+ Detail : fmt . Sprintf ( "role org %q does not match URL %q" , role . OrganizationID , orgID . String ()) ,
50
58
})
51
59
return codersdk.Role {}, false
52
60
}
53
61
54
- if len (role .OrganizationPermissions ) == 1 {
55
- _ , exists := role .OrganizationPermissions [orgID .String ()]
56
- if ! exists {
57
- httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
58
- Message : fmt .Sprintf ("Invalid request, expected permissions for only the organization %q" , orgID .String ()),
59
- Detail : fmt .Sprintf ("only org id %s allowed" , orgID .String ()),
60
- })
61
- return codersdk.Role {}, false
62
- }
63
- }
64
-
65
62
// Make sure all permissions inputted are valid according to our policy.
66
63
rbacRole := db2sdk .RoleToRBAC (role )
67
64
args , err := rolestore .ConvertRoleToDB (rbacRole )
0 commit comments