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
9 changes: 8 additions & 1 deletion pkg/user/RoleGroupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,26 @@ func (impl RoleGroupServiceImpl) CreateRoleGroup(request *bean.RoleGroup) (*bean
//loading policy for safety
casbin2.LoadPolicy()
//create new user in our db on d basis of info got from google api or hex. assign a basic role

model := &repository2.RoleGroup{
Name: request.Name,
Description: request.Description,
}
rgName := strings.ToLower(request.Name)
object := "group:" + strings.ReplaceAll(rgName, " ", "_")

_, err := impl.roleGroupRepository.GetRoleGroupByCasbinName(object)
Copy link
Member

Choose a reason for hiding this comment

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

are we only using this for checking if entry exists or not? if yes then we should use exists clause since this is confusing. Also, add comments

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
}
model.CasbinName = object
model.CreatedBy = request.UserId
model.UpdatedBy = request.UserId
model.CreatedOn = time.Now()
model.UpdatedOn = time.Now()
model.Active = true
model, err := impl.roleGroupRepository.CreateRoleGroup(model, tx)
model, err = impl.roleGroupRepository.CreateRoleGroup(model, tx)
request.Id = model.Id
if err != nil {
impl.logger.Errorw("error in creating new user group", "error", err)
Expand Down
7 changes: 6 additions & 1 deletion 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)
CreateRoleGroupRoleMapping(model *RoleGroupRoleMapping, tx *pg.Tx) (*RoleGroupRoleMapping, error)
GetRoleGroupRoleMapping(model int32) (*RoleGroupRoleMapping, error)
GetRoleGroupRoleMappingByRoleGroupId(roleGroupId int32) ([]*RoleGroupRoleMapping, error)
Expand Down Expand Up @@ -123,6 +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()
Copy link
Member

Choose a reason for hiding this comment

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

what is the need of ordering? if there can be multiple rows in output use limit with this or use slice model

return &model, err
}

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