Skip to content

Commit

Permalink
DOP-4599 fix unecessary entitlements errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anabellabuckvar committed Jun 5, 2024
1 parent 88a39ff commit d9be310
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/job/jobValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export class JobValidator implements IJobValidator {
}

async throwIfUserNotEntitled(job: Job): Promise<void> {
try {
const admin = await this._repoEntitlementRepository.getIsAdmin(job.user);
if (admin) return;
} catch (e) {
throw new InvalidJobError(`Invalid job user: ${job.user}`);
}
const entitlementsObject = await this._repoEntitlementRepository.getRepoEntitlementsByGithubUsername(job.user);
const entitlementToFind = `${job.payload.repoOwner}/${job.payload.repoName}${
job.payload.repoName === MONOREPO_NAME ? `/${job.payload.directory}` : ``
Expand Down
10 changes: 8 additions & 2 deletions src/repositories/repoEntitlementsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ export class RepoEntitlementsRepository extends BaseRepository {
}
}

async getIsAdmin(slackUserId: string): Promise<boolean> {
const query = { slack_user_id: slackUserId };
async getIsAdmin(slackUserId?: string, githubUsername?: string): Promise<boolean> {
if (!arguments.length) {
throw new Error('getIsAdmin function must be given at least one argument');
}
let query;
if (slackUserId) {
query = { slack_user_id: slackUserId };
} else query = { github_username: githubUsername };
const entitlementsObject = await this.findOne(
query,
`Mongo Timeout Error: Timedout while retrieving entitlements for ${slackUserId}`
Expand Down

0 comments on commit d9be310

Please sign in to comment.