diff --git a/ExpressAPI/src/helpers/Prisma/Extensions/UserResultExtension.ts b/ExpressAPI/src/helpers/Prisma/Extensions/UserResultExtension.ts index 6630bca34634f7e35b84af873e5b1cfecc94fcbd..cb52f6e1dcddf3d58c25a239a9b8e9430345f7f0 100644 --- a/ExpressAPI/src/helpers/Prisma/Extensions/UserResultExtension.ts +++ b/ExpressAPI/src/helpers/Prisma/Extensions/UserResultExtension.ts @@ -1,7 +1,7 @@ import { Prisma, UserRole } from '@prisma/client'; import LazyVal from '../../../shared/helpers/LazyVal'; -import GitlabManager from '../../../managers/GitlabManager'; import * as Gitlab from '@gitbeaker/rest'; +import GlobalHelper from '../../GlobalHelper'; export default Prisma.defineExtension(client => { diff --git a/ExpressAPI/src/managers/GitlabManager.ts b/ExpressAPI/src/managers/GitlabManager.ts index 3bf07a4f562b6f72343cdffbc401df07221a8784..1c7c959944bf56a88eb49ad352d7adb62873c8c2 100644 --- a/ExpressAPI/src/managers/GitlabManager.ts +++ b/ExpressAPI/src/managers/GitlabManager.ts @@ -1,14 +1,12 @@ -import Config from '../config/Config'; -import { StatusCodes } from 'http-status-codes'; -import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility'; -import express from 'express'; -import SharedConfig from '../shared/config/SharedConfig'; -import { CommitSchema, ExpandedUserSchema, Gitlab, MemberSchema, ProjectBadgeSchema, ProjectSchema, ReleaseSchema, RepositoryFileExpandedSchema, RepositoryFileSchema, RepositoryTreeSchema, UserSchema } from '@gitbeaker/rest'; -import logger from '../shared/logging/WinstonLogger'; -import { AccessLevel, EditProjectOptions, ProjectVariableSchema, ProtectedBranchAccessLevel, ProtectedBranchSchema } from '@gitbeaker/core'; -import axios from 'axios'; -import parseLinkHeader from 'parse-link-header'; -import DojoStatusCode from '../shared/types/Dojo/DojoStatusCode'; +import Config from '../config/Config'; +import { StatusCodes } from 'http-status-codes'; +import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility'; +import express from 'express'; +import SharedConfig from '../shared/config/SharedConfig'; +import { CommitSchema, ExpandedUserSchema, Gitlab, MemberSchema, ProjectBadgeSchema, ProjectSchema, ReleaseSchema, RepositoryFileExpandedSchema, RepositoryFileSchema, RepositoryTreeSchema } from '@gitbeaker/rest'; +import logger from '../shared/logging/WinstonLogger'; +import { AccessLevel, EditProjectOptions, ProjectVariableSchema, ProtectedBranchAccessLevel, ProtectedBranchSchema } from '@gitbeaker/core'; +import GlobalHelper from '../helpers/GlobalHelper'; class GitlabManager { @@ -30,35 +28,6 @@ class GitlabManager { } } - public async getUserById(id: number): Promise<UserSchema | undefined> { - try { - const user = await this.api.Users.show(id); - - return user.id === id ? user : undefined; - } catch ( e ) { - return undefined; - } - } - - public async getUserByUsername(username: string): Promise<UserSchema | undefined> { - try { - const user = await this.api.Users.all({ - username: username, - maxPages: 1, - perPage : 1 - }); - - - return user.length > 0 && user[0].username === username ? user[0] : undefined; - } catch ( e ) { - return undefined; - } - } - - async getRepository(projectIdOrNamespace: string): Promise<ProjectSchema> { - return await this.api.Projects.show(projectIdOrNamespace); - } - async getRepositoryMembers(idOrNamespace: string): Promise<Array<MemberSchema>> { return await this.api.ProjectMembers.all(idOrNamespace, { includeInherited: true }); } @@ -138,7 +107,7 @@ class GitlabManager { async checkTemplateAccess(projectIdOrNamespace: string, req: express.Request, res?: express.Response): Promise<boolean> { // Get the Gitlab project and check if it have public or internal visibility try { - const project: ProjectSchema = await this.getRepository(projectIdOrNamespace); + const project: ProjectSchema = await GlobalHelper.sharedGitlabManager.getRepository(projectIdOrNamespace); if ( [ 'public', 'internal' ].includes(project.visibility) ) { return StatusCodes.OK;