- Notifications
You must be signed in to change notification settings - Fork927
chore: merge organization member db queries#13542
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1476,14 +1476,6 @@ func (q *querier) GetOrganizationIDsByMemberIDs(ctx context.Context, ids []uuid. | ||
returnfetchWithPostFilter(q.auth,policy.ActionRead,q.db.GetOrganizationIDsByMemberIDs)(ctx,ids) | ||
} | ||
Comment on lines -1479 to -1485 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. Removed these, replaced with 1 | ||
func (q*querier)GetOrganizations(ctx context.Context) ([]database.Organization,error) { | ||
fetch:=func(ctx context.Context,_interface{}) ([]database.Organization,error) { | ||
returnq.db.GetOrganizations(ctx) | ||
@@ -2771,6 +2763,10 @@ func (q *querier) ListWorkspaceAgentPortShares(ctx context.Context, workspaceID | ||
returnq.db.ListWorkspaceAgentPortShares(ctx,workspaceID) | ||
} | ||
func (q*querier)OrganizationMembers(ctx context.Context,arg database.OrganizationMembersParams) ([]database.OrganizationMembersRow,error) { | ||
returnfetchWithPostFilter(q.auth,policy.ActionRead,q.db.OrganizationMembers)(ctx,arg) | ||
} | ||
func (q*querier)ReduceWorkspaceAgentShareLevelToAuthenticatedByTemplate(ctx context.Context,templateID uuid.UUID)error { | ||
template,err:=q.db.GetTemplateByID(ctx,templateID) | ||
iferr!=nil { | ||
@@ -2870,15 +2866,15 @@ func (q *querier) UpdateInactiveUsersToDormant(ctx context.Context, lastSeenAfte | ||
func (q*querier)UpdateMemberRoles(ctx context.Context,arg database.UpdateMemberRolesParams) (database.OrganizationMember,error) { | ||
// Authorized fetch will check that the actor has read access to the org member since the org member is returned. | ||
member,err:=database.ExpectOne(q.OrganizationMembers(ctx, database.OrganizationMembersParams{ | ||
OrganizationID:arg.OrgID, | ||
UserID:arg.UserID, | ||
})) | ||
iferr!=nil { | ||
return database.OrganizationMember{},err | ||
} | ||
originalRoles,err:=q.convertToOrganizationRoles(member.OrganizationMember.OrganizationID,member.OrganizationMember.Roles) | ||
iferr!=nil { | ||
return database.OrganizationMember{},xerrors.Errorf("convert original roles: %w",err) | ||
} | ||
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -157,7 +157,7 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *expec | ||||||||||
iflen(testCase.assertions)>0 { | ||||||||||
// Only run these tests if we know the underlying call makes | ||||||||||
// rbac assertions. | ||||||||||
s.NotAuthorizedErrorTest(ctx,fakeAuthorizer,testCase,callMethod) | ||||||||||
} | ||||||||||
iflen(testCase.assertions)>0|| | ||||||||||
@@ -230,7 +230,7 @@ func (s *MethodTestSuite) NoActorErrorTest(callMethod func(ctx context.Context) | ||||||||||
// NotAuthorizedErrorTest runs the given method with an authorizer that will fail authz. | ||||||||||
// Asserts that the error returned is a NotAuthorizedError. | ||||||||||
func (s*MethodTestSuite)NotAuthorizedErrorTest(ctx context.Context,az*coderdtest.FakeAuthorizer,testCaseexpects,callMethodfunc(ctx context.Context) ([]reflect.Value,error)) { | ||||||||||
s.Run("NotAuthorized",func() { | ||||||||||
az.AlwaysReturn=rbac.ForbiddenWithInternal(xerrors.New("Always fail authz"), rbac.Subject{},"", rbac.Object{},nil) | ||||||||||
@@ -242,9 +242,14 @@ func (s *MethodTestSuite) NotAuthorizedErrorTest(ctx context.Context, az *coderd | ||||||||||
// This is unfortunate, but if we are using `Filter` the error returned will be nil. So filter out | ||||||||||
// any case where the error is nil and the response is an empty slice. | ||||||||||
iferr!=nil||!hasEmptySliceResponse(resp) { | ||||||||||
// Expect the default error | ||||||||||
iftestCase.notAuthorizedExpect=="" { | ||||||||||
s.ErrorContainsf(err,"unauthorized","error string should have a good message") | ||||||||||
s.Errorf(err,"method should an error with disallow authz") | ||||||||||
s.ErrorAs(err,&dbauthz.NotAuthorizedError{},"error should be NotAuthorizedError") | ||||||||||
}else { | ||||||||||
s.ErrorContains(err,testCase.notAuthorizedExpect) | ||||||||||
} | ||||||||||
} | ||||||||||
}) | ||||||||||
@@ -263,8 +268,12 @@ func (s *MethodTestSuite) NotAuthorizedErrorTest(ctx context.Context, az *coderd | ||||||||||
// This is unfortunate, but if we are using `Filter` the error returned will be nil. So filter out | ||||||||||
// any case where the error is nil and the response is an empty slice. | ||||||||||
iferr!=nil||!hasEmptySliceResponse(resp) { | ||||||||||
iftestCase.cancelledCtxExpect=="" { | ||||||||||
s.Errorf(err,"method should an error with cancellation") | ||||||||||
s.ErrorIsf(err,context.Canceled,"error should match context.Canceled") | ||||||||||
}else { | ||||||||||
s.ErrorContains(err,testCase.cancelledCtxExpect) | ||||||||||
} | ||||||||||
} | ||||||||||
}) | ||||||||||
} | ||||||||||
@@ -308,6 +317,13 @@ type expects struct { | ||||||||||
// outputs is optional. Can assert non-error return values. | ||||||||||
outputs []reflect.Value | ||||||||||
errerror | ||||||||||
// Optional override of the default error checks. | ||||||||||
// By default, we search for the expected error strings. | ||||||||||
// If these strings are present, these strings will be searched | ||||||||||
// instead. | ||||||||||
notAuthorizedExpectstring | ||||||||||
cancelledCtxExpectstring | ||||||||||
Comment on lines +320 to +326 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. This used to be done with a static list: coder/coderd/database/dbauthz/setup_test.go Lines 164 to 167 ine8aa9ac
We should move to this new approach, which is much closer to the actual writing of the tests. | ||||||||||
} | ||||||||||
// Asserts is required. Asserts the RBAC authorize calls that should be made. | ||||||||||
@@ -338,6 +354,16 @@ func (m *expects) Errors(err error) *expects { | ||||||||||
returnm | ||||||||||
} | ||||||||||
func (m*expects)WithNotAuthorized(containsstring)*expects { | ||||||||||
m.notAuthorizedExpect=contains | ||||||||||
returnm | ||||||||||
} | ||||||||||
func (m*expects)WithCancelled(containsstring)*expects { | ||||||||||
m.cancelledCtxExpect=contains | ||||||||||
returnm | ||||||||||
} | ||||||||||
// AssertRBAC contains the object and actions to be asserted. | ||||||||||
typeAssertRBACstruct { | ||||||||||
Object rbac.Object | ||||||||||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.