fix(permission): ✨ change permission checking
read permissions from settings.json instead
This commit is contained in:
parent
8744ddcb8c
commit
cd0f67bb44
6 changed files with 128 additions and 60 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"recipe-manager/config"
|
||||
"recipe-manager/data"
|
||||
"recipe-manager/enums/permissions"
|
||||
"recipe-manager/helpers"
|
||||
"recipe-manager/middlewares"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/routers"
|
||||
|
|
@ -90,12 +91,19 @@ func (s *Server) createHandler() {
|
|||
// User Service
|
||||
userService := user.NewUserService(s.cfg, s.database, s.taoLogger)
|
||||
|
||||
// Generate SuperAdmin permissions for seed
|
||||
perms := helpers.LoadCountrySettingsWithPermissions()
|
||||
superPerm := perms[0].CountryPermission
|
||||
for _, p := range perms {
|
||||
superPerm = superPerm | p.CountryPermission
|
||||
}
|
||||
|
||||
// Seed
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "kenta420", "poomipat.c@forth.co.th", "", permissions.SuperAdmin)
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "phu", "pakin.t@forth.co.th", "", permissions.SuperAdmin)
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "wanlop", "wanlop.r@forth.co.th", "", permissions.SuperAdmin)
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "dawit", "dawit.o@forth.co.th", "", permissions.SuperAdmin)
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "narisara", "narisara.k@tao-bin.com", "", permissions.SuperAdmin)
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "kenta420", "poomipat.c@forth.co.th", "", permissions.Permission(superPerm))
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "phu", "pakin.t@forth.co.th", "", permissions.Permission(superPerm))
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "wanlop", "wanlop.r@forth.co.th", "", permissions.Permission(superPerm))
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "dawit", "dawit.o@forth.co.th", "", permissions.Permission(superPerm))
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "narisara", "narisara.k@tao-bin.com", "", permissions.Permission(superPerm))
|
||||
|
||||
// Auth Router
|
||||
r.Group(func(r chi.Router) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue