mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-05 22:11:09 +00:00
Merge pull request #11995 from overleaf/em-unnecessary-returns
Decaf cleanup: unnecessary returns GitOrigin-RevId: e3c006b0e15095c8cbed2911269f704a7fdd1d57
This commit is contained in:
parent
6fdd284ec8
commit
bb9bafdf1a
20 changed files with 241 additions and 281 deletions
|
@ -77,7 +77,7 @@ const AuthenticationManager = {
|
|||
if (match) {
|
||||
_metricsForSuccessfulPasswordMatch(password)
|
||||
}
|
||||
return callback(null, user, match)
|
||||
callback(null, user, match)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
|
|
@ -3,13 +3,6 @@
|
|||
n/handle-callback-err,
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let CollaboratorsEmailHandler
|
||||
const { Project } = require('../../models/Project')
|
||||
const EmailHandler = require('../Email/EmailHandler')
|
||||
|
@ -27,7 +20,7 @@ module.exports = CollaboratorsEmailHandler = {
|
|||
},
|
||||
|
||||
notifyUserOfProjectInvite(project_id, email, invite, sendingUser, callback) {
|
||||
return Project.findOne({ _id: project_id })
|
||||
Project.findOne({ _id: project_id })
|
||||
.select('name owner_ref')
|
||||
.populate('owner_ref')
|
||||
.exec(function (err, project) {
|
||||
|
@ -41,7 +34,7 @@ module.exports = CollaboratorsEmailHandler = {
|
|||
owner: project.owner_ref,
|
||||
sendingUser_id: sendingUser._id,
|
||||
}
|
||||
return EmailHandler.sendEmail('projectInvite', emailOptions, callback)
|
||||
EmailHandler.sendEmail('projectInvite', emailOptions, callback)
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -29,7 +28,7 @@ const CollaboratorsInviteHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
logger.debug({ projectId }, 'fetching invites for project')
|
||||
return ProjectInvite.find({ projectId }, function (err, invites) {
|
||||
ProjectInvite.find({ projectId }, function (err, invites) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error getting invites from mongo', {
|
||||
projectId,
|
||||
|
@ -40,7 +39,7 @@ const CollaboratorsInviteHandler = {
|
|||
{ projectId, count: invites.length },
|
||||
'found invites for project'
|
||||
)
|
||||
return callback(null, invites)
|
||||
callback(null, invites)
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -49,14 +48,14 @@ const CollaboratorsInviteHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
logger.debug({ projectId }, 'counting invites for project')
|
||||
return ProjectInvite.countDocuments({ projectId }, function (err, count) {
|
||||
ProjectInvite.countDocuments({ projectId }, function (err, count) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error getting invites from mongo', {
|
||||
projectId,
|
||||
})
|
||||
return callback(err)
|
||||
}
|
||||
return callback(null, count)
|
||||
callback(null, count)
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -65,7 +64,7 @@ const CollaboratorsInviteHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
const { email } = invite
|
||||
return UserGetter.getUserByAnyEmail(
|
||||
UserGetter.getUserByAnyEmail(
|
||||
email,
|
||||
{ _id: 1 },
|
||||
function (err, existingUser) {
|
||||
|
@ -83,7 +82,7 @@ const CollaboratorsInviteHandler = {
|
|||
)
|
||||
return callback(null)
|
||||
}
|
||||
return ProjectGetter.getProject(
|
||||
ProjectGetter.getProject(
|
||||
projectId,
|
||||
{ _id: 1, name: 1 },
|
||||
function (err, project) {
|
||||
|
@ -101,7 +100,7 @@ const CollaboratorsInviteHandler = {
|
|||
)
|
||||
return callback(null)
|
||||
}
|
||||
return NotificationsBuilder.projectInvite(
|
||||
NotificationsBuilder.projectInvite(
|
||||
invite,
|
||||
project,
|
||||
sendingUser,
|
||||
|
@ -117,7 +116,7 @@ const CollaboratorsInviteHandler = {
|
|||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
return NotificationsBuilder.projectInvite(
|
||||
NotificationsBuilder.projectInvite(
|
||||
{ _id: inviteId },
|
||||
null,
|
||||
null,
|
||||
|
@ -133,7 +132,7 @@ const CollaboratorsInviteHandler = {
|
|||
{ projectId, inviteId: invite._id },
|
||||
'sending notification and email for invite'
|
||||
)
|
||||
return CollaboratorsEmailHandler.notifyUserOfProjectInvite(
|
||||
CollaboratorsEmailHandler.notifyUserOfProjectInvite(
|
||||
projectId,
|
||||
invite.email,
|
||||
invite,
|
||||
|
@ -142,7 +141,7 @@ const CollaboratorsInviteHandler = {
|
|||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return CollaboratorsInviteHandler._trySendInviteNotification(
|
||||
CollaboratorsInviteHandler._trySendInviteNotification(
|
||||
projectId,
|
||||
sendingUser,
|
||||
invite,
|
||||
|
@ -150,7 +149,7 @@ const CollaboratorsInviteHandler = {
|
|||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback()
|
||||
callback()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -165,7 +164,7 @@ const CollaboratorsInviteHandler = {
|
|||
{ projectId, sendingUserId: sendingUser._id, email, privileges },
|
||||
'adding invite'
|
||||
)
|
||||
return Crypto.randomBytes(24, function (err, buffer) {
|
||||
Crypto.randomBytes(24, function (err, buffer) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error generating random token', {
|
||||
projectId,
|
||||
|
@ -182,7 +181,7 @@ const CollaboratorsInviteHandler = {
|
|||
projectId,
|
||||
privileges,
|
||||
})
|
||||
return invite.save(function (err, invite) {
|
||||
invite.save(function (err, invite) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error saving token', {
|
||||
projectId,
|
||||
|
@ -205,7 +204,7 @@ const CollaboratorsInviteHandler = {
|
|||
}
|
||||
}
|
||||
)
|
||||
return callback(null, invite)
|
||||
callback(null, invite)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
@ -215,23 +214,20 @@ const CollaboratorsInviteHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
logger.debug({ projectId, inviteId }, 'removing invite')
|
||||
return ProjectInvite.deleteOne(
|
||||
{ projectId, _id: inviteId },
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error removing invite', {
|
||||
projectId,
|
||||
inviteId,
|
||||
})
|
||||
return callback(err)
|
||||
}
|
||||
CollaboratorsInviteHandler._tryCancelInviteNotification(
|
||||
ProjectInvite.deleteOne({ projectId, _id: inviteId }, function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error removing invite', {
|
||||
projectId,
|
||||
inviteId,
|
||||
function () {}
|
||||
)
|
||||
return callback(null)
|
||||
})
|
||||
return callback(err)
|
||||
}
|
||||
)
|
||||
CollaboratorsInviteHandler._tryCancelInviteNotification(
|
||||
inviteId,
|
||||
function () {}
|
||||
)
|
||||
callback(null)
|
||||
})
|
||||
},
|
||||
|
||||
resendInvite(projectId, sendingUser, inviteId, callback) {
|
||||
|
@ -239,40 +235,37 @@ const CollaboratorsInviteHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
logger.debug({ projectId, inviteId }, 'resending invite email')
|
||||
return ProjectInvite.findOne(
|
||||
{ _id: inviteId, projectId },
|
||||
function (err, invite) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error finding invite', {
|
||||
projectId,
|
||||
inviteId,
|
||||
})
|
||||
return callback(err)
|
||||
}
|
||||
if (invite == null) {
|
||||
logger.err(
|
||||
{ err, projectId, inviteId },
|
||||
'no invite found, nothing to resend'
|
||||
)
|
||||
return callback(null)
|
||||
}
|
||||
return CollaboratorsInviteHandler._sendMessages(
|
||||
ProjectInvite.findOne({ _id: inviteId, projectId }, function (err, invite) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error finding invite', {
|
||||
projectId,
|
||||
sendingUser,
|
||||
invite,
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error resending invite messages', {
|
||||
projectId,
|
||||
inviteId,
|
||||
})
|
||||
return callback(err)
|
||||
}
|
||||
return callback(null)
|
||||
}
|
||||
)
|
||||
inviteId,
|
||||
})
|
||||
return callback(err)
|
||||
}
|
||||
)
|
||||
if (invite == null) {
|
||||
logger.err(
|
||||
{ err, projectId, inviteId },
|
||||
'no invite found, nothing to resend'
|
||||
)
|
||||
return callback(null)
|
||||
}
|
||||
CollaboratorsInviteHandler._sendMessages(
|
||||
projectId,
|
||||
sendingUser,
|
||||
invite,
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error resending invite messages', {
|
||||
projectId,
|
||||
inviteId,
|
||||
})
|
||||
return callback(err)
|
||||
}
|
||||
callback(null)
|
||||
}
|
||||
)
|
||||
})
|
||||
},
|
||||
|
||||
getInviteByToken(projectId, tokenString, callback) {
|
||||
|
@ -280,7 +273,7 @@ const CollaboratorsInviteHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
logger.debug({ projectId }, 'fetching invite by token')
|
||||
return ProjectInvite.findOne(
|
||||
ProjectInvite.findOne(
|
||||
{ projectId, token: tokenString },
|
||||
function (err, invite) {
|
||||
if (err != null) {
|
||||
|
@ -293,7 +286,7 @@ const CollaboratorsInviteHandler = {
|
|||
logger.err({ err, projectId }, 'no invite found')
|
||||
return callback(null, null)
|
||||
}
|
||||
return callback(null, invite)
|
||||
callback(null, invite)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
@ -303,7 +296,7 @@ const CollaboratorsInviteHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
logger.debug({ projectId, userId: user._id }, 'accepting invite')
|
||||
return CollaboratorsInviteHandler.getInviteByToken(
|
||||
CollaboratorsInviteHandler.getInviteByToken(
|
||||
projectId,
|
||||
tokenString,
|
||||
function (err, invite) {
|
||||
|
@ -320,7 +313,7 @@ const CollaboratorsInviteHandler = {
|
|||
return callback(err)
|
||||
}
|
||||
const inviteId = invite._id
|
||||
return CollaboratorsHandler.addUserIdToProject(
|
||||
CollaboratorsHandler.addUserIdToProject(
|
||||
projectId,
|
||||
invite.sendingUserId,
|
||||
user._id,
|
||||
|
@ -336,7 +329,7 @@ const CollaboratorsInviteHandler = {
|
|||
}
|
||||
// Remove invite
|
||||
logger.debug({ projectId, inviteId }, 'removing invite')
|
||||
return ProjectInvite.deleteOne({ _id: inviteId }, function (err) {
|
||||
ProjectInvite.deleteOne({ _id: inviteId }, function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error removing invite', {
|
||||
projectId,
|
||||
|
@ -348,7 +341,7 @@ const CollaboratorsInviteHandler = {
|
|||
inviteId,
|
||||
function () {}
|
||||
)
|
||||
return callback()
|
||||
callback()
|
||||
})
|
||||
}
|
||||
)
|
||||
|
|
|
@ -133,7 +133,7 @@ const FileStoreHandler = {
|
|||
'error in file stream'
|
||||
)
|
||||
)
|
||||
return callback(null, readStream)
|
||||
callback(null, readStream)
|
||||
},
|
||||
|
||||
getFileSize(projectId, fileId, callback) {
|
||||
|
@ -168,14 +168,14 @@ const FileStoreHandler = {
|
|||
uri: this._buildUrl(projectId, fileId),
|
||||
timeout: FIVE_MINS_IN_MS,
|
||||
}
|
||||
return request(opts, function (err, response) {
|
||||
request(opts, function (err, response) {
|
||||
if (err) {
|
||||
logger.warn(
|
||||
{ err, projectId, fileId },
|
||||
'something went wrong deleting file from filestore'
|
||||
)
|
||||
}
|
||||
return callback(err)
|
||||
callback(err)
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -217,7 +217,7 @@ const FileStoreHandler = {
|
|||
uri: this._buildUrl(newProjectId, newFileId),
|
||||
timeout: FIVE_MINS_IN_MS,
|
||||
}
|
||||
return request(opts, function (err, response) {
|
||||
request(opts, function (err, response) {
|
||||
if (err) {
|
||||
OError.tag(
|
||||
err,
|
||||
|
@ -229,10 +229,10 @@ const FileStoreHandler = {
|
|||
newFileId,
|
||||
}
|
||||
)
|
||||
return callback(err)
|
||||
callback(err)
|
||||
} else if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
// successful response
|
||||
return callback(null, opts.uri)
|
||||
callback(null, opts.uri)
|
||||
} else {
|
||||
err = new OError(
|
||||
`non-ok response from filestore for copyFile: ${response.statusCode}`,
|
||||
|
@ -241,7 +241,7 @@ const FileStoreHandler = {
|
|||
statusCode: response.statusCode,
|
||||
}
|
||||
)
|
||||
return callback(err)
|
||||
callback(err)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -24,7 +23,7 @@ const { ObjectId } = require('mongodb')
|
|||
const MILISECONDS_IN_DAY = 86400000
|
||||
module.exports = InactiveProjectManager = {
|
||||
reactivateProjectIfRequired(project_id, callback) {
|
||||
return ProjectGetter.getProject(
|
||||
ProjectGetter.getProject(
|
||||
project_id,
|
||||
{ active: true },
|
||||
function (err, project) {
|
||||
|
@ -43,14 +42,14 @@ module.exports = InactiveProjectManager = {
|
|||
return callback()
|
||||
}
|
||||
|
||||
return DocstoreManager.unarchiveProject(project_id, function (err) {
|
||||
DocstoreManager.unarchiveProject(project_id, function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error reactivating project in docstore', {
|
||||
project_id,
|
||||
})
|
||||
return callback(err)
|
||||
}
|
||||
return ProjectUpdateHandler.markAsActive(project_id, callback)
|
||||
ProjectUpdateHandler.markAsActive(project_id, callback)
|
||||
})
|
||||
}
|
||||
)
|
||||
|
@ -113,11 +112,11 @@ module.exports = InactiveProjectManager = {
|
|||
cb => DocstoreManager.archiveProject(project_id, cb),
|
||||
cb => ProjectUpdateHandler.markAsInactive(project_id, cb),
|
||||
]
|
||||
return async.series(jobs, function (err) {
|
||||
async.series(jobs, function (err) {
|
||||
if (err != null) {
|
||||
logger.warn({ err, project_id }, 'error deactivating project')
|
||||
}
|
||||
return callback(err)
|
||||
callback(err)
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -30,7 +29,7 @@ module.exports = LinkedFilesHandler = {
|
|||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
return ProjectLocator.findElement(
|
||||
ProjectLocator.findElement(
|
||||
{
|
||||
project_id,
|
||||
element_id: file_id,
|
||||
|
@ -40,7 +39,7 @@ module.exports = LinkedFilesHandler = {
|
|||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(null, file, path, parentFolder)
|
||||
callback(null, file, path, parentFolder)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
@ -51,7 +50,7 @@ module.exports = LinkedFilesHandler = {
|
|||
}
|
||||
const projection = { _id: 1, name: 1 }
|
||||
if (data.v1_source_doc_id != null) {
|
||||
return Project.findOne(
|
||||
Project.findOne(
|
||||
{ 'overleaf.id': data.v1_source_doc_id },
|
||||
projection,
|
||||
function (err, project) {
|
||||
|
@ -61,11 +60,11 @@ module.exports = LinkedFilesHandler = {
|
|||
if (project == null) {
|
||||
return callback(new V1ProjectNotFoundError())
|
||||
}
|
||||
return callback(null, project)
|
||||
callback(null, project)
|
||||
}
|
||||
)
|
||||
} else if (data.source_project_id != null) {
|
||||
return ProjectGetter.getProject(
|
||||
ProjectGetter.getProject(
|
||||
data.source_project_id,
|
||||
projection,
|
||||
function (err, project) {
|
||||
|
@ -75,11 +74,11 @@ module.exports = LinkedFilesHandler = {
|
|||
if (project == null) {
|
||||
return callback(new ProjectNotFoundError())
|
||||
}
|
||||
return callback(null, project)
|
||||
callback(null, project)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
return callback(new BadDataError('neither v1 nor v2 id present'))
|
||||
callback(new BadDataError('neither v1 nor v2 id present'))
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -96,14 +95,14 @@ module.exports = LinkedFilesHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
callback = _.once(callback)
|
||||
return FileWriter.writeStreamToDisk(
|
||||
FileWriter.writeStreamToDisk(
|
||||
project_id,
|
||||
readStream,
|
||||
function (err, fsPath) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return EditorController.upsertFile(
|
||||
EditorController.upsertFile(
|
||||
project_id,
|
||||
parent_folder_id,
|
||||
name,
|
||||
|
@ -115,7 +114,7 @@ module.exports = LinkedFilesHandler = {
|
|||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(null, file)
|
||||
callback(null, file)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -135,29 +134,25 @@ module.exports = LinkedFilesHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
callback = _.once(callback)
|
||||
return FileWriter.writeContentToDisk(
|
||||
project_id,
|
||||
content,
|
||||
function (err, fsPath) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return EditorController.upsertFile(
|
||||
project_id,
|
||||
parent_folder_id,
|
||||
name,
|
||||
fsPath,
|
||||
linkedFileData,
|
||||
'upload',
|
||||
user_id,
|
||||
(err, file) => {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(null, file)
|
||||
}
|
||||
)
|
||||
FileWriter.writeContentToDisk(project_id, content, function (err, fsPath) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
)
|
||||
EditorController.upsertFile(
|
||||
project_id,
|
||||
parent_folder_id,
|
||||
name,
|
||||
fsPath,
|
||||
linkedFileData,
|
||||
'upload',
|
||||
user_id,
|
||||
(err, file) => {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
callback(null, file)
|
||||
}
|
||||
)
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -27,7 +26,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
|||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
return ProjectCollabratecDetailsHandler.setCollabratecUsers(
|
||||
ProjectCollabratecDetailsHandler.setCollabratecUsers(
|
||||
project_id,
|
||||
[{ user_id, collabratec_document_id, collabratec_privategroup_id }],
|
||||
callback
|
||||
|
@ -53,11 +52,11 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
|||
},
|
||||
},
|
||||
}
|
||||
return Project.findOne(query, { _id: 1 }, function (err, project) {
|
||||
Project.findOne(query, { _id: 1 }, function (err, project) {
|
||||
if (err != null) {
|
||||
callback(err)
|
||||
}
|
||||
return callback(null, project != null)
|
||||
callback(null, project != null)
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -96,7 +95,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
|||
},
|
||||
},
|
||||
}
|
||||
return Project.updateOne(query, update, callback)
|
||||
Project.updateOne(query, update, callback)
|
||||
},
|
||||
|
||||
setCollabratecUsers(project_id, collabratec_users, callback) {
|
||||
|
@ -122,7 +121,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
|||
}
|
||||
}
|
||||
const update = { $set: { collabratecUsers: collabratec_users } }
|
||||
return Project.updateOne({ _id: project_id }, update, callback)
|
||||
Project.updateOne({ _id: project_id }, update, callback)
|
||||
},
|
||||
|
||||
unlinkCollabratecUserProject(project_id, user_id, callback) {
|
||||
|
@ -144,7 +143,7 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
|||
},
|
||||
},
|
||||
}
|
||||
return Project.updateOne(query, update, callback)
|
||||
Project.updateOne(query, update, callback)
|
||||
},
|
||||
|
||||
updateCollabratecUserIds(old_user_id, new_user_id, callback) {
|
||||
|
@ -160,6 +159,6 @@ module.exports = ProjectCollabratecDetailsHandler = {
|
|||
}
|
||||
const query = { 'collabratecUsers.user_id': old_user_id }
|
||||
const update = { $set: { 'collabratecUsers.$.user_id': new_user_id } }
|
||||
return Project.updateMany(query, update, callback)
|
||||
Project.updateMany(query, update, callback)
|
||||
},
|
||||
}
|
||||
|
|
|
@ -200,9 +200,9 @@ const ProjectController = {
|
|||
|
||||
ProjectDeleter.archiveProject(projectId, userId, function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
next(err)
|
||||
} else {
|
||||
return res.sendStatus(200)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -213,9 +213,9 @@ const ProjectController = {
|
|||
|
||||
ProjectDeleter.unarchiveProject(projectId, userId, function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
next(err)
|
||||
} else {
|
||||
return res.sendStatus(200)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -226,9 +226,9 @@ const ProjectController = {
|
|||
|
||||
ProjectDeleter.trashProject(projectId, userId, function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
next(err)
|
||||
} else {
|
||||
return res.sendStatus(200)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -239,9 +239,9 @@ const ProjectController = {
|
|||
|
||||
ProjectDeleter.untrashProject(projectId, userId, function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
next(err)
|
||||
} else {
|
||||
return res.sendStatus(200)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -490,7 +490,7 @@ const ProjectController = {
|
|||
// and does async.series
|
||||
const allInReconfirmNotificationPeriods =
|
||||
(results && results[0]) || []
|
||||
return cb(null, {
|
||||
cb(null, {
|
||||
list: fullEmails,
|
||||
allInReconfirmNotificationPeriods,
|
||||
})
|
||||
|
@ -1394,7 +1394,7 @@ const ProjectController = {
|
|||
status: 'success',
|
||||
})
|
||||
}
|
||||
return callback(null, user)
|
||||
callback(null, user)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
|
|
@ -927,7 +927,7 @@ const ProjectEntityUpdateHandler = {
|
|||
}
|
||||
)
|
||||
} else if (existingFile) {
|
||||
return ProjectEntityUpdateHandler._replaceFile(
|
||||
ProjectEntityUpdateHandler._replaceFile(
|
||||
projectId,
|
||||
existingFile._id,
|
||||
fsPath,
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -33,7 +32,7 @@ const ProjectUpdateHandler = {
|
|||
lastUpdated: lastUpdatedAt || new Date().getTime(),
|
||||
lastUpdatedBy,
|
||||
}
|
||||
return Project.updateOne(conditions, update, {}, callback)
|
||||
Project.updateOne(conditions, update, {}, callback)
|
||||
},
|
||||
|
||||
// like markAsUpdated but allows lastUpdatedAt to be reset to earlier time
|
||||
|
@ -53,13 +52,13 @@ const ProjectUpdateHandler = {
|
|||
lastUpdated: lastUpdatedAt || new Date().getTime(),
|
||||
lastUpdatedBy,
|
||||
}
|
||||
return Project.updateOne(conditions, update, {}, callback)
|
||||
Project.updateOne(conditions, update, {}, callback)
|
||||
},
|
||||
|
||||
markAsOpened(project_id, callback) {
|
||||
const conditions = { _id: project_id }
|
||||
const update = { lastOpened: Date.now() }
|
||||
return Project.updateOne(conditions, update, {}, function (err) {
|
||||
Project.updateOne(conditions, update, {}, function (err) {
|
||||
if (callback != null) {
|
||||
return callback()
|
||||
}
|
||||
|
@ -69,7 +68,7 @@ const ProjectUpdateHandler = {
|
|||
markAsInactive(project_id, callback) {
|
||||
const conditions = { _id: project_id }
|
||||
const update = { active: false }
|
||||
return Project.updateOne(conditions, update, {}, function (err) {
|
||||
Project.updateOne(conditions, update, {}, function (err) {
|
||||
if (callback != null) {
|
||||
return callback()
|
||||
}
|
||||
|
@ -79,7 +78,7 @@ const ProjectUpdateHandler = {
|
|||
markAsActive(project_id, callback) {
|
||||
const conditions = { _id: project_id }
|
||||
const update = { active: true }
|
||||
return Project.updateOne(conditions, update, {}, function (err) {
|
||||
Project.updateOne(conditions, update, {}, function (err) {
|
||||
if (callback != null) {
|
||||
return callback()
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ function allocate(
|
|||
}
|
||||
|
||||
const query = { referal_id: referalId }
|
||||
return User.findOne(query, { _id: 1 }, function (error, user) {
|
||||
User.findOne(query, { _id: 1 }, function (error, user) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
|
|
|
@ -59,14 +59,14 @@ function createSubscription(
|
|||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
return SubscriptionUpdater.syncSubscription(
|
||||
SubscriptionUpdater.syncSubscription(
|
||||
recurlySubscription,
|
||||
user._id,
|
||||
function (error) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
return callback()
|
||||
callback()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -85,9 +85,9 @@ function updateSubscription(user, planCode, couponCode, callback) {
|
|||
)
|
||||
}
|
||||
if (!hasSubscription) {
|
||||
return callback()
|
||||
callback()
|
||||
} else {
|
||||
return async.series(
|
||||
async.series(
|
||||
[
|
||||
function (cb) {
|
||||
if (!couponCode) {
|
||||
|
@ -316,7 +316,7 @@ function attemptPaypalInvoiceCollection(recurlyAccountCode, callback) {
|
|||
}
|
||||
|
||||
function extendTrial(subscription, daysToExend, callback) {
|
||||
return RecurlyWrapper.extendTrial(
|
||||
RecurlyWrapper.extendTrial(
|
||||
subscription.recurlySubscription_id,
|
||||
daysToExend,
|
||||
callback
|
||||
|
|
|
@ -20,7 +20,7 @@ const Errors = require('../Errors/Errors')
|
|||
|
||||
module.exports = TeamInvitesHandler = {
|
||||
getInvite(token, callback) {
|
||||
return Subscription.findOne(
|
||||
Subscription.findOne(
|
||||
{ 'teamInvites.token': token },
|
||||
function (err, subscription) {
|
||||
if (err) {
|
||||
|
@ -41,7 +41,7 @@ module.exports = TeamInvitesHandler = {
|
|||
if (!email) {
|
||||
return callback(new Error('invalid email'))
|
||||
}
|
||||
return UserGetter.getUser(teamManagerId, function (error, teamManager) {
|
||||
UserGetter.getUser(teamManagerId, function (error, teamManager) {
|
||||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports = {
|
|||
featuresChanged = _featuresChanged(features, docBeforeUpdate.features)
|
||||
}
|
||||
|
||||
return callback(err, features, featuresChanged)
|
||||
callback(err, features, featuresChanged)
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -41,7 +41,7 @@ module.exports = {
|
|||
if (docBeforeUpdate) {
|
||||
featuresChanged = _featuresChanged(features, docBeforeUpdate.features)
|
||||
}
|
||||
return callback(err, featuresChanged)
|
||||
callback(err, featuresChanged)
|
||||
})
|
||||
},
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -27,14 +26,14 @@ module.exports = SystemMessageManager = {
|
|||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
return SystemMessage.find({}, callback)
|
||||
SystemMessage.find({}, callback)
|
||||
},
|
||||
|
||||
clearMessages(callback) {
|
||||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
return SystemMessage.deleteMany({}, callback)
|
||||
SystemMessage.deleteMany({}, callback)
|
||||
},
|
||||
|
||||
createMessage(content, callback) {
|
||||
|
@ -42,7 +41,7 @@ module.exports = SystemMessageManager = {
|
|||
callback = function () {}
|
||||
}
|
||||
const message = new SystemMessage({ content })
|
||||
return message.save(callback)
|
||||
message.save(callback)
|
||||
},
|
||||
|
||||
refreshCache() {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -53,7 +52,7 @@ const TemplatesManager = {
|
|||
logger.warn({ err }, 'error getting zip from template API')
|
||||
return callback(err)
|
||||
})
|
||||
return FileWriter.ensureDumpFolderExists(function (err) {
|
||||
FileWriter.ensureDumpFolderExists(function (err) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
|
@ -73,7 +72,7 @@ const TemplatesManager = {
|
|||
)
|
||||
return callback(new Error('get zip failed'))
|
||||
}
|
||||
return ProjectUploadManager.createProjectFromZipArchiveWithName(
|
||||
ProjectUploadManager.createProjectFromZipArchiveWithName(
|
||||
user_id,
|
||||
projectName,
|
||||
dumpPath,
|
||||
|
@ -85,7 +84,7 @@ const TemplatesManager = {
|
|||
})
|
||||
return callback(err)
|
||||
}
|
||||
return async.series(
|
||||
async.series(
|
||||
[
|
||||
cb => TemplatesManager._setCompiler(project._id, compiler, cb),
|
||||
cb => TemplatesManager._setImage(project._id, imageName, cb),
|
||||
|
@ -110,7 +109,7 @@ const TemplatesManager = {
|
|||
fromV1TemplateId: templateId,
|
||||
fromV1TemplateVersionId: templateVersionId,
|
||||
}
|
||||
return Project.updateOne(
|
||||
Project.updateOne(
|
||||
{ _id: project._id },
|
||||
update,
|
||||
{},
|
||||
|
@ -118,7 +117,7 @@ const TemplatesManager = {
|
|||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(null, project)
|
||||
callback(null, project)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ const TemplatesManager = {
|
|||
}
|
||||
)
|
||||
})
|
||||
return zipReq.pipe(writeStream)
|
||||
zipReq.pipe(writeStream)
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -134,32 +133,28 @@ const TemplatesManager = {
|
|||
if (compiler == null) {
|
||||
return callback()
|
||||
}
|
||||
return ProjectOptionsHandler.setCompiler(project_id, compiler, callback)
|
||||
ProjectOptionsHandler.setCompiler(project_id, compiler, callback)
|
||||
},
|
||||
|
||||
_setImage(project_id, imageName, callback) {
|
||||
if (!imageName) {
|
||||
imageName = 'wl_texlive:2018.1'
|
||||
}
|
||||
return ProjectOptionsHandler.setImageName(project_id, imageName, callback)
|
||||
ProjectOptionsHandler.setImageName(project_id, imageName, callback)
|
||||
},
|
||||
|
||||
_setMainFile(project_id, mainFile, callback) {
|
||||
if (mainFile == null) {
|
||||
return callback()
|
||||
}
|
||||
return ProjectRootDocManager.setRootDocFromName(
|
||||
project_id,
|
||||
mainFile,
|
||||
callback
|
||||
)
|
||||
ProjectRootDocManager.setRootDocFromName(project_id, mainFile, callback)
|
||||
},
|
||||
|
||||
_setBrandVariationId(project_id, brandVariationId, callback) {
|
||||
if (brandVariationId == null) {
|
||||
return callback()
|
||||
}
|
||||
return ProjectOptionsHandler.setBrandVariationId(
|
||||
ProjectOptionsHandler.setBrandVariationId(
|
||||
project_id,
|
||||
brandVariationId,
|
||||
callback
|
||||
|
|
|
@ -138,9 +138,9 @@ const TokenAccessHandler = {
|
|||
{ projectId: project._id },
|
||||
'read-and-write token match on numeric section, but not on full token'
|
||||
)
|
||||
return callback(null, null)
|
||||
callback(null, null)
|
||||
} else {
|
||||
return callback(null, project)
|
||||
callback(null, project)
|
||||
}
|
||||
} catch (error) {
|
||||
err = error
|
||||
|
@ -148,7 +148,7 @@ const TokenAccessHandler = {
|
|||
{ projectId: project._id, cryptoErr: err },
|
||||
'error comparing tokens'
|
||||
)
|
||||
return callback(null, null)
|
||||
callback(null, null)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -160,7 +160,7 @@ const TokenAccessHandler = {
|
|||
} else if (tokenType === TokenAccessHandler.TOKEN_TYPES.READ_AND_WRITE) {
|
||||
TokenAccessHandler.getProjectByReadAndWriteToken(token, callback)
|
||||
} else {
|
||||
return callback(new Error('invalid token type'))
|
||||
callback(new Error('invalid token type'))
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -237,7 +237,7 @@ const TokenAccessHandler = {
|
|||
return callback(null, false, false)
|
||||
}
|
||||
// TODO: think about cleaning up this interface and its usage in AuthorizationManager
|
||||
return callback(
|
||||
callback(
|
||||
null,
|
||||
tokenType === TokenAccessHandler.TOKEN_TYPES.READ_AND_WRITE &&
|
||||
TokenAccessHandler.ANONYMOUS_READ_AND_WRITE_ENABLED,
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -33,7 +32,7 @@ const UserMembershipHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
const query = buildEntityQuery(entityId, entityConfig)
|
||||
return EntityModels[entityConfig.modelName].findOne(query, callback)
|
||||
EntityModels[entityConfig.modelName].findOne(query, callback)
|
||||
},
|
||||
|
||||
createEntity(entityId, entityConfig, callback) {
|
||||
|
@ -41,7 +40,7 @@ const UserMembershipHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
const data = buildEntityQuery(entityId, entityConfig)
|
||||
return EntityModels[entityConfig.modelName].create(data, callback)
|
||||
EntityModels[entityConfig.modelName].create(data, callback)
|
||||
},
|
||||
|
||||
getUsers(entity, entityConfig, callback) {
|
||||
|
@ -49,7 +48,7 @@ const UserMembershipHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
const attributes = entityConfig.fields.read
|
||||
return getPopulatedListOfMembers(entity, attributes, callback)
|
||||
getPopulatedListOfMembers(entity, attributes, callback)
|
||||
},
|
||||
|
||||
addUser(entity, entityConfig, email, callback) {
|
||||
|
@ -57,7 +56,7 @@ const UserMembershipHandler = {
|
|||
callback = function () {}
|
||||
}
|
||||
const attribute = entityConfig.fields.write
|
||||
return UserGetter.getUserByAnyEmail(email, function (error, user) {
|
||||
UserGetter.getUserByAnyEmail(email, function (error, user) {
|
||||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
|
@ -70,7 +69,7 @@ const UserMembershipHandler = {
|
|||
return callback(error)
|
||||
}
|
||||
|
||||
return addUserToEntity(entity, attribute, user, error =>
|
||||
addUserToEntity(entity, attribute, user, error =>
|
||||
callback(error, UserMembershipViewModel.build(user))
|
||||
)
|
||||
})
|
||||
|
@ -84,7 +83,7 @@ const UserMembershipHandler = {
|
|||
if (entity.admin_id != null ? entity.admin_id.equals(userId) : undefined) {
|
||||
return callback(new UserIsManagerError())
|
||||
}
|
||||
return removeUserFromEntity(entity, attribute, userId, callback)
|
||||
removeUserFromEntity(entity, attribute, userId, callback)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -107,7 +106,7 @@ function getPopulatedListOfMembers(entity, attributes, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
return async.map(userObjects, UserMembershipViewModel.buildAsync, callback)
|
||||
async.map(userObjects, UserMembershipViewModel.buildAsync, callback)
|
||||
}
|
||||
|
||||
function addUserToEntity(entity, attribute, user, callback) {
|
||||
|
@ -116,7 +115,7 @@ function addUserToEntity(entity, attribute, user, callback) {
|
|||
}
|
||||
const fieldUpdate = {}
|
||||
fieldUpdate[attribute] = user._id
|
||||
return entity.updateOne({ $addToSet: fieldUpdate }, callback)
|
||||
entity.updateOne({ $addToSet: fieldUpdate }, callback)
|
||||
}
|
||||
|
||||
function removeUserFromEntity(entity, attribute, userId, callback) {
|
||||
|
@ -125,7 +124,7 @@ function removeUserFromEntity(entity, attribute, userId, callback) {
|
|||
}
|
||||
const fieldUpdate = {}
|
||||
fieldUpdate[attribute] = userId
|
||||
return entity.updateOne({ $pull: fieldUpdate }, callback)
|
||||
entity.updateOne({ $pull: fieldUpdate }, callback)
|
||||
}
|
||||
|
||||
function buildEntityQuery(entityId, entityConfig, loggedInUser) {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -34,7 +33,7 @@ const UserMembershipsHandler = {
|
|||
}
|
||||
|
||||
// remove the user from all entities types
|
||||
return async.map(
|
||||
async.map(
|
||||
entityConfigs,
|
||||
(entityConfig, innerCallback) =>
|
||||
UserMembershipsHandler.removeUserFromEntities(
|
||||
|
@ -52,7 +51,7 @@ const UserMembershipsHandler = {
|
|||
}
|
||||
const removeOperation = { $pull: {} }
|
||||
removeOperation.$pull[entityConfig.fields.write] = userId
|
||||
return EntityModels[entityConfig.modelName].updateMany(
|
||||
EntityModels[entityConfig.modelName].updateMany(
|
||||
{},
|
||||
removeOperation,
|
||||
callback
|
||||
|
@ -65,7 +64,7 @@ const UserMembershipsHandler = {
|
|||
}
|
||||
const query = Object.assign({}, entityConfig.baseQuery)
|
||||
query[entityConfig.fields.access] = userId
|
||||
return EntityModels[entityConfig.modelName].find(
|
||||
EntityModels[entityConfig.modelName].find(
|
||||
query,
|
||||
function (error, entities) {
|
||||
if (entities == null) {
|
||||
|
@ -74,7 +73,7 @@ const UserMembershipsHandler = {
|
|||
if (error != null) {
|
||||
return callback(error)
|
||||
}
|
||||
return async.mapSeries(
|
||||
async.mapSeries(
|
||||
entities,
|
||||
(entity, cb) => entity.fetchV1Data(cb),
|
||||
callback
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
|
@ -46,25 +45,22 @@ module.exports = LaunchpadController = {
|
|||
// * how does all this work with ldap and saml?
|
||||
const sessionUser = SessionManager.getSessionUser(req.session)
|
||||
const authMethod = LaunchpadController._getAuthMethod()
|
||||
return LaunchpadController._atLeastOneAdminExists(function (
|
||||
err,
|
||||
adminUserExists
|
||||
) {
|
||||
LaunchpadController._atLeastOneAdminExists(function (err, adminUserExists) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
if (!sessionUser) {
|
||||
if (!adminUserExists) {
|
||||
return res.render(Path.resolve(__dirname, '../views/launchpad'), {
|
||||
res.render(Path.resolve(__dirname, '../views/launchpad'), {
|
||||
adminUserExists,
|
||||
authMethod,
|
||||
})
|
||||
} else {
|
||||
AuthenticationController.setRedirectInSession(req)
|
||||
return res.redirect('/login')
|
||||
res.redirect('/login')
|
||||
}
|
||||
} else {
|
||||
return UserGetter.getUser(
|
||||
UserGetter.getUser(
|
||||
sessionUser._id,
|
||||
{ isAdmin: 1 },
|
||||
function (err, user) {
|
||||
|
@ -72,13 +68,13 @@ module.exports = LaunchpadController = {
|
|||
return next(err)
|
||||
}
|
||||
if (hasAdminAccess(user)) {
|
||||
return res.render(Path.resolve(__dirname, '../views/launchpad'), {
|
||||
res.render(Path.resolve(__dirname, '../views/launchpad'), {
|
||||
wsUrl: Settings.wsUrl,
|
||||
adminUserExists,
|
||||
authMethod,
|
||||
})
|
||||
} else {
|
||||
return res.redirect('/restricted')
|
||||
res.redirect('/restricted')
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -90,14 +86,14 @@ module.exports = LaunchpadController = {
|
|||
if (callback == null) {
|
||||
callback = function () {}
|
||||
}
|
||||
return UserGetter.getUser(
|
||||
UserGetter.getUser(
|
||||
{ isAdmin: true },
|
||||
{ _id: 1, isAdmin: 1 },
|
||||
function (err, user) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(null, user != null)
|
||||
callback(null, user != null)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
@ -112,7 +108,7 @@ module.exports = LaunchpadController = {
|
|||
}
|
||||
logger.debug({ email }, 'sending test email')
|
||||
const emailOptions = { to: email }
|
||||
return EmailHandler.sendEmail('testEmail', emailOptions, function (err) {
|
||||
EmailHandler.sendEmail('testEmail', emailOptions, function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error sending test email', {
|
||||
email,
|
||||
|
@ -140,7 +136,7 @@ module.exports = LaunchpadController = {
|
|||
}
|
||||
|
||||
logger.debug({ email }, 'attempted register first admin user')
|
||||
return LaunchpadController._atLeastOneAdminExists(function (err, exists) {
|
||||
LaunchpadController._atLeastOneAdminExists(function (err, exists) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
|
@ -164,42 +160,39 @@ module.exports = LaunchpadController = {
|
|||
'creating admin account for specified external-auth user'
|
||||
)
|
||||
|
||||
return UserRegistrationHandler.registerNewUser(
|
||||
body,
|
||||
function (err, user) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error with registerNewUser', {
|
||||
email,
|
||||
authMethod,
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
return User.updateOne(
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: { isAdmin: true },
|
||||
emails: [{ email }],
|
||||
},
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error setting user to admin', {
|
||||
user_id: user._id,
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
AuthenticationController.setRedirectInSession(req, '/launchpad')
|
||||
logger.debug(
|
||||
{ email, user_id: user._id, authMethod },
|
||||
'created first admin account'
|
||||
)
|
||||
|
||||
return res.json({ redir: '/launchpad', email })
|
||||
}
|
||||
)
|
||||
UserRegistrationHandler.registerNewUser(body, function (err, user) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error with registerNewUser', {
|
||||
email,
|
||||
authMethod,
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
)
|
||||
|
||||
User.updateOne(
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: { isAdmin: true },
|
||||
emails: [{ email }],
|
||||
},
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error setting user to admin', {
|
||||
user_id: user._id,
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
AuthenticationController.setRedirectInSession(req, '/launchpad')
|
||||
logger.debug(
|
||||
{ email, user_id: user._id, authMethod },
|
||||
'created first admin account'
|
||||
)
|
||||
|
||||
res.json({ redir: '/launchpad', email })
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
|
@ -213,7 +206,7 @@ module.exports = LaunchpadController = {
|
|||
}
|
||||
|
||||
logger.debug({ email }, 'attempted register first admin user')
|
||||
return LaunchpadController._atLeastOneAdminExists(function (err, exists) {
|
||||
LaunchpadController._atLeastOneAdminExists(function (err, exists) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
|
@ -246,39 +239,36 @@ module.exports = LaunchpadController = {
|
|||
}
|
||||
|
||||
const body = { email, password }
|
||||
return UserRegistrationHandler.registerNewUser(
|
||||
body,
|
||||
function (err, user) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
logger.debug({ user_id: user._id }, 'making user an admin')
|
||||
User.updateOne(
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: {
|
||||
isAdmin: true,
|
||||
emails: [{ email }],
|
||||
},
|
||||
},
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error setting user to admin', {
|
||||
user_id: user._id,
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
{ email, user_id: user._id },
|
||||
'created first admin account'
|
||||
)
|
||||
res.json({ redir: '/launchpad' })
|
||||
}
|
||||
)
|
||||
UserRegistrationHandler.registerNewUser(body, function (err, user) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
)
|
||||
|
||||
logger.debug({ user_id: user._id }, 'making user an admin')
|
||||
User.updateOne(
|
||||
{ _id: user._id },
|
||||
{
|
||||
$set: {
|
||||
isAdmin: true,
|
||||
emails: [{ email }],
|
||||
},
|
||||
},
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error setting user to admin', {
|
||||
user_id: user._id,
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
{ email, user_id: user._id },
|
||||
'created first admin account'
|
||||
)
|
||||
res.json({ redir: '/launchpad' })
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue