Skip to content

Commit

Permalink
Merge pull request #141 from Sohith-code/cbrelease-4.8.20-custom-regi…
Browse files Browse the repository at this point in the history
…stration-sohith

hidden some options for state admin
  • Loading branch information
sureshece16 authored Dec 27, 2024
2 parents 17d30da + 2a5f293 commit 37dee4d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
Access</button>
<button mat-menu-item (click)="goToRoute('mentormanage', row)">Mentor
Management</button>
<button mat-menu-item (click)="goToRoute('designation_master', row)">Manage
<button mat-menu-item (click)="goToRoute('designation_master', row)"
*ngIf="needCreate">Manage
Designations</button>
<!-- <button mat-menu-item
(click)="goToRoute('grade_setting', row)">Grades/Group</button> -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<div class="flex-display" [ngClass]="{ 'override-text-css': isReportsPath}">

<ws-widget-ui-user-table *ngIf="currentTab==='users'" [tableData]="tabledata" [data]="data"
[otherInput]="createdDepartment" [needAddAdmin]="true" [needCreateUser]="true" (actionsClick)="editUser($event)"
(searchByEnterKey)="onEnterkySearch($event)">
[otherInput]="createdDepartment" [needAddAdmin]="true" [needCreateUser]="isAllowed(allowedCreateRoles)"
(actionsClick)="editUser($event)" (searchByEnterKey)="onEnterkySearch($event)">
</ws-widget-ui-user-table>

<ws-app-roles-access *ngIf="currentTab==='rolesandaccess'" (clickedDepartment)="fClickedDepartment($event)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class UsersComponent implements OnInit, AfterViewInit, OnDestroy {
}
}
isReportsPath = false
userRoles: any
allowedCreateRoles = ['DASHBOARD_ADMIN', 'SPV_ADMIN', 'SPV_PUBLISHER']
constructor(private usersSvc: UsersService, private router: Router,
private route: ActivatedRoute,
private profile: ProfileV2Service,
Expand All @@ -52,6 +54,7 @@ export class UsersComponent implements OnInit, AfterViewInit, OnDestroy {
) {
}
ngOnInit() {
this.userRoles = this.route.parent && this.route.parent.snapshot.data.configService.userRoles
this.tabsData = [
{
name: 'Users',
Expand Down Expand Up @@ -133,6 +136,10 @@ export class UsersComponent implements OnInit, AfterViewInit, OnDestroy {
this.tabledata['actions'] = [{ name: 'Edit', label: 'Edit info', optional: true, icon: 'remove_red_eye', type: 'button' }]
}

if (!this.isAllowed(this.allowedCreateRoles)) {
this.tabsData = this.tabsData.filter(item => !(['designation_master'].includes(item.key)))
}

}
ngAfterViewInit() {
// this.elementPosition = this.menuElement.nativeElement.parentElement.offsetTop
Expand Down Expand Up @@ -299,4 +306,12 @@ export class UsersComponent implements OnInit, AfterViewInit, OnDestroy {
return 'cbp-providers'
}
}

isAllowed(allowedRoles: string[]): boolean {
if (this.userRoles && this.userRoles.size > 0) {
const lowerConfigRoles = new Set([...this.userRoles].map(role => role.toLowerCase()))
return allowedRoles.some(role => lowerConfigRoles.has(role.toLowerCase()))
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
</div>
<ng-container>
<ws-widget-directory-table [selectedDepartment]='currentDepartment' [tableData]='tabledata' [data]='data'
(eOnRowClick)="onRoleClick($event)" (actionsClick)="actionClick($event)"
(searchByEnterKey)="onEnterkySearch($event)" (pageChangeEvent)="onPageChange($event)">
[needCreate]="isAllowed(allowedCreateRoles)" (eOnRowClick)="onRoleClick($event)"
(actionsClick)="actionClick($event)" (searchByEnterKey)="onEnterkySearch($event)"
(pageChangeEvent)="onPageChange($event)">
</ws-widget-directory-table>
</ng-container>
</mat-card-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class DirectoryViewComponent implements OnInit {
currentTab: any
pagination = { limit: 20, offset: 0 }
totalCount = 0
userRoles: any
allowedCreateRoles = ['DASHBOARD_ADMIN', 'SPV_ADMIN', 'SPV_PUBLISHER']
constructor(
public dialog: MatDialog,
private route: ActivatedRoute,
Expand All @@ -54,6 +56,8 @@ export class DirectoryViewComponent implements OnInit {
&& data.profile.data.length > 0
&& data.profile.data[0]
})
this.userRoles = this.route.parent && this.route.parent.snapshot.data.configService.userRoles

}

ngOnInit() {
Expand Down Expand Up @@ -107,6 +111,11 @@ export class DirectoryViewComponent implements OnInit {
loader: true,
tableDataCount: this.totalCount
}

const isAllowed = this.isAllowed(this.allowedCreateRoles)
if (!isAllowed) {
delete this.tabledata.link
}
} else {
this.tabledata = {
actions: [{ name: 'Edit', label: 'Edit info', icon: 'remove_red_eye', type: 'button' }],
Expand Down Expand Up @@ -155,7 +164,9 @@ export class DirectoryViewComponent implements OnInit {
depatName: role.data.channel,
orgName: role.data.mdo || role.data.organisation,
tab: role.type,
subOrgType: role.data.type
// subOrgType: !this.isAllowed(this.allowedCreateRoles) ? 'ministry' : role.data.type ? role.data.type : 'cbp-providers'
// subOrgType: !this.isAllowed(this.allowedCreateRoles) ? 'ministry' : role.data.type ? role.data.type : 'ministry'
subOrgType: this.getSubOrgType(role.data.type)
}
})
}
Expand Down Expand Up @@ -379,4 +390,22 @@ export class DirectoryViewComponent implements OnInit {

return this.datePipe.transform(isoDateString, 'dd/MM/yyyy, hh:mm a')
}

isAllowed(allowedRoles: string[]): boolean {
if (this.userRoles && this.userRoles.size > 0) {
const lowerConfigRoles = new Set([...this.userRoles].map(role => role.toLowerCase()))
return allowedRoles.some(role => lowerConfigRoles.has(role.toLowerCase()))
}
return false
}

getSubOrgType(type: string) {
if (this.currentFilter === 'organisation') {
return 'ministry'
}
else if (type === 'cbp-providers') {
return 'cbp-providers'
}
return ''
}
}

0 comments on commit 37dee4d

Please sign in to comment.