Commit ce2acbce authored by Jure's avatar Jure

Merge branch 'fix-consistent-return' into 'master'

Fix consistent-return lint errors

See merge request !29
parents b4fe43c4 a0bbf1cf
......@@ -6,7 +6,6 @@
},
"extends": ["pubsweet"],
"rules": {
"consistent-return": 0,
"prefer-destructuring": ["error", {
"VariableDeclarator": {
"array": false,
......@@ -24,7 +23,6 @@
"jsx-a11y/click-events-have-key-events": 0,
"jsx-a11y/label-has-for": 0,
"jsx-a11y/no-static-element-interactions": 0,
"import/extensions": 0,
"import/no-dynamic-require": 0,
"import/no-extraneous-dependencies": 0,
"import/no-named-as-default": 0,
......
......@@ -61,11 +61,11 @@ const EpubBackend = app => {
switch (req.query.destination) {
case 'folder':
return output.folder(epub, res)
output.folder(epub, res)
break
case 'attachment':
default:
return output.attachment(epub, res, id)
output.attachment(epub, res, id)
}
} catch (e) {
next(e)
......
......@@ -10,7 +10,7 @@ const { validateSetupDbConfig } = require('../validations')
const checkNoDb = async mergedDbConfig => {
const exists = await dbExists()
if (!exists) return null
if (!exists) return
if (!mergedDbConfig.clobber) {
logger.error(
......
......@@ -3,7 +3,7 @@ const winston = require('winston')
module.exports = {
'pubsweet-server': {
logger: winston,
logger: new winston.Logger({ level: 'warn' }),
secret: 'test',
sse: false,
},
......
......@@ -44,15 +44,16 @@ const verifyPassword = (username, password, done) => {
})
.then(([user, isValid]) => {
if (isValid) {
return done(null, user, { id: user.id })
done(null, user, { id: user.id })
return
}
logger.debug('Invalid password for user:', username)
return done(null, false, { message: errorMessage })
done(null, false, { message: errorMessage })
})
.catch(err => {
logger.debug('User not found', err)
if (err) {
return done(null, false, { message: errorMessage })
done(null, false, { message: errorMessage })
}
})
}
......
......@@ -48,14 +48,13 @@ class Team extends Model {
async save() {
await Promise.all(
this.members.map(member =>
User.find(member).then(user => {
if (!user.teams.includes(this.id)) {
user.teams.push(this.id)
return user.save()
}
}),
),
this.members.map(async member => {
const user = await User.find(member)
if (!user.teams.includes(this.id)) {
user.teams.push(this.id)
await user.save()
}
}),
)
return super.save()
......@@ -63,14 +62,13 @@ class Team extends Model {
async delete() {
await Promise.all(
this.members.map(member =>
User.find(member).then(user => {
if (user.teams.includes(this.id)) {
user.teams = _.without(user.teams, this.id)
return user.save()
}
}),
),
this.members.map(async member => {
const user = await User.find(member)
if (user.teams.includes(this.id)) {
user.teams = _.without(user.teams, this.id)
await user.save()
}
}),
)
return super.delete()
......
......@@ -2,7 +2,7 @@ global.db = require('../db')()
module.exports = () => {
if (!db.rel) {
return db.setSchema([
db.setSchema([
{
singular: 'collection',
plural: 'collections',
......
......@@ -89,7 +89,7 @@ api.get(
target: collection,
})
return res.status(STATUS.OK).json(properties)
res.status(STATUS.OK).json(properties)
} catch (err) {
next(err)
}
......
......@@ -106,7 +106,7 @@ api.get(
fragments = fragments.map(fieldSelector(req))
return res.status(STATUS.OK).json(fragments)
res.status(STATUS.OK).json(fragments)
} catch (err) {
next(err)
}
......@@ -123,7 +123,7 @@ api.get(
fragment.owners = await User.ownersWithUsername(fragment)
const properties = await applyPermissionFilter({ req, target: fragment })
return res.status(STATUS.OK).json(properties)
res.status(STATUS.OK).json(properties)
} catch (err) {
res.status(STATUS.NOT_FOUND).json(err.message)
}
......@@ -276,21 +276,19 @@ api.get(
authBearerAndPublic,
async (req, res, next) => {
try {
const fragment = await Fragment.find(req.params.fragmentId)
let fragment = await Fragment.find(req.params.fragmentId)
const permission = await authsome.can(req.user, req.method, fragment)
if (!permission) {
throw authorizationError(req.user, req.method, fragment)
}
return Fragment.find(req.params.fragmentId).then(fragment => {
if (permission.filter) {
fragment = permission.filter(fragment)
}
return res.status(STATUS.OK).json(fragment)
})
if (permission.filter) {
fragment = permission.filter(fragment)
}
res.status(STATUS.OK).json(fragment)
} catch (err) {
res.status(STATUS.NOT_FOUND).json(err.message)
next(err)
}
},
)
......
......@@ -12,7 +12,10 @@ const storage = multer.diskStorage({
destination: 'uploads/',
filename(req, file, cb) {
crypto.pseudoRandomBytes(16, (err, raw) => {
if (err) return cb(err)
if (err) {
cb(err)
return
}
cb(null, raw.toString('hex') + path.extname(file.originalname))
})
......
......@@ -34,7 +34,7 @@ api.get('/users/authenticate', authBearer, async (req, res, next) => {
const user = await User.find(req.user)
user.token = req.authInfo.token
user.teams = await Promise.all(user.teams.map(teamId => Team.find(teamId)))
return res.status(STATUS.OK).json(user)
res.status(STATUS.OK).json(user)
} catch (err) {
next(err)
}
......@@ -47,7 +47,7 @@ api.post('/users', async (req, res, next) => {
if (req.body.admin) throw new ValidationError('invalid property: admin')
user = await user.save()
return res.status(STATUS.CREATED).json(user)
res.status(STATUS.CREATED).json(user)
} catch (err) {
next(err)
}
......@@ -64,7 +64,7 @@ api.get('/users', authBearer, async (req, res, next) => {
const users = (await User.all()).filter(createFilterFromQuery(req.query))
return res.status(STATUS.OK).json({ users })
res.status(STATUS.OK).json({ users })
} catch (err) {
next(err)
}
......@@ -80,7 +80,7 @@ api.get('/users/:id', authBearer, async (req, res, next) => {
throw authorizationError(req.user, req.method, req.path)
}
return res.status(STATUS.OK).json(user)
res.status(STATUS.OK).json(user)
} catch (err) {
next(err)
}
......@@ -96,7 +96,7 @@ api.delete('/users/:id', authBearer, async (req, res, next) => {
throw authorizationError(req.user, req.method, req.path)
}
user = await user.delete()
return res.status(STATUS.OK).json(user)
res.status(STATUS.OK).json(user)
} catch (err) {
next(err)
}
......@@ -126,7 +126,7 @@ api.patch('/users/:id', authBearer, async (req, res, next) => {
user = await user.save()
user = await User.find(req.params.id)
return res.status(STATUS.OK).json(user)
res.status(STATUS.OK).json(user)
} catch (err) {
next(err)
}
......
......@@ -57,9 +57,7 @@ Util.getTeams = async opts => {
opts.req.method,
team,
)
if (permission) {
return team
}
return permission ? team : undefined
}),
)
......
......@@ -33,7 +33,10 @@ prompt.get(
},
},
(err, result) => {
if (err) return logger.info(err)
if (err) {
logger.info(err)
return
}
logger.info('Received the following answers:')
logger.info(` username: ${result.username}`)
......
......@@ -30,6 +30,8 @@ async function teamPermissions(user, operation, object, context) {
}
}
}
return false
}
function unauthenticatedUser(operation, object) {
......
/* eslint-disable import/extensions */
import 'typeface-fira-mono'
import 'typeface-fira-sans'
import 'typeface-fira-sans-condensed'
......
Markdown is supported
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