Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/abpframework/abp into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet-erim committed Jul 18, 2020
2 parents c31ecc3 + fb78229 commit 4f698ed
Showing 1 changed file with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ApplicationConfiguration, ConfigState, GetAppConfiguration } from '@abp/ng.core';
import { Component, EventEmitter, Input, Output, Renderer2, TrackByFunction } from '@angular/core';
import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { finalize, map, pluck, take, tap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { finalize, map, pluck, switchMap, take, tap } from 'rxjs/operators';
import { GetPermissions, UpdatePermissions } from '../actions/permission-management.actions';
import { PermissionManagement } from '../models/permission-management';
import { PermissionManagementState } from '../states/permission-management.state';
Expand Down Expand Up @@ -203,7 +204,6 @@ export class PermissionManagementComponent
}

submit() {
this.modalBusy = true;
const unchangedPermissions = getPermissions(
this.store.selectSnapshot(PermissionManagementState.getPermissionGroups),
);
Expand All @@ -217,23 +217,29 @@ export class PermissionManagementComponent
)
.map(({ name, isGranted }) => ({ name, isGranted }));

if (changedPermissions.length) {
this.store
.dispatch(
new UpdatePermissions({
providerKey: this.providerKey,
providerName: this.providerName,
permissions: changedPermissions,
}),
)
.pipe(finalize(() => (this.modalBusy = false)))
.subscribe(() => {
this.visible = false;
});
} else {
this.modalBusy = false;
if (!changedPermissions.length) {
this.visible = false;
return;
}

this.modalBusy = true;
this.store
.dispatch(
new UpdatePermissions({
providerKey: this.providerKey,
providerName: this.providerName,
permissions: changedPermissions,
}),
)
.pipe(
switchMap(() =>
this.shouldFetchAppConfig() ? this.store.dispatch(GetAppConfiguration) : of(null),
),
finalize(() => (this.modalBusy = false)),
)
.subscribe(() => {
this.visible = false;
});
}

openModal() {
Expand Down Expand Up @@ -268,6 +274,18 @@ export class PermissionManagementComponent
0,
);
}

shouldFetchAppConfig() {
const currentUser = this.store.selectSnapshot(
ConfigState.getOne('currentUser'),
) as ApplicationConfiguration.CurrentUser;

if (this.providerName === 'R') return currentUser.roles.some(role => role === this.providerKey);

if (this.providerName === 'U') return currentUser.id === this.providerKey;

return false;
}
}

function findMargin(
Expand Down

0 comments on commit 4f698ed

Please sign in to comment.