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

Method postOrgRoles

enterprise/coderd/roles.go:34–87  ·  view source on GitHub ↗

postOrgRoles will allow creating a custom organization role @Summary Insert a custom organization role @ID insert-a-custom-organization-role @Security CoderSessionToken @Accept json @Produce json @Param organization path string true "Organization ID" format(uuid) @Param request body codersdk.Custom

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

Source from the content-addressed store, hash-verified

32// @Success 200 {array} codersdk.Role
33// @Router /api/v2/organizations/{organization}/members/roles [post]
34func (api *API) postOrgRoles(rw http.ResponseWriter, r *http.Request) {
35 var (
36 ctx = r.Context()
37 db = api.Database
38 auditor = api.AGPL.Auditor.Load()
39 organization = httpmw.OrganizationParam(r)
40 aReq, commitAudit = audit.InitRequest[database.CustomRole](rw, &audit.RequestParams{
41 Audit: *auditor,
42 Log: api.Logger,
43 Request: r,
44 Action: database.AuditActionCreate,
45 OrganizationID: organization.ID,
46 })
47 )
48 defer commitAudit()
49
50 var req codersdk.CustomRoleRequest
51 if !httpapi.Read(ctx, rw, r, &req) {
52 return
53 }
54
55 if !validOrganizationRoleRequest(ctx, req, rw) {
56 return
57 }
58
59 inserted, err := db.InsertCustomRole(ctx, database.InsertCustomRoleParams{
60 Name: req.Name,
61 DisplayName: req.DisplayName,
62 OrganizationID: uuid.NullUUID{
63 UUID: organization.ID,
64 Valid: true,
65 },
66 SitePermissions: slice.List(req.SitePermissions, sdkPermissionToDB),
67 OrgPermissions: slice.List(req.OrganizationPermissions, sdkPermissionToDB),
68 UserPermissions: slice.List(req.UserPermissions, sdkPermissionToDB),
69 // Satisfy the linter (we don't support member permissions in non-system roles).
70 MemberPermissions: database.CustomRolePermissions{},
71 IsSystem: false,
72 })
73 if httpapi.Is404Error(err) {
74 httpapi.ResourceNotFound(rw)
75 return
76 }
77 if err != nil {
78 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
79 Message: "Failed to update role permissions",
80 Detail: err.Error(),
81 })
82 return
83 }
84 aReq.New = inserted
85
86 httpapi.Write(ctx, rw, http.StatusOK, db2sdk.Role(inserted))
87}
88
89// putOrgRoles will allow updating a custom organization role
90//

Callers

nothing calls this directly

Calls 13

OrganizationParamFunction · 0.92
InitRequestFunction · 0.92
ReadFunction · 0.92
ListFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
RoleFunction · 0.92
ContextMethod · 0.65
InsertCustomRoleMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected