Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/user/RoleGroupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func (impl RoleGroupServiceImpl) CreateRoleGroup(request *bean.RoleGroup) (*bean
rgName := strings.ToLower(request.Name)
object := "group:" + strings.ReplaceAll(rgName, " ", "_")

roleGroup, err := impl.roleGroupRepository.GetRoleGroupByCasbinName(object)
exists, err := impl.roleGroupRepository.CheckRoleGroupExistByCasbinName(object)
if err != nil && err != pg.ErrNoRows {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need ErrNoRows check?

impl.logger.Errorw("error in getting role group by casbin name", "err", err, "casbinName", object)
return nil, err
} else if roleGroup != nil {
} else if exists {
impl.logger.Errorw("role group already present", "err", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add roleGroup name for debugging

return nil, errors.New("role group already exist")
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/user/repository/RoleGroupRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type RoleGroupRepository interface {
GetRoleGroupListByName(name string) ([]*RoleGroup, error)
GetAllRoleGroup() ([]*RoleGroup, error)
GetRoleGroupListByCasbinNames(name []string) ([]*RoleGroup, error)
GetRoleGroupByCasbinName(name string) (*RoleGroup, error)
CheckRoleGroupExistByCasbinName(name string) (bool, error)
CreateRoleGroupRoleMapping(model *RoleGroupRoleMapping, tx *pg.Tx) (*RoleGroupRoleMapping, error)
GetRoleGroupRoleMapping(model int32) (*RoleGroupRoleMapping, error)
GetRoleGroupRoleMappingByRoleGroupId(roleGroupId int32) ([]*RoleGroupRoleMapping, error)
Expand Down Expand Up @@ -123,10 +123,11 @@ func (impl RoleGroupRepositoryImpl) GetRoleGroupListByCasbinNames(names []string
err := impl.dbConnection.Model(&model).Where("casbin_name in (?)", pg.In(names)).Where("active = ?", true).Select()
return model, err
}
func (impl RoleGroupRepositoryImpl) GetRoleGroupByCasbinName(name string) (*RoleGroup, error) {
var model RoleGroup
err := impl.dbConnection.Model(&model).Where("casbin_name = ?", name).Where("active = ?", true).Order("updated_on desc").Select()
return &model, err

func (impl RoleGroupRepositoryImpl) CheckRoleGroupExistByCasbinName(name string) (bool, error) {
var model *RoleGroup
return impl.dbConnection.Model(&model).Where("casbin_name = ?", name).Where("active = ?", true).Exists()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using pointer to pointer, fix this


}

func (impl RoleGroupRepositoryImpl) CreateRoleGroupRoleMapping(model *RoleGroupRoleMapping, tx *pg.Tx) (*RoleGroupRoleMapping, error) {
Expand Down