Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

fix: grant pending permissions not working correctly#50059

Merged
kopancek merged 2 commits into
mainfrom
milan/fix_grant_pending_perms
Mar 28, 2023
Merged

fix: grant pending permissions not working correctly#50059
kopancek merged 2 commits into
mainfrom
milan/fix_grant_pending_perms

Conversation

@kopancek

Copy link
Copy Markdown
Contributor

Description

GrantPendingPermissions can be called multiple times in a loop. When using unified perms, it uses a method that by default removed old records from the table, effectively replacing existing records with new records.

However this behavior is not correct for granting pending permissions, which should only add new records, not remove old ones. Fixing this allows us to call GrantPendingPermissions in a loop without causing incosistencies in the database.

Test plan

extensively unit tested so that we are sure it works for both legacy and unified permissions

GrantPendingPermissions can be called multiple times in a loop.
When using unified perms, it uses a method that by default
removed old records from the table, effectively replacing existing
records with new records.

However this behavior is not correct for granting pending permissions,
which should only add new records, not remove old ones. Fixing this
allows us to call GrantPendingPermissions in a loop without causing
incosistencies in the database.
@kopancek kopancek requested a review from a team March 28, 2023 12:26
@cla-bot cla-bot Bot added the cla-signed label Mar 28, 2023
@sourcegraph-bot

sourcegraph-bot commented Mar 28, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 80771f4...4c90545.

Notify File(s)
@unknwon enterprise/internal/database/perms_store.go
enterprise/internal/database/perms_store_test.go

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@erzhtor erzhtor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

return s.setUserExternalAccountPerms(ctx, user, repoIDs, source, true)
}

func (s *permsStore) setUserExternalAccountPerms(ctx context.Context, user authz.UserIDWithExternalAccountID, repoIDs []int32, source authz.PermsSource, deleteOldPerms bool) (*database.SetPermissionsResult, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor renaming suggestion deleteOldPerms -> replaceRoles.

@kopancek kopancek enabled auto-merge (squash) March 28, 2023 14:17
@kopancek kopancek merged commit d7ca3ca into main Mar 28, 2023
@kopancek kopancek deleted the milan/fix_grant_pending_perms branch March 28, 2023 14:35
github-actions Bot pushed a commit that referenced this pull request Mar 28, 2023
## Description

GrantPendingPermissions can be called multiple times in a loop. When
using unified perms, it uses a method that by default removed old
records from the table, effectively replacing existing records with new
records.

However this behavior is not correct for granting pending permissions,
which should only add new records, not remove old ones. Fixing this
allows us to call GrantPendingPermissions in a loop without causing
incosistencies in the database.

## Test plan

extensively unit tested so that we are sure it works for both legacy and
unified permissions

(cherry picked from commit d7ca3ca)
coury-clark pushed a commit that referenced this pull request Mar 28, 2023
…50073)

## Description

GrantPendingPermissions can be called multiple times in a loop. When
using unified perms, it uses a method that by default removed old
records from the table, effectively replacing existing records with new
records.

However this behavior is not correct for granting pending permissions,
which should only add new records, not remove old ones. Fixing this
allows us to call GrantPendingPermissions in a loop without causing
incosistencies in the database.

## Test plan

extensively unit tested so that we are sure it works for both legacy and
unified permissions
 <br> Backport d7ca3ca from #50059

Co-authored-by: Milan Freml <kopancek@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants