Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdcc5023

Browse files
committed
fixup cli
1 parent031da75 commitdcc5023

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

‎cli/organizationroles.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (r *RootCmd) editOrganizationRole(orgContext *OrganizationContext) *serpent
153153
returnerr
154154
}
155155

156+
createNewRole:=false
156157
varcustomRole codersdk.Role
157158
ifjsonInput {
158159
// JSON Upload mode
@@ -179,12 +180,13 @@ func (r *RootCmd) editOrganizationRole(orgContext *OrganizationContext) *serpent
179180
returnxerrors.Errorf("missing role name argument, usage:\"coder organizations roles edit <role_name>\"")
180181
}
181182

182-
interactiveRole,err:=interactiveOrgRoleEdit(inv,org.ID,client)
183+
interactiveRole,newRole,err:=interactiveOrgRoleEdit(inv,org.ID,client)
183184
iferr!=nil {
184185
returnxerrors.Errorf("editing role: %w",err)
185186
}
186187

187188
customRole=*interactiveRole
189+
createNewRole=newRole
188190

189191
preview:=fmt.Sprintf("permissions: %d site, %d org, %d user",
190192
len(customRole.SitePermissions),len(customRole.OrganizationPermissions),len(customRole.UserPermissions))
@@ -203,7 +205,12 @@ func (r *RootCmd) editOrganizationRole(orgContext *OrganizationContext) *serpent
203205
// Do not actually post
204206
updated=customRole
205207
}else {
206-
updated,err=client.PatchOrganizationRole(ctx,customRole)
208+
switchcreateNewRole {
209+
casetrue:
210+
updated,err=client.CreateOrganizationRole(ctx,customRole)
211+
default:
212+
updated,err=client.UpdateOrganizationRole(ctx,customRole)
213+
}
207214
iferr!=nil {
208215
returnxerrors.Errorf("patch role: %w",err)
209216
}
@@ -223,11 +230,12 @@ func (r *RootCmd) editOrganizationRole(orgContext *OrganizationContext) *serpent
223230
returncmd
224231
}
225232

226-
funcinteractiveOrgRoleEdit(inv*serpent.Invocation,orgID uuid.UUID,client*codersdk.Client) (*codersdk.Role,error) {
233+
funcinteractiveOrgRoleEdit(inv*serpent.Invocation,orgID uuid.UUID,client*codersdk.Client) (*codersdk.Role,bool,error) {
234+
newRole:=false
227235
ctx:=inv.Context()
228236
roles,err:=client.ListOrganizationRoles(ctx,orgID)
229237
iferr!=nil {
230-
returnnil,xerrors.Errorf("listing roles: %w",err)
238+
returnnil,newRole,xerrors.Errorf("listing roles: %w",err)
231239
}
232240

233241
// Make sure the role actually exists first
@@ -246,22 +254,23 @@ func interactiveOrgRoleEdit(inv *serpent.Invocation, orgID uuid.UUID, client *co
246254
IsConfirm:true,
247255
})
248256
iferr!=nil {
249-
returnnil,xerrors.Errorf("abort: %w",err)
257+
returnnil,newRole,xerrors.Errorf("abort: %w",err)
250258
}
251259

252260
originalRole.Role= codersdk.Role{
253261
Name:inv.Args[0],
254262
OrganizationID:orgID.String(),
255263
}
264+
newRole=true
256265
}
257266

258267
// Some checks since interactive mode is limited in what it currently sees
259268
iflen(originalRole.SitePermissions)>0 {
260-
returnnil,xerrors.Errorf("unable to edit role in interactive mode, it contains site wide permissions")
269+
returnnil,newRole,xerrors.Errorf("unable to edit role in interactive mode, it contains site wide permissions")
261270
}
262271

263272
iflen(originalRole.UserPermissions)>0 {
264-
returnnil,xerrors.Errorf("unable to edit role in interactive mode, it contains user permissions")
273+
returnnil,newRole,xerrors.Errorf("unable to edit role in interactive mode, it contains user permissions")
265274
}
266275

267276
role:=&originalRole.Role
@@ -283,13 +292,13 @@ customRoleLoop:
283292
Options:append(permissionPreviews(role,allowedResources),done,abort),
284293
})
285294
iferr!=nil {
286-
returnrole,xerrors.Errorf("selecting resource: %w",err)
295+
returnrole,newRole,xerrors.Errorf("selecting resource: %w",err)
287296
}
288297
switchselected {
289298
casedone:
290299
break customRoleLoop
291300
caseabort:
292-
returnrole,xerrors.Errorf("edit role %q aborted",role.Name)
301+
returnrole,newRole,xerrors.Errorf("edit role %q aborted",role.Name)
293302
default:
294303
strs:=strings.Split(selected,"::")
295304
resource:=strings.TrimSpace(strs[0])
@@ -300,7 +309,7 @@ customRoleLoop:
300309
Defaults:defaultActions(role,resource),
301310
})
302311
iferr!=nil {
303-
returnrole,xerrors.Errorf("selecting actions for resource %q: %w",resource,err)
312+
returnrole,newRole,xerrors.Errorf("selecting actions for resource %q: %w",resource,err)
304313
}
305314
applyOrgResourceActions(role,resource,actions)
306315
// back to resources!
@@ -309,7 +318,7 @@ customRoleLoop:
309318
// This println is required because the prompt ends us on the same line as some text.
310319
_,_=fmt.Println()
311320

312-
returnrole,nil
321+
returnrole,newRole,nil
313322
}
314323

315324
funcapplyOrgResourceActions(role*codersdk.Role,resourcestring,actions []string) {

‎site/src/api/typesGenerated.ts

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp