Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class PanelsComponent implements OnInit {
stringId: null,
petriNetId: null,
permissions: {},
users: {}
actors: {}
};
this.workflow = {
stringId: 'ID',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {UserService} from '../../user/services/user.service';
import {Case} from '../../resources/interface/case';
import {PetriNetReferenceWithPermissions} from '../../process/petri-net-reference-with-permissions';
import {Permissions, PermissionType, UserPermissions} from '../../process/permissions';
import {User} from "../../user/models/user";

@Injectable({
providedIn: 'root'
Expand All @@ -31,7 +32,7 @@ export class PermissionService {
}

const rolePermValue = this.checkRolePerms(case_.permissions, permission);
const userPermValue = this.checkUserPerms(case_.users, permission);
const userPermValue = this.checkUserPerms(case_.actors, permission);
return this.resolvePermissions(rolePermValue, userPermValue);
}

Expand Down Expand Up @@ -108,14 +109,37 @@ export class PermissionService {
public checkUserPerms(users: UserPermissions, permission): boolean | undefined {
let userPermValue: boolean;
if (!!users) {
const loggedUserId = this._userService.user.getSelfOrImpersonated().id;
Object.keys(users).forEach(user => {
if (user === loggedUserId && users[user][permission] !== undefined) {
userPermValue = userPermValue === undefined ?
users[user][permission] : userPermValue && users[user][permission];
const loggedUser: User = this._userService.user.getSelfOrImpersonated();
const processedActorIds: Array<string> = [];
Object.keys(users).forEach(actorId => {
if (userPermValue === false || processedActorIds.includes(actorId)
|| actorId !== loggedUser.id && !loggedUser.nextGroups?.includes(actorId)) {
return;
}
let currentUserPermission: boolean = this.getPermissionByUserOrGroup(users, permission, loggedUser);
if (currentUserPermission !== undefined) {
userPermValue = userPermValue === undefined ? currentUserPermission : userPermValue && currentUserPermission;
}
loggedUser.nextGroups !== undefined ? processedActorIds.push(actorId, ...loggedUser.nextGroups) : processedActorIds.push(actorId);
});
}
return userPermValue;
}

protected getPermissionByUserOrGroup(permissions: UserPermissions, permission, loggedUser: User): boolean | undefined {
let userPermValue: boolean;
if (permissions[loggedUser.id] !== undefined) {
userPermValue = permissions[loggedUser.id][permission];
}
if (loggedUser.nextGroups === undefined || loggedUser.nextGroups.length === 0 || userPermValue === false) {
return userPermValue;
}
loggedUser.nextGroups.forEach(function(groupId) {
if (permissions[groupId] !== undefined && permissions[groupId][permission] !== undefined) {
userPermValue = userPermValue === undefined ?
permissions[groupId][permission] : userPermValue && permissions[groupId][permission];
}
})
return userPermValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Component, ComponentPrefixes} from '../../models/component';
import {Validation} from '../../models/validation';

export class UserField extends DataField<UserValue> {
// todo rebranding to actor-field
constructor(stringId: string, title: string, behavior: Behavior, value: UserValue, private _roles: Array<ProcessRole>,
placeholder?: string, description?: string, layout?: Layout, validations?: Array<Validation>, component?: Component,
parentTaskId?: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {TestBed} from '@angular/core/testing';
describe('UserValue', () => {
it('should create an instance', () => {
let user: UserValue;
user = new UserValue('0', 'realmID0', 'name', 'surname', 'mail');
user = new UserValue('0', 'realmID0', 'name', 'surname', 'name surname','mail');
expect(user.id).toEqual('0');
expect(user.firstName).toEqual('name');
expect(user.lastName).toEqual('surname');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export class UserValue {
* @param _realmId the id of the selected user realm
* @param _firstName the first name of the selected user
* @param _lastName the surname of the selected user
* @param _fullName the full name of the selected user
* @param _username email of the selected user
*/
constructor(private _id: string, private _realmId: string, private _firstName: string, private _lastName: string, private _username: string) {
constructor(private _id: string, private _realmId: string, private _firstName: string, private _lastName: string,
private _fullName: string, private _username: string) {
}

get id(): string {
Expand All @@ -32,7 +34,7 @@ export class UserValue {
}

get fullName(): string {
return this._firstName + ' ' + this._lastName;
return this._fullName;
}

get username(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {expect} from "@ngbracket/ngx-layout/_private-utils/testing";
describe('UserListValue', () => {
it('should create an instance', () => {
let user: UserListValue;
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'mail')]]));
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'name surname', 'mail')]]));
expect(user.userValues.get('0').id).toEqual('0');
expect(user.userValues.get('0').firstName).toEqual('name');
expect(user.userValues.get('0').lastName).toEqual('surname');
Expand All @@ -16,13 +16,13 @@ describe('UserListValue', () => {

it('should get last', () => {
let user: UserListValue;
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'mail')]]));
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'name surname', 'mail')]]));
expect(user.getLast().id === '0').toBeTruthy();
});

it('should remove', () => {
let user: UserListValue;
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'mail')]]));
user = new UserListValue(new Map([['0', new UserValue('0', 'realmID0','name', 'surname', 'name surname', 'mail')]]));
expect(user.userValues.size === 1).toBeTruthy();
user.removeUserValue('0');
expect(user.userValues.size === 0).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { UserValue } from '../../user-field/models/user-value';

export class UserListValue {
// TODO: rebranding to actor-list-field

private _userValues: Map<string, UserValue>;

Expand All @@ -31,7 +32,7 @@ export class UserListValue {

public getLast(): UserValue {
if (this._userValues.size == 0) {
return new UserValue('', '', '', '', '');
return new UserValue('', '', '', '', '', '');
}
return Array.from(this._userValues.values()).pop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('AbstractSearchModeComponent', () => {
}));

it('should transform UserValue into id', fakeAsync(() => {
component.formControls[0].setValue(new UserValue('7', 'realmID0', '', '', ''));
component.formControls[0].setValue(new UserValue('7', 'realmID0', '', '', '',''));
tick(600);
expect(headerSpy).toHaveBeenCalledWith(0, '7');
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export abstract class AbstractPanelWithImmediateDataComponent extends AbstractPa
icon: 'file_copy',
type: immediate.type
};
case 'userList':
return {value: immediate.value?.userValues.map(obj => obj.fullName).join(', '), icon: 'account_circle', type: immediate.type};
case 'user':
return {value: immediate.value.fullName, icon: 'account_circle', type: immediate.type};
case 'actorList':
return {value: immediate.value?.actorValues?.map(obj => obj.fullName).join(', '), icon: 'account_circle', type: immediate.type};
case 'actor':
return {value: immediate.value?.fullName, icon: 'account_circle', type: immediate.type};
case 'boolean':
return {
value: this._translate.instant('dataField.values.boolean.' + immediate.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class TestWrapperComponent {
delete: true
}
},
users: {},
actors: {},
color: 'color',
creationDate: [],
lastModified: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export interface Case {
/**
* **Example:** {}
*/
users?: UserPermissions;
userRefs?: UserRefs;
actors?: UserPermissions;
actorRefs?: UserRefs;
/**
* **Example:** []
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ describe('CaseDataset', () => {
{stringId: 'multichoice_mapField', title: 'title', type: 'multichoice_map'},
{stringId: 'fileField', title: 'title', type: 'file'},
{stringId: 'fileListField', title: 'title', type: 'fileList'},
{stringId: 'userListField', title: 'title', type: 'userList'},
{stringId: 'userField', title: 'title', type: 'user'},
{stringId: 'actorListField', title: 'title', type: 'actorList'},
{stringId: 'actorField', title: 'title', type: 'actor'},
{stringId: 'dateField', title: 'title', type: 'date'},
{stringId: 'dateTimeField', title: 'title', type: 'dateTime'},
];
Expand Down Expand Up @@ -142,9 +142,9 @@ describe('CaseDataset', () => {
expect(metadata.values).toEqual([v]);
}, operatorService);
});
it('userList field search', (done) => {
it('actorList field search', (done) => {
const v = 'value';
serializationTest(done, category, Equals, 'userList', v, (metadata) => {
serializationTest(done, category, Equals, 'actorList', v, (metadata) => {
expect(metadata.values).toEqual([v]);
}, operatorService);
});
Expand All @@ -160,9 +160,9 @@ describe('CaseDataset', () => {
expect(metadata.values).toEqual([v]);
}, operatorService);
});
it('user field search', (done) => {
it('actor field search', (done) => {
const v = mockUserSearchValue('Test User', '7');
serializationTest(done, category, Equals, 'user', v, (metadata) => {
serializationTest(done, category, Equals, 'actor', v, (metadata) => {
const mockedSerializedValue = mockUserSearchValue('Test User', '7');
delete mockedSerializedValue.icon;
expect(metadata.values).toEqual([mockedSerializedValue]);
Expand Down Expand Up @@ -223,9 +223,9 @@ describe('CaseDataset', () => {
deserializationTest(done, category, Equals, 'fileList', v, (d, c) => valueObjectsComparison(d, c),
operatorService, allowedNets$);
});
it('userList field search', (done) => {
it('actorList field search', (done) => {
const v = 'value';
deserializationTest(done, category, Equals, 'userList', v, (d, c) => valueObjectsComparison(d, c),
deserializationTest(done, category, Equals, 'actorList', v, (d, c) => valueObjectsComparison(d, c),
operatorService, allowedNets$);
});
it('number field search', (done) => {
Expand All @@ -238,9 +238,9 @@ describe('CaseDataset', () => {
deserializationTest(done, category, Equals, 'boolean', v, (d, c) => valueObjectsComparison(d, c),
operatorService, allowedNets$);
});
it('user field search', (done) => {
it('actor field search', (done) => {
const v = mockUserSearchValue('Test User', '7');
deserializationTest(done, category, Equals, 'user', v, (d, c) => valueObjectsComparison(d, c),
deserializationTest(done, category, Equals, 'actor', v, (d, c) => valueObjectsComparison(d, c),
operatorService, allowedNets$);
});
it('date field search', (done) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class CaseDataset extends Category<Datafield> implements AutocompleteOpti
return SearchInputType.NUMBER;
case 'boolean':
return SearchInputType.BOOLEAN;
case 'user':
case 'actor':
return SearchInputType.AUTOCOMPLETE;
default:
return SearchInputType.TEXT;
Expand Down Expand Up @@ -173,8 +173,8 @@ export class CaseDataset extends Category<Datafield> implements AutocompleteOpti
this._operatorService.getOperator(Equals),
this._operatorService.getOperator(NotEquals)
];
case 'user':
case 'userList':
case 'actor':
case 'actorList':
return [
this._operatorService.getOperator(Equals),
this._operatorService.getOperator(NotEquals),
Expand Down Expand Up @@ -259,9 +259,9 @@ export class CaseDataset extends Category<Datafield> implements AutocompleteOpti
return resolver.getIndex(datafield.fieldId, SearchIndex.FILE_NAME,
this.isSelectedOperator(Equals) || this.isSelectedOperator(NotEquals) || this.isSelectedOperator(Substring)
|| this.isSelectedOperator(IsNull));
case 'user':
case 'userList':
return resolver.getIndex(datafield.fieldId, SearchIndex.USER_ID);
case 'actor':
case 'actorList':
return resolver.getIndex(datafield.fieldId, SearchIndex.ACTOR_ID);
case 'i18n':
return resolver.getIndex(datafield.fieldId, SearchIndex.TEXT, this.isSelectedOperator(Equals) || this.isSelectedOperator(NotEquals) || this.isSelectedOperator(Substring)
|| this.isSelectedOperator(IsNull));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export class CaseSimpleDataset extends NoConfigurationCategory<string> {
case 'fileList':
this._elasticKeyword = resolver.getIndex(this._fieldId, SearchIndex.FILE_NAME, this.isSelectedOperator(Substring));
break;
case 'user':
case 'userList':
this._elasticKeyword = resolver.getIndex(this._fieldId, SearchIndex.USER_ID);
case 'actor':
case 'actorList':
this._elasticKeyword = resolver.getIndex(this._fieldId, SearchIndex.ACTOR_ID);
break;
case 'i18n':
this._elasticKeyword = resolver.getIndex(this._fieldId, SearchIndex.TEXT, this.isSelectedOperator(Equals) || this.isSelectedOperator(NotEquals) || this.isSelectedOperator(Substring))
Expand All @@ -115,7 +115,7 @@ export class CaseSimpleDataset extends NoConfigurationCategory<string> {
return this._operatorService.getOperator(Equals);
case 'boolean':
return this._operatorService.getOperator(Equals);
case 'user':
case 'actor':
return this._operatorService.getOperator(Equals);
case 'date':
return this._operatorService.getOperator(EqualsDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class DatafieldMapKey implements SearchAutocompleteOption<string> {
return 'check_box';
case 'number':
return 'looks_one';
case 'user':
case 'actor':
return 'person';
case 'userList':
case 'actorList':
return 'people';
case 'dateTime':
return 'schedule';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ export enum SearchIndex {
*
* Used by User and UserListFields
*/
USER_ID = 'userIdValue',
ACTOR_ID = 'actorIdValue',
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ describe('AbstractMultiUserAssignComponent', () => {
});

it('should select', () => {
component.userWasSelected(new UserValue('0', 'realmID0', '', '', ''));
component.userWasSelected(new UserValue('0', 'realmID0', '', '', '',''));
expect(component.currentUsers).toBeTruthy();
expect(component.currentUsers.find(u => u.id === '0')).toBeTruthy()
});

it('should unselect', () => {
component.userWasSelected(new UserValue('0', 'realmID0', '', '', ''));
component.userWasSelected(new UserValue('0', 'realmID0', '', '', '',''));
expect(component.currentUsers).toBeTruthy();
expect(component.currentUsers.find(u => u.id === '0')).toBeTruthy()
component.userWasUnselected(new UserValue('0', 'realmID0', '', '', ''));
component.userWasUnselected(new UserValue('0', 'realmID0', '', '', '',''));
expect(component.currentUsers.length === 0).toBeTruthy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ class TestUserComponent extends AbstractBaseUserAssignListComponent implements O
template: '<ncc-test-user [searchUserControl]="formControl"></ncc-test-user>'
})
class TestWrapperComponent {
injectedData = {roles: [], value: new UserValue('5', 'realmID0','admin', 'netgrif', 'super@netgrif.com')} as UserListInjectedData;
injectedData = {roles: [], value: new UserValue('5', 'realmID0','admin', 'netgrif', 'admin netgrif', 'super@netgrif.com')} as UserListInjectedData;
formControl = new FormControl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ class TestUserComponent extends AbstractMultiUserAssignListComponent {
template: '<ncc-test-user [searchUserControl]="formControl"></ncc-test-user>'
})
class TestWrapperComponent {
injectedData = {roles: [], value: new UserValue('5', 'realmID0', 'admin', 'netgrif', 'super@netgrif.com')} as UserListInjectedData;
injectedData = {roles: [], value: new UserValue('5', 'realmID0', 'admin', 'netgrif', 'admin netgrif', 'super@netgrif.com')} as UserListInjectedData;
formControl = new FormControl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export abstract class AbstractMultiUserAssignListComponent extends AbstractBaseU
const index = this._currentlySelectedUsers.indexOf(selectedUser.id);
if (index > -1) {
this._currentlySelectedUsers.splice(index, 1);
this.userUnselected.emit(new UserValue(selectedUser.id, selectedUser.realmId, selectedUser.firstName, selectedUser.lastName, selectedUser.username));
this.userUnselected.emit(new UserValue(selectedUser.id, selectedUser.realmId, selectedUser.firstName, selectedUser.lastName, selectedUser.fullName, selectedUser.username));
} else {
this._currentlySelectedUsers.push(selectedUser.id);
this.userSelected.emit(new UserValue(selectedUser.id, selectedUser.realmId, selectedUser.firstName, selectedUser.lastName, selectedUser.username));
this.userSelected.emit(new UserValue(selectedUser.id, selectedUser.realmId, selectedUser.firstName, selectedUser.lastName, selectedUser.fullName, selectedUser.username));
}
this._selectedUsers$.next([...this._currentlySelectedUsers]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ class TestUserComponent extends AbstractMultiUserAssignItemComponent {
template: '<ncc-test-user [user]="user"></ncc-test-user>'
})
class TestWrapperComponent {
user = new UserValue('0', 'realmID0', '', '', '');
user = new UserValue('0', 'realmID0', '', '', '', '');
}
Loading
Loading