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,
|
THAI_PERMISSION = 1 << 0,
|
||||||
MALAY_PERMISSION = 1 << 1,
|
MALAY_PERMISSION = 1 << 1,
|
||||||
AUS_PERMISSION = 1 << 2,
|
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[] {
|
export function getPermissions(perms: number) : UserPermissions[] {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export class CallbackComponent implements OnInit {
|
||||||
email: params['email'],
|
email: params['email'],
|
||||||
name: params['name'],
|
name: params['name'],
|
||||||
picture: params['picture'],
|
picture: params['picture'],
|
||||||
permissions: getPermissions(params['permissions'])
|
permissions: getPermissions(params['permissions']),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { CommonModule, NgOptimizedImage } from '@angular/common';
|
import { CommonModule, NgOptimizedImage } from '@angular/common';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { UserService } from '../services/user.service';
|
||||||
|
import { UserPermissions } from '../auth/userPermissions';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
standalone: true,
|
standalone: true,
|
||||||
|
|
@ -26,6 +28,7 @@ import { Router } from '@angular/router';
|
||||||
height="225"
|
height="225"
|
||||||
priority="true"
|
priority="true"
|
||||||
(click)="onClick(country.id)"
|
(click)="onClick(country.id)"
|
||||||
|
*ngIf="acccessibleCountries.includes(country.id)"
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -43,13 +46,18 @@ import { Router } from '@angular/router';
|
||||||
height="225"
|
height="225"
|
||||||
priority="true"
|
priority="true"
|
||||||
(click)="onClick(alpha.id)"
|
(click)="onClick(alpha.id)"
|
||||||
|
*ngIf="acccessibleCountries.includes(alpha.id)"
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
export class DepartmentComponent {
|
export class DepartmentComponent {
|
||||||
|
acccessibleCountries:string[] = [];
|
||||||
|
|
||||||
countries: { id: string; img: string }[] = [
|
countries: { id: string; img: string }[] = [
|
||||||
{
|
{
|
||||||
id: 'tha',
|
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) {
|
onClick(id: string) {
|
||||||
void this.router.navigate([`/${id}/recipes`]);
|
void this.router.navigate([`/${id}/recipes`]);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
></path>
|
></path>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<a routerLink="/recipes" class="flex ml-14 max-sm:hidden">
|
<a routerLink="/{{ current_department }}/recipes" class="flex ml-14 max-sm:hidden">
|
||||||
<img
|
<img
|
||||||
src="assets/logo.svg"
|
src="assets/logo.svg"
|
||||||
class="h-10 md:h-20 px-4"
|
class="h-10 md:h-20 px-4"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
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 { DatePipe, NgFor, NgIf } from '@angular/common';
|
||||||
import { GoogleButtonComponent } from 'src/app/shared/googleButton/googleButton.component';
|
import { GoogleButtonComponent } from 'src/app/shared/googleButton/googleButton.component';
|
||||||
import { UserService } from '../services/user.service';
|
import { UserService } from '../services/user.service';
|
||||||
|
|
@ -19,16 +19,19 @@ interface MenuItem {
|
||||||
imports: [RouterModule, NgFor, NgIf, GoogleButtonComponent, DatePipe],
|
imports: [RouterModule, NgFor, NgIf, GoogleButtonComponent, DatePipe],
|
||||||
})
|
})
|
||||||
export class LayoutComponent implements OnInit, OnDestroy {
|
export class LayoutComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
current_department = this._router.snapshot.paramMap.get('department')!;
|
||||||
|
|
||||||
menuItems: MenuItem[] = [
|
menuItems: MenuItem[] = [
|
||||||
{
|
{
|
||||||
name: 'Recipe',
|
name: 'Recipe',
|
||||||
icon_url: 'assets/icons/recipes.svg',
|
icon_url: 'assets/icons/recipes.svg',
|
||||||
link: '/recipes',
|
link: '/'+this.current_department+'/recipes',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Log',
|
name: 'Log',
|
||||||
icon_url: 'assets/icons/logs.svg',
|
icon_url: 'assets/icons/logs.svg',
|
||||||
link: '/log',
|
link: '/'+this.current_department+'/log',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
date = new Date();
|
date = new Date();
|
||||||
|
|
@ -37,7 +40,12 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
||||||
user: User | null = null;
|
user: User | null = null;
|
||||||
exit$ = new Subject<void>();
|
exit$ = new Subject<void>();
|
||||||
|
|
||||||
constructor(private _userService: UserService) {}
|
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private _userService: UserService,
|
||||||
|
private _router: ActivatedRoute
|
||||||
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this._userService.currentUser
|
this._userService.currentUser
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,13 @@ import {
|
||||||
} from '@angular/forms';
|
} from '@angular/forms';
|
||||||
import { forEach, isEqual, sortBy } from 'lodash';
|
import { forEach, isEqual, sortBy } from 'lodash';
|
||||||
import { first } from 'rxjs';
|
import { first } from 'rxjs';
|
||||||
|
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
||||||
import {
|
import {
|
||||||
RecipeDetail,
|
RecipeDetail,
|
||||||
RecipeDetailMat,
|
RecipeDetailMat,
|
||||||
} from 'src/app/core/models/recipe.model';
|
} from 'src/app/core/models/recipe.model';
|
||||||
import { RecipeService } from 'src/app/core/services/recipe.service';
|
import { RecipeService } from 'src/app/core/services/recipe.service';
|
||||||
|
import { UserService } from 'src/app/core/services/user.service';
|
||||||
import { Action, ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
|
import { Action, ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
@ -30,7 +32,8 @@ export class RecipeListComponent implements OnInit {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _recipeService: RecipeService,
|
private _recipeService: RecipeService,
|
||||||
private _formBuilder: FormBuilder
|
private _formBuilder: FormBuilder,
|
||||||
|
private _userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
recipeListForm = this._formBuilder.group(
|
recipeListForm = this._formBuilder.group(
|
||||||
|
|
@ -51,17 +54,17 @@ export class RecipeListComponent implements OnInit {
|
||||||
result.forEach((recipeDetailMat: RecipeDetailMat) => {
|
result.forEach((recipeDetailMat: RecipeDetailMat) => {
|
||||||
this.recipeListData.push(
|
this.recipeListData.push(
|
||||||
this._formBuilder.group({
|
this._formBuilder.group({
|
||||||
isUse: recipeDetailMat.isUse,
|
isUse: [{ value: recipeDetailMat.isUse, disabled: !this.isEditable()}],
|
||||||
materialPathId: recipeDetailMat.materialPathId,
|
materialPathId: [{value:recipeDetailMat.materialPathId, disabled: !this.isEditable()}],
|
||||||
name: [{ value: recipeDetailMat.name, disabled: true }],
|
name: [{ value: recipeDetailMat.name, disabled: true }],
|
||||||
mixOrder: recipeDetailMat.mixOrder,
|
mixOrder: [{ value:recipeDetailMat.mixOrder, disabled: !this.isEditable()}],
|
||||||
stirTime: recipeDetailMat.stirTime,
|
stirTime: [{value:recipeDetailMat.stirTime, disabled: !this.isEditable()}],
|
||||||
powderGram: recipeDetailMat.powderGram,
|
powderGram: [{value:recipeDetailMat.powderGram, disabled: !this.isEditable()}],
|
||||||
powderTime: recipeDetailMat.powderTime,
|
powderTime: [{value:recipeDetailMat.powderTime, disabled: !this.isEditable()}],
|
||||||
syrupGram: recipeDetailMat.syrupGram,
|
syrupGram: [{value:recipeDetailMat.syrupGram, disabled: !this.isEditable()}],
|
||||||
syrupTime: recipeDetailMat.syrupTime,
|
syrupTime: [{value: recipeDetailMat.syrupTime, disabled: !this.isEditable()}],
|
||||||
waterCold: recipeDetailMat.waterCold,
|
waterCold: [{value:recipeDetailMat.waterCold, disabled: !this.isEditable()}],
|
||||||
waterYield: recipeDetailMat.waterYield,
|
waterYield: [{value:recipeDetailMat.waterYield, disabled: !this.isEditable()}],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -99,4 +102,8 @@ export class RecipeListComponent implements OnInit {
|
||||||
get recipeListData(): FormArray {
|
get recipeListData(): FormArray {
|
||||||
return this.recipeListForm.get('recipeListData') as FormArray;
|
return this.recipeListForm.get('recipeListData') as FormArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isEditable(){
|
||||||
|
return this._userService.getCurrentUser()!.permissions.includes(UserPermissions.EDITOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -6,10 +6,12 @@ const (
|
||||||
ThaiPermission Permission = 1 << iota
|
ThaiPermission Permission = 1 << iota
|
||||||
MalayPermission
|
MalayPermission
|
||||||
AusPermission
|
AusPermission
|
||||||
|
Alpha3Permission
|
||||||
// NOTE: Add more permission here
|
// NOTE: Add more permission here
|
||||||
|
Viewer = 1 << 4
|
||||||
|
Editor = Viewer << 3
|
||||||
// SuperAdmin have max uint
|
// SuperAdmin have max uint
|
||||||
SuperAdmin = ThaiPermission | MalayPermission | AusPermission
|
SuperAdmin = ThaiPermission | MalayPermission | AusPermission | Alpha3Permission | (Editor | Viewer)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (userPermissions Permission) IsHavePermission(requiredPermissions Permission) bool {
|
func (userPermissions Permission) IsHavePermission(requiredPermissions Permission) bool {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue