@abp/ng.permission-management 7.2.2 → 7.3.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -2
- package/{esm2020 → esm2022}/abp-ng.permission-management.mjs +4 -4
- package/{esm2020 → esm2022}/lib/components/index.mjs +1 -1
- package/esm2022/lib/components/permission-management.component.mjs +257 -0
- package/{esm2020 → esm2022}/lib/enums/components.mjs +1 -1
- package/{esm2020 → esm2022}/lib/models/index.mjs +1 -1
- package/{esm2020 → esm2022}/lib/models/permission-management.mjs +1 -1
- package/esm2022/lib/permission-management.module.mjs +20 -0
- package/{esm2020 → esm2022}/proxy/abp-ng.permission-management-proxy.mjs +4 -4
- package/{esm2020 → esm2022}/proxy/lib/index.mjs +1 -1
- package/{esm2020 → esm2022}/proxy/lib/proxy/index.mjs +2 -2
- package/{esm2020 → esm2022}/proxy/lib/proxy/models.mjs +1 -1
- package/esm2022/proxy/lib/proxy/permissions.service.mjs +31 -0
- package/{esm2020 → esm2022}/proxy/public-api.mjs +1 -1
- package/{esm2020 → esm2022}/public-api.mjs +4 -4
- package/{fesm2015 → fesm2022}/abp-ng.permission-management-proxy.mjs +27 -27
- package/{fesm2015 → fesm2022}/abp-ng.permission-management-proxy.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/abp-ng.permission-management.mjs +257 -257
- package/{fesm2020 → fesm2022}/abp-ng.permission-management.mjs.map +1 -1
- package/index.d.ts +5 -5
- package/lib/components/index.d.ts +1 -1
- package/lib/components/permission-management.component.d.ts +54 -54
- package/lib/enums/components.d.ts +3 -3
- package/lib/models/index.d.ts +1 -1
- package/lib/models/permission-management.d.ts +16 -16
- package/lib/permission-management.module.d.ts +9 -9
- package/package.json +24 -18
- package/proxy/index.d.ts +5 -5
- package/proxy/lib/index.d.ts +1 -1
- package/proxy/lib/proxy/index.d.ts +2 -2
- package/proxy/lib/proxy/models.d.ts +28 -28
- package/proxy/lib/proxy/permissions.service.d.ts +12 -12
- package/proxy/public-api.d.ts +1 -1
- package/public-api.d.ts +4 -4
- package/esm2020/lib/components/permission-management.component.mjs +0 -256
- package/esm2020/lib/permission-management.module.mjs +0 -19
- package/esm2020/proxy/lib/proxy/permissions.service.mjs +0 -30
- package/fesm2015/abp-ng.permission-management.mjs +0 -274
- package/fesm2015/abp-ng.permission-management.mjs.map +0 -1
- package/fesm2020/abp-ng.permission-management-proxy.mjs +0 -36
- package/fesm2020/abp-ng.permission-management-proxy.mjs.map +0 -1
- package/proxy/src/lib/proxy/README.md +0 -17
|
@@ -10,267 +10,267 @@ import * as i4 from '@angular/forms';
|
|
|
10
10
|
import * as i5 from '@abp/ng.theme.shared';
|
|
11
11
|
import { ThemeSharedModule } from '@abp/ng.theme.shared';
|
|
12
12
|
|
|
13
|
-
class PermissionManagementComponent {
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this._visible
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
getChecked(name) {
|
|
54
|
-
return (this.permissions.find(per => per.name === name) || { isGranted: false }).isGranted;
|
|
55
|
-
}
|
|
56
|
-
setSelectedGroup(group) {
|
|
57
|
-
this.selectedGroup = group;
|
|
58
|
-
if (!this.selectedGroup) {
|
|
59
|
-
this.selectedGroupPermissions = [];
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const margin = `margin-${document.body.dir === 'rtl' ? 'right' : 'left'}.px`;
|
|
63
|
-
const permissions = (this.data.groups.find(group => group.name === this.selectedGroup?.name) || {}).permissions ||
|
|
64
|
-
[];
|
|
65
|
-
this.selectedGroupPermissions = permissions.map(permission => ({
|
|
66
|
-
...permission,
|
|
67
|
-
style: { [margin]: findMargin(permissions, permission) },
|
|
68
|
-
isGranted: (this.permissions.find(per => per.name === permission.name) || {}).isGranted,
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
setDisabled(permissions) {
|
|
72
|
-
if (permissions.length) {
|
|
73
|
-
this.disableSelectAllTab = permissions.every(permission => permission.isGranted &&
|
|
74
|
-
permission.grantedProviders?.every(p => p.providerName !== this.providerName));
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
this.disableSelectAllTab = false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
isGrantedByOtherProviderName(grantedProviders) {
|
|
81
|
-
if (grantedProviders.length) {
|
|
82
|
-
return grantedProviders.findIndex(p => p.providerName !== this.providerName) > -1;
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
onClickCheckbox(clickedPermission) {
|
|
87
|
-
if (clickedPermission.isGranted &&
|
|
88
|
-
this.isGrantedByOtherProviderName(clickedPermission.grantedProviders))
|
|
89
|
-
return;
|
|
90
|
-
setTimeout(() => {
|
|
91
|
-
this.permissions = this.permissions.map(per => {
|
|
92
|
-
if (clickedPermission.name === per.name) {
|
|
93
|
-
return { ...per, isGranted: !per.isGranted };
|
|
94
|
-
}
|
|
95
|
-
else if (clickedPermission.name === per.parentName && clickedPermission.isGranted) {
|
|
96
|
-
return { ...per, isGranted: false };
|
|
97
|
-
}
|
|
98
|
-
else if (clickedPermission.parentName === per.name && !clickedPermission.isGranted) {
|
|
99
|
-
return { ...per, isGranted: true };
|
|
100
|
-
}
|
|
101
|
-
return per;
|
|
102
|
-
});
|
|
103
|
-
this.setTabCheckboxState();
|
|
104
|
-
this.setGrantCheckboxState();
|
|
105
|
-
}, 0);
|
|
106
|
-
}
|
|
107
|
-
setTabCheckboxState() {
|
|
108
|
-
const selectableGroupPermissions = this.selectedGroupPermissions.filter(per => per.grantedProviders.every(p => p.providerName === this.providerName));
|
|
109
|
-
const selectedPermissions = selectableGroupPermissions.filter(per => per.isGranted);
|
|
110
|
-
const element = document.querySelector('#select-all-in-this-tabs');
|
|
111
|
-
if (selectedPermissions.length === selectableGroupPermissions.length) {
|
|
112
|
-
element.indeterminate = false;
|
|
113
|
-
this.selectThisTab = true;
|
|
114
|
-
}
|
|
115
|
-
else if (selectedPermissions.length === 0) {
|
|
116
|
-
element.indeterminate = false;
|
|
117
|
-
this.selectThisTab = false;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
element.indeterminate = true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
setGrantCheckboxState() {
|
|
124
|
-
const selectablePermissions = this.permissions.filter(per => per.grantedProviders.every(p => p.providerName === this.providerName));
|
|
125
|
-
const selectedAllPermissions = selectablePermissions.filter(per => per.isGranted);
|
|
126
|
-
const checkboxElement = document.querySelector('#select-all-in-all-tabs');
|
|
127
|
-
if (selectedAllPermissions.length === selectablePermissions.length) {
|
|
128
|
-
checkboxElement.indeterminate = false;
|
|
129
|
-
this.selectAllTab = true;
|
|
130
|
-
}
|
|
131
|
-
else if (selectedAllPermissions.length === 0) {
|
|
132
|
-
checkboxElement.indeterminate = false;
|
|
133
|
-
this.selectAllTab = false;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
checkboxElement.indeterminate = true;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
onClickSelectThisTab() {
|
|
140
|
-
this.selectedGroupPermissions.forEach(permission => {
|
|
141
|
-
if (permission.isGranted && this.isGrantedByOtherProviderName(permission.grantedProviders))
|
|
142
|
-
return;
|
|
143
|
-
const index = this.permissions.findIndex(per => per.name === permission.name);
|
|
144
|
-
this.permissions = [
|
|
145
|
-
...this.permissions.slice(0, index),
|
|
146
|
-
{ ...this.permissions[index], isGranted: !this.selectThisTab },
|
|
147
|
-
...this.permissions.slice(index + 1),
|
|
148
|
-
];
|
|
149
|
-
});
|
|
150
|
-
this.setGrantCheckboxState();
|
|
151
|
-
}
|
|
152
|
-
onClickSelectAll() {
|
|
153
|
-
this.permissions = this.permissions.map(permission => ({
|
|
154
|
-
...permission,
|
|
155
|
-
isGranted: this.isGrantedByOtherProviderName(permission.grantedProviders) || !this.selectAllTab,
|
|
156
|
-
}));
|
|
157
|
-
if (!this.disableSelectAllTab) {
|
|
158
|
-
this.selectThisTab = !this.selectAllTab;
|
|
159
|
-
this.setTabCheckboxState();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
onChangeGroup(group) {
|
|
163
|
-
this.setDisabled(group.permissions);
|
|
164
|
-
this.setSelectedGroup(group);
|
|
165
|
-
this.setTabCheckboxState();
|
|
166
|
-
}
|
|
167
|
-
submit() {
|
|
168
|
-
const unchangedPermissions = getPermissions(this.data.groups);
|
|
169
|
-
const changedPermissions = this.permissions
|
|
170
|
-
.filter(per => (unchangedPermissions.find(unchanged => unchanged.name === per.name) || {}).isGranted ===
|
|
171
|
-
per.isGranted
|
|
172
|
-
? false
|
|
173
|
-
: true)
|
|
174
|
-
.map(({ name, isGranted }) => ({ name, isGranted }));
|
|
175
|
-
if (!changedPermissions.length) {
|
|
176
|
-
this.visible = false;
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
this.modalBusy = true;
|
|
180
|
-
this.service
|
|
181
|
-
.update(this.providerName, this.providerKey, { permissions: changedPermissions })
|
|
182
|
-
.pipe(switchMap(() => this.shouldFetchAppConfig() ? this.configState.refreshAppState() : of(null)), finalize(() => (this.modalBusy = false)))
|
|
183
|
-
.subscribe(() => {
|
|
184
|
-
this.visible = false;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
openModal() {
|
|
188
|
-
if (!this.providerKey || !this.providerName) {
|
|
189
|
-
throw new Error('Provider Key and Provider Name are required.');
|
|
190
|
-
}
|
|
191
|
-
return this.service.get(this.providerName, this.providerKey).pipe(tap((permissionRes) => {
|
|
192
|
-
this.data = permissionRes;
|
|
193
|
-
this.permissions = getPermissions(permissionRes.groups);
|
|
194
|
-
this.setSelectedGroup(permissionRes.groups[0]);
|
|
195
|
-
this.disabledSelectAllInAllTabs = this.permissions.every(per => per.isGranted &&
|
|
196
|
-
per.grantedProviders.every(provider => provider.providerName !== this.providerName));
|
|
197
|
-
}));
|
|
198
|
-
}
|
|
199
|
-
initModal() {
|
|
200
|
-
// TODO: Refactor
|
|
201
|
-
setTimeout(() => {
|
|
202
|
-
this.setDisabled(this.selectedGroup?.permissions || []);
|
|
203
|
-
this.setTabCheckboxState();
|
|
204
|
-
this.setGrantCheckboxState();
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
getAssignedCount(groupName) {
|
|
208
|
-
return this.permissions.reduce((acc, val) => (val.groupName === groupName && val.isGranted ? acc + 1 : acc), 0);
|
|
209
|
-
}
|
|
210
|
-
shouldFetchAppConfig() {
|
|
211
|
-
const currentUser = this.configState.getOne('currentUser');
|
|
212
|
-
if (this.providerName === 'R')
|
|
213
|
-
return currentUser.roles.some(role => role === this.providerKey);
|
|
214
|
-
if (this.providerName === 'U')
|
|
215
|
-
return currentUser.id === this.providerKey;
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
222
|
-
type: Component,
|
|
223
|
-
args: [{ selector: 'abp-permission-management', exportAs: 'abpPermissionManagement', template: "<abp-modal [(visible)]=\"visible\" [busy]=\"modalBusy\" [options]=\"{ size: 'lg' }\">\r\n <ng-container *ngIf=\"data.entityDisplayName || entityDisplayName\">\r\n <ng-template #abpHeader>\r\n <h4>\r\n {{ 'AbpPermissionManagement::Permissions' | abpLocalization }} -\r\n {{ entityDisplayName || data.entityDisplayName }}\r\n </h4>\r\n </ng-template>\r\n <ng-template #abpBody>\r\n <div class=\"row\">\r\n <div class=\"col-md-4\">\r\n <div class=\"form-check mb-2\">\r\n <input\r\n #selectAllInAllTabsRef\r\n type=\"checkbox\"\r\n id=\"select-all-in-all-tabs\"\r\n name=\"select-all-in-all-tabs\"\r\n class=\"form-check-input\"\r\n [(ngModel)]=\"selectAllTab\"\r\n (click)=\"onClickSelectAll()\"\r\n [disabled]=\"disabledSelectAllInAllTabs\"\r\n />\r\n <label class=\"form-check-label\" for=\"select-all-in-all-tabs\">{{\r\n 'AbpPermissionManagement::SelectAllInAllTabs' | abpLocalization\r\n }}</label>\r\n </div>\r\n\r\n <hr class=\"mt-2 mb-2\" />\r\n <div class=\"overflow-auto\">\r\n <ul class=\"nav nav-pills flex-column\">\r\n <li *ngFor=\"let group of data.groups; trackBy: trackByFn\" class=\"nav-item\">\r\n <a\r\n *ngIf=\"{ assignedCount: getAssignedCount(group.name) } as count\"\r\n class=\"nav-link pointer\"\r\n [class.active]=\"selectedGroup?.name === group?.name\"\r\n (click)=\"onChangeGroup(group)\"\r\n (select)=\"setDisabled(group.permissions)\"\r\n >\r\n <div [class.font-weight-bold]=\"count.assignedCount\">\r\n {{ group?.displayName }}\r\n <span *ngIf=\"count.assignedCount > 0\">({{ count.assignedCount }})</span>\r\n </div>\r\n </a>\r\n </li>\r\n </ul>\r\n </div>\r\n </div>\r\n <div class=\"col-md-8 overflow-auto\">\r\n <div class=\"ps-1\">\r\n <div class=\"form-check mb-2\">\r\n <input\r\n #selectAllInThisTabsRef\r\n type=\"checkbox\"\r\n id=\"select-all-in-this-tabs\"\r\n name=\"select-all-in-this-tabs\"\r\n class=\"form-check-input\"\r\n [(ngModel)]=\"selectThisTab\"\r\n [disabled]=\"disableSelectAllTab\"\r\n (click)=\"onClickSelectThisTab()\"\r\n />\r\n <label class=\"form-check-label\" for=\"select-all-in-this-tabs\">{{\r\n 'AbpPermissionManagement::SelectAllInThisTab' | abpLocalization\r\n }}</label>\r\n </div>\r\n <hr class=\"my-2\" />\r\n <div\r\n *ngFor=\"let permission of selectedGroupPermissions; let i = index; trackBy: trackByFn\"\r\n [ngStyle]=\"permission.style\"\r\n class=\"form-check mb-2\"\r\n >\r\n <input\r\n #permissionCheckbox\r\n type=\"checkbox\"\r\n [checked]=\"getChecked(permission.name)\"\r\n [value]=\"getChecked(permission.name)\"\r\n [attr.id]=\"permission.name\"\r\n class=\"form-check-input\"\r\n [disabled]=\"isGrantedByOtherProviderName(permission.grantedProviders)\"\r\n (click)=\"onClickCheckbox(permission, permissionCheckbox.value)\"\r\n />\r\n <label class=\"form-check-label\" [attr.for]=\"permission.name\"\r\n >{{ permission.displayName }}\r\n <ng-container *ngIf=\"!hideBadges\">\r\n <span\r\n *ngFor=\"let provider of permission.grantedProviders\"\r\n class=\"badge bg-light text-dark\"\r\n >{{ provider.providerName }}: {{ provider.providerKey }}</span\r\n >\r\n </ng-container>\r\n </label>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-template>\r\n <ng-template #abpFooter>\r\n <button type=\"button\" class=\"btn btn-secondary\" abpClose>\r\n {{ 'AbpIdentity::Cancel' | abpLocalization }}\r\n </button>\r\n <abp-button iconClass=\"fa fa-check\" (click)=\"submit()\">{{\r\n 'AbpIdentity::Save' | abpLocalization\r\n }}</abp-button>\r\n </ng-template>\r\n </ng-container>\r\n</abp-modal>\r\n", styles: [".overflow-scroll{max-height:70vh;overflow-y:scroll}\n"] }]
|
|
224
|
-
}], ctorParameters: function () { return [{ type: i1.PermissionsService }, { type: i2.ConfigStateService }]; }, propDecorators: { providerName: [{
|
|
225
|
-
type: Input
|
|
226
|
-
}], providerKey: [{
|
|
227
|
-
type: Input
|
|
228
|
-
}], hideBadges: [{
|
|
229
|
-
type: Input
|
|
230
|
-
}], entityDisplayName: [{
|
|
231
|
-
type: Input
|
|
232
|
-
}], visible: [{
|
|
233
|
-
type: Input
|
|
234
|
-
}], visibleChange: [{
|
|
235
|
-
type: Output
|
|
236
|
-
}], selectAllInThisTabsRef: [{
|
|
237
|
-
type: ViewChildren,
|
|
238
|
-
args: ['selectAllInThisTabsRef']
|
|
239
|
-
}], selectAllInAllTabsRef: [{
|
|
240
|
-
type: ViewChildren,
|
|
241
|
-
args: ['selectAllInAllTabsRef']
|
|
242
|
-
}] } });
|
|
243
|
-
function findMargin(permissions, permission) {
|
|
244
|
-
const parentPermission = permissions.find(per => per.name === permission.parentName);
|
|
245
|
-
if (parentPermission && parentPermission.parentName) {
|
|
246
|
-
let margin = 20;
|
|
247
|
-
return (margin += findMargin(permissions, parentPermission));
|
|
248
|
-
}
|
|
249
|
-
return parentPermission ? 20 : 0;
|
|
250
|
-
}
|
|
251
|
-
function getPermissions(groups) {
|
|
252
|
-
return groups.reduce((acc, val) => [
|
|
253
|
-
...acc,
|
|
254
|
-
...val.permissions.map(p => ({ ...p, groupName: val.name || '' })),
|
|
255
|
-
], []);
|
|
13
|
+
class PermissionManagementComponent {
|
|
14
|
+
get visible() {
|
|
15
|
+
return this._visible;
|
|
16
|
+
}
|
|
17
|
+
set visible(value) {
|
|
18
|
+
if (value === this._visible)
|
|
19
|
+
return;
|
|
20
|
+
if (value) {
|
|
21
|
+
this.openModal().subscribe(() => {
|
|
22
|
+
this._visible = true;
|
|
23
|
+
this.visibleChange.emit(true);
|
|
24
|
+
concat(this.selectAllInAllTabsRef.changes, this.selectAllInThisTabsRef.changes)
|
|
25
|
+
.pipe(take(1))
|
|
26
|
+
.subscribe(() => {
|
|
27
|
+
this.initModal();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.setSelectedGroup(null);
|
|
33
|
+
this._visible = false;
|
|
34
|
+
this.visibleChange.emit(false);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
constructor(service, configState) {
|
|
38
|
+
this.service = service;
|
|
39
|
+
this.configState = configState;
|
|
40
|
+
this.hideBadges = false;
|
|
41
|
+
this._visible = false;
|
|
42
|
+
this.visibleChange = new EventEmitter();
|
|
43
|
+
this.data = { groups: [], entityDisplayName: '' };
|
|
44
|
+
this.permissions = [];
|
|
45
|
+
this.selectThisTab = false;
|
|
46
|
+
this.selectAllTab = false;
|
|
47
|
+
this.disableSelectAllTab = false;
|
|
48
|
+
this.disabledSelectAllInAllTabs = false;
|
|
49
|
+
this.modalBusy = false;
|
|
50
|
+
this.selectedGroupPermissions = [];
|
|
51
|
+
this.trackByFn = (_, item) => item.name;
|
|
52
|
+
}
|
|
53
|
+
getChecked(name) {
|
|
54
|
+
return (this.permissions.find(per => per.name === name) || { isGranted: false }).isGranted;
|
|
55
|
+
}
|
|
56
|
+
setSelectedGroup(group) {
|
|
57
|
+
this.selectedGroup = group;
|
|
58
|
+
if (!this.selectedGroup) {
|
|
59
|
+
this.selectedGroupPermissions = [];
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const margin = `margin-${document.body.dir === 'rtl' ? 'right' : 'left'}.px`;
|
|
63
|
+
const permissions = (this.data.groups.find(group => group.name === this.selectedGroup?.name) || {}).permissions ||
|
|
64
|
+
[];
|
|
65
|
+
this.selectedGroupPermissions = permissions.map(permission => ({
|
|
66
|
+
...permission,
|
|
67
|
+
style: { [margin]: findMargin(permissions, permission) },
|
|
68
|
+
isGranted: (this.permissions.find(per => per.name === permission.name) || {}).isGranted,
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
setDisabled(permissions) {
|
|
72
|
+
if (permissions.length) {
|
|
73
|
+
this.disableSelectAllTab = permissions.every(permission => permission.isGranted &&
|
|
74
|
+
permission.grantedProviders?.every(p => p.providerName !== this.providerName));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.disableSelectAllTab = false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
isGrantedByOtherProviderName(grantedProviders) {
|
|
81
|
+
if (grantedProviders.length) {
|
|
82
|
+
return grantedProviders.findIndex(p => p.providerName !== this.providerName) > -1;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
onClickCheckbox(clickedPermission) {
|
|
87
|
+
if (clickedPermission.isGranted &&
|
|
88
|
+
this.isGrantedByOtherProviderName(clickedPermission.grantedProviders))
|
|
89
|
+
return;
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
this.permissions = this.permissions.map(per => {
|
|
92
|
+
if (clickedPermission.name === per.name) {
|
|
93
|
+
return { ...per, isGranted: !per.isGranted };
|
|
94
|
+
}
|
|
95
|
+
else if (clickedPermission.name === per.parentName && clickedPermission.isGranted) {
|
|
96
|
+
return { ...per, isGranted: false };
|
|
97
|
+
}
|
|
98
|
+
else if (clickedPermission.parentName === per.name && !clickedPermission.isGranted) {
|
|
99
|
+
return { ...per, isGranted: true };
|
|
100
|
+
}
|
|
101
|
+
return per;
|
|
102
|
+
});
|
|
103
|
+
this.setTabCheckboxState();
|
|
104
|
+
this.setGrantCheckboxState();
|
|
105
|
+
}, 0);
|
|
106
|
+
}
|
|
107
|
+
setTabCheckboxState() {
|
|
108
|
+
const selectableGroupPermissions = this.selectedGroupPermissions.filter(per => per.grantedProviders.every(p => p.providerName === this.providerName));
|
|
109
|
+
const selectedPermissions = selectableGroupPermissions.filter(per => per.isGranted);
|
|
110
|
+
const element = document.querySelector('#select-all-in-this-tabs');
|
|
111
|
+
if (selectedPermissions.length === selectableGroupPermissions.length) {
|
|
112
|
+
element.indeterminate = false;
|
|
113
|
+
this.selectThisTab = true;
|
|
114
|
+
}
|
|
115
|
+
else if (selectedPermissions.length === 0) {
|
|
116
|
+
element.indeterminate = false;
|
|
117
|
+
this.selectThisTab = false;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
element.indeterminate = true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
setGrantCheckboxState() {
|
|
124
|
+
const selectablePermissions = this.permissions.filter(per => per.grantedProviders.every(p => p.providerName === this.providerName));
|
|
125
|
+
const selectedAllPermissions = selectablePermissions.filter(per => per.isGranted);
|
|
126
|
+
const checkboxElement = document.querySelector('#select-all-in-all-tabs');
|
|
127
|
+
if (selectedAllPermissions.length === selectablePermissions.length) {
|
|
128
|
+
checkboxElement.indeterminate = false;
|
|
129
|
+
this.selectAllTab = true;
|
|
130
|
+
}
|
|
131
|
+
else if (selectedAllPermissions.length === 0) {
|
|
132
|
+
checkboxElement.indeterminate = false;
|
|
133
|
+
this.selectAllTab = false;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
checkboxElement.indeterminate = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
onClickSelectThisTab() {
|
|
140
|
+
this.selectedGroupPermissions.forEach(permission => {
|
|
141
|
+
if (permission.isGranted && this.isGrantedByOtherProviderName(permission.grantedProviders))
|
|
142
|
+
return;
|
|
143
|
+
const index = this.permissions.findIndex(per => per.name === permission.name);
|
|
144
|
+
this.permissions = [
|
|
145
|
+
...this.permissions.slice(0, index),
|
|
146
|
+
{ ...this.permissions[index], isGranted: !this.selectThisTab },
|
|
147
|
+
...this.permissions.slice(index + 1),
|
|
148
|
+
];
|
|
149
|
+
});
|
|
150
|
+
this.setGrantCheckboxState();
|
|
151
|
+
}
|
|
152
|
+
onClickSelectAll() {
|
|
153
|
+
this.permissions = this.permissions.map(permission => ({
|
|
154
|
+
...permission,
|
|
155
|
+
isGranted: this.isGrantedByOtherProviderName(permission.grantedProviders) || !this.selectAllTab,
|
|
156
|
+
}));
|
|
157
|
+
if (!this.disableSelectAllTab) {
|
|
158
|
+
this.selectThisTab = !this.selectAllTab;
|
|
159
|
+
this.setTabCheckboxState();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
onChangeGroup(group) {
|
|
163
|
+
this.setDisabled(group.permissions);
|
|
164
|
+
this.setSelectedGroup(group);
|
|
165
|
+
this.setTabCheckboxState();
|
|
166
|
+
}
|
|
167
|
+
submit() {
|
|
168
|
+
const unchangedPermissions = getPermissions(this.data.groups);
|
|
169
|
+
const changedPermissions = this.permissions
|
|
170
|
+
.filter(per => (unchangedPermissions.find(unchanged => unchanged.name === per.name) || {}).isGranted ===
|
|
171
|
+
per.isGranted
|
|
172
|
+
? false
|
|
173
|
+
: true)
|
|
174
|
+
.map(({ name, isGranted }) => ({ name, isGranted }));
|
|
175
|
+
if (!changedPermissions.length) {
|
|
176
|
+
this.visible = false;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
this.modalBusy = true;
|
|
180
|
+
this.service
|
|
181
|
+
.update(this.providerName, this.providerKey, { permissions: changedPermissions })
|
|
182
|
+
.pipe(switchMap(() => this.shouldFetchAppConfig() ? this.configState.refreshAppState() : of(null)), finalize(() => (this.modalBusy = false)))
|
|
183
|
+
.subscribe(() => {
|
|
184
|
+
this.visible = false;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
openModal() {
|
|
188
|
+
if (!this.providerKey || !this.providerName) {
|
|
189
|
+
throw new Error('Provider Key and Provider Name are required.');
|
|
190
|
+
}
|
|
191
|
+
return this.service.get(this.providerName, this.providerKey).pipe(tap((permissionRes) => {
|
|
192
|
+
this.data = permissionRes;
|
|
193
|
+
this.permissions = getPermissions(permissionRes.groups);
|
|
194
|
+
this.setSelectedGroup(permissionRes.groups[0]);
|
|
195
|
+
this.disabledSelectAllInAllTabs = this.permissions.every(per => per.isGranted &&
|
|
196
|
+
per.grantedProviders.every(provider => provider.providerName !== this.providerName));
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
initModal() {
|
|
200
|
+
// TODO: Refactor
|
|
201
|
+
setTimeout(() => {
|
|
202
|
+
this.setDisabled(this.selectedGroup?.permissions || []);
|
|
203
|
+
this.setTabCheckboxState();
|
|
204
|
+
this.setGrantCheckboxState();
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
getAssignedCount(groupName) {
|
|
208
|
+
return this.permissions.reduce((acc, val) => (val.groupName === groupName && val.isGranted ? acc + 1 : acc), 0);
|
|
209
|
+
}
|
|
210
|
+
shouldFetchAppConfig() {
|
|
211
|
+
const currentUser = this.configState.getOne('currentUser');
|
|
212
|
+
if (this.providerName === 'R')
|
|
213
|
+
return currentUser.roles.some(role => role === this.providerKey);
|
|
214
|
+
if (this.providerName === 'U')
|
|
215
|
+
return currentUser.id === this.providerKey;
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: PermissionManagementComponent, deps: [{ token: i1.PermissionsService }, { token: i2.ConfigStateService }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
219
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.1", type: PermissionManagementComponent, selector: "abp-permission-management", inputs: { providerName: "providerName", providerKey: "providerKey", hideBadges: "hideBadges", entityDisplayName: "entityDisplayName", visible: "visible" }, outputs: { visibleChange: "visibleChange" }, viewQueries: [{ propertyName: "selectAllInThisTabsRef", predicate: ["selectAllInThisTabsRef"], descendants: true }, { propertyName: "selectAllInAllTabsRef", predicate: ["selectAllInAllTabsRef"], descendants: true }], exportAs: ["abpPermissionManagement"], ngImport: i0, template: "<abp-modal [(visible)]=\"visible\" [busy]=\"modalBusy\" [options]=\"{ size: 'lg' }\">\r\n <ng-container *ngIf=\"data.entityDisplayName || entityDisplayName\">\r\n <ng-template #abpHeader>\r\n <h4>\r\n {{ 'AbpPermissionManagement::Permissions' | abpLocalization }} -\r\n {{ entityDisplayName || data.entityDisplayName }}\r\n </h4>\r\n </ng-template>\r\n <ng-template #abpBody>\r\n <div class=\"row\">\r\n <div class=\"col-md-4\">\r\n <div class=\"form-check mb-2\">\r\n <input\r\n #selectAllInAllTabsRef\r\n type=\"checkbox\"\r\n id=\"select-all-in-all-tabs\"\r\n name=\"select-all-in-all-tabs\"\r\n class=\"form-check-input\"\r\n [(ngModel)]=\"selectAllTab\"\r\n (click)=\"onClickSelectAll()\"\r\n [disabled]=\"disabledSelectAllInAllTabs\"\r\n />\r\n <label class=\"form-check-label\" for=\"select-all-in-all-tabs\">{{\r\n 'AbpPermissionManagement::SelectAllInAllTabs' | abpLocalization\r\n }}</label>\r\n </div>\r\n\r\n <hr class=\"mt-2 mb-2\" />\r\n <div class=\"overflow-auto\">\r\n <ul class=\"nav nav-pills flex-column\">\r\n <li *ngFor=\"let group of data.groups; trackBy: trackByFn\" class=\"nav-item\">\r\n <a\r\n *ngIf=\"{ assignedCount: getAssignedCount(group.name) } as count\"\r\n class=\"nav-link pointer\"\r\n [class.active]=\"selectedGroup?.name === group?.name\"\r\n (click)=\"onChangeGroup(group)\"\r\n (select)=\"setDisabled(group.permissions)\"\r\n >\r\n <div [class.font-weight-bold]=\"count.assignedCount\">\r\n {{ group?.displayName }}\r\n <span *ngIf=\"count.assignedCount > 0\">({{ count.assignedCount }})</span>\r\n </div>\r\n </a>\r\n </li>\r\n </ul>\r\n </div>\r\n </div>\r\n <div class=\"col-md-8 overflow-auto\">\r\n <div class=\"ps-1\">\r\n <div class=\"form-check mb-2\">\r\n <input\r\n #selectAllInThisTabsRef\r\n type=\"checkbox\"\r\n id=\"select-all-in-this-tabs\"\r\n name=\"select-all-in-this-tabs\"\r\n class=\"form-check-input\"\r\n [(ngModel)]=\"selectThisTab\"\r\n [disabled]=\"disableSelectAllTab\"\r\n (click)=\"onClickSelectThisTab()\"\r\n />\r\n <label class=\"form-check-label\" for=\"select-all-in-this-tabs\">{{\r\n 'AbpPermissionManagement::SelectAllInThisTab' | abpLocalization\r\n }}</label>\r\n </div>\r\n <hr class=\"my-2\" />\r\n <div\r\n *ngFor=\"let permission of selectedGroupPermissions; let i = index; trackBy: trackByFn\"\r\n [ngStyle]=\"permission.style\"\r\n class=\"form-check mb-2\"\r\n >\r\n <input\r\n #permissionCheckbox\r\n type=\"checkbox\"\r\n [checked]=\"getChecked(permission.name)\"\r\n [value]=\"getChecked(permission.name)\"\r\n [attr.id]=\"permission.name\"\r\n class=\"form-check-input\"\r\n [disabled]=\"isGrantedByOtherProviderName(permission.grantedProviders)\"\r\n (click)=\"onClickCheckbox(permission, permissionCheckbox.value)\"\r\n />\r\n <label class=\"form-check-label\" [attr.for]=\"permission.name\"\r\n >{{ permission.displayName }}\r\n <ng-container *ngIf=\"!hideBadges\">\r\n <span\r\n *ngFor=\"let provider of permission.grantedProviders\"\r\n class=\"badge bg-light text-dark\"\r\n >{{ provider.providerName }}: {{ provider.providerKey }}</span\r\n >\r\n </ng-container>\r\n </label>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-template>\r\n <ng-template #abpFooter>\r\n <button type=\"button\" class=\"btn btn-secondary\" abpClose>\r\n {{ 'AbpIdentity::Cancel' | abpLocalization }}\r\n </button>\r\n <abp-button iconClass=\"fa fa-check\" (click)=\"submit()\">{{\r\n 'AbpIdentity::Save' | abpLocalization\r\n }}</abp-button>\r\n </ng-template>\r\n </ng-container>\r\n</abp-modal>\r\n", styles: [".overflow-scroll{max-height:70vh;overflow-y:scroll}\n"], dependencies: [{ kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: i4.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i5.ButtonComponent, selector: "abp-button", inputs: ["buttonId", "buttonClass", "buttonType", "formName", "iconClass", "loading", "disabled", "attributes"], outputs: ["click", "focus", "blur", "abpClick", "abpFocus", "abpBlur"] }, { kind: "component", type: i5.ModalComponent, selector: "abp-modal", inputs: ["visible", "busy", "options", "suppressUnsavedChangesWarning"], outputs: ["visibleChange", "init", "appear", "disappear"] }, { kind: "directive", type: i5.ModalCloseDirective, selector: "[abpClose]" }, { kind: "pipe", type: i2.LocalizationPipe, name: "abpLocalization" }] }); }
|
|
220
|
+
}
|
|
221
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: PermissionManagementComponent, decorators: [{
|
|
222
|
+
type: Component,
|
|
223
|
+
args: [{ selector: 'abp-permission-management', exportAs: 'abpPermissionManagement', template: "<abp-modal [(visible)]=\"visible\" [busy]=\"modalBusy\" [options]=\"{ size: 'lg' }\">\r\n <ng-container *ngIf=\"data.entityDisplayName || entityDisplayName\">\r\n <ng-template #abpHeader>\r\n <h4>\r\n {{ 'AbpPermissionManagement::Permissions' | abpLocalization }} -\r\n {{ entityDisplayName || data.entityDisplayName }}\r\n </h4>\r\n </ng-template>\r\n <ng-template #abpBody>\r\n <div class=\"row\">\r\n <div class=\"col-md-4\">\r\n <div class=\"form-check mb-2\">\r\n <input\r\n #selectAllInAllTabsRef\r\n type=\"checkbox\"\r\n id=\"select-all-in-all-tabs\"\r\n name=\"select-all-in-all-tabs\"\r\n class=\"form-check-input\"\r\n [(ngModel)]=\"selectAllTab\"\r\n (click)=\"onClickSelectAll()\"\r\n [disabled]=\"disabledSelectAllInAllTabs\"\r\n />\r\n <label class=\"form-check-label\" for=\"select-all-in-all-tabs\">{{\r\n 'AbpPermissionManagement::SelectAllInAllTabs' | abpLocalization\r\n }}</label>\r\n </div>\r\n\r\n <hr class=\"mt-2 mb-2\" />\r\n <div class=\"overflow-auto\">\r\n <ul class=\"nav nav-pills flex-column\">\r\n <li *ngFor=\"let group of data.groups; trackBy: trackByFn\" class=\"nav-item\">\r\n <a\r\n *ngIf=\"{ assignedCount: getAssignedCount(group.name) } as count\"\r\n class=\"nav-link pointer\"\r\n [class.active]=\"selectedGroup?.name === group?.name\"\r\n (click)=\"onChangeGroup(group)\"\r\n (select)=\"setDisabled(group.permissions)\"\r\n >\r\n <div [class.font-weight-bold]=\"count.assignedCount\">\r\n {{ group?.displayName }}\r\n <span *ngIf=\"count.assignedCount > 0\">({{ count.assignedCount }})</span>\r\n </div>\r\n </a>\r\n </li>\r\n </ul>\r\n </div>\r\n </div>\r\n <div class=\"col-md-8 overflow-auto\">\r\n <div class=\"ps-1\">\r\n <div class=\"form-check mb-2\">\r\n <input\r\n #selectAllInThisTabsRef\r\n type=\"checkbox\"\r\n id=\"select-all-in-this-tabs\"\r\n name=\"select-all-in-this-tabs\"\r\n class=\"form-check-input\"\r\n [(ngModel)]=\"selectThisTab\"\r\n [disabled]=\"disableSelectAllTab\"\r\n (click)=\"onClickSelectThisTab()\"\r\n />\r\n <label class=\"form-check-label\" for=\"select-all-in-this-tabs\">{{\r\n 'AbpPermissionManagement::SelectAllInThisTab' | abpLocalization\r\n }}</label>\r\n </div>\r\n <hr class=\"my-2\" />\r\n <div\r\n *ngFor=\"let permission of selectedGroupPermissions; let i = index; trackBy: trackByFn\"\r\n [ngStyle]=\"permission.style\"\r\n class=\"form-check mb-2\"\r\n >\r\n <input\r\n #permissionCheckbox\r\n type=\"checkbox\"\r\n [checked]=\"getChecked(permission.name)\"\r\n [value]=\"getChecked(permission.name)\"\r\n [attr.id]=\"permission.name\"\r\n class=\"form-check-input\"\r\n [disabled]=\"isGrantedByOtherProviderName(permission.grantedProviders)\"\r\n (click)=\"onClickCheckbox(permission, permissionCheckbox.value)\"\r\n />\r\n <label class=\"form-check-label\" [attr.for]=\"permission.name\"\r\n >{{ permission.displayName }}\r\n <ng-container *ngIf=\"!hideBadges\">\r\n <span\r\n *ngFor=\"let provider of permission.grantedProviders\"\r\n class=\"badge bg-light text-dark\"\r\n >{{ provider.providerName }}: {{ provider.providerKey }}</span\r\n >\r\n </ng-container>\r\n </label>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </ng-template>\r\n <ng-template #abpFooter>\r\n <button type=\"button\" class=\"btn btn-secondary\" abpClose>\r\n {{ 'AbpIdentity::Cancel' | abpLocalization }}\r\n </button>\r\n <abp-button iconClass=\"fa fa-check\" (click)=\"submit()\">{{\r\n 'AbpIdentity::Save' | abpLocalization\r\n }}</abp-button>\r\n </ng-template>\r\n </ng-container>\r\n</abp-modal>\r\n", styles: [".overflow-scroll{max-height:70vh;overflow-y:scroll}\n"] }]
|
|
224
|
+
}], ctorParameters: function () { return [{ type: i1.PermissionsService }, { type: i2.ConfigStateService }]; }, propDecorators: { providerName: [{
|
|
225
|
+
type: Input
|
|
226
|
+
}], providerKey: [{
|
|
227
|
+
type: Input
|
|
228
|
+
}], hideBadges: [{
|
|
229
|
+
type: Input
|
|
230
|
+
}], entityDisplayName: [{
|
|
231
|
+
type: Input
|
|
232
|
+
}], visible: [{
|
|
233
|
+
type: Input
|
|
234
|
+
}], visibleChange: [{
|
|
235
|
+
type: Output
|
|
236
|
+
}], selectAllInThisTabsRef: [{
|
|
237
|
+
type: ViewChildren,
|
|
238
|
+
args: ['selectAllInThisTabsRef']
|
|
239
|
+
}], selectAllInAllTabsRef: [{
|
|
240
|
+
type: ViewChildren,
|
|
241
|
+
args: ['selectAllInAllTabsRef']
|
|
242
|
+
}] } });
|
|
243
|
+
function findMargin(permissions, permission) {
|
|
244
|
+
const parentPermission = permissions.find(per => per.name === permission.parentName);
|
|
245
|
+
if (parentPermission && parentPermission.parentName) {
|
|
246
|
+
let margin = 20;
|
|
247
|
+
return (margin += findMargin(permissions, parentPermission));
|
|
248
|
+
}
|
|
249
|
+
return parentPermission ? 20 : 0;
|
|
250
|
+
}
|
|
251
|
+
function getPermissions(groups) {
|
|
252
|
+
return groups.reduce((acc, val) => [
|
|
253
|
+
...acc,
|
|
254
|
+
...val.permissions.map(p => ({ ...p, groupName: val.name || '' })),
|
|
255
|
+
], []);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
class PermissionManagementModule {
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
264
|
-
type: NgModule,
|
|
265
|
-
args: [{
|
|
266
|
-
declarations: [PermissionManagementComponent],
|
|
267
|
-
imports: [CoreModule, ThemeSharedModule],
|
|
268
|
-
exports: [PermissionManagementComponent],
|
|
269
|
-
}]
|
|
258
|
+
class PermissionManagementModule {
|
|
259
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: PermissionManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
260
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.1", ngImport: i0, type: PermissionManagementModule, declarations: [PermissionManagementComponent], imports: [CoreModule, ThemeSharedModule], exports: [PermissionManagementComponent] }); }
|
|
261
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: PermissionManagementModule, imports: [CoreModule, ThemeSharedModule] }); }
|
|
262
|
+
}
|
|
263
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: PermissionManagementModule, decorators: [{
|
|
264
|
+
type: NgModule,
|
|
265
|
+
args: [{
|
|
266
|
+
declarations: [PermissionManagementComponent],
|
|
267
|
+
imports: [CoreModule, ThemeSharedModule],
|
|
268
|
+
exports: [PermissionManagementComponent],
|
|
269
|
+
}]
|
|
270
270
|
}] });
|
|
271
271
|
|
|
272
|
-
/**
|
|
273
|
-
* Generated bundle index. Do not edit.
|
|
272
|
+
/**
|
|
273
|
+
* Generated bundle index. Do not edit.
|
|
274
274
|
*/
|
|
275
275
|
|
|
276
276
|
export { PermissionManagementComponent, PermissionManagementModule };
|