Skip to content

Commit

Permalink
fix org service test expecting member list to include admin
Browse files Browse the repository at this point in the history
Tool: gitpod/catfood.gitpod.cloud
  • Loading branch information
filiptronicek committed Feb 7, 2025
1 parent ac0e2c5 commit 004e07a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions components/server/src/api/organization-service-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required");
}

const members = await this.orgService.listMembers(ctxUserId(), req.organizationId);
const members = await this.orgService.listMembers(ctxUserId(), req.organizationId, true);
//TODO pagination
const response = new ListOrganizationMembersResponse();
response.members = members.map((member) => this.apiConverter.toOrganizationMember(member));
Expand Down Expand Up @@ -218,7 +218,7 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
this.apiConverter.fromOrgMemberRole(req.role),
);
const member = await this.orgService
.listMembers(ctxUserId(), req.organizationId)
.listMembers(ctxUserId(), req.organizationId, true)
.then((members) => members.find((member) => member.userId === req.userId));
return new UpdateOrganizationMemberResponse({
member: member && this.apiConverter.toOrganizationMember(member),
Expand Down
10 changes: 7 additions & 3 deletions components/server/src/orgs/organization-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,13 @@ export class OrganizationService {
}

/**
* List members of an organization, excluding the built-in installation admin user and all deleted users.
* List members of an organization, excluding all deleted users and optionally the built-in installation admin user.
*/
public async listMembers(userId: string, orgId: string): Promise<OrgMemberInfo[]> {
public async listMembers(
userId: string,
orgId: string,
excludeInstallationAdmin?: boolean,
): Promise<OrgMemberInfo[]> {
await this.auth.checkPermissionOnOrganization(userId, "read_members", orgId);
const members = await this.teamDB.findMembersByTeam(orgId);

Expand All @@ -278,7 +282,7 @@ export class OrganizationService {
if (user.markedDeleted) {
return null;
}
if (user.id === BUILTIN_INSTLLATION_ADMIN_USER_ID) {
if (excludeInstallationAdmin && user.id === BUILTIN_INSTLLATION_ADMIN_USER_ID) {
return null;
}

Expand Down

0 comments on commit 004e07a

Please sign in to comment.