Skip to content

Commit

Permalink
Merge pull request #55 from ArtisanCloud/develop
Browse files Browse the repository at this point in the history
refact(role): change DoesRoleExist logic
  • Loading branch information
Matrix-X authored Dec 3, 2022
2 parents b9184bf + f538a98 commit 7ab92a6
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions authorization/rbac/models/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,21 @@ func (mdl *Role) GetTreeList(db *gorm.DB, conditions *map[string]interface{}, pr
return roles, err
}

func (mdl *Role) CheckRoleNameAvailable(db *gorm.DB) (err error) {
func (mdl *Role) DoesRoleExist(db *gorm.DB) (bool, error) {

result := db.
//Debug().
Where("name", mdl.Name).
Where("index_role_id != ?", mdl.UniqueID).
Where("index_role_id = ?", mdl.UniqueID).
First(&Role{})

if result.Error != nil && errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil
return false, nil
}

if result.Error != nil {
return result.Error
return false, result.Error
}

err = errors.New("role name is not available")

return err
return true, nil
}

0 comments on commit 7ab92a6

Please sign in to comment.