Skip to content

chore: remove UpsertCustomRole in favor of Insert + Update #14217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make gen
  • Loading branch information
Emyrk committed Aug 13, 2024
commit e53fabdf2b58d66890179abd0742ac5d1e96f0ee
14 changes: 13 additions & 1 deletion cli/organizationroles.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *RootCmd) editOrganizationRole(orgContext *OrganizationContext) *serpent
return err
}

createNewRole := false
createNewRole := true
var customRole codersdk.Role
if jsonInput {
// JSON Upload mode
Expand All @@ -175,6 +175,18 @@ func (r *RootCmd) editOrganizationRole(orgContext *OrganizationContext) *serpent
}
return xerrors.Errorf("json input does not appear to be a valid role")
}

existingRoles, err := client.ListOrganizationRoles(ctx, org.ID)
if err != nil {
return xerrors.Errorf("listing existing roles: %w", err)
}
for _, existingRole := range existingRoles {
if strings.EqualFold(customRole.Name, existingRole.Name) {
// Editing an existing role
createNewRole = false
break
}
}
} else {
if len(inv.Args) == 0 {
return xerrors.Errorf("missing role name argument, usage: \"coder organizations roles edit <role_name>\"")
Expand Down
16 changes: 8 additions & 8 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

157 changes: 157 additions & 0 deletions docs/reference/api/members.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion enterprise/coderd/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (api *API) postOrgRoles(rw http.ResponseWriter, r *http.Request) {
// @Param request body codersdk.CustomRoleRequest true "Upsert role request"
// @Tags Members
// @Success 200 {array} codersdk.Role
// @Router /organizations/{organization}/members/roles [patch]
// @Router /organizations/{organization}/members/roles [put]
func (api *API) putOrgRoles(rw http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
Expand Down