| | |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/flipped-aurora/gin-vue-admin/server/global" |
| | | "github.com/flipped-aurora/gin-vue-admin/server/model/system" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | ) |
| | | |
| | |
| | | |
| | | var AuthorityServiceApp = new(AuthorityService) |
| | | |
| | | func (authorityService *AuthorityService) CreateAuthority(auth model.Authority) int { |
| | | _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.AuthorityId).Find() |
| | | if err != gorm.ErrRecordNotFound { |
| | | return ecode.RoleExist |
| | | } |
| | | |
| | | err = model.NewSysAuthoritySearch().Create(&auth) |
| | | // CreateAuthority create authority and return authority id and error code |
| | | func (authorityService *AuthorityService) CreateAuthority(auth model.Authority) (int, uint) { |
| | | // check if authority name exists |
| | | err := model.NewSysAuthoritySearch().Create(&auth) |
| | | if err != nil { |
| | | return ecode.SubOrderExist |
| | | return ecode.RoleExist, 0 |
| | | } |
| | | |
| | | return ecode.OK |
| | | return ecode.OK, auth.Id |
| | | } |
| | | |
| | | func (authorityService *AuthorityService) UpdateAuthority(auth model.Authority) int { |
| | | _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.AuthorityId).Find() |
| | | _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.Id).Find() |
| | | if err != nil { |
| | | return ecode.RoleNotExist |
| | | } |
| | | |
| | | err = model.NewSysAuthoritySearch().SetAuthorityId(auth.AuthorityId).Update(&auth) |
| | | err = model.NewSysAuthoritySearch().SetAuthorityId(auth.Id).Update(&auth) |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (authorityService *AuthorityService) DeleteAuthority(auth *model.Authority) int { |
| | | _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.AuthorityId).Find() |
| | | _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.Id).Find() |
| | | if err != nil { |
| | | return ecode.RoleNotExist |
| | | } |
| | |
| | | return ecode.RoleDeleteErr1 |
| | | } |
| | | |
| | | authorityId := strconv.Itoa(int(auth.AuthorityId)) |
| | | authorityId := strconv.Itoa(int(auth.Id)) |
| | | CasbinServiceApp.ClearCasbin(0, authorityId) |
| | | return ecode.OK |
| | | } |
| | |
| | | } |
| | | |
| | | //@author: [piexlmax](https://github.com/piexlmax) |
| | | //@function: SetDataAuthority |
| | | //@function: SetMenuAuthority |
| | | //@description: 设置角色资源权限 |
| | | //@param: auth model.Authority |
| | | //@return: error |
| | |
| | | //@param: auth *model.Authority |
| | | //@return: error |
| | | |
| | | func (authorityService *AuthorityService) SetMenuAuthority(auth *system.SysAuthority) error { |
| | | var s system.SysAuthority |
| | | global.GVA_DB.Preload("SysBaseMenus").First(&s, "authority_id = ?", auth.AuthorityId) |
| | | err := global.GVA_DB.Model(&s).Association("SysBaseMenus").Replace(&auth.SysBaseMenus) |
| | | return err |
| | | func (authorityService *AuthorityService) SetMenuAuthority(auth *model.Authority) error { |
| | | return model.NewSysAuthoritySearch().SetMenuAuthority(auth) |
| | | } |