Long Profile Role Permission tab Handled
This commit is contained in:
parent
64495523aa
commit
5e7eb4316c
|
|
@ -109,6 +109,7 @@ namespace HRM.DA
|
|||
_employees = employees;
|
||||
_processMonth = processMonth;
|
||||
_euroRate = euroRate;
|
||||
|
||||
UpdateprocessStatus("Collecting Employee basic information....");
|
||||
this.Initialize();
|
||||
this.AddEmployeeToProcess();
|
||||
|
|
|
|||
|
|
@ -1,24 +1,173 @@
|
|||
import { Injectable, EventEmitter } from '@angular/core';
|
||||
import { CanActivate, Router } from '@angular/router';
|
||||
import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { catchError, map, shareReplay } from 'rxjs/operators';
|
||||
import { AuthService } from '../_services/auth/auth.service';
|
||||
import { HRMNotificationService } from '../app.notification.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthGuard implements CanActivate {
|
||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
public menuEvent: EventEmitter<boolean>;
|
||||
|
||||
constructor(private authService: AuthService, private router: Router) {
|
||||
/**
|
||||
* Pages every logged-in user may open even when they are not in the user's role menu:
|
||||
* the home pages that login / the dashboard redirect to, and the forced change-password
|
||||
* screen (shown before the menu is loaded). Keep these normalized (lower case, no slashes).
|
||||
*/
|
||||
private static readonly ALWAYS_ALLOWED: string[] = [
|
||||
'',
|
||||
'landing-page',
|
||||
'ess/ess-dashboard',
|
||||
'ess/landing-page',
|
||||
'authentication/change-password',
|
||||
];
|
||||
|
||||
/** Every link that exists in the master menu (all roles), cached per login token. */
|
||||
private allMenuLinks$: Observable<string[] | null> = null;
|
||||
private allMenuLinksToken: string = null;
|
||||
|
||||
constructor(private authService: AuthService, private router: Router,
|
||||
private notificationService: HRMNotificationService) {
|
||||
this.menuEvent = new EventEmitter();
|
||||
this.authService.logout$.subscribe(() => this.onLogout());
|
||||
}
|
||||
canActivate(): boolean {
|
||||
if (this.authService.loggedIn()) {
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | boolean | UrlTree {
|
||||
if (!this.authService.loggedIn()) {
|
||||
this.router.navigate(['/login']);
|
||||
return false;
|
||||
}
|
||||
return this.checkMenuPermission(state.url);
|
||||
}
|
||||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | boolean | UrlTree {
|
||||
return this.canActivate(route, state);
|
||||
}
|
||||
private checkMenuPermission(url: string): Observable<boolean | UrlTree> | boolean | UrlTree {
|
||||
debugger;
|
||||
const target = AuthGuard.normalize(url);
|
||||
if (AuthGuard.ALWAYS_ALLOWED.indexOf(target) >= 0) {
|
||||
return true;
|
||||
}
|
||||
// this.alertify.error('You shall not pass!!!');
|
||||
this.router.navigate(['/login']);
|
||||
// this.router.navigate(['']);
|
||||
return false;
|
||||
|
||||
const userLinks = this.collectLinks(this.getMenuList());
|
||||
if (userLinks.some(l => AuthGuard.covers(l, target))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The app uses HashLocationStrategy (#/...): editing / pasting a URL in the address bar
|
||||
// does NOT reload the page, it fires a 'hashchange'/'popstate' navigation. So a direct hit
|
||||
// is the very first navigation OR any navigation not started by the app's own code.
|
||||
const trigger = this.router.getCurrentNavigation()?.trigger;
|
||||
const isDirectHit = !this.router.navigated || trigger !== 'imperative';
|
||||
if (isDirectHit) {
|
||||
return this.isVisitedInApp(target) ? true : this.deny();
|
||||
}
|
||||
|
||||
return this.getAllMenuLinks().pipe(
|
||||
map(allLinks => {
|
||||
debugger;
|
||||
if (allLinks !== null && allLinks.some(l => AuthGuard.covers(l, target))) {
|
||||
return this.deny();
|
||||
}
|
||||
// Not a menu screen (or master menu unavailable): allow and remember it.
|
||||
this.rememberVisitedInApp(target);
|
||||
return true;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private deny(): UrlTree {
|
||||
this.notificationService.showError('You do not have permission to access this page.');
|
||||
return this.router.createUrlTree(['/']);
|
||||
}
|
||||
|
||||
/** Non-menu pages this user reached through in-app navigation, per browser tab. */
|
||||
private static readonly VISITED_KEY = 'menuGuardVisited';
|
||||
|
||||
private getVisited(): { token: string, urls: string[] } {
|
||||
const token = localStorage.getItem('token');
|
||||
try {
|
||||
const data = JSON.parse(sessionStorage.getItem(AuthGuard.VISITED_KEY));
|
||||
if (data && data.token === token && Array.isArray(data.urls)) {
|
||||
return data;
|
||||
}
|
||||
} catch { }
|
||||
return { token: token, urls: [] };
|
||||
}
|
||||
|
||||
private isVisitedInApp(target: string): boolean {
|
||||
return this.getVisited().urls.indexOf(target) >= 0;
|
||||
}
|
||||
|
||||
private rememberVisitedInApp(target: string): void {
|
||||
const data = this.getVisited();
|
||||
if (data.urls.indexOf(target) < 0) {
|
||||
data.urls.push(target);
|
||||
try { sessionStorage.setItem(AuthGuard.VISITED_KEY, JSON.stringify(data)); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private getAllMenuLinks(): Observable<string[] | null> {
|
||||
const token = localStorage.getItem('token');
|
||||
if (this.allMenuLinks$ == null || this.allMenuLinksToken !== token) {
|
||||
this.allMenuLinksToken = token;
|
||||
const request$ = this.authService.getMenuesFromConfig().pipe(
|
||||
map((items: any[]) => this.collectLinks(items)),
|
||||
catchError(() => {
|
||||
// Don't keep a failed result - retry on the next navigation.
|
||||
this.resetMenuCache();
|
||||
return of(null);
|
||||
}),
|
||||
shareReplay(1)
|
||||
);
|
||||
this.allMenuLinks$ = request$;
|
||||
}
|
||||
return this.allMenuLinks$;
|
||||
}
|
||||
|
||||
private resetMenuCache(): void {
|
||||
this.allMenuLinks$ = null;
|
||||
this.allMenuLinksToken = null;
|
||||
}
|
||||
|
||||
private onLogout(): void {
|
||||
this.resetMenuCache();
|
||||
sessionStorage.removeItem(AuthGuard.VISITED_KEY);
|
||||
}
|
||||
|
||||
/** Flattens a menu tree (menuList) or a flat RolePermission list into normalized links. */
|
||||
private collectLinks(items: any[]): string[] {
|
||||
const links: string[] = [];
|
||||
const walk = (nodes: any[]) => {
|
||||
if (!Array.isArray(nodes)) { return; }
|
||||
for (const node of nodes) {
|
||||
if (node == null) { continue; }
|
||||
const link = node.routerLink ?? node.link ?? node.Link;
|
||||
if (typeof link === 'string') {
|
||||
const normalized = AuthGuard.normalize(link);
|
||||
if (normalized !== '') { // the dashboard link "/" must not cover every URL
|
||||
links.push(normalized);
|
||||
}
|
||||
}
|
||||
walk(node.items);
|
||||
}
|
||||
};
|
||||
walk(items);
|
||||
return links;
|
||||
}
|
||||
|
||||
/** Lower case, decoded path without query string, fragment, matrix params or edge slashes. */
|
||||
private static normalize(url: string): string {
|
||||
let path = (url || '').split('?')[0].split('#')[0];
|
||||
path = path.split('/').map(seg => seg.split(';')[0]).join('/');
|
||||
try { path = decodeURIComponent(path); } catch { }
|
||||
return path.replace(/^\/+|\/+$/g, '').toLowerCase();
|
||||
}
|
||||
|
||||
/** True when the menu link is the target itself or a parent path of it (segment boundary). */
|
||||
private static covers(link: string, target: string): boolean {
|
||||
return target === link || target.startsWith(link + '/');
|
||||
}
|
||||
|
||||
public getMenuList(): any {
|
||||
|
|
@ -39,8 +188,8 @@ export class AuthGuard implements CanActivate {
|
|||
if (x.label === "") {
|
||||
if (x.items.length > 0) {
|
||||
for (let i = 0; i < x.items.length; i++) {
|
||||
if (x.items[i].label === "Dashboard") {
|
||||
x.label = "Dashboard";
|
||||
if (x.items[i].label === "Dash-Board") {
|
||||
x.label = "Dash-Board";
|
||||
x.items = null;
|
||||
x.routerLink = "/";
|
||||
break;
|
||||
|
|
@ -53,7 +202,6 @@ export class AuthGuard implements CanActivate {
|
|||
menuKey:menu.menuCode || '',
|
||||
label: menu.label || '',
|
||||
icon: menu.icon || null,
|
||||
dividerAfter: menu.dividerAfter || false,
|
||||
routerLink: menu.routerLink || null,
|
||||
items: menu.items ? this.transformMenuData(menu.items) : null
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -210,6 +210,10 @@ export class AuthService {
|
|||
return this.apiService.httpPost<number>('/Authentication/saveUserRole', params);
|
||||
}
|
||||
// ---------- User Role Permission maker-checker ----------
|
||||
/** True when this session is, or is linked to, a Super User login (may send role changes). */
|
||||
CanMakeUserRoleChange() {
|
||||
return this.apiService.httpGet<boolean>('/Authentication/CanMakeUserRoleChange');
|
||||
}
|
||||
GetUserRoleState(roleType: EnumRoleType, userID?: number, employeeID?: number) {
|
||||
return this.apiService.httpGet<UserRoleState>('/Authentication/GetUserRoleState/' + roleType + '/'
|
||||
+ (userID ?? 0) + '/' + (employeeID ?? 0));
|
||||
|
|
|
|||
|
|
@ -400,6 +400,7 @@
|
|||
<app-life-cycle-entry [SetEmployee]="pickerEmployee" [fromCoreHr]="true"></app-life-cycle-entry>
|
||||
</div>
|
||||
</app-tab-panel>
|
||||
@if (isSuperUser) {
|
||||
<app-tab-panel header="Role Permission" leftIcon="pi pi-user" (onChange)="RolePermission()">
|
||||
<div class="grid form-group">
|
||||
<div class="lg:col-8">
|
||||
|
|
@ -412,6 +413,23 @@
|
|||
<!--<div *ngIf="userid ==undefined" class="lg:col-6">
|
||||
Password: {{password}}
|
||||
</div>-->
|
||||
@if (roleState && roleHasPending) {
|
||||
<div class="lg:col-12">
|
||||
<p><i class="pi pi-clock"></i> <b>Change waiting for approval.</b>
|
||||
Until another administrator approves it in Authentication > User Role Permission, the employee keeps the current roles.</p>
|
||||
@if (pendingRoleAddNames.length > 0) { <p>Will get: {{ pendingRoleAddNames.join(', ') }}</p> }
|
||||
@if (pendingRoleRemoveNames.length > 0) { <p>Will lose: {{ pendingRoleRemoveNames.join(', ') }}</p> }
|
||||
</div>
|
||||
}
|
||||
@if (roleState && !roleState.hasLogin) {
|
||||
<div class="lg:col-12">
|
||||
<p><i class="pi pi-info-circle"></i> No login yet. Sending this change creates one, switched off; it can sign in, and the login details are e-mailed, only after approval.</p>
|
||||
</div>
|
||||
} @else if (roleState?.loginWaiting) {
|
||||
<div class="lg:col-12">
|
||||
<p><i class="pi pi-info-circle"></i> The login is waiting for this change to be approved and cannot sign in yet.</p>
|
||||
</div>
|
||||
}
|
||||
<div class="lg:col-12">
|
||||
<kendo-grid [data]="_allroles" [(selectedKeys)]="_selectedUserRoles"
|
||||
[selectable]="userRoleselectableSettings" [kendoGridSelectBy]="'id'" (selectionChange)="onSelectionRoleChange($event)">
|
||||
|
|
@ -419,12 +437,20 @@
|
|||
[class]="{'text-center': true}"></kendo-grid-checkbox-column>
|
||||
<kendo-grid-column field="name" title="Role-Name">
|
||||
</kendo-grid-column>
|
||||
<kendo-grid-column title="Status" [width]="220">
|
||||
<ng-template kendoGridCellTemplate let-dataItem>
|
||||
{{ roleStatusText(dataItem.id) }}
|
||||
</ng-template>
|
||||
</kendo-grid-column>
|
||||
</kendo-grid>
|
||||
</div>
|
||||
|
||||
<div class="lg:col-12" align="right">
|
||||
<button class="k-button k-primary" kendoButton (click)="onUserRoleSave()" style="height:auto;">
|
||||
Assign Role
|
||||
<button kendoButton type="button" fillMode="flat" [disabled]="!hasRoleDraftChanges" (click)="onUserRoleReset()" style="height:auto;">
|
||||
Reset
|
||||
</button>
|
||||
<button kendoButton type="button" themeColor="primary" [disabled]="!hasRoleDraftChanges" (click)="onUserRoleSave()" style="height:auto;">
|
||||
Send for approval
|
||||
</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
|
@ -456,6 +482,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</app-tab-panel>
|
||||
}
|
||||
</app-tab-view>
|
||||
|
||||
@if (nidPopUp||tinPopUp||dlnoPopUp||passnoPopUp||signaturePopUp) {
|
||||
|
|
|
|||
|
|
@ -11,10 +11,14 @@ import {
|
|||
EnumExtension,
|
||||
EnumGender,
|
||||
EnumMaritalStatus,
|
||||
EnumAuthStatus,
|
||||
EnumRoleType,
|
||||
EnumStatus,
|
||||
EnumSystemType
|
||||
EnumSystemType,
|
||||
EnumUserType
|
||||
} from '../../../_models/enums';
|
||||
import { JwtHelperService } from '@auth0/angular-jwt';
|
||||
import { EnumUserRoleRequestType, UserRoleChangeRequest, UserRoleState } from '../../../_models/Authentication/UserRole';
|
||||
import { Grade } from '../../../_models/Basic/grade';
|
||||
import { Department } from '../../../_models/Basic/department';
|
||||
import { Role } from '../../../_models/Authentication/role';
|
||||
|
|
@ -115,6 +119,8 @@ export class GeneralComponent implements OnInit {
|
|||
designationpicker: DynamicPicker;
|
||||
userPassword = '';
|
||||
_selectedUserRoles: number[];
|
||||
/** The employee's live Self Service roles and any change waiting for approval (maker-checker). */
|
||||
roleState: UserRoleState;
|
||||
_gridRoles: Role[];
|
||||
_allroles: Role[];
|
||||
|
||||
|
|
@ -309,6 +315,8 @@ export class GeneralComponent implements OnInit {
|
|||
if (this.hrEmployee.id !== undefined && this.hrEmployee.id !== 0) {
|
||||
this.showEmpImage();
|
||||
this.userid = undefined;
|
||||
this.roleState = undefined;
|
||||
this._selectedUserRoles = [];
|
||||
var emp: SearchEmployee = new SearchEmployee();
|
||||
emp.employeeID = this.employeeService.hrEmployee.id;
|
||||
emp.employeeNo = this.employeeService.hrEmployee.employeeNo;
|
||||
|
|
@ -367,6 +375,7 @@ export class GeneralComponent implements OnInit {
|
|||
}
|
||||
);
|
||||
this.setUserRoleSelectableSettings();
|
||||
this.loadCanMakeRoleChange();
|
||||
|
||||
this.contact = new EmpContact();
|
||||
this.employeeService.Employee_Get_Completed.subscribe(
|
||||
|
|
@ -439,9 +448,131 @@ export class GeneralComponent implements OnInit {
|
|||
this.userRoleselectableSettings = {
|
||||
checkboxOnly: true,
|
||||
mode: 'multiple', // this.mode
|
||||
enabled: !this.roleLocked,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The Role Permission tab is for a Super User only: a Super User session, or an Admin/ESS session of
|
||||
* a person who also has a Super User login (the server decides, and allows only them too).
|
||||
*/
|
||||
isSuperUser = false;
|
||||
|
||||
private loadCanMakeRoleChange(): void {
|
||||
const token = localStorage.getItem('token');
|
||||
const user = token ? new JwtHelperService().decodeToken(token) : undefined;
|
||||
if (user == undefined) {
|
||||
this.isSuperUser = false;
|
||||
return;
|
||||
}
|
||||
if (user.UserType == EnumUserType.SuperUser) {
|
||||
this.isSuperUser = true;
|
||||
return;
|
||||
}
|
||||
this.userService.CanMakeUserRoleChange().subscribe(
|
||||
(resp: boolean) => { this.isSuperUser = resp === true; },
|
||||
() => { this.isSuperUser = false; }
|
||||
);
|
||||
}
|
||||
|
||||
get roleHasPending(): boolean {
|
||||
return (this.roleState?.pending ?? []).length > 0;
|
||||
}
|
||||
|
||||
/** Ticks cannot change until the roles are loaded, or while a change waits for approval. */
|
||||
get roleLocked(): boolean {
|
||||
return !this.roleState || this.roleHasPending;
|
||||
}
|
||||
|
||||
get pendingRoleAddNames(): string[] {
|
||||
return (this.roleState?.pending ?? []).filter(p => p.requestType == EnumUserRoleRequestType.Add).map(p => p.roleName);
|
||||
}
|
||||
|
||||
get pendingRoleRemoveNames(): string[] {
|
||||
return (this.roleState?.pending ?? []).filter(p => p.requestType == EnumUserRoleRequestType.Remove).map(p => p.roleName);
|
||||
}
|
||||
|
||||
get hasRoleDraftChanges(): boolean {
|
||||
if (this.roleLocked) {
|
||||
return false;
|
||||
}
|
||||
const live = this.roleState.liveRoleIDs ?? [];
|
||||
const ticked = this._selectedUserRoles ?? [];
|
||||
return ticked.some(id => !live.includes(id)) || live.some(id => !ticked.includes(id));
|
||||
}
|
||||
|
||||
/** Badge of one role row, the same wording as Authentication > User Role Permission. */
|
||||
roleStatusText(roleID: number): string {
|
||||
if (!this.roleState) {
|
||||
return '';
|
||||
}
|
||||
const live = (this.roleState.liveRoleIDs ?? []).includes(roleID);
|
||||
const pending = (this.roleState.pending ?? []).find(p => p.roleID == roleID);
|
||||
if (pending) {
|
||||
return pending.requestType == EnumUserRoleRequestType.Remove ? 'Removal - Not Yet Approved' : 'New - Not Yet Approved';
|
||||
}
|
||||
const ticked = (this._selectedUserRoles ?? []).includes(roleID);
|
||||
if (!live && ticked) {
|
||||
return 'To be added';
|
||||
}
|
||||
if (live && !ticked) {
|
||||
return 'To be removed';
|
||||
}
|
||||
return live ? 'Active' : 'Not assigned';
|
||||
}
|
||||
|
||||
/** Ticks show the live roles, or what is asked for while a change waits for approval. */
|
||||
private resetRoleSelection(): void {
|
||||
const live = this.roleState?.liveRoleIDs ?? [];
|
||||
const pending = this.roleState?.pending ?? [];
|
||||
const removing = pending.filter(p => p.requestType == EnumUserRoleRequestType.Remove).map(p => p.roleID);
|
||||
const adding = pending.filter(p => p.requestType == EnumUserRoleRequestType.Add).map(p => p.roleID);
|
||||
this._selectedUserRoles = [...live.filter(id => !removing.includes(id)), ...adding.filter(id => !live.includes(id))];
|
||||
this.setUserRoleSelectableSettings();
|
||||
}
|
||||
|
||||
/** Loads the Self Service roles that can be given and the employee's role state. */
|
||||
private loadRoleState(): void {
|
||||
const employeeID = this.employeeService.hrEmployee?.id;
|
||||
if (!employeeID) {
|
||||
return;
|
||||
}
|
||||
this.roleState = undefined;
|
||||
this._selectedUserRoles = [];
|
||||
this.setUserRoleSelectableSettings();
|
||||
this.loadingPanel.ShowLoadingPanel = true;
|
||||
this.userService.getAllRoles().subscribe(
|
||||
(resp: any) => {
|
||||
this._allroles = (resp ?? []).filter((r: Role) => r.roleType == EnumRoleType.Self_Service);
|
||||
},
|
||||
(err: any) => {
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
this.notificationService.showError(err?.error ?? err);
|
||||
},
|
||||
() => {
|
||||
this.userService.GetUserRoleState(EnumRoleType.Self_Service, undefined, employeeID).subscribe(
|
||||
(state: UserRoleState) => {
|
||||
this.roleState = state;
|
||||
const live = state?.liveRoleIDs ?? [];
|
||||
const pending = (state?.pending ?? []).map(p => p.roleID);
|
||||
// Only approved roles can be given; keep any the employee has or has asked for.
|
||||
this._allroles = this._allroles.filter(r =>
|
||||
r.roleStatus == EnumAuthStatus.Approved || r.roleStatus == EnumAuthStatus.Active
|
||||
|| live.includes(r.id) || pending.includes(r.id));
|
||||
this.resetRoleSelection();
|
||||
},
|
||||
(err: any) => {
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
this.notificationService.showError(err?.error ?? err);
|
||||
},
|
||||
() => {
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public GetSelectedEmployee(childData) {
|
||||
//debugger;
|
||||
if (childData != undefined) {
|
||||
|
|
@ -771,47 +902,49 @@ export class GeneralComponent implements OnInit {
|
|||
public onSelectionRoleChange(event: any): void {
|
||||
this._selectedUserRoles = [...this._selectedUserRoles];
|
||||
}
|
||||
/**
|
||||
* Maker side of the User Role Permission maker-checker: the ticked roles are sent for approval
|
||||
* (SaveUserRoleRequest) and nothing is live until another administrator approves them in
|
||||
* Authentication > User Role Permission. An employee without a login gets one, switched off.
|
||||
*/
|
||||
public onUserRoleSave(): void {
|
||||
|
||||
if (this._selectedUserRoles.length == 0) {
|
||||
this.notificationService.showWarning('select a role for Acess permision.');
|
||||
if (!this.roleState) {
|
||||
this.notificationService.showWarning('Roles are not loaded yet.');
|
||||
return;
|
||||
}
|
||||
if (this.roleHasPending) {
|
||||
this.notificationService.showWarning('This employee already has a role change waiting for approval.');
|
||||
return;
|
||||
}
|
||||
if (!this.hasRoleDraftChanges) {
|
||||
this.notificationService.showWarning('Nothing changed.');
|
||||
return;
|
||||
}
|
||||
|
||||
let userRoles: UserRole[] = [];
|
||||
this._selectedUserRoles.forEach(r => {
|
||||
|
||||
var userRole: UserRole = new UserRole();
|
||||
if (this.userid != undefined) {
|
||||
userRole.userID = this.userid;
|
||||
}
|
||||
userRole.payrollTypeID = this.employeeService.hrEmployee.payrollTypeID;
|
||||
userRole.employeeID = this.employeeService.hrEmployee.id;
|
||||
|
||||
userRole.loginIDView = this.employeeService.hrEmployee.employeeNo;
|
||||
userRole.roleID = r;
|
||||
|
||||
userRoles.push(userRole);
|
||||
});
|
||||
const request = new UserRoleChangeRequest();
|
||||
request.roleType = EnumRoleType.Self_Service;
|
||||
request.userID = this.roleState.userID;
|
||||
request.employeeID = this.roleState.employeeID ?? this.employeeService.hrEmployee.id;
|
||||
request.payrollTypeID = this.roleState.payrollTypeID ?? this.employeeService.hrEmployee.payrollTypeID;
|
||||
request.roleIDs = this._selectedUserRoles.slice();
|
||||
|
||||
this.loadingPanel.ShowLoadingPanel = true;
|
||||
this.userService.SaveUserRoleRequest(request).subscribe(
|
||||
() => { },
|
||||
(err: any) => {
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
this.notificationService.showError(err?.error ?? err);
|
||||
},
|
||||
() => {
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
this.notificationService.showSuccess('Sent for approval. Nothing changes until another administrator approves it.');
|
||||
this.loadRoleState();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
this.userService.saveUserRole(userRoles)
|
||||
.subscribe(
|
||||
(resp: any) => {
|
||||
},
|
||||
(err: any) => {
|
||||
//ON ERROR
|
||||
this.notificationService.showSuccess(err.error);
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
},
|
||||
() => {
|
||||
this.notificationService.showSuccess('Data Saved scuccessfully.');
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
public onUserRoleReset(): void {
|
||||
this.resetRoleSelection();
|
||||
}
|
||||
|
||||
generateDefaultNumber(): string {
|
||||
|
|
@ -835,7 +968,7 @@ export class GeneralComponent implements OnInit {
|
|||
this.pickerEmployee = emp;
|
||||
}
|
||||
this.userid = undefined;
|
||||
if (e.index == 2 && this.employeeService.hrEmployee.id > 0) {
|
||||
if (e.index == 2 && this.employeeService.hrEmployee.id > 0 && this.isSuperUser) {
|
||||
this.loadingPanel.ShowLoadingPanel = true;
|
||||
this.loginid = this.employeeService.hrEmployee.employeeNo;
|
||||
this.userService.GetUserByLoingID(this.hrEmployee.employeeNo, EnumSystemType.Self_Service).subscribe(
|
||||
|
|
@ -866,43 +999,7 @@ export class GeneralComponent implements OnInit {
|
|||
//console.log(this.employeeService.hrEmployee.birthDate.getFullYear());
|
||||
|
||||
}
|
||||
this.userService.getAllRoles().subscribe(
|
||||
(resp: any) => {
|
||||
this._allroles = resp;
|
||||
this._allroles = this._allroles.filter(r => r.roleType == EnumRoleType.Self_Service);
|
||||
},
|
||||
(err: any) => {
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
this.notificationService.showError(err.error);
|
||||
},
|
||||
() => {
|
||||
var emp: SearchEmployee[] = [];
|
||||
this._selectedUserRoles = [];
|
||||
var srchemp = new SearchEmployee();
|
||||
srchemp.employeeID = this.employeeService.hrEmployee.id;
|
||||
emp.push(srchemp);
|
||||
this.userService.GetEmpUserRole(emp).subscribe(
|
||||
(resp: any) => {
|
||||
debugger;
|
||||
var userRoles: UserRole[] = resp;
|
||||
if (userRoles != undefined && userRoles.length > 0) {
|
||||
userRoles.forEach(y => {
|
||||
this._selectedUserRoles.push(y.roleID);
|
||||
}
|
||||
);
|
||||
}
|
||||
this._selectedUserRoles = [...this._selectedUserRoles];
|
||||
},
|
||||
(err: any) => {
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
this.notificationService.showError(err.error);
|
||||
},
|
||||
() => {
|
||||
this.loadingPanel.ShowLoadingPanel = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
this.loadRoleState();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1568,6 +1568,44 @@ namespace HRM.UI.Controllers
|
|||
return CanManageUserAccessType(currentUser);
|
||||
}
|
||||
|
||||
// The Super User login that makes a role change in this session: the session's own login when it
|
||||
// is a super user, otherwise the super user login linked to the same employee (a super user who
|
||||
// has switched to Admin or ESS, e.g. on Employee Profile > Role Permission). The change is
|
||||
// recorded under that super user, so the same person cannot approve it after switching back.
|
||||
// Null when the person is not a super user.
|
||||
private int? UserRoleMakerID(CurrentUser currentUser)
|
||||
{
|
||||
if (CanManageUserRole(currentUser))
|
||||
return currentUser.UserID;
|
||||
try
|
||||
{
|
||||
if ((currentUser.EmployeeID ?? 0) <= 0)
|
||||
return null;
|
||||
int superUserID = this._userService.GetUserId((int)currentUser.EmployeeID, EnumUserType.SuperUser);
|
||||
return superUserID > 0 ? superUserID : (int?)null;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// A login with no linked employee.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Whether this session may send role changes (shows the Employee Profile > Role Permission tab).
|
||||
[HttpGet("CanMakeUserRoleChange")]
|
||||
public ActionResult CanMakeUserRoleChange()
|
||||
{
|
||||
try
|
||||
{
|
||||
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
||||
return Ok(UserRoleMakerID(currentUser) != null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// Admin requests are about a User-type login; Self Service requests about an employee + payroll type.
|
||||
private static string CheckUserRoleSubject(UserRoleSubject subject)
|
||||
{
|
||||
|
|
@ -1593,7 +1631,7 @@ namespace HRM.UI.Controllers
|
|||
try
|
||||
{
|
||||
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
||||
if (!CanManageUserRole(currentUser))
|
||||
if (UserRoleMakerID(currentUser) == null)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status403Forbidden, "You are not allowed to manage user roles.");
|
||||
}
|
||||
|
|
@ -1623,7 +1661,8 @@ namespace HRM.UI.Controllers
|
|||
try
|
||||
{
|
||||
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
||||
if (!CanManageUserRole(currentUser))
|
||||
int? makerID = UserRoleMakerID(currentUser);
|
||||
if (makerID == null)
|
||||
{
|
||||
return StatusCode(StatusCodes.Status403Forbidden, "You are not allowed to change user roles.");
|
||||
}
|
||||
|
|
@ -1672,7 +1711,7 @@ namespace HRM.UI.Controllers
|
|||
}
|
||||
|
||||
request.RoleIDs = wanted;
|
||||
int changed = this._userRoleService.RequestChange(request, currentUser.UserID);
|
||||
int changed = this._userRoleService.RequestChange(request, makerID.Value);
|
||||
if (changed == 0)
|
||||
{
|
||||
return BadRequest("Nothing changed.");
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@
|
|||
//"Default": "provider=sql;sqlSyntax=SQL;server=103.197.204.164,1718;Database=MasterProjectDB;User Id=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;",
|
||||
//"SqlCommandConnection": "Data Source=103.197.204.164,1718;Initial Catalog=autocrop;Persist Security Info=True; User ID=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;", // Development
|
||||
|
||||
"Default": "provider=sql;sqlSyntax=SQL;server=103.197.204.164,1718;Database=MasterProjectDBUATBRAC;User Id= DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;",
|
||||
"SqlCommandConnection": "Data Source=103.197.204.164,1718;Initial Catalog=MasterProjectDBUATBRAC;Persist Security Info=True; User ID=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;" // Development
|
||||
"Default": "provider=sql;sqlSyntax=SQL;server=103.197.204.164,1718;Database=MasterProjectDBBRAC;User Id= DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;",
|
||||
"SqlCommandConnection": "Data Source=103.197.204.164,1718;Initial Catalog=MasterProjectDBBRAC;Persist Security Info=True; User ID=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;" // Development
|
||||
|
||||
},
|
||||
"Calendar": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user