Skip to content

feat: implement organization role sync #14649

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 13 commits into from
Sep 17, 2024
Prev Previous commit
Next Next commit
linting
  • Loading branch information
Emyrk committed Sep 16, 2024
commit f51fae7c99648c9959765c814618b169ba632066
1 change: 1 addition & 0 deletions coderd/idpsync/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ func (o orgGroupAssert) Assert(t *testing.T, orgID uuid.UUID, db database.Store,
}
}

//nolint:revive
func (o orgRoleAssert) Assert(t *testing.T, orgID uuid.UUID, db database.Store, notMember bool, user database.User) {
t.Helper()

Expand Down
5 changes: 3 additions & 2 deletions coderd/idpsync/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func (s AGPLIDPSync) SyncRoles(ctx context.Context, db database.Store, user data

// sync roles per organization
orgMemberships, err := tx.OrganizationMembers(ctx, database.OrganizationMembersParams{
UserID: user.ID,
OrganizationID: uuid.Nil,
UserID: user.ID,
})
if err != nil {
return xerrors.Errorf("get organizations by user id: %w", err)
Expand Down Expand Up @@ -241,7 +242,7 @@ func (s AGPLIDPSync) syncSiteWideRoles(ctx context.Context, tx database.Store, u
return nil
}

func (s AGPLIDPSync) RolesFromClaim(field string, claims jwt.MapClaims) ([]string, error) {
func (AGPLIDPSync) RolesFromClaim(field string, claims jwt.MapClaims) ([]string, error) {
rolesRow, ok := claims[field]
if !ok {
// If no claim is provided than we can assume the user is just
Expand Down
2 changes: 2 additions & 0 deletions coderd/idpsync/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ func TestRoleSyncTable(t *testing.T) {
// per organization. This limits the number of db calls to O(1) if there
// are no changes. Which is the usual case, as user's roles do not change often.
func TestNoopNoDiff(t *testing.T) {
t.Parallel()

ctx := context.Background()
ctrl := gomock.NewController(t)
mDB := dbmock.NewMockStore(ctrl)
Expand Down