Skip to content

Commit acc9a97

Browse files
committed
Refactor user-related methods to include realm handling
- Updated user-related service methods to support realm IDs with default fallbacks. - Adjusted API endpoint URLs and test cases to reflect added realm-specific logic. - Minor formatting fixes and trailing comma additions for better consistency.
1 parent e9dfbf4 commit acc9a97

File tree

13 files changed

+195
-158
lines changed

13 files changed

+195
-158
lines changed

projects/netgrif-components-core/src/lib/authentication/models/user.transformer.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ describe('UserTransformer', () => {
1010
const userTransformer = new UserTransformer();
1111
expect(userTransformer.transform({
1212
id: 'string',
13+
username: 'string',
14+
realmId: 'string',
1315
email: 'string',
1416
name: 'string',
17+
firstName: 'string',
1518
surname: 'string',
19+
lastName: 'string',
1620
fullName: 'string string',
1721
groups: [],
1822
authorities: [{authority: 'ADMIN'}],
1923
processRoles: [{stringId: 'string', description: 'desc', name: 'name', importId: 'importId'}],
2024
nextGroups: [],
21-
_links: {}
25+
_links: {},
2226
}).fullName).toEqual('string string');
2327
});
2428

projects/netgrif-components-core/src/lib/authorization/permission/permission.service.spec.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ describe('PermissionService', () => {
2727
NoopAnimationsModule,
2828
BrowserAnimationsModule,
2929
TranslateLibModule,
30-
HttpClientTestingModule
30+
HttpClientTestingModule,
3131
],
3232
providers: [
3333
PermissionService,
3434
{provide: UserService, useClass: MockUserService},
3535
],
3636
declarations: [],
37-
schemas: [NO_ERRORS_SCHEMA]
37+
schemas: [NO_ERRORS_SCHEMA],
3838
});
3939
permissionService = TestBed.inject(PermissionService);
4040
userService = TestBed.inject(UserService);
4141
}));
4242

4343
it('should canAssign be true with role', () => {
4444
(userService as unknown as MockUserService).user =
45-
new User('', '', '', '', [], [{stringId: 'assignRole', name: '', importId: ''}]);
45+
new User('', '', '', '', '', '', [], [{stringId: 'assignRole', name: '', importId: ''}]);
4646
const task = {
4747
caseId: 'string',
4848
transitionId: 'string',
@@ -52,8 +52,8 @@ describe('PermissionService', () => {
5252
user: undefined,
5353
roles: {
5454
assignRole: {
55-
assign: true
56-
}
55+
assign: true,
56+
},
5757
},
5858
startDate: undefined,
5959
finishDate: undefined,
@@ -64,19 +64,19 @@ describe('PermissionService', () => {
6464
layout: {
6565
offset: 0,
6666
cols: undefined,
67-
rows: undefined
67+
rows: undefined,
6868
},
6969
dataGroups: [],
7070
_links: {},
7171
users: {},
72-
userRefs: {}
72+
userRefs: {},
7373
};
7474
expect(permissionService.canAssign(task)).toBeTrue();
7575
});
7676

7777
it('should canAssign be false with role', () => {
7878
(userService as unknown as MockUserService).user =
79-
new User('', '', '', '', [], [{stringId: 'assignRole', name: '', importId: ''}]);
79+
new User('', '', '', '', '', '', [], [{stringId: 'assignRole', name: '', importId: ''}]);
8080
const task = {
8181
caseId: 'string',
8282
transitionId: 'string',
@@ -86,8 +86,8 @@ describe('PermissionService', () => {
8686
user: undefined,
8787
roles: {
8888
assignRole: {
89-
assign: false
90-
}
89+
assign: false,
90+
},
9191
},
9292
startDate: undefined,
9393
finishDate: undefined,
@@ -98,19 +98,19 @@ describe('PermissionService', () => {
9898
layout: {
9999
offset: 0,
100100
cols: undefined,
101-
rows: undefined
101+
rows: undefined,
102102
},
103103
dataGroups: [],
104104
_links: {},
105105
users: {},
106-
userRefs: {}
106+
userRefs: {},
107107
};
108108
expect(permissionService.canAssign(task)).toBeFalse();
109109
});
110110

111111
it('should canAssign be true with userRef', () => {
112112
(userService as unknown as MockUserService).user =
113-
new User('user123', '', '', '', [], [{stringId: 'assignRole', name: '', importId: ''}]);
113+
new User('user123', '', '', '', '', '', [], [{stringId: 'assignRole', name: '', importId: ''}]);
114114
const task = {
115115
caseId: 'string',
116116
transitionId: 'string',
@@ -128,27 +128,27 @@ describe('PermissionService', () => {
128128
layout: {
129129
offset: 0,
130130
cols: undefined,
131-
rows: undefined
131+
rows: undefined,
132132
},
133133
dataGroups: [],
134134
_links: {},
135135
users: {
136136
user123: {
137-
assign: true
138-
}
137+
assign: true,
138+
},
139139
},
140140
userRefs: {
141141
userList1: {
142-
assign: true
143-
}
144-
}
142+
assign: true,
143+
},
144+
},
145145
};
146146
expect(permissionService.canAssign(task)).toBeTrue();
147147
});
148148

149149
it('should canAssign be false with userRef', () => {
150150
(userService as unknown as MockUserService).user =
151-
new User('', '', '', '', [], [{stringId: 'assignRole', name: '', importId: ''}]);
151+
new User('', '', '', '', '', '', [], [{stringId: 'assignRole', name: '', importId: ''}]);
152152
const task = {
153153
caseId: 'string',
154154
transitionId: 'string',
@@ -166,31 +166,31 @@ describe('PermissionService', () => {
166166
layout: {
167167
offset: 0,
168168
cols: undefined,
169-
rows: undefined
169+
rows: undefined,
170170
},
171171
dataGroups: [],
172172
_links: {},
173173
users: {},
174174
userRefs: {
175175
userList1: {
176-
assign: true
177-
}
178-
}
176+
assign: true,
177+
},
178+
},
179179
};
180180
expect(permissionService.canAssign(task)).toBeFalse();
181181
});
182182

183183
it('should canDelete', () => {
184184
(userService as unknown as MockUserService).user =
185-
new User('', '', '', '', [], [{stringId: 'deleteRole', name: '', importId: ''}]);
185+
new User('', '', '', '', '', '', [], [{stringId: 'deleteRole', name: '', importId: ''}]);
186186
const case_ = {
187187
stringId: 'string',
188188
title: 'string',
189189
author: {email: 'email', fullName: 'fullName'},
190190
permissions: {
191191
deleteRole: {
192-
delete: true
193-
}
192+
delete: true,
193+
},
194194
},
195195
users: {},
196196
color: 'color',
@@ -207,29 +207,29 @@ describe('PermissionService', () => {
207207
processIdentifier: 0,
208208
time: 0,
209209
timeSecond: 0,
210-
timestamp: 0
210+
timestamp: 0,
211211
},
212212
immediateData: [
213213
{stringId: 'date', title: 'string', type: 'date', value: [2020, 1, 1, 10, 10]},
214214
{stringId: 'string', title: 'string', type: 'string', value: 'dasdsadsad'},
215215
{stringId: 'dateTime', title: 'string', type: 'dateTime', value: [2020, 1, 1, 10, 10]},
216216
{stringId: 'enum', title: 'string', type: 'enumeration', value: {defaultValue: 'dasd'}},
217-
]
217+
],
218218
};
219219
expect(permissionService.hasCasePermission(case_, PermissionType.DELETE)).toBeTrue();
220220
});
221221

222222
it('should canDelete be false', () => {
223223
(userService as unknown as MockUserService).user =
224-
new User('', '', '', '', [], [{stringId: 'deleteRole', name: '', importId: ''}]);
224+
new User('', '', '', '', '', '', [], [{stringId: 'deleteRole', name: '', importId: ''}]);
225225
const case_ = {
226226
stringId: 'string',
227227
title: 'string',
228228
author: {email: 'email', fullName: 'fullName'},
229229
permissions: {
230230
deleteRole: {
231-
delete: false
232-
}
231+
delete: false,
232+
},
233233
},
234234
users: {},
235235
color: 'color',
@@ -246,14 +246,14 @@ describe('PermissionService', () => {
246246
processIdentifier: 0,
247247
time: 0,
248248
timeSecond: 0,
249-
timestamp: 0
249+
timestamp: 0,
250250
},
251251
immediateData: [
252252
{stringId: 'date', title: 'string', type: 'date', value: [2020, 1, 1, 10, 10]},
253253
{stringId: 'string', title: 'string', type: 'string', value: 'dasdsadsad'},
254254
{stringId: 'dateTime', title: 'string', type: 'dateTime', value: [2020, 1, 1, 10, 10]},
255255
{stringId: 'enum', title: 'string', type: 'enumeration', value: {defaultValue: 'dasd'}},
256-
]
256+
],
257257
};
258258
expect(permissionService.hasCasePermission(case_, PermissionType.DELEGATE)).toBeFalse();
259259
});
@@ -269,13 +269,13 @@ describe('PermissionService', () => {
269269
defaultCaseName: '',
270270
initials: '',
271271
version: '',
272-
title: ''
272+
title: '',
273273
});
274274
net.permissions = {};
275275
expect(permissionService.hasNetPermission(PermissionType.CREATE, net)).toBeFalse();
276276

277277
(userService as unknown as MockUserService).user =
278-
new User('', '', '', '', [], [{stringId: 'role1', name: '', importId: ''}]);
278+
new User('', '', '', '', '', '', [], [{stringId: 'role1', name: '', importId: ''}]);
279279
net.permissions = {role1: {create: true}};
280280
expect(permissionService.hasNetPermission(PermissionType.CREATE, net)).toBeTrue();
281281

@@ -286,7 +286,7 @@ describe('PermissionService', () => {
286286
expect(permissionService.hasNetPermission(PermissionType.CREATE, net)).toBeFalse();
287287

288288
(userService as unknown as MockUserService).user =
289-
new User('', '', '', '', [],
289+
new User('', '', '', '', '', '', [],
290290
[{stringId: 'role1', name: '', importId: ''}, {stringId: 'role2', name: '', importId: ''}]);
291291
net.permissions = {role1: {create: false}, role2: {create: true}};
292292
expect(permissionService.hasNetPermission(PermissionType.CREATE, net)).toBeFalse();
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import {TestBed} from '@angular/core/testing';
22

3-
import {MaterialModule} from "../../material/material.module";
4-
import {CommonModule} from "@angular/common";
5-
import {FlexModule} from "@ngbracket/ngx-layout";
6-
import {BrowserAnimationsModule, NoopAnimationsModule} from "@angular/platform-browser/animations";
7-
import {TranslateLibModule} from "../../translate/translate-lib.module";
8-
import {HttpClientTestingModule} from "@angular/common/http/testing";
9-
import {UserService} from "../../user/services/user.service";
10-
import {MockUserService} from "../../utility/tests/mocks/mock-user.service";
11-
import { Injectable, NO_ERRORS_SCHEMA } from '@angular/core';
12-
import {ConfigurationService} from "../../configuration/configuration.service";
13-
import {TestConfigurationService} from "../../utility/tests/test-config";
14-
import {AuthenticationModule} from "../../authentication/authentication.module";
15-
import {RouterTestingModule} from "@angular/router/testing";
16-
import { RoleGuardService } from './role-guard.service';
17-
import { Access, View } from '../../../commons/schema';
18-
import { User } from '../../user/models/user';
3+
import {MaterialModule} from '../../material/material.module';
4+
import {CommonModule} from '@angular/common';
5+
import {FlexModule} from '@ngbracket/ngx-layout';
6+
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
7+
import {TranslateLibModule} from '../../translate/translate-lib.module';
8+
import {HttpClientTestingModule} from '@angular/common/http/testing';
9+
import {UserService} from '../../user/services/user.service';
10+
import {MockUserService} from '../../utility/tests/mocks/mock-user.service';
11+
import {Injectable, NO_ERRORS_SCHEMA} from '@angular/core';
12+
import {ConfigurationService} from '../../configuration/configuration.service';
13+
import {TestConfigurationService} from '../../utility/tests/test-config';
14+
import {AuthenticationModule} from '../../authentication/authentication.module';
15+
import {RouterTestingModule} from '@angular/router/testing';
16+
import {RoleGuardService} from './role-guard.service';
17+
import {Access, View} from '../../../commons/schema';
18+
import {User} from '../../user/models/user';
1919

2020
describe('RoleGuardService', () => {
2121
let service: RoleGuardService;
@@ -39,7 +39,7 @@ describe('RoleGuardService', () => {
3939
{provide: UserService, useClass: CustomMockUserService},
4040
],
4141
declarations: [],
42-
schemas: [NO_ERRORS_SCHEMA]
42+
schemas: [NO_ERRORS_SCHEMA],
4343
});
4444
service = TestBed.inject(RoleGuardService);
4545
});
@@ -49,22 +49,22 @@ describe('RoleGuardService', () => {
4949
});
5050

5151
it('should access view with role only', () => {
52-
const view = {access: {role: ['test.role_user']} as Access} as View
52+
const view = {access: {role: ['test.role_user']} as Access} as View;
5353
expect(service.canAccessView(view, 'test')).toBeTrue();
5454
});
5555

5656
it('should not access view', () => {
57-
const view = {access: {role: [], bannedRole: []} as Access} as View
57+
const view = {access: {role: [], bannedRole: []} as Access} as View;
5858
expect(service.canAccessView(view, 'test')).toBeFalse();
5959
});
6060

6161
it('should not access view with banned role only', () => {
62-
const view = {access: {bannedRole: ['test.banned_role']} as Access} as View
62+
const view = {access: {bannedRole: ['test.banned_role']} as Access} as View;
6363
expect(service.canAccessView(view, 'test')).toBeFalse();
6464
});
6565

6666
it('should not access view with role and banned role', () => {
67-
const view = {access: {role: ['test.role_user'], bannedRole: ['test.banned_role']} as Access} as View
67+
const view = {access: {role: ['test.role_user'], bannedRole: ['test.banned_role']} as Access} as View;
6868
expect(service.canAccessView(view, 'test')).toBeFalse();
6969
});
7070
});
@@ -73,22 +73,22 @@ describe('RoleGuardService', () => {
7373
class CustomMockUserService extends MockUserService {
7474
constructor() {
7575
super();
76-
this._user = new User('123', 'test@netgrif.com', 'Test', 'User', ['ROLE_USER'], [{
76+
this._user = new User('123', 'test@netgrif.com', 'test@netgrif.com', 'realm', 'Test', 'User', ['ROLE_USER'], [{
7777
stringId: 'role_user',
7878
name: 'role_user',
7979
description: '',
8080
importId: 'role_user',
8181
netImportId: 'test',
8282
netVersion: '1.0.0',
8383
netStringId: 'test',
84-
},{
84+
}, {
8585
stringId: 'banned_role',
8686
name: 'banned_role',
8787
description: '',
8888
importId: 'banned_role',
8989
netImportId: 'test',
9090
netVersion: '1.0.0',
9191
netStringId: 'test',
92-
} ]);
92+
}]);
9393
}
9494
}

0 commit comments

Comments
 (0)