@@ -107,80 +107,3 @@ func (h enterpriseCustomRoleHandler) PatchOrganizationRole(ctx context.Context,
107
107
108
108
return db2sdk .Role (convertedInsert ), true
109
109
}
110
-
111
- // patchRole will allow creating a custom role
112
- //
113
- // @Summary Upsert a custom site-wide role
114
- // @ID upsert-a-custom-site-wide-role
115
- // @Security CoderSessionToken
116
- // @Produce json
117
- // @Tags Members
118
- // @Success 200 {array} codersdk.Role
119
- // @Router /users/roles [patch]
120
- func (api * API ) patchRole (rw http.ResponseWriter , r * http.Request ) {
121
- ctx := r .Context ()
122
-
123
- var req codersdk.Role
124
- if ! httpapi .Read (ctx , rw , r , & req ) {
125
- return
126
- }
127
-
128
- if err := httpapi .NameValid (req .Name ); err != nil {
129
- httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
130
- Message : "Invalid role name" ,
131
- Detail : err .Error (),
132
- })
133
- return
134
- }
135
-
136
- if len (req .OrganizationPermissions ) > 0 {
137
- // Org perms should be assigned only in org specific roles. Otherwise,
138
- // it gets complicated to keep track of who can do what.
139
- httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
140
- Message : "Invalid request, not allowed to assign organization permissions for a site wide role." ,
141
- Detail : "site wide roles may not contain organization specific permissions" ,
142
- })
143
- return
144
- }
145
-
146
- // Make sure all permissions inputted are valid according to our policy.
147
- rbacRole := db2sdk .RoleToRBAC (req )
148
- args , err := rolestore .ConvertRoleToDB (rbacRole )
149
- if err != nil {
150
- httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
151
- Message : "Invalid request" ,
152
- Detail : err .Error (),
153
- })
154
- return
155
- }
156
-
157
- inserted , err := api .Database .UpsertCustomRole (ctx , database.UpsertCustomRoleParams {
158
- Name : args .Name ,
159
- DisplayName : args .DisplayName ,
160
- SitePermissions : args .SitePermissions ,
161
- OrgPermissions : args .OrgPermissions ,
162
- UserPermissions : args .UserPermissions ,
163
- })
164
- if httpapi .Is404Error (err ) {
165
- httpapi .ResourceNotFound (rw )
166
- return
167
- }
168
- if err != nil {
169
- httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
170
- Message : "Failed to update role permissions" ,
171
- Detail : err .Error (),
172
- })
173
- return
174
- }
175
-
176
- convertedInsert , err := rolestore .ConvertDBRole (inserted )
177
- if err != nil {
178
- httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
179
- Message : "Permissions were updated, unable to read them back out of the database." ,
180
- Detail : err .Error (),
181
- })
182
- return
183
- }
184
-
185
- httpapi .Write (ctx , rw , http .StatusOK , db2sdk .Role (convertedInsert ))
186
- }
0 commit comments