Skip to content

Conversation

@Shivam-nagar23
Copy link
Member

@Shivam-nagar23 Shivam-nagar23 commented Aug 16, 2023

Description

Fixes #3772

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit/api test cases.

Does this PR introduce a user-facing change?


}
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

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


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?

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


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

@prakarsh-dt
Copy link
Collaborator

@Shivam-nagar23 @kartik-579 @vikramdevtron What is the blocker here? Why are we not merging this?

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Shivam-nagar23 Shivam-nagar23 merged commit fe45d34 into main Aug 22, 2023
@Shivam-nagar23 Shivam-nagar23 deleted the role-group-duplication-fix branch August 22, 2023 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Devtron allows saving permission group with same name

4 participants