Repository navigation
feat(api-client): change the access (client scopes) of an existing API client #4611
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../features/api-client/api-client-scope-selection/api-client-scope-selection.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| @if (scopes.hasValue()) { | ||
| @let offeredScopes = scopes.value(); | ||
| <mat-selection-list | ||
| [formControl]="control()" | ||
| aria-label="Access" | ||
| i18n-aria-label | ||
| > | ||
| @for (scope of offeredScopes; track scope.name) { | ||
| <mat-list-option [value]="scope.name"> | ||
| <span matListItemTitle>{{ scope.label }}</span> | ||
| </mat-list-option> | ||
| } | ||
| </mat-selection-list> | ||
| } @else if (scopes.isLoading()) { | ||
| <mat-progress-bar mode="indeterminate"></mat-progress-bar> | ||
| } @else if (loadingError(); as loadingError) { | ||
| <p class="color-error" role="alert">{{ loadingError }}</p> | ||
| } | ||
|
|
||
| @if (singleSignOnSelected()) { | ||
| <app-hint-box type="warning" class="margin-top-small"> | ||
| <span i18n> | ||
| With single sign-on, the external system can sign in to this system as any | ||
| of its users, including administrators, without their password. Only give | ||
| this access to systems you fully trust. | ||
| </span> | ||
| </app-hint-box> | ||
| } |
62 changes: 62 additions & 0 deletions
62
...pp/features/api-client/api-client-scope-selection/api-client-scope-selection.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { | ||
| ChangeDetectionStrategy, | ||
| Component, | ||
| computed, | ||
| inject, | ||
| input, | ||
| resource, | ||
| } from "@angular/core"; | ||
| import { toObservable, toSignal } from "@angular/core/rxjs-interop"; | ||
| import { FormControl, ReactiveFormsModule } from "@angular/forms"; | ||
| import { MatListModule } from "@angular/material/list"; | ||
| import { MatProgressBarModule } from "@angular/material/progress-bar"; | ||
| import { startWith, switchMap } from "rxjs"; | ||
| import { HintBoxComponent } from "#src/app/core/common-components/hint-box/hint-box.component"; | ||
| import { ApiClientService, errorMessageOf } from "../api-client.service"; | ||
| import { getScopeLabel, SINGLE_SIGN_ON_SCOPE } from "../api-client-scopes"; | ||
|
|
||
| /** | ||
| * Select the access (client scopes) of an API client, from those the backend offers. | ||
| */ | ||
| @Component({ | ||
| selector: "app-api-client-scope-selection", | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| imports: [ | ||
| MatListModule, | ||
| MatProgressBarModule, | ||
| ReactiveFormsModule, | ||
| HintBoxComponent, | ||
| ], | ||
| templateUrl: "./api-client-scope-selection.component.html", | ||
| }) | ||
| export class ApiClientScopeSelectionComponent { | ||
| private readonly apiClientService = inject(ApiClientService); | ||
|
|
||
| /** the names of the selected client scopes */ | ||
| readonly control = input.required<FormControl<string[]>>(); | ||
|
|
||
| /** the client scopes the API client can be given */ | ||
| readonly scopes = resource({ | ||
| loader: async () => | ||
| (await this.apiClientService.getScopes()).map((scope) => ({ | ||
| name: scope.name, | ||
| label: getScopeLabel(scope.name, scope.description), | ||
| })), | ||
| }); | ||
| readonly loadingError = computed(() => | ||
| this.scopes.error() ? errorMessageOf(this.scopes.error()) : undefined, | ||
| ); | ||
|
|
||
| private readonly selectedScopes = toSignal( | ||
| toObservable(this.control).pipe( | ||
| switchMap((control) => | ||
| control.valueChanges.pipe(startWith(control.value)), | ||
| ), | ||
| ), | ||
| { initialValue: [] as string[] }, | ||
| ); | ||
|
|
||
| readonly singleSignOnSelected = computed(() => | ||
| this.selectedScopes().includes(SINGLE_SIGN_ON_SCOPE), | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...res/api-client/edit-api-client-scopes-dialog/edit-api-client-scopes-dialog.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <h2 mat-dialog-title i18n>Access of "{{ apiClient.name }}"</h2> | ||
| <app-dialog-close mat-dialog-close></app-dialog-close> | ||
|
|
||
| <mat-dialog-content> | ||
| <p i18n> | ||
| Choose what the external system can access through the API. It keeps its | ||
| current credentials. Access tokens it already got keep their previous access | ||
| until they expire. | ||
| </p> | ||
|
|
||
| <app-api-client-scope-selection | ||
| [control]="scopes" | ||
| ></app-api-client-scope-selection> | ||
|
|
||
| @if (error(); as error) { | ||
| <p class="color-error" role="alert">{{ error }}</p> | ||
| } | ||
| </mat-dialog-content> | ||
|
|
||
| <mat-dialog-actions> | ||
| <button | ||
| mat-raised-button | ||
| color="accent" | ||
| type="button" | ||
| (click)="save()" | ||
| [disabled]="scopes.invalid || scopes.pristine || saving()" | ||
| i18n="Button label" | ||
| > | ||
| Save | ||
| </button> | ||
| <button mat-button mat-dialog-close i18n="Button label">Cancel</button> | ||
| </mat-dialog-actions> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.