Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_REVOKE_ROLE, VARCHAR_FIELD_LENGTH, TEXT_FIELD_LENGTH } from '../../../../utils/constants';
import { maybe, required, checkType, composeRules, restrictToSchema } from 'rulr';
const validateRevokeRole = maybe(composeRules([
restrictToSchema({
user_id: required(checkType(String)),
role_id: required(checkType(String))
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_REVOKE_ROLE});
validateRevokeRole(req.params, ['user']);
await config.service.revokeUserRole(req.params);
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { CREATED } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_CREATE_PERMISSION, VARCHAR_FIELD_LENGTH, TEXT_FIELD_LENGTH } from '../../../../utils/constants';
import { maxLength } from '../../../../utils/validate';
import { maybe, required, optional, checkType,composeRules, first, restrictToSchema } from 'rulr';
import * as R from 'ramda';
const validateCreatePermission = maybe(composeRules([
restrictToSchema({
name: required(maxLength(VARCHAR_FIELD_LENGTH)),
label: optional(maxLength(VARCHAR_FIELD_LENGTH)),
description: optional(maxLength(TEXT_FIELD_LENGTH)),
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_CREATE_PERMISSION});
validateCreatePermission(req.body, ['Permission']);
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_UPDATE_PERMISSION,VARCHAR_FIELD_LENGTH,TEXT_FIELD_LENGTH } from '../../../../utils/constants';
import { maxLength } from '../../../../utils/validate';
import { maybe, optional,composeRules, restrictToSchema } from 'rulr';
const validateUpdatePermission = maybe(composeRules([
restrictToSchema({
name: optional(maxLength(VARCHAR_FIELD_LENGTH)),
label: optional(maxLength(VARCHAR_FIELD_LENGTH)),
description: optional(maxLength(TEXT_FIELD_LENGTH)),
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_UPDATE_PERMISSION});
validateUpdatePermission(req.body, ['permission']);
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_UPDATE_ROLE, VARCHAR_FIELD_LENGTH,TEXT_FIELD_LENGTH } from '../../../../utils/constants';
import { maxLength } from '../../../../utils/validate';
import { maybe, optional, composeRules, restrictToSchema } from 'rulr';
const validateUpdatePost = maybe(composeRules([
restrictToSchema({
name: optional(maxLength(VARCHAR_FIELD_LENGTH)),
description: optional(maxLength(TEXT_FIELD_LENGTH)),
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_UPDATE_ROLE});
validateUpdatePost(req.body, ['role']);
const {role_id} = req.params;
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_ASSIGN_ROLE } from '../../../../utils/constants';
import { maybe, required, checkType, composeRules, restrictToSchema } from 'rulr';
const validateAssignUserRole = maybe(composeRules([
restrictToSchema({
role_id: required(checkType(String))
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_ASSIGN_ROLE});
validateAssignUserRole(req.body, ['user']);
const {user_id} = req.params;
const {role_id} = req.body;
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import { minLength, validateMatchingPasswords } from '../../../../utils/validate';
import { maybe, required, checkType, composeRules, first, restrictToSchema } from 'rulr';
const validateResetPassword = maybe(composeRules([
restrictToSchema({
token: required(checkType(String)),
password: required(minLength(6)),
password_confirmation: required(checkType(String)),
}),
first(checkType(Object), validateMatchingPasswords)
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
validateResetPassword(req.body, ['user']);
const {token, password } = req.body;
await config.service.resetPassword({token, password});
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_UPDATE_POST, VARCHAR_FIELD_LENGTH, TEXT_FIELD_LENGTH } from '../../../../utils/constants';
import { maxLength } from '../../../../utils/validate';
import { maybe, optional, checkType,composeRules, restrictToSchema }from 'rulr';
const validateUpdatePost = maybe(composeRules([
restrictToSchema({
user_id: optional(checkType(Number)),
title: optional(maxLength(VARCHAR_FIELD_LENGTH)),
body: optional(maxLength(TEXT_FIELD_LENGTH)),
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_UPDATE_POST});
validateUpdatePost(req.body, ['post']);
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { CREATED } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_CREATE_ROLE, VARCHAR_FIELD_LENGTH, TEXT_FIELD_LENGTH } from '../../../../utils/constants';
import { maxLength } from '../../../../utils/validate';
import { maybe, required, optional, composeRules, restrictToSchema } from 'rulr';
const validateCreateRole = maybe(composeRules([
restrictToSchema({
name: required(maxLength(VARCHAR_FIELD_LENGTH)),
description: optional(maxLength(TEXT_FIELD_LENGTH)),
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_CREATE_ROLE});
validateCreateRole(req.body, ['role']);
const createRole = await config.service.createRole(req.body);
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_ASSIGN_PERMISSION } from '../../../../utils/constants';
import { maybe, required, checkType, composeRules, restrictToSchema } from 'rulr';
const validateAssignRolePermission = maybe( composeRules([
restrictToSchema({
permission_id: required(checkType(String))
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_ASSIGN_PERMISSION});
validateAssignRolePermission(req.body, ['role']);
const {role_id} = req.params;
const {permission_id} = req.body;
import Config from '../../Config';
import catchErrors from '../../utils/catchErrors';
import { OK } from 'http-status-codes';
import getAuthUserAndPermissions from '../../../../utils/jwt/getAuthUserAndPermissions';
import hasPermission from '../../../../utils/jwt/hasPermission';
import { CAN_REVOKE_PERMISSION, VARCHAR_FIELD_LENGTH, TEXT_FIELD_LENGTH } from '../../../../utils/constants';
import { maybe, required, checkType,composeRules, restrictToSchema } from 'rulr';
const validateRevokeRolePermission = maybe(composeRules([
restrictToSchema({
permission_id: required(checkType(String)),
role_id: required(checkType(String))
})
]));
export default (config: Config) => {
return catchErrors(config, async (req, res) => {
const { permissions } = await getAuthUserAndPermissions({req, service: config.service});
hasPermission({permissions, permissionName: CAN_REVOKE_PERMISSION});
validateRevokeRolePermission(req.params, ['role']);
await config.service.revokeRolePermission(req.params);