Adapt screen to check code owners to this being a self service now With change I25cff9f08 we opened the Check Code Owner REST endpoint for normal users. Adapt the screen to check code owners to this now: * Remove the note saying that administrator permissions are needed. * Separate options that everyone can use from admin only options * Disable the input fields for admin only options if the current user is not an admin Bug: Google b/345161989 Change-Id: I638ddce265afe916c3874c8432d992cb620689d8 Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/web/gr-check-code-owner.ts b/web/gr-check-code-owner.ts index cba304f..7214527 100644 --- a/web/gr-check-code-owner.ts +++ b/web/gr-check-code-owner.ts
@@ -25,6 +25,12 @@ } } +// https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#capability-info +export interface AccountCapabilityInfo { + administrateServer: boolean; + 'code-owners-checkCodeOwner': boolean; +} + @customElement('gr-check-code-owner') export class GrCheckCodeOwner extends LitElement { @query('#projectInput') @@ -54,6 +60,9 @@ @state() isChecking = false; + @state() + hasAdminPermissions = false; + static override get styles() { return [ window.Gerrit.styles.font as CSSResult, @@ -84,14 +93,7 @@ Checks the code ownership of a user for a path in a branch, see <a href="${window.CANONICAL_PATH || ''}/plugins/code-owners/Documentation/rest-api.html#check-code-owner" target="_blank">documentation<a/>. </p> - <p> - Requires that the caller has the - <a href="${window.CANONICAL_PATH || ''}/plugins/code-owners/Documentation/rest-api.html#checkCodeOwner" target="_blank">Check Code Owner</a> - or the - <a href="${window.CANONICAL_PATH || ''}/Documentation/access-control.html#capability_administrateServer" target="_blank">Administrate Server</a> - global capability. - </p> - <p>All fields, except the 'Calling User' field, are required.</p> + <p>Required fields:</p> <fieldset> <section> <span class="title"> @@ -162,6 +164,13 @@ /> </span> </section> + </fieldset> + <p>Admin options (usage requires having the + <a href="${window.CANONICAL_PATH || ''}/plugins/code-owners/Documentation/rest-api.html#checkCodeOwner" target="_blank">Check Code Owner</a> + or the + <a href="${window.CANONICAL_PATH || ''}/Documentation/access-control.html#capability_administrateServer" target="_blank">Administrate Server</a> + global capability): + <fieldset> <section> <span class="title"> <gr-tooltip-content @@ -175,6 +184,7 @@ <input id="userInput" type="text" + ?disabled=${!this.hasAdminPermissions} @input=${this.validateData} /> </span> @@ -205,6 +215,22 @@ `; } + override connectedCallback() { + super.connectedCallback(); + this.checkAdminPermissions(); + } + + private async checkAdminPermissions() { + await this.plugin + .restApi() + .get<AccountCapabilityInfo>('/accounts/self/capabilities/') + .then(capabilities => { + this.hasAdminPermissions = capabilities && + (capabilities['administrateServer'] || + capabilities['code-owners-checkCodeOwner']); + }); + } + private validateData() { this.dataValid = this.validateHasValue(this.projectInput.value) &&