diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index 8a37a05..c9252c8 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts @@ -1,4 +1,4 @@ -import { inject, NgModule } from '@angular/core'; +import { inject, NgModule } from "@angular/core"; import { ActivatedRouteSnapshot, CanActivateFn, @@ -6,14 +6,14 @@ import { RouterModule, RouterStateSnapshot, Routes, -} from '@angular/router'; -import { UserService } from './core/services/user.service'; -import { map } from 'rxjs'; -import { UserPermissions } from './core/auth/userPermissions'; +} from "@angular/router"; +import { UserService } from "./core/services/user.service"; +import { map } from "rxjs"; +import { UserPermissions } from "./core/auth/userPermissions"; const authGuard: CanActivateFn = ( route: ActivatedRouteSnapshot, - state: RouterStateSnapshot + state: RouterStateSnapshot, ) => { const userService: UserService = inject(UserService); const router: Router = inject(Router); @@ -23,12 +23,12 @@ const authGuard: CanActivateFn = ( if (isAuth) { return true; } - return router.createUrlTree(['/login'], { + return router.createUrlTree(["/login"], { queryParams: { redirectUrl: state.url, }, }); - }) + }), ); }; @@ -42,21 +42,23 @@ const permissionsGuard: ( const user = userService.getCurrentUser(); if (user == null) - return router.createUrlTree(['/login'], { + return router.createUrlTree(["/login"], { queryParams: { redirectUrl: state.url, }, }); + console.log("require following permissions", requiredPermissions); + if ( requiredPermissions.every((permission) => - user.permissions.includes(permission) + user.permissions.includes(permission), ) ) { return true; } - return router.createUrlTree(['/unauthorized'], { + return router.createUrlTree(["/unauthorized"], { queryParams: { redirectUrl: state.url, }, @@ -73,47 +75,47 @@ const loginGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => { return true; } // redirect to redirectUrl query param - console.log("redirectURL", route.queryParams['redirectUrl']); + console.log("redirectURL", route.queryParams["redirectUrl"]); return router.createUrlTree([ - router.parseUrl(route.queryParams['redirectUrl'] ?? 'departments'), + router.parseUrl(route.queryParams["redirectUrl"] ?? "departments"), ]); // return false; - }) + }), ); }; const routes: Routes = [ { - path: 'login', + path: "login", loadComponent: () => - import('./core/auth/auth.component').then((m) => m.AuthComponent), + import("./core/auth/auth.component").then((m) => m.AuthComponent), canActivate: [loginGuard], }, { - path: 'callback', + path: "callback", loadComponent: () => - import('./core/callback/callback.component').then( - (m) => m.CallbackComponent + import("./core/callback/callback.component").then( + (m) => m.CallbackComponent, ), }, { - path: 'departments', + path: "departments", loadComponent: () => - import('./core/department/department.component').then( - (m) => m.DepartmentComponent + import("./core/department/department.component").then( + (m) => m.DepartmentComponent, ), canActivate: [authGuard], }, { - path: ':department', + path: ":department", loadComponent: () => - import('./core/layout/layout.component').then((m) => m.LayoutComponent), + import("./core/layout/layout.component").then((m) => m.LayoutComponent), children: [ { - path: 'recipes', + path: "recipes", loadComponent: () => - import('./features/recipes/recipes.component').then( - (m) => m.RecipesComponent + import("./features/recipes/recipes.component").then( + (m) => m.RecipesComponent, ), canActivate: [ authGuard, @@ -121,10 +123,10 @@ const routes: Routes = [ ], }, { - path: 'recipe/:productCode', + path: "recipe/:productCode", loadComponent: () => import( - './features/recipes/recipe-details/recipe-details.component' + "./features/recipes/recipe-details/recipe-details.component" ).then((m) => m.RecipeDetailsComponent), canActivate: [ authGuard, @@ -132,38 +134,38 @@ const routes: Routes = [ ], }, { - path: 'log', + path: "log", loadComponent: () => - import('./features/changelog/changelog.component').then( - (m) => m.ChangelogComponent + import("./features/changelog/changelog.component").then( + (m) => m.ChangelogComponent, ), }, { - path: 'materials', + path: "materials", loadComponent: () => import( - './features/material-settings/material-settings.component' + "./features/material-settings/material-settings.component" ).then((m) => m.MaterialSettingsComponent), }, { - path: 'toppings', + path: "toppings", loadComponent: () => - import('./features/toppings/toppings.component').then( - (t) => t.ToppingsComponent + import("./features/toppings/toppings.component").then( + (t) => t.ToppingsComponent, ), }, ], }, { - path: '', - pathMatch: 'full', - redirectTo: 'departments', + path: "", + pathMatch: "full", + redirectTo: "departments", }, { - path: 'unauthorized', + path: "unauthorized", loadComponent: () => - import('./core/auth/unauthorized.component').then( - (m) => m.UnauthorizedComponent + import("./core/auth/unauthorized.component").then( + (m) => m.UnauthorizedComponent, ), }, // { @@ -172,8 +174,8 @@ const routes: Routes = [ // import('./core/notfound.component').then((m) => m.NotfoundComponent), // }, { - path: '**', - redirectTo: 'departments', + path: "**", + redirectTo: "departments", }, ]; diff --git a/client/src/app/core/auth/userPermissions.ts b/client/src/app/core/auth/userPermissions.ts index 78b2a18..7935d40 100644 --- a/client/src/app/core/auth/userPermissions.ts +++ b/client/src/app/core/auth/userPermissions.ts @@ -8,13 +8,28 @@ export enum UserPermissions { VIEWER = 1 << 4, EDITOR = 1 << 7, + DUBAI_PERMISSION = 1 << 8, + COUNTER_PERMISSION = 1 << 9, + SINGAPORE_PERMISSION = 1 << 10, + COCKTAIL_PERMISSION = 1 << 11, + // add new permission by shifting after 7. eg. 8,9,... // also do add at server - SUPER_ADMIN_PERMISSION = THAI_PERMISSION | MALAY_PERMISSION | AUS_PERMISSION | ALPHA3_PERMISSION | (EDITOR | VIEWER) + SUPER_ADMIN_PERMISSION = THAI_PERMISSION | + MALAY_PERMISSION | + AUS_PERMISSION | + ALPHA3_PERMISSION | + COUNTER_PERMISSION | + SINGAPORE_PERMISSION | + DUBAI_PERMISSION | + COCKTAIL_PERMISSION | + (EDITOR | VIEWER), } -export function getPermissions(perms: number) : UserPermissions[] { - return Object.values(UserPermissions) - .filter(permission => typeof permission === 'number' && (perms & permission) !== 0) as UserPermissions[]; +export function getPermissions(perms: number): UserPermissions[] { + return Object.values(UserPermissions).filter( + (permission) => + typeof permission === "number" && (perms & permission) !== 0, + ) as UserPermissions[]; } diff --git a/client/src/app/core/callback/callback.component.ts b/client/src/app/core/callback/callback.component.ts index 8f6986d..e485f17 100644 --- a/client/src/app/core/callback/callback.component.ts +++ b/client/src/app/core/callback/callback.component.ts @@ -1,37 +1,42 @@ -import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; -import { UserService } from '../services/user.service'; -import {getPermissions} from "../auth/userPermissions"; +import { Component, OnInit } from "@angular/core"; +import { ActivatedRoute, Router } from "@angular/router"; +import { UserService } from "../services/user.service"; +import { getPermissions } from "../auth/userPermissions"; @Component({ - selector: 'app-callback', + selector: "app-callback", standalone: true, - templateUrl: './callback.component.html', + templateUrl: "./callback.component.html", }) export class CallbackComponent implements OnInit { constructor( private route: ActivatedRoute, private router: Router, - private userService: UserService + private userService: UserService, ) {} ngOnInit(): void { this.route.queryParams.subscribe((params) => { - console.log(params); + console.log(params, params["permissions"]); - if (params['email'] && params['name'] && params['picture'] && params['permissions']) { + if ( + params["email"] && + params["name"] && + params["picture"] && + params["permissions"] + ) { this.userService.setAuth({ - email: params['email'], - name: params['name'], - picture: params['picture'], - permissions: getPermissions(params['permissions']), + email: params["email"], + name: params["name"], + picture: params["picture"], + permissions: getPermissions(params["permissions"]), }); } - if (params['redirect_to']) { - void this.router.navigate([params['redirect_to']]); + if (params["redirect_to"]) { + void this.router.navigate([params["redirect_to"]]); } else { - void this.router.navigate(['/']); + void this.router.navigate(["/"]); } }); } diff --git a/client/src/app/core/department/department.component.ts b/client/src/app/core/department/department.component.ts index 9958071..d74dcb0 100644 --- a/client/src/app/core/department/department.component.ts +++ b/client/src/app/core/department/department.component.ts @@ -1,11 +1,11 @@ -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'; -import { NotFoundHandler } from 'src/app/shared/helpers/notFoundHandler'; -import { AsyncStorage } from 'src/app/shared/helpers/asyncStorage'; -import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe'; +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"; +import { NotFoundHandler } from "src/app/shared/helpers/notFoundHandler"; +import { AsyncStorage } from "src/app/shared/helpers/asyncStorage"; +import { getCountryMapSwitcher } from "src/app/shared/helpers/recipe"; @Component({ standalone: true, @@ -56,33 +56,43 @@ import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe'; `, }) - - export class DepartmentComponent { - acccessibleCountries:string[] = []; + acccessibleCountries: string[] = []; // top row country countries: { id: string; img: string }[] = [ { - id: 'tha', - img: 'assets/departments/tha_plate.png', + id: "tha", + img: "assets/departments/tha_plate.png", }, { - id: 'mys', - img: 'assets/departments/mys_plate.png', + id: "mys", + img: "assets/departments/mys_plate.png", }, { - id: 'aus', - img: 'assets/departments/aus_plate.png', + id: "aus", + img: "assets/departments/aus_plate.png", }, // add new country here! + { + id: "sgp", + img: "assets/departments/sgp_plate.png", + }, + { + id: "counter", + img: "assets/departments/counter01_plate.png", + }, ]; // bottom row country alphas: { id: string; img: string }[] = [ { - id: 'alpha-3', - img: 'assets/departments/alpha-3.png', + id: "alpha-3", + img: "assets/departments/alpha-3.png", + }, + { + id: "cocktail", + img: "assets/departments/cocktail_tha.png", }, ]; @@ -91,45 +101,66 @@ export class DepartmentComponent { constructor( private router: Router, - private _userService: UserService + private _userService: UserService, ) { let perms = _userService.getCurrentUser()!.permissions; - console.log("GainAccesses",perms) + console.log("GainAccesses", perms); for (let perm of perms) { switch (perm) { case UserPermissions.THAI_PERMISSION: - this.acccessibleCountries.push('tha'); + this.acccessibleCountries.push("tha"); break; case UserPermissions.MALAY_PERMISSION: - this.acccessibleCountries.push('mys'); + this.acccessibleCountries.push("mys"); break; case UserPermissions.AUS_PERMISSION: - this.acccessibleCountries.push('aus'); + this.acccessibleCountries.push("aus"); break; case UserPermissions.ALPHA3_PERMISSION: - this.acccessibleCountries.push('alpha-3'); + this.acccessibleCountries.push("alpha-3"); + break; + case UserPermissions.SINGAPORE_PERMISSION: + this.acccessibleCountries.push("sgp"); + break; + case UserPermissions.COUNTER_PERMISSION: + this.acccessibleCountries.push("counter"); + break; + case UserPermissions.DUBAI_PERMISSION: + this.acccessibleCountries.push("dubai"); + break; + case UserPermissions.COCKTAIL_PERMISSION: + this.acccessibleCountries.push("cocktail"); break; default: break; } } + + console.log("OK", this.acccessibleCountries); } onClick(id: string) { // add handler for redirect - this.notfoundHandler.handleSwitchCountry(id, async () => { - // set country - await AsyncStorage.setItem('currentRecipeCountry', getCountryMapSwitcher(id)); - // set filename, don't know which file was a target so use default - await AsyncStorage.setItem('currentRecipeFile', 'default'); - }, async () => { - // set country to `tha` - await AsyncStorage.setItem('currentRecipeCountry', 'Thailand'); - // set filename, don't know which file was a target so use default - await AsyncStorage.setItem('currentRecipeFile', 'default'); - // safely return to recipes - }); + this.notfoundHandler.handleSwitchCountry( + id, + async () => { + // set country + await AsyncStorage.setItem( + "currentRecipeCountry", + getCountryMapSwitcher(id), + ); + // set filename, don't know which file was a target so use default + await AsyncStorage.setItem("currentRecipeFile", "default"); + }, + async () => { + // set country to `tha` + await AsyncStorage.setItem("currentRecipeCountry", "Thailand"); + // set filename, don't know which file was a target so use default + await AsyncStorage.setItem("currentRecipeFile", "default"); + // safely return to recipes + }, + ); void this.router.navigate([`/${id}/recipes`]); } } diff --git a/client/src/app/shared/helpers/debugger.ts b/client/src/app/shared/helpers/debugger.ts index ed5818b..3ee9194 100644 --- a/client/src/app/shared/helpers/debugger.ts +++ b/client/src/app/shared/helpers/debugger.ts @@ -133,7 +133,6 @@ export class Debugger { } }); break; - default: if(cmd.startsWith("fn::")){ @@ -204,6 +203,23 @@ export class Debugger { } else if(cmd.startsWith("var::")){ let varname = cmd.substring(5); this.output.push(JSON.stringify(holdon[varname])); + } else if(cmd.startsWith("load::")){ + + } else { + // assume varname + + + if(cmd.endsWith("#window")){ + let exposed: string = cmd.split(" ")[0]; + console.log("try exposed to window "+exposed); + let estr = "window."+exposed+" = \""+holdon[exposed]+"\""; + console.log("estr", estr); + let eval_res = eval(estr); + console.log("eval_res", eval_res); + this.output.push(JSON.stringify(eval_res)); + } else { + this.output.push(JSON.stringify(holdon[cmd])); + } } break; @@ -217,9 +233,9 @@ export class Debugger { } } else if (!line.startsWith("//") && line != ""){ - if(!line.startsWith("window") && !line.startsWith("let") && !line.startsWith("var")){ - line = "window."+line; - } + // if(!line.startsWith("window") && !line.startsWith("let") && !line.startsWith("var")){ + // line = "window."+line; + // } try { diff --git a/client/src/app/shared/helpers/notFoundHandler.ts b/client/src/app/shared/helpers/notFoundHandler.ts index 79f540d..2f1c059 100644 --- a/client/src/app/shared/helpers/notFoundHandler.ts +++ b/client/src/app/shared/helpers/notFoundHandler.ts @@ -4,7 +4,10 @@ export function departmentList() { 'tha', 'mys', 'aus', - 'alpha-3' + 'alpha-3', + 'sgp', + 'dubai', + 'counter' ]; } @@ -28,7 +31,16 @@ export class NotFoundHandler { handleSwitchCountry(country: string, callback: () => Promise, error?: () => Promise) { let checkCondition = departmentList().includes(country); if(checkCondition) { - callback(); + // callback(); + Promise.allSettled([ + Promise.resolve(callback()) + ]).then((results) => { + // console.log("Resolved callback: ",results) + if(results[0].status == 'fulfilled'){ + console.info("Callback executed successfully"); + } + }); + } else { if(error) error(); diff --git a/client/src/app/shared/helpers/recipe.ts b/client/src/app/shared/helpers/recipe.ts index 073276f..098556d 100644 --- a/client/src/app/shared/helpers/recipe.ts +++ b/client/src/app/shared/helpers/recipe.ts @@ -114,6 +114,9 @@ export var countryMap: Tuple[] = [ new Tuple('tha', 'Thailand'), new Tuple('mys', 'Malaysia'), new Tuple('aus', 'Australia'), + new Tuple('sgp', 'Singapore'), + new Tuple('dubai', 'UAE Dubai'), + new Tuple('counter', 'Counter') ]; export function getCountryMapSwitcher(param: string) { diff --git a/client/src/environments/environment.development.ts b/client/src/environments/environment.development.ts index dd9d9ef..b207d5b 100644 --- a/client/src/environments/environment.development.ts +++ b/client/src/environments/environment.development.ts @@ -1,4 +1,5 @@ export const environment = { production: false, - api: 'http://localhost:8080', + api: "http://localhost:8080", + imgApi: "http://localhost:36527", }; diff --git a/client/src/environments/environment.ts b/client/src/environments/environment.ts index 16ac628..3ebd6d0 100644 --- a/client/src/environments/environment.ts +++ b/client/src/environments/environment.ts @@ -1,4 +1,5 @@ export const environment = { production: true, - api: 'https://recipe.taobin.io:8090/api', + api: "https://recipe.taobin.io:8090/api", + imgApi: "https://recipe.taobin.io:8090/img", }; diff --git a/server/country.settings.json b/server/country.settings.json index 63b9053..f9fce2d 100644 --- a/server/country.settings.json +++ b/server/country.settings.json @@ -1,44 +1,56 @@ [ - { - "ignore": true, - "name": "New Country in full name", - "short": "Short name", - "permissions": "use number after 128, do not use 16 and 128" - }, - { - "name": "Thailand", - "short": "tha", - "permissions": 1, - "dir": "tha" - }, - { - "name": "Malaysia", - "short": "mys", - "permissions": 2, - "dir": "mys" - }, - { - "name": "Australia", - "short": "aus", - "permissions": 4, - "dir": "aus" - }, - { - "name": "Alpha3", - "short": "alpha-3", - "permissions": 8, - "dir": "alpha-3" - }, - { - "name": "UAE Dubai", - "short": "uae-dubai", - "permissions": 256, - "dir": "dubai" - }, - { - "name": "Counter Cafe", - "short": "counter", - "permissions": 512, - "dir": "counter" - } -] \ No newline at end of file + { + "ignore": true, + "name": "New Country in full name", + "short": "Short name", + "permissions": "use number after 128, do not use 16 and 128" + }, + { + "name": "Thailand", + "short": "tha", + "permissions": 1, + "dir": "tha" + }, + { + "name": "Malaysia", + "short": "mys", + "permissions": 2, + "dir": "mys" + }, + { + "name": "Australia", + "short": "aus", + "permissions": 4, + "dir": "aus" + }, + { + "name": "Alpha3", + "short": "alpha-3", + "permissions": 8, + "dir": "alpha-3" + }, + { + "name": "UAE Dubai", + "short": "uae-dubai", + "permissions": 256, + "dir": "dubai" + }, + { + "name": "Counter Cafe", + "short": "counter", + "permissions": 512, + "dir": "counter01" + }, + { + "name": "Singapore", + "short": "sgp", + "permissions": 1024, + "dir": "sgp" + }, + { + "name": "Cocktail", + "short": "cocktail", + "permissions": 2048, + "dir": "cocktail_tha" + } +] diff --git a/server/data/data.go b/server/data/data.go index ebf4756..b44fd4a 100644 --- a/server/data/data.go +++ b/server/data/data.go @@ -183,6 +183,22 @@ var ( CountryID: "aus", CountryName: "Australia", }, + { + CountryID: "dubai", + CountryName: "UAE Dubai", + }, + { + CountryID: "counter01", + CountryName: "Counter Cafe", + }, + { + CountryID: "sgp", + CountryName: "Singapore", + }, + { + CountryID: "cocktail_tha", + CountryName: "Cocktail", + }, } ) @@ -304,6 +320,8 @@ func NewData(taoLogger *logger.TaoLogger, redisClient *RedisCli) *Data { // log.Panic("Error when read default recipe file:", err) // } + fmt.Println(CurrentCountryIDMap) + return &Data{ CurrentFile: currentFileMap, CurrentCountryID: CurrentCountryIDMap, @@ -1178,9 +1196,11 @@ func (d *Data) GetSubmenusOfRecipe(countryID, filename, productCode string) ([]m func (d *Data) GetCountryNameByID(countryID string) (string, error) { for _, country := range d.Countries { if country.CountryID == countryID { + fmt.Println("Found " + countryID) return country.CountryName, nil } } + fmt.Println("Not found " + countryID) return "", fmt.Errorf("country ID: %s not found", countryID) } diff --git a/server/data/database.db b/server/data/database.db index dbb70d0..756734a 100644 Binary files a/server/data/database.db and b/server/data/database.db differ diff --git a/server/git_recipe_worker.go b/server/git_recipe_worker.go index 5350211..0f20964 100644 --- a/server/git_recipe_worker.go +++ b/server/git_recipe_worker.go @@ -2,7 +2,6 @@ package main import ( "context" - "fmt" "os/exec" "time" ) @@ -31,7 +30,7 @@ func RunGitRecipeWorker() { for { err := pull_request() if err != nil { - fmt.Println(err) + //fmt.Println(err) } time.Sleep(10 * time.Minute) } diff --git a/server/helpers/filereader.go b/server/helpers/filereader.go index 8715551..a7916d5 100644 --- a/server/helpers/filereader.go +++ b/server/helpers/filereader.go @@ -140,20 +140,20 @@ type CountryNamePerms struct { func LoadCountrySettingsWithPermissions() []CountryNamePerms { res := make([]CountryNamePerms, 0) - path, err := os.Getwd() - if err != nil { - log.Println(err) - } - fmt.Println(path) + // path, err := os.Getwd() + // if err != nil { + // log.Println(err) + // } + // fmt.Println(path) - files, err := os.ReadDir(path) - if err != nil { - log.Fatalln(err) - } + // files, err := os.ReadDir(path) + // if err != nil { + // log.Fatalln(err) + // } - for _, file := range files { - fmt.Println(file.Name(), file.IsDir()) - } + // for _, file := range files { + // fmt.Println(file.Name(), file.IsDir()) + // } // read file country.settings.json content, err := os.Open("./country.settings.json") diff --git a/server/middlewares/authorized.go b/server/middlewares/authorized.go index 08c5110..bd0f689 100644 --- a/server/middlewares/authorized.go +++ b/server/middlewares/authorized.go @@ -88,6 +88,7 @@ func ValidatePermissions(p []permissions.Permission, nextRoute http.HandlerFunc) for _, pm := range p { if !u.Permissions.IsHavePermission(pm) { // If not have permission response unauthorized + fmt.Println("tried access " + fmt.Sprintf("%v", pm)) w.WriteHeader(http.StatusUnauthorized) err := json.NewEncoder(w).Encode("Unauthorized") if err != nil { @@ -106,6 +107,7 @@ func ValidateOwnerOrPermissions(p []permissions.Permission, nextRoute http.Handl reqUserID := chi.URLParam(r, "id") u := r.Context().Value("user").(*models.User) + fmt.Println(u) if reqUserID == "" { // If not have permission response unauthorized w.WriteHeader(http.StatusUnauthorized) diff --git a/server/routers/recipe.go b/server/routers/recipe.go index f9e8e49..3628491 100644 --- a/server/routers/recipe.go +++ b/server/routers/recipe.go @@ -155,6 +155,7 @@ func (rr *RecipeRouter) Route(r chi.Router) { for k := range rr.data.AllRecipeFiles { countryName, err := rr.data.GetCountryNameByID(k) if err != nil { + rr.taoLogger.Log.Error("RecipeRouter.Countries", zap.Any(countryName, err)) continue } keys = append(keys, countryName) @@ -854,7 +855,7 @@ func (rr *RecipeRouter) getImageOfProductCode(w http.ResponseWriter, r *http.Req http.Error(w, err.Error(), http.StatusNotFound) } - rr.taoLogger.Log.Debug("GetImageFromFast", zap.Int("Code", resp.StatusCode)); + rr.taoLogger.Log.Debug("GetImageFromFast", zap.Int("Code", resp.StatusCode)) img_data, err := png.Decode(resp.Body) if err != nil { @@ -864,7 +865,6 @@ func (rr *RecipeRouter) getImageOfProductCode(w http.ResponseWriter, r *http.Req imgResult = img_data - // write image png.Encode(w, imgResult) } diff --git a/server/routers/user.go b/server/routers/user.go index ab6b492..2cb4474 100644 --- a/server/routers/user.go +++ b/server/routers/user.go @@ -34,6 +34,10 @@ func (ur *UserRouter) Route(r chi.Router) { superPerm = superPerm | p.CountryPermission } + if superPerm < 3999 { + superPerm = superPerm | permissions.Editor | permissions.Viewer + } + // Users r.Route("/users", func(r chi.Router) { r.Get("/", middlewares.ValidatePermissions([]permissions.Permission{permissions.Permission(superPerm)}, ur.getUsers)) diff --git a/server/server.go b/server/server.go index bc21253..252ceeb 100644 --- a/server/server.go +++ b/server/server.go @@ -100,6 +100,9 @@ func (s *Server) createHandler() { for _, p := range perms { superPerm = superPerm | p.CountryPermission } + if superPerm < 3999 { + superPerm = superPerm | permissions.Editor | permissions.Viewer + } // Seed _ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "kenta420", "poomipat.c@forth.co.th", "", permissions.Permission(superPerm)) diff --git a/server/services/logger/logger.go b/server/services/logger/logger.go index 1681fdb..ecb3d56 100644 --- a/server/services/logger/logger.go +++ b/server/services/logger/logger.go @@ -22,6 +22,7 @@ func (tl *TaoLogger) initConfig() *zap.Logger { productionConfig := zap.NewProductionEncoderConfig() productionConfig.EncodeTime = zapcore.ISO8601TimeEncoder + productionConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder // fileEncoder := zapcore.NewJSONEncoder(productionConfig) consoleEncoder := zapcore.NewConsoleEncoder(productionConfig)