Skip to content

Commit

Permalink
feat(iam): remove reference to role creation in main user creation
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Feb 17, 2025
1 parent b04df5b commit 0fbc711
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,43 +112,6 @@
<vcl-hint-error error="required">This field is required.</vcl-hint-error>
</vcl-form-control-group>

<!-- Roles -->
@if (options.uniqueRoleAssociationsScopingInstances.length) {
<vcl-form-control-group>
<vcl-label
>Roles ({{
options.uniqueRoleAssociationsScopingInstances.length
}})</vcl-label
>
<vcl-select-list
formControlName="roleAssociations"
selectionMode="multiple"
>
@for (rai of options.uniqueRoleAssociationsScopingInstances; track
rai.role?.id) { @for (instance of rai.scopingInstances; track
instance.instance.id) {
<vcl-select-list-item
[value]="rai.role?.id ?? '' | resolveRoleAssociationKey : instance"
>
{{ rai.role?.name || 'N/A' }} [{{ rai | listScopingInstanceNames }}]
<vcl-sub-label>{{ rai.role?.description || 'N/A' }}</vcl-sub-label>
</vcl-select-list-item>
} }
</vcl-select-list>
</vcl-form-control-group>
}

<div class="row justify-end">
<button
vcl-button
class="transparent"
type="button"
(click)="addRoleAssociations()"
>
Assign Roles
</button>
</div>

<!-- Buttons -->
<div class="loose-button-group">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import {
import { FormGroup, NgForm } from '@angular/forms';

import { ModeType } from '@console-core/graphql';
import {
ILocale,
IRoleAssociationScopingInstance,
ITimezone,
IUser,
} from '@console-core/types';
import { ILocale, ITimezone, IUser } from '@console-core/types';

@Component({
selector: 'app-user-creation-form',
Expand All @@ -28,12 +23,10 @@ export class UserCreationFormComponent {
user: IUser | null;
locales: ILocale[];
timezones: ITimezone[];
uniqueRoleAssociationsScopingInstances: IRoleAssociationScopingInstance[];
} = {
user: null,
locales: [],
timezones: [],
uniqueRoleAssociationsScopingInstances: [],
};

@Input()
Expand All @@ -48,10 +41,6 @@ export class UserCreationFormComponent {
@ViewChild('form')
form!: NgForm;

addRoleAssociations() {
this.addRole.next();
}

onReset(): void {
// TODO this.editForm.form.resetForm(this.schema);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {
ChangeDetectionStrategy,
Component,
OnDestroy,
OnInit,
} from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy } from '@angular/core';
import { combineLatest, map } from 'rxjs';

import { LayerRef, LayerService } from '@vcl/ng-vcl';
import { IamFacade } from '@console-core/state';

import { IamFacade, UserService } from '@console-core/state';

import { IamRoleAssociationModalComponent } from './role-association-modal.component';
import { JssFormService } from './services';

@Component({
Expand All @@ -22,7 +14,6 @@ import { JssFormService } from './services';
[schema]="vm.userCreationForm"
[options]="vm.options"
[update]="create"
(addRole)="handleActionEvent()"
/>
</div>
</ng-container>
Expand All @@ -31,18 +22,15 @@ import { JssFormService } from './services';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class IamCreateComponent implements OnInit, OnDestroy {
roleAssociationLayer!: LayerRef;

export class IamCreateComponent implements OnDestroy {
create = this.iamFacade.create;

readonly vm$ = combineLatest([
this.iamFacade.selected$,
this.jssFormService.userForm$,
this.jssFormService.formOptions$,
this.jssFormService.roleAssociationsSchema$,
]).pipe(
map(([_, form, options, roleAssociationsSchema]) => {
map(([_, form, options]) => {
return {
userCreationForm: form,
options: {
Expand All @@ -52,60 +40,16 @@ export class IamCreateComponent implements OnInit, OnDestroy {
uniqueRoleAssociationsScopingInstances:
options.roleAssociationsScopingInstances,
},
roleAssociationsSchema,
};
})
);

constructor(
private readonly layerService: LayerService,
private readonly iamFacade: IamFacade,
private readonly userService: UserService,
private readonly jssFormService: JssFormService
) {}

ngOnInit(): void {
this.roleAssociationLayer = this.layerService.create(
IamRoleAssociationModalComponent,
{
closeOnBackdropClick: false,
closeOnEscape: false,
}
);
}

ngOnDestroy(): void {
this.jssFormService.destroy();
this.iamFacade.setTempRoleAssociations([]);
}

handleActionEvent(): void {
this.roleAssociationLayer
.open({
data: {
title: 'Assign Roles',
},
})
.subscribe(
(result: {
value: {
role: 'administrator-r-id';
instanceType: 'urn:restorecommerce:acs:model:organization.Organization';
instanceId: 'nfuse-root-organization';
}[];
}) => {
if (result) {
const roleAssociations = result.value.map((ra) => ({
...this.userService.createRoleAssociation(
ra.role,
ra.instanceType,
ra.instanceId
),
}));

this.iamFacade.setTempRoleAssociations(roleAssociations);
}
}
);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
OnDestroy,
TemplateRef,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { combineLatest } from 'rxjs';
import { map, tap } from 'rxjs/operators';

import { JssFormComponent, LayerRef, LayerService } from '@vcl/ng-vcl';

import { ROUTER } from '@console-core/config';
import {
IamFacade,
RouterFacade,
UserService,
filterEmptyAndNullishAndUndefined,
} from '@console-core/state';

Expand All @@ -33,49 +22,15 @@ import { JssFormService } from './services';
[options]="vm.options"
[update]="update"
[id]="vm.id"
(addRole)="handleActionEvent()"
/>
</div>
<ng-template
#tplLayerRef
let-title="title"
>
<vcl-panel-dialog
[showCloseButton]="true"
(close)="tplLayer.close()"
class="panel-dialog"
>
<vcl-panel-title>{{ title }}</vcl-panel-title>
<div class="row">
<div class="flex-12">
<vcl-jss-form
autocomplete="off"
ngDefaultControl
#roleAssociationsForm="vclJssForm"
[schema]="vm.roleAssociationsSchema"
(formAction)="onAction($event)"
(formSubmit)="onSubmit()"
/>
</div>
</div>
</vcl-panel-dialog>
</ng-template>
</ng-container>
`,
providers: [JssFormService],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class IamEditComponent implements OnDestroy, AfterViewInit {
@ViewChild('roleAssociationsForm')
roleAssociationsForm!: JssFormComponent;

@ViewChild('tplLayerRef')
tplLayerRef!: TemplateRef<HTMLElement>;

tplLayer!: LayerRef;

export class IamEditComponent implements OnDestroy {
update = this.iamFacade.update;

readonly vm$ = combineLatest({
Expand Down Expand Up @@ -103,67 +58,19 @@ export class IamEditComponent implements OnDestroy, AfterViewInit {
user: options.user,
locales: options.locales,
timezones: options.timezones,
uniqueRoleAssociationsScopingInstances:
options.roleAssociationsScopingInstances,
};
})
),
roleAssociationsSchema: this.jssFormService.roleAssociationsSchema$,
});

constructor(
private readonly router: Router,
private readonly layerService: LayerService,
private readonly viewContainerRef: ViewContainerRef,
private readonly routerFacade: RouterFacade,
private readonly iamFacade: IamFacade,
private readonly userService: UserService,
private readonly jssFormService: JssFormService
) {}

ngAfterViewInit(): void {
this.tplLayer = this.layerService.createTemplateLayer(
this.tplLayerRef,
this.viewContainerRef
);
}

ngOnDestroy(): void {
this.jssFormService.destroy();
this.iamFacade.setTempRoleAssociations([]);
}

handleActionEvent(): void {
this.tplLayer.open({ data: { title: 'Assign Roles' } });
}

onAction(action: string): void {
if ('close' === action) {
this.tplLayer.close();
}
}

onSubmit(): void {
if (
this.roleAssociationsForm?.form.invalid ||
this.roleAssociationsForm?.form.pristine
) {
return;
}

this.tplLayer.close();

const roleAssociations =
this.roleAssociationsForm.form?.value.roleAssociationsArray.map(
(ra: { role: string; instanceType: string; instanceId: string }) => ({
...this.userService.createRoleAssociation(
ra.role,
ra.instanceType,
ra.instanceId
),
})
);

this.iamFacade.setTempRoleAssociations(roleAssociations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ export class JssFormService {
roleAssociationsScopingInstances: [],
})
);
roleAssociationsSchema$ = new BehaviorSubject<VCLFormFieldSchemaRoot>(
this.buildRoleAssociationsSchema({
roles: [],
organizations: [],
users: [],
})
);

private destroy$ = new Subject<void>();

Expand Down Expand Up @@ -139,13 +132,6 @@ export class JssFormService {
roleAssociationsScopingInstances,
})
);
this.roleAssociationsSchema$.next(
this.buildRoleAssociationsSchema({
roles,
organizations,
users,
})
);
}
);
}
Expand All @@ -159,15 +145,11 @@ export class JssFormService {

destroy() {
this.userForm$.complete();
this.roleAssociationsSchema$.complete();
this.destroy$.next();
this.destroy$.complete();
}

createUserForm({
user,
roleAssociationsScopingInstances,
}: IUserSchemaOptions): FormGroup {
createUserForm({ user }: IUserSchemaOptions): FormGroup {
const form = this.fb.group({
firstName: [user?.firstName, [Validators.required]],
lastName: [user?.lastName || '', [Validators.required]],
Expand All @@ -190,13 +172,6 @@ export class JssFormService {
: {}),
localeId: [user?.localeId || '', [Validators.required]],
timezoneId: [user?.timezoneId || '', [Validators.required]],
roleAssociations: [
...roleAssociationsScopingInstances.flatMap((rai) =>
rai.scopingInstances?.map(
(inst) => `${rai.role?.id}|${inst.instanceType}|${inst.instance.id}`
)
),
],
});

const inviteControl = form.get('invite');
Expand Down

0 comments on commit 0fbc711

Please sign in to comment.