Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.route({
method: 'POST',
path: '/message/{conversationId}',
config: {
id: 'message',
handler: postMessageHandler,
auth: {
strategy: authStrategy,
scope: _.values(USER_ROLES)
},
description: 'Post a message to a conversation.',
tags: ['api', 'Chat', 'Post Message'],
validate: {
// headers: headersValidation,
params: {
conversationId: RestHapi.joiHelper.joiObjectId()
},
payload: {
text: Joi.string().required()
}
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
}
}
}
server.route({
method: 'PUT',
path: '/user/{_id}/activate',
config: {
handler: activateAccountHandler,
auth: {
strategy: authStrategy,
scope: ['root', 'activateUser', '!-activateUser']
},
description: 'Activate user account.',
tags: ['api', 'User', 'Activate Account'],
validate: {
headers: headersValidation,
params: {
_id: RestHapi.joiHelper.joiObjectId()
}
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
},
'policies': [auditLog(mongoose, {}, Log), rankAuth(mongoose, "_id")]
}
}
});
}());
assignScope: { $elemMatch: { $eq: roleName } }
}
request.query.$where = Object.assign(where, request.query.$where);
return RestHapi.list(Permission, request.query, Log)
.then(function (result) {
reply(result)
})
.catch(function (error) {
Log.error(error);
return reply(RestHapi.errorHelper.formatResponse(error));
})
};
const queryModel = RestHapi.joiHelper.generateJoiListQueryModel(Permission, Log)
server.route({
method: 'GET',
path: '/permission/available',
config: {
handler: getAvailablePermissionsHandler,
auth: {
strategy: authStrategy,
scope: [USER_ROLES.SUPER_ADMIN, USER_ROLES.ADMIN]
},
description: 'Get the permissions available for the current user to assign.',
tags: ['api', 'Available Permissions'],
validate: {
headers: headersValidation,
query: queryModel
},
server.route({
method: 'GET',
path: '/conversation/my',
config: {
handler: getConversationHandler,
auth: {
strategy: authStrategy,
scope: _.values(USER_ROLES)
},
description: 'Get the conversation between the current user and other specified users.',
tags: ['api', 'Chat', 'Get Conversation'],
validate: {
headers: headersValidation,
query: {
user: RestHapi.joiHelper.joiObjectId(),
conversation: RestHapi.joiHelper.joiObjectId()
}
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
}
}
}
});
}());
};
server.route({
method: 'GET',
path: '/user/{_id}/scope',
config: {
handler: getUserScopeHandler,
auth: {
strategy: authStrategy,
scope: ['root', 'readUserScope', '!-readUserScope']
},
description: 'Get user effective permissions.',
tags: ['api', 'User', 'Get User Scope'],
validate: {
params: {
_id: RestHapi.joiHelper.joiObjectId()
}
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
}
}
}
});
}());
validate: {
headers: headersValidation,
query: queryModel
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
}
},
response: {
schema: Joi.object({ docs: Joi.array().items(RestHapi.joiHelper.generateJoiReadModel(Permission)), pages: Joi.any(), items: Joi.any() })
}
}
});
}());
server.route({
method: 'PUT',
path: '/user/{_id}/enable',
config: {
handler: enableAccountHandler,
auth: {
strategy: authStrategy,
scope: ['root', 'enableUser', '!-enableUser']
},
description: 'Enable user account.',
tags: ['api', 'User', 'Enable Account'],
validate: {
headers: headersValidation,
params: {
_id: RestHapi.joiHelper.joiObjectId()
}
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
},
'policies': [auditLog(mongoose, {}, Log)]
}
}
});
}());
server.route({
method: 'PUT',
path: '/user/{_id}/enable',
config: {
handler: enableAccountHandler,
auth: {
strategy: authStrategy,
scope: ['root', 'enableUser', '!-enableUser']
},
description: 'Enable user account.',
tags: ['api', 'User', 'Enable Account'],
validate: {
headers: headersValidation,
params: {
_id: RestHapi.joiHelper.joiObjectId()
}
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
},
policies: [
auditLog(mongoose, {}, Log),
rankAuth(mongoose, '_id'),
demoAuth
]
Log.error(err)
throw Boom.badImplementation(err)
}
}
server.route({
method: 'PUT',
path: '/user/{_id}/password',
config: {
handler: handler,
auth: null,
description: "Update a user's password.",
tags: ['api', 'User', 'Password'],
validate: {
params: {
_id: RestHapi.joiHelper.joiObjectId().required()
},
payload: {
password: Joi.string()
.required()
.description("The user's new password")
}
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
}
server.route({
method: 'PUT',
path: '/user/{_id}/enable',
config: {
handler: enableAccountHandler,
auth: {
strategy: authStrategy,
scope: ['root', 'enableUser', '!-enableUser']
},
description: 'Enable user account.',
tags: ['api', 'User', 'Enable Account'],
validate: {
headers: headersValidation,
params: {
_id: RestHapi.joiHelper.joiObjectId()
}
},
plugins: {
'hapi-swagger': {
responseMessages: [
{ code: 200, message: 'Success' },
{ code: 400, message: 'Bad Request' },
{ code: 404, message: 'Not Found' },
{ code: 500, message: 'Internal Server Error' }
]
},
'policies': [auditLog(mongoose, {}, Log), rankAuth(mongoose, "_id")]
}
}
});
}());