data permision works
This commit is contained in:
parent
53210c0ac5
commit
da3dc3c61a
|
|
@ -54,85 +54,73 @@ ON
|
||||||
|
|
||||||
|
|
||||||
";
|
";
|
||||||
|
// Restricts #tmpEmpSrc to the user's data permissions.
|
||||||
|
// Each configured permission type (1=Category, 2=Grade, 3=Department, 4=Location) is a filter;
|
||||||
|
// when several types are configured an employee must satisfy all of them (same rule as before).
|
||||||
|
// Department and Location permissions include all child nodes.
|
||||||
|
// Parameters: %n = UserID, %n = PayrollTypeID.
|
||||||
public const string fnddataPermissionSQL = @"
|
public const string fnddataPermissionSQL = @"
|
||||||
IF EXISTS
|
DECLARE @dpUserID INT = %n, @dpPayrollTypeID INT = %n;
|
||||||
(
|
|
||||||
SELECT*
|
|
||||||
FROM DataPermission
|
|
||||||
WHERE userid = %n and PayrollTypeID = %n and PermissionType=1
|
|
||||||
)
|
|
||||||
BEGIN
|
|
||||||
delete from #tmpEmpSrc where categoryid not in ( select referenceid from DataPermission where UserID =%n and PayrollTypeID =%n and PermissionType=1);
|
|
||||||
END;
|
|
||||||
IF EXISTS
|
|
||||||
(
|
|
||||||
SELECT*
|
|
||||||
FROM DataPermission
|
|
||||||
WHERE userid = %n and PayrollTypeID = %n and PermissionType=2
|
|
||||||
)
|
|
||||||
BEGIN
|
|
||||||
delete from #tmpEmpSrc where GRADEID not in ( select referenceid from DataPermission where UserID =%n and PayrollTypeID =%n and PermissionType=2);
|
|
||||||
END;
|
|
||||||
|
|
||||||
IF EXISTS
|
IF OBJECT_ID('tempdb..#dpPerm') IS NOT NULL DROP TABLE #dpPerm;
|
||||||
(
|
IF OBJECT_ID('tempdb..#dpDept') IS NOT NULL DROP TABLE #dpDept;
|
||||||
SELECT*
|
IF OBJECT_ID('tempdb..#dpLoc') IS NOT NULL DROP TABLE #dpLoc;
|
||||||
FROM DataPermission
|
|
||||||
WHERE userid = %n and PayrollTypeID = %n and PermissionType=3
|
|
||||||
)
|
|
||||||
BEGIN
|
|
||||||
IF OBJECT_ID('tempdb..#TEMPDOC') IS NOT NULL DROP TABLE #TEMPDOC
|
|
||||||
;WITH
|
|
||||||
cteReports(departmentid)
|
|
||||||
|
|
||||||
AS
|
-- Read DataPermission once instead of once per type
|
||||||
|
SELECT DISTINCT PermissionType, ReferenceID
|
||||||
|
INTO #dpPerm
|
||||||
|
FROM DataPermission
|
||||||
|
WHERE UserID = @dpUserID
|
||||||
|
AND PayrollTypeID = @dpPayrollTypeID
|
||||||
|
AND ReferenceID IS NOT NULL
|
||||||
|
AND ISNULL(PermissionStatus, 0) <> 3; -- 3 = Removed
|
||||||
|
|
||||||
|
-- Category (1)
|
||||||
|
IF EXISTS (SELECT 1 FROM #dpPerm WHERE PermissionType = 1)
|
||||||
|
DELETE FROM #tmpEmpSrc
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM #dpPerm p WHERE p.PermissionType = 1 AND p.ReferenceID = #tmpEmpSrc.CategoryID);
|
||||||
|
|
||||||
|
-- Grade (2)
|
||||||
|
IF EXISTS (SELECT 1 FROM #dpPerm WHERE PermissionType = 2)
|
||||||
|
DELETE FROM #tmpEmpSrc
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM #dpPerm p WHERE p.PermissionType = 2 AND p.ReferenceID = #tmpEmpSrc.GradeID);
|
||||||
|
|
||||||
|
-- Department (3): permitted departments plus all descendants
|
||||||
|
IF EXISTS (SELECT 1 FROM #dpPerm WHERE PermissionType = 3)
|
||||||
|
BEGIN
|
||||||
|
;WITH cteDept (DepartmentID) AS
|
||||||
(
|
(
|
||||||
SELECT departmentid FROM DEPARTMENT
|
SELECT ReferenceID FROM #dpPerm WHERE PermissionType = 3
|
||||||
|
|
||||||
WHERE DEPARTMENTID in (select referenceid from DataPermission where UserID = %n and PayrollTypeID = %n and PermissionType = 3)
|
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
SELECT d.DEPARTMENTID FROM DEPARTMENT d INNER JOIN cteDept c ON d.PARENTID = c.DepartmentID
|
||||||
|
)
|
||||||
|
SELECT DISTINCT DepartmentID INTO #dpDept FROM cteDept;
|
||||||
|
|
||||||
SELECT e.departmentid FROM DEPARTMENT e
|
DELETE FROM #tmpEmpSrc
|
||||||
INNER JOIN cteReports r ON e.PARENTID = r.departmentid
|
WHERE NOT EXISTS (SELECT 1 FROM #dpDept x WHERE x.DepartmentID = #tmpEmpSrc.DepartmentID);
|
||||||
) SELECT* INTO #TEMPDOC FROM cteReports
|
|
||||||
|
|
||||||
|
DROP TABLE #dpDept;
|
||||||
delete from #tmpEmpSrc where Departmentid NOT in (SELECT * FROM #TEMPDOC);
|
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
-- Location (4): permitted locations plus all descendants
|
||||||
IF EXISTS
|
IF EXISTS (SELECT 1 FROM #dpPerm WHERE PermissionType = 4)
|
||||||
(
|
BEGIN
|
||||||
SELECT*
|
;WITH cteLoc (LocationID) AS
|
||||||
FROM DataPermission
|
|
||||||
WHERE userid = %n and PayrollTypeID = %n and PermissionType=4
|
|
||||||
)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
IF OBJECT_ID('tempdb..#tmpLOC') IS NOT NULL
|
|
||||||
DROP TABLE #tmpLOC
|
|
||||||
|
|
||||||
-- delete from #tmpEmpSrc where locationid NOT in (
|
|
||||||
; WITH
|
|
||||||
cteReports(locationid)
|
|
||||||
|
|
||||||
AS
|
|
||||||
(
|
(
|
||||||
SELECT locationid FROM location
|
SELECT ReferenceID FROM #dpPerm WHERE PermissionType = 4
|
||||||
|
|
||||||
WHERE LOCATIONid in (select referenceid from DataPermission where UserID = %n and PayrollTypeID = %n and PermissionType = 4)
|
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
SELECT l.LOCATIONID FROM LOCATION l INNER JOIN cteLoc c ON l.PARENTID = c.LocationID
|
||||||
|
)
|
||||||
|
SELECT DISTINCT LocationID INTO #dpLoc FROM cteLoc;
|
||||||
|
|
||||||
SELECT e.locationid FROM location e
|
DELETE FROM #tmpEmpSrc
|
||||||
INNER JOIN cteReports r ON e.PARENTID = r.locationid
|
WHERE NOT EXISTS (SELECT 1 FROM #dpLoc x WHERE x.LocationID = #tmpEmpSrc.LocationID);
|
||||||
) SELECT* INTO #tmpLOC FROM cteReports
|
|
||||||
|
|
||||||
|
DROP TABLE #dpLoc;
|
||||||
|
END;
|
||||||
|
|
||||||
delete from #tmpEmpSrc where locationid NOT in ( SELECT *FROM #tmpLOC);
|
DROP TABLE #dpPerm;
|
||||||
DROP TABLE #tmpLOC;
|
";
|
||||||
END;";
|
|
||||||
|
|
||||||
public const string fnddropTempSQL = @"
|
public const string fnddropTempSQL = @"
|
||||||
|
|
||||||
|
|
@ -161,11 +149,8 @@ END;";
|
||||||
}
|
}
|
||||||
internal static IDataReader Search(TransactionContext tc, string sql, int userid, int payrolltypeid)
|
internal static IDataReader Search(TransactionContext tc, string sql, int userid, int payrolltypeid)
|
||||||
{
|
{
|
||||||
string qry = SQLParser.MakeSQL(SearchEmployeeDA.fndSQL + SearchEmployeeDA.fnddataPermissionSQL + SearchEmployeeDA.fnddropTempSQL, sql,
|
string qry = SQLParser.MakeSQL(SearchEmployeeDA.fndSQL + SearchEmployeeDA.fnddataPermissionSQL + SearchEmployeeDA.fnddropTempSQL,
|
||||||
userid, payrolltypeid,userid, payrolltypeid, userid, payrolltypeid, userid, payrolltypeid,
|
sql, userid, payrolltypeid);
|
||||||
userid, payrolltypeid, userid, payrolltypeid, userid, payrolltypeid, userid, payrolltypeid);
|
|
||||||
//return tc.ExecuteReader(@"%q" +
|
|
||||||
// "", sql, userid, payrolltypeid, userid, payrolltypeid, userid, payrolltypeid, userid, payrolltypeid, userid, payrolltypeid);
|
|
||||||
return tc.ExecuteReader(qry);
|
return tc.ExecuteReader(qry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@
|
||||||
<div class="p-col-12 p-lg-4">
|
<div class="p-col-12 p-lg-4">
|
||||||
<kendo-dropdownlist
|
<kendo-dropdownlist
|
||||||
style="width:100%"
|
style="width:100%"
|
||||||
[data]="users"
|
[data]="filteredUsers"
|
||||||
|
[filterable]="true"
|
||||||
|
(filterChange)="handleUserFilter($event)"
|
||||||
[defaultItem]="{ userName: 'Select User', id: null }"
|
[defaultItem]="{ userName: 'Select User', id: null }"
|
||||||
[textField]="'userName'"
|
[textField]="'userName'"
|
||||||
[valueField]="'id'"
|
[valueField]="'id'"
|
||||||
|
|
@ -115,6 +117,9 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-col-12 p-lg-12">
|
<div class="p-col-12 p-lg-12">
|
||||||
|
<div style="text-align:right; font-weight:600; margin-bottom:6px;">
|
||||||
|
Total: {{ _dataPermissionGrid?.length || 0 }}
|
||||||
|
</div>
|
||||||
<kendo-grid [data]="_dataPermissionGrid"
|
<kendo-grid [data]="_dataPermissionGrid"
|
||||||
[pageable]="true"
|
[pageable]="true"
|
||||||
[sortable]="true"
|
[sortable]="true"
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ export class DataPermssionComponent implements OnInit {
|
||||||
selectedUserType: EnumUserType;
|
selectedUserType: EnumUserType;
|
||||||
public _getUserSubscriber$: Subscription;
|
public _getUserSubscriber$: Subscription;
|
||||||
public users: User[];
|
public users: User[];
|
||||||
|
public filteredUsers: User[] = [];
|
||||||
public selectedUser: User;
|
public selectedUser: User;
|
||||||
currentUser: User;
|
currentUser: User;
|
||||||
_dataPermissionGrid: DataPermission[];
|
_dataPermissionGrid: DataPermission[];
|
||||||
|
|
@ -57,6 +58,7 @@ export class DataPermssionComponent implements OnInit {
|
||||||
this.userService.GetUsers(this._selectedRoleType.value).subscribe(
|
this.userService.GetUsers(this._selectedRoleType.value).subscribe(
|
||||||
(x) => {
|
(x) => {
|
||||||
this.users = x;
|
this.users = x;
|
||||||
|
this.filteredUsers = x ? x.slice() : [];
|
||||||
this.utilityHandlerService.ShowLoadingPanel = false;
|
this.utilityHandlerService.ShowLoadingPanel = false;
|
||||||
},
|
},
|
||||||
(x) => {
|
(x) => {
|
||||||
|
|
@ -69,10 +71,19 @@ export class DataPermssionComponent implements OnInit {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.users = [];
|
this.users = [];
|
||||||
|
this.filteredUsers = [];
|
||||||
this.selectedUser = undefined;
|
this.selectedUser = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleUserFilter(value: string): void {
|
||||||
|
const term = (value || '').trim().toLowerCase();
|
||||||
|
const source = this.users || [];
|
||||||
|
this.filteredUsers = term
|
||||||
|
? source.filter(u => (u.userName || '').toLowerCase().indexOf(term) !== -1)
|
||||||
|
: source.slice();
|
||||||
|
}
|
||||||
|
|
||||||
EventPermissionType(selectedPermissionType: any): void {
|
EventPermissionType(selectedPermissionType: any): void {
|
||||||
this.isDepartment = false;
|
this.isDepartment = false;
|
||||||
this.isCategory = false;
|
this.isCategory = false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user