Skip to content

Commit

Permalink
feat: Add deny delete menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Dec 12, 2023
1 parent 405341f commit 2fcee95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type General struct {
DefaultLoginPwd string `default:"6351623c8cef86fefabfa7da046fc619"` // abc-123
WorkDir string // From command arguments
MenuFile string // From schema.Menus (JSON/YAML)
DenyDeleteMenu bool
HTTP struct {
Addr string `default:":8080"`
ShutdownTimeout int `default:"10"` // seconds
Expand Down
5 changes: 5 additions & 0 deletions internal/mods/rbac/biz/menu.biz.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/LyricTian/gin-admin/v10/internal/config"
"github.com/LyricTian/gin-admin/v10/internal/mods/rbac/dal"
"github.com/LyricTian/gin-admin/v10/internal/mods/rbac/schema"
"github.com/LyricTian/gin-admin/v10/pkg/encoding/json"
Expand Down Expand Up @@ -440,6 +441,10 @@ func (a *Menu) Update(ctx context.Context, id string, formItem *schema.MenuForm)

// Delete the specified menu from the data access object.
func (a *Menu) Delete(ctx context.Context, id string) error {
if config.C.General.DenyDeleteMenu {
return errors.BadRequest("", "Menu deletion is not allowed")
}

menu, err := a.MenuDAL.Get(ctx, id)
if err != nil {
return err
Expand Down

0 comments on commit 2fcee95

Please sign in to comment.