Commit c39c5090 authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

handle new gitlab users

5 merge requests!143updating yml config,!91Prepare prod,!90Testing,!89Testing,!79Mlab 383
This commit is part of merge request !79. Comments created here will be created in the context of that merge request.
Showing with 42 additions and 27 deletions
+42 -27
......@@ -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({
......
......@@ -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)
......
......@@ -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/services')
} else {
res.render(lang+'/account/newInformation', {
user: loggedInUser,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment