Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
m4lab_tv1
User Account
Commits
c39c5090
Commit
c39c5090
authored
3 years ago
by
Rosanny Sihombing
Browse files
Options
Download
Email Patches
Plain Diff
handle new gitlab users
parent
2a084f63
master
MLAB-677
devel
reset-jul13
reset-merge
testing
5 merge requests
!143
updating yml config
,
!91
Prepare prod
,
!90
Testing
,
!89
Testing
,
!79
Mlab 383
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
routes/gitlab.js
+10
-9
routes/gitlab.js
routes/methods.js
+5
-1
routes/methods.js
routes/routes-account.js
+27
-17
routes/routes-account.js
with
42 additions
and
27 deletions
+42
-27
routes/gitlab.js
+
10
-
9
View file @
c39c5090
...
...
@@ -14,10 +14,7 @@ var gitlab = {
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
config
.
gitlab
.
token_readWriteProjects
}
})
.
then
(
res
=>
userData
=
{
id
:
res
.
data
[
0
].
id
,
username
:
res
.
data
[
0
].
username
})
.
then
(
res
=>
res
.
data
[
0
])
.
catch
(
err
=>
console
.
error
(
err
))
},
createNewPages
:
async
function
(
newPagesData
,
newLogoFile
,
template
)
{
...
...
@@ -72,8 +69,10 @@ var gitlab = {
getUserProjects
:
async
function
(
gitlabUserId
)
{
return
axios
({
method
:
'
get
'
,
url
:
'
https://transfer.hft-stuttgart.de/gitlab/api/v4/users/
'
+
gitlabUserId
+
'
/projects?private_token=
'
+
config
.
gitlab
.
token_readWriteProjects
+
'
&owned=true&simple=true&visibility=public
'
url
:
'
https://transfer.hft-stuttgart.de/gitlab/api/v4/users/
'
+
gitlabUserId
+
'
/projects?owned=true&visibility=public
'
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
config
.
gitlab
.
token_readWriteProjects
}
})
.
then
(
res
=>
res
.
data
)
.
catch
(
err
=>
console
.
error
(
err
))
...
...
@@ -81,11 +80,13 @@ var gitlab = {
getProjectById
:
async
function
(
projectId
)
{
return
axios
({
method
:
'
get
'
,
url
:
'
https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/
'
+
projectId
+
'
?private_token=
'
+
config
.
gitlab
.
token_readWriteProjects
url
:
'
https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/
'
+
projectId
,
headers
:
{
'
Authorization
'
:
'
Bearer
'
+
config
.
gitlab
.
token_readWriteProjects
}
})
.
then
(
res
=>
res
.
data
)
.
catch
(
err
=>
console
.
error
(
err
))
.
catch
(
err
=>
console
.
error
(
err
.
response
.
status
))
},
getProjectPipelineLatestStatus
:
async
function
(
projectId
)
{
return
axios
({
...
...
This diff is collapsed.
Click to expand it.
routes/methods.js
+
5
-
1
View file @
c39c5090
...
...
@@ -228,7 +228,11 @@ var methods = {
getGitlabId
:
async
function
(
userId
)
{
try
{
let
rows
=
await
dbconn
.
user
.
promise
().
query
(
'
SELECT gu.gitlab_userId FROM user_gitlab gu, user u WHERE u.id = "
'
+
userId
+
'
" and gu.user_id = u.id
'
)
return
rows
[
0
][
0
].
gitlab_userId
if
(
rows
[
0
][
0
])
{
return
rows
[
0
][
0
].
gitlab_userId
}
else
{
return
null
}
}
catch
(
err
)
{
console
.
error
(
err
)
...
...
This diff is collapsed.
Click to expand it.
routes/routes-account.js
+
27
-
17
View file @
c39c5090
...
...
@@ -118,7 +118,9 @@ module.exports = function (app, config, passport, i18n) {
)
let
userGitlabId
=
await
methods
.
getGitlabId
(
loggedInUser
.
id
)
loggedInUser
.
setGitlabUserId
(
userGitlabId
)
if
(
userGitlabId
)
{
loggedInUser
.
setGitlabUserId
(
userGitlabId
)
}
return
loggedInUser
}
...
...
@@ -192,8 +194,10 @@ module.exports = function (app, config, passport, i18n) {
if
(
loggedInUser
.
getGitlabUserId
())
{
// for users who have activated their gitlab account
let
userProjects
=
await
gitlab
.
getUserProjects
(
loggedInUser
.
getGitlabUserId
())
if
(
!
userProjects
)
res
.
status
(
500
).
send
(
"
something went wrong :/
"
)
if
(
!
userProjects
)
{
console
.
error
(
"
something went wrong
"
)
res
.
status
(
500
).
render
(
lang
+
'
/500
'
,
{
error
:
"
something went wrong
"
})
}
for
(
project
in
userProjects
)
{
if
(
userProjects
[
project
].
tag_list
.
includes
(
'
website
'
))
{
...
...
@@ -217,19 +221,25 @@ module.exports = function (app, config, passport, i18n) {
})
}
else
{
// for users who have not activated their gitlab account yet
let
gitlabUser
=
await
gitlab
.
getUserByEmail
(
loggedInUser
.
getEmail
())
// RS: if error, then what?
let
gitlabActivationData
=
{
user_id
:
loggedInUser
.
getId
(),
gitlab_userId
:
gitlabUser
.
id
}
// RS: update to await
methods
.
addGitlabUser
(
gitlabActivationData
,
function
(
err
){
if
(
err
)
{
res
.
status
(
500
).
render
(
lang
+
'
/500
'
,
{
error
:
err
})
}
else
{
loggedInUser
.
setGitlabUserId
(
gitlabActivationData
.
gitlab_userId
)
res
.
redirect
(
'
/account/services
'
)
}
})
if
(
!
gitlabUser
)
{
res
.
render
(
lang
+
'
/account/services
'
,
{
user
:
loggedInUser
,
gitlabRepos
:
null
,
gitlabPages
:
null
})
}
else
{
let
gitlabActivationData
=
{
user_id
:
loggedInUser
.
getId
(),
gitlab_userId
:
gitlabUser
.
id
}
// RS: update to await?
methods
.
addGitlabUser
(
gitlabActivationData
,
function
(
err
){
if
(
err
)
{
res
.
status
(
500
).
render
(
lang
+
'
/500
'
,
{
error
:
err
})
}
else
{
res
.
redirect
(
'
/account/services
'
)
}
})
}
}
}
}
...
...
@@ -471,7 +481,7 @@ module.exports = function (app, config, passport, i18n) {
let
loggedInUser
=
await
getLoggedInUserData
(
req
.
user
.
email
)
let
gitlabUser
=
await
gitlab
.
getUserByEmail
(
loggedInUser
.
getEmail
())
if
(
!
gitlabUser
)
{
// no user found
res
.
redirect
(
'
/account/service
'
)
res
.
redirect
(
'
/account/service
s
'
)
}
else
{
res
.
render
(
lang
+
'
/account/newInformation
'
,
{
user
:
loggedInUser
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets