Skip to content
Snippets Groups Projects

Return error when client headers are missing (issue #19)

Closed joel.vonderwe requested to merge jw_issue_timeout into main
3 files
+ 13
6
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -16,6 +16,7 @@ import GitlabProfile from '../shared/types/Gitlab/GitlabProfile';
@@ -16,6 +16,7 @@ import GitlabProfile from '../shared/types/Gitlab/GitlabProfile';
import GitlabRelease from '../shared/types/Gitlab/GitlabRelease';
import GitlabRelease from '../shared/types/Gitlab/GitlabRelease';
import { CommitSchema, Gitlab } from '@gitbeaker/rest';
import { CommitSchema, Gitlab } from '@gitbeaker/rest';
import logger from '../shared/logging/WinstonLogger';
import logger from '../shared/logging/WinstonLogger';
 
import DojoStatusCode from '../shared/types/Dojo/DojoStatusCode';
class GitlabManager {
class GitlabManager {
@@ -169,16 +170,18 @@ class GitlabManager {
@@ -169,16 +170,18 @@ class GitlabManager {
return response.data;
return response.data;
}
}
async checkTemplateAccess(projectIdOrNamespace: string, req: express.Request): Promise<StatusCodes> {
async checkTemplateAccess(projectIdOrNamespace: string, req: express.Request, res: express.Response) {
// Get the Gitlab project and check if it have public or internal visibility
// Get the Gitlab project and check if it have public or internal visibility
try {
try {
const project: GitlabRepository = await this.getRepository(projectIdOrNamespace);
const project: GitlabRepository = await this.getRepository(projectIdOrNamespace);
if ( [ GitlabVisibility.PUBLIC.valueOf(), GitlabVisibility.INTERNAL.valueOf() ].includes(project.visibility) ) {
if ( [ GitlabVisibility.PUBLIC.valueOf(), GitlabVisibility.INTERNAL.valueOf() ].includes(project.visibility) ) {
return StatusCodes.OK;
req.session.sendResponse(res, StatusCodes.OK);
 
return;
}
}
} catch ( e ) {
} catch ( e ) {
return StatusCodes.NOT_FOUND;
req.session.sendResponse(res, StatusCodes.NOT_FOUND, undefined, 'Template not found', DojoStatusCode.GITLAB_TEMPLATE_NOT_FOUND);
 
return;
}
}
// Check if the user and dojo are members (with at least reporter access) of the project
// Check if the user and dojo are members (with at least reporter access) of the project
@@ -197,7 +200,11 @@ class GitlabManager {
@@ -197,7 +200,11 @@ class GitlabManager {
}
}
});
});
return isUsersAtLeastReporter.user && isUsersAtLeastReporter.dojo ? StatusCodes.OK : StatusCodes.UNAUTHORIZED;
if ( isUsersAtLeastReporter.user && isUsersAtLeastReporter.dojo ) {
 
req.session.sendResponse(res, StatusCodes.OK);
 
} else {
 
req.session.sendResponse(res, StatusCodes.UNAUTHORIZED, undefined, 'Template access unauthorized', DojoStatusCode.GITLAB_TEMPLATE_ACCESS_UNAUTHORIZED);
 
}
}
}
async protectBranch(repoId: number, branchName: string, allowForcePush: boolean, allowedToMerge: GitlabAccessLevel, allowedToPush: GitlabAccessLevel, allowedToUnprotect: GitlabAccessLevel): Promise<GitlabMember> {
async protectBranch(repoId: number, branchName: string, allowForcePush: boolean, allowedToMerge: GitlabAccessLevel, allowedToPush: GitlabAccessLevel, allowedToUnprotect: GitlabAccessLevel): Promise<GitlabMember> {
Loading