Skip to content
Snippets Groups Projects
Commit 9a059fef authored by michael.minelli's avatar michael.minelli Committed by michael.minelli
Browse files

GitlabManager => Move some function to shared one

parent e838a45b
No related branches found
No related tags found
No related merge requests found
import { Prisma, UserRole } from '@prisma/client'; import { Prisma, UserRole } from '@prisma/client';
import LazyVal from '../../../shared/helpers/LazyVal'; import LazyVal from '../../../shared/helpers/LazyVal';
import GitlabManager from '../../../managers/GitlabManager';
import * as Gitlab from '@gitbeaker/rest'; import * as Gitlab from '@gitbeaker/rest';
import GlobalHelper from '../../GlobalHelper';
export default Prisma.defineExtension(client => { export default Prisma.defineExtension(client => {
......
import Config from '../config/Config'; import Config from '../config/Config';
import { StatusCodes } from 'http-status-codes'; import { StatusCodes } from 'http-status-codes';
import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility'; import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility';
import express from 'express'; import express from 'express';
import SharedConfig from '../shared/config/SharedConfig'; import SharedConfig from '../shared/config/SharedConfig';
import { CommitSchema, ExpandedUserSchema, Gitlab, MemberSchema, ProjectBadgeSchema, ProjectSchema, ReleaseSchema, RepositoryFileExpandedSchema, RepositoryFileSchema, RepositoryTreeSchema, UserSchema } from '@gitbeaker/rest'; import { CommitSchema, ExpandedUserSchema, Gitlab, MemberSchema, ProjectBadgeSchema, ProjectSchema, ReleaseSchema, RepositoryFileExpandedSchema, RepositoryFileSchema, RepositoryTreeSchema } from '@gitbeaker/rest';
import logger from '../shared/logging/WinstonLogger'; import logger from '../shared/logging/WinstonLogger';
import { AccessLevel, EditProjectOptions, ProjectVariableSchema, ProtectedBranchAccessLevel, ProtectedBranchSchema } from '@gitbeaker/core'; import { AccessLevel, EditProjectOptions, ProjectVariableSchema, ProtectedBranchAccessLevel, ProtectedBranchSchema } from '@gitbeaker/core';
import axios from 'axios'; import GlobalHelper from '../helpers/GlobalHelper';
import parseLinkHeader from 'parse-link-header';
import DojoStatusCode from '../shared/types/Dojo/DojoStatusCode';
class GitlabManager { class GitlabManager {
...@@ -30,35 +28,6 @@ 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>> { async getRepositoryMembers(idOrNamespace: string): Promise<Array<MemberSchema>> {
return await this.api.ProjectMembers.all(idOrNamespace, { includeInherited: true }); return await this.api.ProjectMembers.all(idOrNamespace, { includeInherited: true });
} }
...@@ -138,7 +107,7 @@ class GitlabManager { ...@@ -138,7 +107,7 @@ class GitlabManager {
async checkTemplateAccess(projectIdOrNamespace: string, req: express.Request, res?: express.Response): Promise<boolean> { 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 // Get the Gitlab project and check if it have public or internal visibility
try { try {
const project: ProjectSchema = await this.getRepository(projectIdOrNamespace); const project: ProjectSchema = await GlobalHelper.sharedGitlabManager.getRepository(projectIdOrNamespace);
if ( [ 'public', 'internal' ].includes(project.visibility) ) { if ( [ 'public', 'internal' ].includes(project.visibility) ) {
return StatusCodes.OK; return StatusCodes.OK;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment