Skip to content

Commit 4fd571b

Browse files
committed
user can issue and revoke for themselves
1 parent 06df4f3 commit 4fd571b

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "management-portal-clr",
3-
"version": "0.6.7",
3+
"version": "0.6.8",
44
"license": "Apache license 2.0",
55
"repository": {
66
"type": "git",

src/app/common/mrnUtil.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
export const getMrnPrefixFromOrgMrn = (orgMrn: string): string => {
1818
const list = orgMrn.split(':');
1919
return list.slice(0,3).join(':')+':entity:'+list.slice(4,6).join(':')+":";
20+
}
21+
22+
export const isUserEditingTheirOwnData = (userMrn: string, mrnInToken: string): boolean => {
23+
return userMrn === mrnInToken;
2024
}

src/app/components/item-view/item-view.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ import { CertificateRevocation } from 'src/app/backend-api/identity-registry';
3232
import { getReasonOptionFromRevocationReason, ReasonOption } from 'src/app/common/certRevokeInfo';
3333
import { migrateVesselAttributes } from 'src/app/common/filterObject';
3434
import { ItemFormComponent } from '../item-form/item-form.component';
35-
import { getMrnPrefixFromOrgMrn } from 'src/app/common/mrnUtil';
35+
import { getMrnPrefixFromOrgMrn, isUserEditingTheirOwnData } from 'src/app/common/mrnUtil';
3636
import { ORG_ADMIN_AT_MIR } from 'src/app/common/variables';
3737
import { ItemTableComponent } from "../item-table/item-table.component";
3838
import { InputGeometryComponent } from '../input-geometry/input-geometry.component';
3939
import { preprocessToShow } from 'src/app/common/itemPreprocessor';
40+
import { loadLang } from 'src/app/common/translateHelper';
4041

4142
@Component({
4243
selector: 'app-item-view',
@@ -109,7 +110,7 @@ export class ItemViewComponent {
109110
private translate: TranslateService,
110111
private notifier: NotifierService,
111112
private fileHelper: FileHelperService,
112-
authService: AuthService,
113+
private authService: AuthService,
113114
@Inject(LOCALE_ID) public locale: string,
114115
) {
115116
for (const reason in CertificateRevocation.RevocationReasonEnum) {
@@ -119,13 +120,25 @@ export class ItemViewComponent {
119120
authService.getOrgMrnFromToken().then((orgMrn) => {
120121
this.orgMrn = orgMrn;
121122
});
123+
124+
loadLang(translate);
122125
}
123126

124127
ngOnChanges(simpleChange: any) {
125128
if (!simpleChange.item || !simpleChange.item.currentValue)
126129
return;
127130

128131
this.item = simpleChange.item.currentValue && simpleChange.item.currentValue;
132+
133+
// give permission when user access their own profile
134+
if (this.itemType === ItemType.User && !this.hasEditPermission) {
135+
this.authService.getUserMrnFromToken().then((userMrn) => {
136+
if (isUserEditingTheirOwnData(this.item.mrn, userMrn)) {
137+
this.hasEditPermission = true;
138+
}
139+
});
140+
}
141+
129142
if (this.item && this.itemType === ItemType.Role) {
130143
this.itemId = this.item.id;
131144
this.setForm();

src/app/pages/detail-view/detail-view.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { catchError, firstValueFrom, Observable, of, throwError } from 'rxjs';
2525
import { AuthService } from 'src/app/auth/auth.service';
2626
import { InstanceDto, XmlDto } from 'src/app/backend-api/service-registry';
2727
import { ItemType, MCPComponentContext } from 'src/app/common/menuType';
28-
import { getMrnPrefixFromOrgMrn } from 'src/app/common/mrnUtil';
28+
import { getMrnPrefixFromOrgMrn, isUserEditingTheirOwnData } from 'src/app/common/mrnUtil';
2929
import { mustIncludePatternValidator } from 'src/app/common/mustIncludeValidator';
3030
import { ItemManagerService } from 'src/app/common/shared/item-manager.service';
3131
import { loadLang } from 'src/app/common/translateHelper';
@@ -103,6 +103,12 @@ export class DetailViewComponent {
103103

104104
this.itemManagerService.fetchMyRolesInOrg(orgMrn).then((roles) => {
105105
this.hasEditPermission = this.authService.hasPermission(this.itemType, roles, mcpContext, orgMrn === this.id);
106+
// user can't edit their own data
107+
// if (this.itemType === ItemType.User && !this.hasEditPermission) {
108+
// this.authService.getUserMrnFromToken().then((mrn) => {
109+
// this.hasEditPermission = isUserEditingTheirOwnData(this.id, mrn);
110+
// });
111+
// }
106112
});
107113
if (this.isEditing) {
108114
this.itemManagerService.fetchAllRolesInOrg(orgMrn).then((roles) => {

src/app/pages/list-view/list-view.component.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { TranslateService } from '@ngx-translate/core';
3030
import { ORG_ADMIN_AT_MIR } from 'src/app/common/variables';
3131
import { ItemManagerService } from 'src/app/common/shared/item-manager.service';
3232
import RoleNameEnum = Role.RoleNameEnum;
33+
import { isUserEditingTheirOwnData } from 'src/app/common/mrnUtil';
3334

3435
@Component({
3536
selector: 'app-list-view',
@@ -52,6 +53,7 @@ export class ListViewComponent {
5253
totalPages = 0;
5354
totalElements = 0;
5455
hasEditPermission = false;
56+
currentUserMrn = '';
5557
apiBase = 'ir';
5658
private readonly notifier: NotifierService;
5759

@@ -81,7 +83,11 @@ export class ListViewComponent {
8183
this.itemManagerService.fetchMyRolesInOrg(this.orgMrn).then((roles: RoleNameEnum[]) => {
8284
this.hasEditPermission = this.authService.hasPermission(this.itemType, roles, mcpContext);
8385
});
84-
86+
87+
// fetch user's own MRN from token and store it
88+
// this.authService.getUserMrnFromToken().then((userMrn) => {
89+
// this.currentUserMrn = userMrn;
90+
// });
8591
});
8692
});
8793
}
@@ -185,11 +191,17 @@ export class ListViewComponent {
185191
}
186192
this.moveToEditPage(selectedItem);
187193
}
188-
if (!this.hasEditPermission) {
189-
this.notifier.notify('error', this.translate.instant('error.resource.permissionError'));
190-
return ;
191-
}
192-
this.moveToEditPage(selectedItem);
194+
// user can edit for their own profile
195+
// else if (this.itemType === ItemType.User && isUserEditingTheirOwnData(selectedItem.mrn, this.currentUserMrn)) {
196+
// this.moveToEditPage(selectedItem);
197+
// }
198+
else {
199+
if (!this.hasEditPermission) {
200+
this.notifier.notify('error', this.translate.instant('error.resource.permissionError'));
201+
return ;
202+
}
203+
this.moveToEditPage(selectedItem);
204+
}
193205
}
194206

195207
view = (selectedItem: any) => {

0 commit comments

Comments
 (0)