add perms; editor, viewer
This commit is contained in:
parent
b647517ca6
commit
1ac38f26cb
8 changed files with 74 additions and 21 deletions
|
|
@ -3,9 +3,12 @@ export enum UserPermissions {
|
|||
THAI_PERMISSION = 1 << 0,
|
||||
MALAY_PERMISSION = 1 << 1,
|
||||
AUS_PERMISSION = 1 << 2,
|
||||
ALPHA3_PERMISSION = 1 << 3,
|
||||
|
||||
VIEWER = 1 << 4,
|
||||
EDITOR = 1 << 7,
|
||||
|
||||
SUPER_ADMIN_PERMISSION = THAI_PERMISSION | MALAY_PERMISSION | AUS_PERMISSION
|
||||
SUPER_ADMIN_PERMISSION = THAI_PERMISSION | MALAY_PERMISSION | AUS_PERMISSION | ALPHA3_PERMISSION | (EDITOR | VIEWER)
|
||||
}
|
||||
|
||||
export function getPermissions(perms: number) : UserPermissions[] {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export class CallbackComponent implements OnInit {
|
|||
email: params['email'],
|
||||
name: params['name'],
|
||||
picture: params['picture'],
|
||||
permissions: getPermissions(params['permissions'])
|
||||
permissions: getPermissions(params['permissions']),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { CommonModule, NgOptimizedImage } from '@angular/common';
|
||||
import { Router } from '@angular/router';
|
||||
import { UserService } from '../services/user.service';
|
||||
import { UserPermissions } from '../auth/userPermissions';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
|
|
@ -26,6 +28,7 @@ import { Router } from '@angular/router';
|
|||
height="225"
|
||||
priority="true"
|
||||
(click)="onClick(country.id)"
|
||||
*ngIf="acccessibleCountries.includes(country.id)"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -43,13 +46,18 @@ import { Router } from '@angular/router';
|
|||
height="225"
|
||||
priority="true"
|
||||
(click)="onClick(alpha.id)"
|
||||
*ngIf="acccessibleCountries.includes(alpha.id)"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
|
||||
|
||||
export class DepartmentComponent {
|
||||
acccessibleCountries:string[] = [];
|
||||
|
||||
countries: { id: string; img: string }[] = [
|
||||
{
|
||||
id: 'tha',
|
||||
|
|
@ -72,7 +80,32 @@ export class DepartmentComponent {
|
|||
},
|
||||
];
|
||||
|
||||
constructor(private router: Router) {}
|
||||
constructor(
|
||||
private router: Router,
|
||||
private _userService: UserService
|
||||
) {
|
||||
let perms = _userService.getCurrentUser()!.permissions;
|
||||
console.log("GainAccesses",perms)
|
||||
|
||||
for (let perm of perms) {
|
||||
switch (perm) {
|
||||
case UserPermissions.THAI_PERMISSION:
|
||||
this.acccessibleCountries.push('tha');
|
||||
break;
|
||||
case UserPermissions.MALAY_PERMISSION:
|
||||
this.acccessibleCountries.push('mys');
|
||||
break;
|
||||
case UserPermissions.AUS_PERMISSION:
|
||||
this.acccessibleCountries.push('aus');
|
||||
break;
|
||||
case UserPermissions.ALPHA3_PERMISSION:
|
||||
this.acccessibleCountries.push('alpha-3');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClick(id: string) {
|
||||
void this.router.navigate([`/${id}/recipes`]);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
></path>
|
||||
</svg>
|
||||
</button>
|
||||
<a routerLink="/recipes" class="flex ml-14 max-sm:hidden">
|
||||
<a routerLink="/{{ current_department }}/recipes" class="flex ml-14 max-sm:hidden">
|
||||
<img
|
||||
src="assets/logo.svg"
|
||||
class="h-10 md:h-20 px-4"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { ActivatedRoute, RouterModule } from '@angular/router';
|
||||
import { DatePipe, NgFor, NgIf } from '@angular/common';
|
||||
import { GoogleButtonComponent } from 'src/app/shared/googleButton/googleButton.component';
|
||||
import { UserService } from '../services/user.service';
|
||||
|
|
@ -19,16 +19,19 @@ interface MenuItem {
|
|||
imports: [RouterModule, NgFor, NgIf, GoogleButtonComponent, DatePipe],
|
||||
})
|
||||
export class LayoutComponent implements OnInit, OnDestroy {
|
||||
|
||||
current_department = this._router.snapshot.paramMap.get('department')!;
|
||||
|
||||
menuItems: MenuItem[] = [
|
||||
{
|
||||
name: 'Recipe',
|
||||
icon_url: 'assets/icons/recipes.svg',
|
||||
link: '/recipes',
|
||||
link: '/'+this.current_department+'/recipes',
|
||||
},
|
||||
{
|
||||
name: 'Log',
|
||||
icon_url: 'assets/icons/logs.svg',
|
||||
link: '/log',
|
||||
link: '/'+this.current_department+'/log',
|
||||
},
|
||||
];
|
||||
date = new Date();
|
||||
|
|
@ -37,7 +40,12 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|||
user: User | null = null;
|
||||
exit$ = new Subject<void>();
|
||||
|
||||
constructor(private _userService: UserService) {}
|
||||
|
||||
|
||||
constructor(
|
||||
private _userService: UserService,
|
||||
private _router: ActivatedRoute
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this._userService.currentUser
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue