MCPcopy Index your code
hub / github.com/coder/coder / deleteOrgRole

Method deleteOrgRole

enterprise/coderd/roles.go:191–265  ·  view source on GitHub ↗

deleteOrgRole will remove a custom role from an organization @Summary Delete a custom organization role @ID delete-a-custom-organization-role @Security CoderSessionToken @Produce json @Param organization path string true "Organization ID" format(uuid) @Param roleName path string true "Role name" @T

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

189// @Success 200 {array} codersdk.Role
190// @Router /api/v2/organizations/{organization}/members/roles/{roleName} [delete]
191func (api *API) deleteOrgRole(rw http.ResponseWriter, r *http.Request) {
192 var (
193 ctx = r.Context()
194 auditor = api.AGPL.Auditor.Load()
195 organization = httpmw.OrganizationParam(r)
196 aReq, commitAudit = audit.InitRequest[database.CustomRole](rw, &audit.RequestParams{
197 Audit: *auditor,
198 Log: api.Logger,
199 Request: r,
200 Action: database.AuditActionDelete,
201 OrganizationID: organization.ID,
202 })
203 )
204 defer commitAudit()
205
206 rolename := chi.URLParam(r, "roleName")
207
208 // Catch requests that try to delete system roles.
209 if !validOrganizationRoleRequest(ctx, codersdk.CustomRoleRequest{Name: rolename}, rw) {
210 return
211 }
212
213 roles, err := api.Database.CustomRoles(ctx, database.CustomRolesParams{
214 LookupRoles: []database.NameOrganizationPair{
215 {
216 Name: rolename,
217 OrganizationID: organization.ID,
218 },
219 },
220 ExcludeOrgRoles: false,
221 IncludeSystemRoles: false,
222 // Linter requires all fields to be set. This field is not actually required.
223 OrganizationID: organization.ID,
224 })
225 if err != nil {
226 httpapi.InternalServerError(rw, err)
227 return
228 }
229 if len(roles) == 0 {
230 httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
231 Message: fmt.Sprintf("No custom role with the name %s found", rolename),
232 Detail: "no role found",
233 Validations: nil,
234 })
235 return
236 }
237 if len(roles) > 1 {
238 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
239 Message: fmt.Sprintf("Multiple roles with the name %s found", rolename),
240 Detail: "multiple roles found, this should never happen",
241 Validations: nil,
242 })
243 return
244 }
245 aReq.Old = roles[0]
246
247 err = api.Database.DeleteCustomRole(ctx, database.DeleteCustomRoleParams{
248 Name: rolename,

Callers

nothing calls this directly

Calls 11

OrganizationParamFunction · 0.92
InitRequestFunction · 0.92
InternalServerErrorFunction · 0.92
WriteFunction · 0.92
IsUnauthorizedErrorFunction · 0.92
ForbiddenFunction · 0.92
ContextMethod · 0.65
CustomRolesMethod · 0.65
DeleteCustomRoleMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected