-
Notifications
You must be signed in to change notification settings - Fork 554
fix: duplicate role-group-fix #3774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
026fee7
duplicate role-group-fix
Shivam-nagar23 f04296a
condition addition
Shivam-nagar23 e71452f
review comments
Shivam-nagar23 31421a0
review comments
Shivam-nagar23 3b4f532
review comments
Shivam-nagar23 b5f0c82
Merge branch 'main' into role-group-duplication-fix
Shivam-nagar23 2633de0
Merge branch 'main' into role-group-duplication-fix
Shivam-nagar23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| if err != nil && err != pg.ErrNoRows { | ||
|
||
| 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) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -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() | ||
|
||
| return &model, err | ||
| } | ||
|
|
||
| func (impl RoleGroupRepositoryImpl) CreateRoleGroupRoleMapping(model *RoleGroupRoleMapping, tx *pg.Tx) (*RoleGroupRoleMapping, error) { | ||
| err := tx.Insert(model) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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