Skip to content
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

Fix issue where default add/remove setting in change role by username was incorrect #4334

Merged
merged 3 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="usernames" *ngIf="!(blocked$ | async)">
<div class="usernames__addRemove">
<mat-radio-group [value]="(canRemove$ | async) && (canAdd$ | async)" (change)="setIsRemove($event)">
<mat-radio-button [disabled]="!(canAdd$ | async)" [value]="true">
<mat-radio-group [value]="currentValue" (change)="setIsRemove($event)">
<mat-radio-button [disabled]="!(canAdd$ | async)" [value]="false">
Add Roles{{(canAdd$ | async) ? '' : ' (Disabled via feature flag)'}}
</mat-radio-button>
<mat-radio-button [disabled]="!(canRemove$ | async)" [value]="false">
<mat-radio-button [disabled]="!(canRemove$ | async)" [value]="true">
Remove Roles{{(canRemove$ | async) ? '' : ' (Disabled via feature flag)'}}</mat-radio-button>
</mat-radio-group>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { MatRadioChange } from '@angular/material/radio';
import { Store } from '@ngrx/store';
import { BehaviorSubject, combineLatest, Observable, of } from 'rxjs';
import { first, map, publishReplay, refCount, startWith, switchMap, take, tap } from 'rxjs/operators';
import { first, map, publishReplay, refCount, startWith, switchMap } from 'rxjs/operators';

import { PermissionConfig, PermissionTypes } from '../../../../../../../core/src/core/current-user-permissions.config';
import { CurrentUserPermissionsService } from '../../../../../../../core/src/core/current-user-permissions.service';
Expand Down Expand Up @@ -50,6 +50,7 @@ export class ManageUsersSetUsernamesComponent implements OnInit {
public canAdd$: Observable<boolean>;
public canRemove$: Observable<boolean>;
public blocked$: Observable<boolean>;
public currentValue: boolean;

public stackedActionConfig: StackedInputActionConfig = {
isEmailInput: false,
Expand All @@ -71,37 +72,29 @@ export class ManageUsersSetUsernamesComponent implements OnInit {
const ffRemovePermConfig = new PermissionConfig(PermissionTypes.FEATURE_FLAG, CFFeatureFlagTypes.unset_roles_by_username);
this.canAdd$ = waitForCFPermissions(store, activeRouteCfOrgSpace.cfGuid).pipe(
switchMap(() => userPerms.can(ffSetPermConfig, activeRouteCfOrgSpace.cfGuid)),
tap(canAdd => {
if (!canAdd) {
this.setIsRemove({ source: null, value: false });
}
}),
first(),
publishReplay(1),
refCount()
);
this.canRemove$ = waitForCFPermissions(store, activeRouteCfOrgSpace.cfGuid).pipe(
switchMap(() => userPerms.can(ffRemovePermConfig, activeRouteCfOrgSpace.cfGuid)),
tap(canRemove => {
if (!canRemove) {
this.setIsRemove({ source: null, value: true });
}
}),
first(),
publishReplay(1),
refCount()
);

this.blocked$ = combineLatest([this.canAdd$, this.canRemove$]).pipe(
map(([canAdd, canRemove]) => {
if (canAdd && canRemove) {
// Set initial value to be add
this.setIsRemove({ source: null, value: true });
}
return false;
}),
const canAddRemove = combineLatest([this.canAdd$, this.canRemove$]);

// Set starting value of add/remove radio button
canAddRemove.pipe(first()).subscribe(([canAdd]) => this.setIsRemove({ source: null, value: !canAdd }))

// Block content until we know the add/remove state
this.blocked$ = canAddRemove.pipe(
map(() => false),
first(),
startWith(true),
take(2)
publishReplay(1),
refCount(),
);

}
Expand All @@ -125,8 +118,8 @@ export class ManageUsersSetUsernamesComponent implements OnInit {
}

setIsRemove(event: MatRadioChange) {
// Note - event.value is flipped
this.store.dispatch(new UsersRolesSetIsRemove(!event.value));
this.store.dispatch(new UsersRolesSetIsRemove(event.value));
this.currentValue = event.value;
}

onNext: StepOnNextFunction = () => {
Expand Down