-
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 |
|---|---|---|
|
|
@@ -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 { | ||
| 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) | ||
|
||
| return nil, errors.New("role group already exist") | ||
| } | ||
|
|
||
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) | ||
| CheckRoleGroupExistByCasbinName(name string) (bool, error) | ||
| CreateRoleGroupRoleMapping(model *RoleGroupRoleMapping, tx *pg.Tx) (*RoleGroupRoleMapping, error) | ||
| GetRoleGroupRoleMapping(model int32) (*RoleGroupRoleMapping, error) | ||
| GetRoleGroupRoleMappingByRoleGroupId(roleGroupId int32) ([]*RoleGroupRoleMapping, error) | ||
|
|
@@ -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() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
|
||
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.
do we still need ErrNoRows check?