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
9f589825
Commit
9f589825
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
GitlabManager => Add custom error status code
parent
85aca0f7
No related branches found
No related tags found
1 merge request
!3
Return error when client headers are missing (issue #19)
Pipeline
#30019
failed
1 year ago
Stage: code_quality
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ExpressAPI/src/managers/GitlabManager.ts
+11
-4
11 additions, 4 deletions
ExpressAPI/src/managers/GitlabManager.ts
ExpressAPI/src/routes/GitlabRoutes.ts
+1
-1
1 addition, 1 deletion
ExpressAPI/src/routes/GitlabRoutes.ts
ExpressAPI/src/shared
+1
-1
1 addition, 1 deletion
ExpressAPI/src/shared
with
13 additions
and
6 deletions
ExpressAPI/src/managers/GitlabManager.ts
+
11
−
4
View file @
9f589825
...
@@ -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
>
{
...
...
This diff is collapsed.
Click to expand it.
ExpressAPI/src/routes/GitlabRoutes.ts
+
1
−
1
View file @
9f589825
...
@@ -14,7 +14,7 @@ class GitlabRoutes implements RoutesManager {
...
@@ -14,7 +14,7 @@ class GitlabRoutes implements RoutesManager {
private
async
checkTemplateAccess
(
req
:
express
.
Request
,
res
:
express
.
Response
)
{
private
async
checkTemplateAccess
(
req
:
express
.
Request
,
res
:
express
.
Response
)
{
const
gitlabProjectIdOrNamespace
:
string
=
req
.
params
.
gitlabProjectIdOrNamespace
;
const
gitlabProjectIdOrNamespace
:
string
=
req
.
params
.
gitlabProjectIdOrNamespace
;
return
res
.
status
(
await
GitlabManager
.
checkTemplateAccess
(
gitlabProjectIdOrNamespace
,
req
)).
send
(
);
await
GitlabManager
.
checkTemplateAccess
(
gitlabProjectIdOrNamespace
,
req
,
res
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
shared
@
6e8f4584
Compare
1346565c
...
6e8f4584
Subproject commit
1346565c5759be045a1347f82eea230d393e38cb
Subproject commit
6e8f45841ca086956d34370cb3639262e69aa3c3
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