Skip to content

Commit

Permalink
Merge pull request #39 from nicelizhi/dev-1.2.0
Browse files Browse the repository at this point in the history
Dev 1.2.0
  • Loading branch information
xxl4 authored Nov 7, 2023
2 parents 4a71711 + 1ed0af0 commit 225c139
Show file tree
Hide file tree
Showing 31 changed files with 977 additions and 107 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/mirror.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'GitHub Actions Mirror'

on: [push, delete]

jobs:
mirror_to_gitee:
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v1
- name: 'Mirror to gitee'
uses: pixta-dev/repository-mirroring-action@v1
with:
target_repo_url:
[email protected]:nicelizhi/easy-admin.git
ssh_private_key:
${{ secrets.GITEE_KEY }}
45 changes: 41 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,63 @@
export PATH := $(GOPATH)/bin:$(PATH)
export GO111MODULE=on
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOCLEAN=$(GOCMD) clean
GOGET=$(GOCMD) get
LDFLAGS := -s -w
# application name
PROJECT:=easy-admin

# application version
VERSION := 1.2.0
# application url
URL := https://github.com/nicelizhi/easy-admin

.PHONY: build

all:
make build-ui
make build

# build vue ui
build-ui:
@echo "build node start"
cd ./ui/ && npm run build:prod

# build go application
build:
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -a -installsuffix "" -o easy-admin .
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -a -installsuffix "" -o $(PROJECT) .

# make build-linux
build-linux:
@docker build -t easy-admin:latest .
make build-ui
make build
@docker build -t $(PROJECT):$(VERSION) .
@echo "build successful"

# build sql go application version
build-sqlite:
go build -tags sqlite3 -ldflags="$(LDFLAGS)" -a -installsuffix -o easy-admin .
go build -tags sqlite3 -ldflags="$(LDFLAGS)" -a -installsuffix -o $(PROJECT) .

clean:
$(GOCLEAN)
rm ./$(PROJECT)

test:
$(GOTEST)

restart:
make stop
make start

.PHONY: start
start:
nohup ./$(PROJECT) server -c=config/settings.dev_steve.yml >> acc.txt &
ps aux | grep "$(PROJECT)"

stop:
pkill $(PROJECT)

# debug file
debug:
dlv debug $(file)
3 changes: 1 addition & 2 deletions app/admin/apis/go_admin.go → app/admin/apis/easy_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"github.com/gin-gonic/gin"
)

func GoAdmin(c *gin.Context) {
func EasyAdminStart(c *gin.Context) {
c.Header("Content-Type", "text/html; charset=utf-8")
c.String(200, string(resource.Html))
}

func Favicon(c *gin.Context) {
//c.Header("Content-Type", "text/html; charset=utf-8")
c.String(200, string(resource.Favicon))
}
8 changes: 5 additions & 3 deletions app/admin/models/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package models

import (
"time"

"gorm.io/plugin/soft_delete"
)

type BaseModel struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt soft_delete.DeletedAt `json:"deletedAt"`
}
2 changes: 1 addition & 1 deletion app/admin/router/sys_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func sysBaseRouter(r *gin.RouterGroup) {
go ws.WebsocketManager.SendAllService()

if config.ApplicationConfig.Mode != "prod" {
r.GET("/", apis.GoAdmin)
r.GET("/", apis.EasyAdminStart)

r.GET("/favicon.ico", apis.Favicon)
r.StaticFS("/css", http.FS(CssResource()))
Expand Down
4 changes: 2 additions & 2 deletions app/admin/service/sys_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (e *SysApi) Update(c *dto.SysApiUpdateReq, p *actions.DataPermission) error
var model = models.SysApi{}
db := e.Orm.Debug().First(&model, c.GetId())
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")
}
c.Generate(&model)
db = e.Orm.Save(&model)
Expand All @@ -104,7 +104,7 @@ func (e *SysApi) Remove(d *dto.SysApiDeleteReq, p *actions.DataPermission) error
return err
}
if db.RowsAffected == 0 {
return errors.New("无权删除该数据")
return errors.New("no right to delete this data")
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions app/admin/service/sys_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (e *SysConfig) Update(c *dto.SysConfigControl) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")

}
return nil
Expand All @@ -94,7 +94,7 @@ func (e *SysConfig) SetSysConfig(c *[]dto.GetSetSysConfigReq) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")
}
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func (e *SysConfig) Remove(d *dto.SysConfigDeleteReq) error {
return err
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
err = errors.New("no right to delete this data")
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions app/admin/service/sys_dept.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (e *SysDept) Update(c *dto.SysDeptUpdateReq) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")
}
return nil
}
Expand All @@ -139,7 +139,7 @@ func (e *SysDept) Remove(d *dto.SysDeptDeleteReq) error {
return err
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
err = errors.New("no right to delete this data")
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions app/admin/service/sys_dict_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (e *SysDictData) Update(c *dto.SysDictDataUpdateReq) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")

}
return nil
Expand All @@ -98,7 +98,7 @@ func (e *SysDictData) Remove(c *dto.SysDictDataDeleteReq) error {
return err
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
err = errors.New("no right to delete this data")
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions app/admin/service/sys_dict_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (e *SysDictType) Update(c *dto.SysDictTypeUpdateReq) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")

}
return nil
Expand All @@ -102,7 +102,7 @@ func (e *SysDictType) Remove(d *dto.SysDictTypeDeleteReq) error {
return err
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
err = errors.New("no right to delete this data")
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion app/admin/service/sys_login_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (e *SysLoginLog) Remove(c *dto.SysLoginLogDeleteReq) error {
return err
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
err = errors.New("no right to delete this data")
return err
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions app/admin/service/sys_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (e *SysMenu) Update(c *dto.SysMenuUpdateReq) *SysMenu {
return e
}
if db.RowsAffected == 0 {
_ = e.AddError(errors.New("无权更新该数据"))
_ = e.AddError(errors.New("do not have permission to update this data"))
return e
}
var menuList []models.SysMenu
Expand All @@ -198,7 +198,7 @@ func (e *SysMenu) Remove(d *dto.SysMenuDeleteReq) *SysMenu {
_ = e.AddError(err)
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
err = errors.New("no right to delete this data")
_ = e.AddError(err)
}
return e
Expand Down Expand Up @@ -397,7 +397,7 @@ func (e *SysMenu) getByRoleName(roleName string) ([]models.SysMenu, error) {
data := make([]models.SysMenu, 0)

if roleName == "admin" {
err = e.Orm.Where(" menu_type in ('M','C') and deleted_at is null").
err = e.Orm.Where(" menu_type in ('M','C') and deleted_at = 0").
Order("sort").
Find(&data).
Error
Expand Down
2 changes: 1 addition & 1 deletion app/admin/service/sys_opera_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (e *SysOperaLog) Remove(d *dto.SysOperaLogDeleteReq) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权删除该数据")
return errors.New("no right to delete this data")
}
return nil
}
4 changes: 2 additions & 2 deletions app/admin/service/sys_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (e *SysPost) Update(c *dto.SysPostUpdateReq) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")

}
return nil
Expand All @@ -99,7 +99,7 @@ func (e *SysPost) Remove(d *dto.SysPostDeleteReq) error {
return err
}
if db.RowsAffected == 0 {
err = errors.New("无权删除该数据")
err = errors.New("no right to delete this data")
return err
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions app/admin/service/sys_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (e *SysRole) Update(c *dto.SysRoleUpdateReq, cb *casbin.SyncedEnforcer) err
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")
}

// 清除 sys_casbin_rule 权限表里 当前角色的所有记录
Expand Down Expand Up @@ -218,7 +218,7 @@ func (e *SysRole) Remove(c *dto.SysRoleDeleteReq, cb *casbin.SyncedEnforcer) err
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")
}

// 清除 sys_casbin_rule 权限表里 当前角色的所有记录
Expand Down Expand Up @@ -276,7 +276,7 @@ func (e *SysRole) UpdateDataScope(c *dto.RoleDataScopeReq) *SysRole {
return e
}
if db.RowsAffected == 0 {
_ = e.AddError(errors.New("无权更新该数据"))
_ = e.AddError(errors.New("do not have permission to update this data"))
return e
}
return e
Expand Down Expand Up @@ -306,7 +306,7 @@ func (e *SysRole) UpdateStatus(c *dto.UpdateStatusReq) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")
}
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions app/admin/service/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (e *SysUser) Update(c *dto.SysUserUpdateReq, p *actions.DataPermission) err
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")

}
c.Generate(&model)
Expand Down Expand Up @@ -126,7 +126,7 @@ func (e *SysUser) UpdateAvatar(c *dto.UpdateSysUserAvatarReq, p *actions.DataPer
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")

}
err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error
Expand All @@ -149,7 +149,7 @@ func (e *SysUser) UpdateStatus(c *dto.UpdateSysUserStatusReq, p *actions.DataPer
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("don not have permission to update this data")

}
err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error
Expand All @@ -172,7 +172,7 @@ func (e *SysUser) ResetPwd(c *dto.ResetSysUserPwdReq, p *actions.DataPermission)
return err
}
if db.RowsAffected == 0 {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")
}
c.Generate(&model)
err = e.Orm.Omit("username", "nick_name", "phone", "role_id", "avatar", "sex").Save(&model).Error
Expand All @@ -197,7 +197,7 @@ func (e *SysUser) Remove(c *dto.SysUserById, p *actions.DataPermission) error {
return err
}
if db.RowsAffected == 0 {
return errors.New("无权删除该数据")
return errors.New("no right to delete this data")
}
return nil
}
Expand All @@ -218,7 +218,7 @@ func (e *SysUser) UpdatePwd(id int, oldPassword, newPassword string, p *actions.
First(c, id).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.New("无权更新该数据")
return errors.New("do not have permission to update this data")
}
e.Log.Errorf("db error: %s", err)
return err
Expand Down
Loading

0 comments on commit 225c139

Please sign in to comment.