add perm check
This commit is contained in:
parent
1ac38f26cb
commit
900127dd45
3 changed files with 52 additions and 4 deletions
|
|
@ -295,7 +295,16 @@
|
|||
>
|
||||
<!-- <div> Commit Message </div> -->
|
||||
<!-- <p class="text-2xl mr-8 text-gray-400 dark:text-gray-500">Commit Message</p> -->
|
||||
<input type="text" name="commit-message" id="commit-message" placeholder="Commit Message" class="input input-bordered mr-8 w-full max-w-xs" [value]="productCode" (keyup)="onKeyUpCommitMsg($event)"/>
|
||||
<input
|
||||
type="text"
|
||||
name="commit-message"
|
||||
id="commit-message"
|
||||
placeholder="Commit Message"
|
||||
class="input input-bordered mr-8 w-full max-w-xs"
|
||||
[value]="productCode"
|
||||
(keyup)="onKeyUpCommitMsg($event)"
|
||||
[disabled]="!isEditable()"
|
||||
/>
|
||||
<button
|
||||
(click)="onPressConfirmClose()"
|
||||
class="btn btn-error w-36 text-white mr-2"
|
||||
|
|
@ -305,7 +314,7 @@
|
|||
<button
|
||||
(click)="onPressConfirmSave()"
|
||||
class="btn btn-success w-36 text-white"
|
||||
[disabled]="!isValueChanged"
|
||||
[disabled]="!isValueChanged || !isEditable()"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import {
|
|||
} from 'src/app/core/models/recipe.model';
|
||||
import { ActionRecord } from 'src/app/shared/actionRecord/actionRecord';
|
||||
import { UserService } from 'src/app/core/services/user.service';
|
||||
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
||||
|
||||
@Component({
|
||||
selector: 'app-recipe-details',
|
||||
|
|
@ -201,4 +202,8 @@ export class RecipeDetailsComponent implements OnInit {
|
|||
this.repl = repl as never[];
|
||||
this.isValueChanged ||= repl != undefined;
|
||||
}
|
||||
|
||||
isEditable(){
|
||||
return this._userService.getCurrentUser()!.permissions.includes(UserPermissions.EDITOR);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import { ActivatedRoute, RouterLink } from '@angular/router';
|
|||
import { NgSelectModule } from '@ng-select/ng-select';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MaterialService } from 'src/app/core/services/material.service';
|
||||
import { UserService } from 'src/app/core/services/user.service';
|
||||
import { UserPermissions } from 'src/app/core/auth/userPermissions';
|
||||
|
||||
@Component({
|
||||
selector: 'app-recipes',
|
||||
|
|
@ -116,6 +118,7 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
|||
private _recipeService: RecipeService,
|
||||
private _materialService: MaterialService,
|
||||
private route: ActivatedRoute,
|
||||
private _userService: UserService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
|
@ -257,8 +260,21 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
|||
this.currentCountryFilterSubScription = this.currentCountryFilter.subscribe(
|
||||
(c) => {
|
||||
const countries = this._recipeService.getRecipeFileCountries();
|
||||
if (countries.length > 0) {
|
||||
this.recipeCountryFiltered = lodash.filter(countries, (country) =>
|
||||
|
||||
// do perms
|
||||
let accessibleCountries = [];
|
||||
|
||||
for(let country of countries){
|
||||
if(this.grantAccessCountry(country)){
|
||||
accessibleCountries.push(country);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
console.log('granted accessible countries', accessibleCountries);
|
||||
|
||||
if (accessibleCountries.length > 0) {
|
||||
this.recipeCountryFiltered = lodash.filter(accessibleCountries, (country) =>
|
||||
country.toLowerCase().includes(c.toLowerCase())
|
||||
);
|
||||
}
|
||||
|
|
@ -266,6 +282,24 @@ export class RecipesComponent implements OnInit, OnDestroy {
|
|||
);
|
||||
}
|
||||
|
||||
// Grant access to view a country recipe
|
||||
grantAccessCountry(countryName: string):boolean{
|
||||
if(countryName.toLowerCase().startsWith("tha")
|
||||
&& this._userService.getCurrentUser()!.permissions.includes(UserPermissions.THAI_PERMISSION)){
|
||||
return true;
|
||||
} else if (countryName.toLowerCase().startsWith("aus")
|
||||
&& this._userService.getCurrentUser()!.permissions.includes(UserPermissions.AUS_PERMISSION)){
|
||||
return true;
|
||||
} else if (countryName.toLowerCase().startsWith("malay")
|
||||
&& this._userService.getCurrentUser()!.permissions.includes(UserPermissions.MALAY_PERMISSION)){
|
||||
return true;
|
||||
} else if (countryName.toLowerCase().startsWith("alpha-3")
|
||||
&& this._userService.getCurrentUser()!.permissions.includes(UserPermissions.ALPHA3_PERMISSION)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getRecipeFiles() {
|
||||
this.currentFileFilterSubScription = this.currentFileFilter.subscribe(
|
||||
(c) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue