增加插件安装功能并提升其他功能稳定性 (#1155)
* 增加安装插件demo * 前端上传demo * 插件安装初版 * 调整菜单结构 * fix: 修改密码校验 jwt 中的用户 id * router.go:fix logger的中间件是默认的,这边日志可以删除;cors的日志打印应当在上面两行启用的时候再进行注释 * 登陆==>登录 * 抽离插件安装方法 * 调整插件功能 提升灵活度 Co-authored-by: zeromake <a390720046@gmail.com> Co-authored-by: Lu JJ <275955589@qq.com> Co-authored-by: pnck <hio131@gmail.com> Co-authored-by: feixuanyu <994085848@qq.com>
This commit is contained in:
committed by
GitHub
co-authored by
zeromake
Lu JJ
pnck
feixuanyu
parent
063ceffb11
commit
4bf872d292
@@ -131,7 +131,7 @@ func (authorityService *AuthorityService) DeleteAuthority(auth *system.SysAuthor
|
||||
return
|
||||
}
|
||||
}
|
||||
err = global.GVA_DB.Delete(&[]system.SysUseAuthority{}, "sys_authority_authority_id = ?", auth.AuthorityId).Error
|
||||
err = global.GVA_DB.Delete(&[]system.SysUserAuthority{}, "sys_authority_authority_id = ?", auth.AuthorityId).Error
|
||||
err = global.GVA_DB.Delete(&[]system.SysAuthorityBtn{}, "authority_id = ?", auth.AuthorityId).Error
|
||||
authorityId := strconv.Itoa(int(auth.AuthorityId))
|
||||
CasbinServiceApp.ClearCasbin(0, authorityId)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
cp "github.com/otiai10/copy"
|
||||
"go.uber.org/zap"
|
||||
"go/ast"
|
||||
"go/format"
|
||||
@@ -12,8 +13,10 @@ import (
|
||||
"go/token"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -681,7 +684,7 @@ func (vi *Visitor) addStruct(genDecl *ast.GenDecl) ast.Visitor {
|
||||
case *ast.StructType:
|
||||
f := &ast.Field{
|
||||
Names: []*ast.Ident{
|
||||
&ast.Ident{
|
||||
{
|
||||
Name: vi.StructName,
|
||||
Obj: &ast.Object{
|
||||
Kind: ast.Var,
|
||||
@@ -834,3 +837,81 @@ func (autoCodeService *AutoCodeService) CreatePlug(plug system.AutoPlugReq) erro
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (autoCodeService *AutoCodeService) InstallPlugin(file *multipart.FileHeader) (err error) {
|
||||
const GVAPLUGPATH = "./gva-plug-temp/"
|
||||
defer os.RemoveAll(GVAPLUGPATH)
|
||||
_, err = os.Stat(GVAPLUGPATH)
|
||||
if os.IsNotExist(err) {
|
||||
os.Mkdir(GVAPLUGPATH, os.ModePerm)
|
||||
}
|
||||
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
out, err := os.Create(GVAPLUGPATH + file.Filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, src)
|
||||
|
||||
paths, err := utils.Unzip(GVAPLUGPATH+file.Filename, GVAPLUGPATH)
|
||||
var webIndex = 0
|
||||
var serverIndex = 0
|
||||
for i := range paths {
|
||||
paths[i] = filepath.ToSlash(paths[i])
|
||||
pathArr := strings.Split(paths[i], "/")
|
||||
if pathArr[len(pathArr)-2] == "server" && pathArr[len(pathArr)-1] == "plugin" {
|
||||
serverIndex = i + 1
|
||||
}
|
||||
if pathArr[len(pathArr)-2] == "web" && pathArr[len(pathArr)-1] == "plugin" {
|
||||
webIndex = i + 1
|
||||
}
|
||||
}
|
||||
if webIndex == 0 && serverIndex == 0 {
|
||||
fmt.Println("非标准插件,请按照文档自动迁移使用")
|
||||
return errors.New("非标准插件,请按照文档自动迁移使用")
|
||||
}
|
||||
|
||||
if webIndex != 0 {
|
||||
webNameArr := strings.Split(filepath.ToSlash(paths[webIndex]), "/")
|
||||
webName := webNameArr[len(webNameArr)-1]
|
||||
var form = filepath.ToSlash(global.GVA_CONFIG.AutoCode.Root + global.GVA_CONFIG.AutoCode.Server + "/" + paths[webIndex])
|
||||
var to = filepath.ToSlash(global.GVA_CONFIG.AutoCode.Root + global.GVA_CONFIG.AutoCode.Web + "/plugin/" + webName)
|
||||
_, err := os.Stat(to)
|
||||
if err == nil {
|
||||
fmt.Println("web 已存在同名插件,请自行手动安装")
|
||||
return errors.New("web 已存在同名插件,请自行手动安装")
|
||||
}
|
||||
err = cp.Copy(form, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if serverIndex != 0 {
|
||||
serverNameArr := strings.Split(filepath.ToSlash(paths[serverIndex]), "/")
|
||||
serverName := serverNameArr[len(serverNameArr)-1]
|
||||
var form = filepath.ToSlash(global.GVA_CONFIG.AutoCode.Root + global.GVA_CONFIG.AutoCode.Server + "/" + paths[serverIndex])
|
||||
var to = filepath.ToSlash(global.GVA_CONFIG.AutoCode.Root + global.GVA_CONFIG.AutoCode.Server + "/plugin/" + serverName)
|
||||
_, err := os.Stat(to)
|
||||
if err == nil {
|
||||
fmt.Println("server 已存在同名插件,请自行手动安装")
|
||||
return errors.New("server 已存在同名插件,请自行手动安装")
|
||||
}
|
||||
err = cp.Copy(form, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,7 @@ func (userService *UserService) Login(u *system.SysUser) (userInter *system.SysU
|
||||
|
||||
func (userService *UserService) ChangePassword(u *system.SysUser, newPassword string) (userInter *system.SysUser, err error) {
|
||||
var user system.SysUser
|
||||
err = global.GVA_DB.Where("username = ?", u.Username).First(&user).Error
|
||||
if err != nil {
|
||||
if err = global.GVA_DB.Where("id = ?", u.ID).First(&user).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ok := utils.BcryptCheck(u.Password, user.Password); !ok {
|
||||
@@ -117,12 +116,12 @@ func (userService *UserService) GetUserInfoList(info request.PageInfo) (list int
|
||||
//@param: uuid uuid.UUID, authorityId string
|
||||
//@return: err error
|
||||
|
||||
func (userService *UserService) SetUserAuthority(id uint, uuid uuid.UUID, authorityId uint) (err error) {
|
||||
assignErr := global.GVA_DB.Where("sys_user_id = ? AND sys_authority_authority_id = ?", id, authorityId).First(&system.SysUseAuthority{}).Error
|
||||
func (userService *UserService) SetUserAuthority(id uint, authorityId uint) (err error) {
|
||||
assignErr := global.GVA_DB.Where("sys_user_id = ? AND sys_authority_authority_id = ?", id, authorityId).First(&system.SysUserAuthority{}).Error
|
||||
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
|
||||
return errors.New("该用户无此角色")
|
||||
}
|
||||
err = global.GVA_DB.Where("uuid = ?", uuid).First(&system.SysUser{}).Update("authority_id", authorityId).Error
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&system.SysUser{}).Update("authority_id", authorityId).Error
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -134,13 +133,13 @@ func (userService *UserService) SetUserAuthority(id uint, uuid uuid.UUID, author
|
||||
|
||||
func (userService *UserService) SetUserAuthorities(id uint, authorityIds []uint) (err error) {
|
||||
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
TxErr := tx.Delete(&[]system.SysUseAuthority{}, "sys_user_id = ?", id).Error
|
||||
TxErr := tx.Delete(&[]system.SysUserAuthority{}, "sys_user_id = ?", id).Error
|
||||
if TxErr != nil {
|
||||
return TxErr
|
||||
}
|
||||
var useAuthority []system.SysUseAuthority
|
||||
var useAuthority []system.SysUserAuthority
|
||||
for _, v := range authorityIds {
|
||||
useAuthority = append(useAuthority, system.SysUseAuthority{
|
||||
useAuthority = append(useAuthority, system.SysUserAuthority{
|
||||
SysUserId: id, SysAuthorityAuthorityId: v,
|
||||
})
|
||||
}
|
||||
@@ -169,7 +168,7 @@ func (userService *UserService) DeleteUser(id int) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = global.GVA_DB.Delete(&[]system.SysUseAuthority{}, "sys_user_id = ?", id).Error
|
||||
err = global.GVA_DB.Delete(&[]system.SysUserAuthority{}, "sys_user_id = ?", id).Error
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user