Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoBackendAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Backend
DojoBackendAPI
Commits
9a059fef
Commit
9a059fef
authored
1 year ago
by
michael.minelli
Committed by
michael.minelli
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
GitlabManager => Move some function to shared one
parent
e838a45b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ExpressAPI/src/helpers/Prisma/Extensions/UserResultExtension.ts
+1
-1
1 addition, 1 deletion
...sAPI/src/helpers/Prisma/Extensions/UserResultExtension.ts
ExpressAPI/src/managers/GitlabManager.ts
+10
-41
10 additions, 41 deletions
ExpressAPI/src/managers/GitlabManager.ts
with
11 additions
and
42 deletions
ExpressAPI/src/helpers/Prisma/Extensions/UserResultExtension.ts
+
1
−
1
View file @
9a059fef
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
=>
{
...
...
This diff is collapsed.
Click to expand it.
ExpressAPI/src/managers/GitlabManager.ts
+
10
−
41
View file @
9a059fef
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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment