Skip to content

Commit

Permalink
add OrganizationsAclService#getOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek committed May 19, 2024
1 parent 0498208 commit 7d2f080
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ describe('OrganizationsAclService', () => {
expect(exist).toBe(true);
});

it('should check if org has owner', async () => {
const orgId = new Types.ObjectId();
const hasOwner = await service.hasOwner(orgId);
expect(hasOwner).toBe(true);
});

it('should get org owner', async () => {
const orgId = new Types.ObjectId();
const owner = await service.getOwner(orgId);
expect(owner).toEqual(expect.any(Types.ObjectId));
});

it('should paginate rules', async () => {
const rules = await service.paginateRules(new Types.ObjectId(), { page: 1 });

Expand Down
15 changes: 12 additions & 3 deletions apps/api/src/models/organizations/organizations-acl.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,25 @@ export class OrganizationsAclService {
}

/**
* Checks does specified organization has a designated owner.
* Get id of designated owner of organization, returns null if organization
* has no designated owner.
*/
async hasOwner(organization: Types.ObjectId): Promise<boolean> {
async getOwner(organization: Types.ObjectId): Promise<Types.ObjectId> {
const allRules = await this.getAllRules(organization);
if (!allRules) {
throw new Error('Organization not found');
}

const rule = allRules.find((rule) => rule.role == OrganizationSecurityRole.OWNER);
return rule != undefined;
return rule ? rule.user : null;
}

/**
* Checks does specified organization has a designated owner.
*/
async hasOwner(organization: Types.ObjectId): Promise<boolean> {
const owner = await this.getOwner(organization);
return owner != undefined;
}

/**
Expand Down

0 comments on commit 7d2f080

Please sign in to comment.