How to use the feathers-hooks-common.unless function in feathers-hooks-common

To help you get started, we’ve selected a few feathers-hooks-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Human-Connection / API / server / services / comments / comments.hooks.js View on Github external
),
      hook => {
        delete hook.params.query.deleted;
        return hook;
      }
    ],
    get: [
      iff(
        hook => hook.params.headers && hook.params.headers.authorization,
        authenticate('jwt')
      )
    ],
    create: [
      authenticate('jwt'),
      // Allow seeder to seed comments
      unless(isProvider('server'),
        isVerified()
      ),
      associateCurrentUser(),
      createExcerpt({ length: 180 })
    ],
    update: [
      authenticate('jwt'),
      unless(isProvider('server'),
        isVerified(),
        restrictToOwner()
      ),
      createExcerpt({ length: 180 }),
      setNow('updatedAt')
    ],
    patch: [
      authenticate('jwt'),
github Human-Connection / API / server / services / comments / comments.hooks.js View on Github external
),
      associateCurrentUser(),
      createExcerpt({ length: 180 })
    ],
    update: [
      authenticate('jwt'),
      unless(isProvider('server'),
        isVerified(),
        restrictToOwner()
      ),
      createExcerpt({ length: 180 }),
      setNow('updatedAt')
    ],
    patch: [
      authenticate('jwt'),
      unless(isProvider('server'),
        isVerified(),
        unless((hook) => {
          // TODO: change that to a more sane method by going through the server with an custom service
          // only allow upvoteCount increment for non owners
          // the data has to be the exact copy of the valid object
          const valid = {$inc: {upvoteCount: 1}};
          return (!_.difference(_.keys(valid), _.keys(hook.data)).length) &&
                (!_.difference(_.keys(valid.$inc), _.keys(hook.data.$inc)).length) &&
                (!_.difference(_.values(valid.$inc), _.values(hook.data.$inc)).length);
        }, restrictToOwner())
      ),
      createExcerpt({ length: 180 }),
      setNow('updatedAt'),
      // SoftDelete uses patch to delete items
      // Make changes to deleted items here
      patchDeletedData({
github Human-Connection / API / server / services / comments / comments.hooks.js View on Github external
createExcerpt({ length: 180 })
    ],
    update: [
      authenticate('jwt'),
      unless(isProvider('server'),
        isVerified(),
        restrictToOwner()
      ),
      createExcerpt({ length: 180 }),
      setNow('updatedAt')
    ],
    patch: [
      authenticate('jwt'),
      unless(isProvider('server'),
        isVerified(),
        unless((hook) => {
          // TODO: change that to a more sane method by going through the server with an custom service
          // only allow upvoteCount increment for non owners
          // the data has to be the exact copy of the valid object
          const valid = {$inc: {upvoteCount: 1}};
          return (!_.difference(_.keys(valid), _.keys(hook.data)).length) &&
                (!_.difference(_.keys(valid.$inc), _.keys(hook.data.$inc)).length) &&
                (!_.difference(_.values(valid.$inc), _.values(hook.data.$inc)).length);
        }, restrictToOwner())
      ),
      createExcerpt({ length: 180 }),
      setNow('updatedAt'),
      // SoftDelete uses patch to delete items
      // Make changes to deleted items here
      patchDeletedData({
        data: {
          content: 'DELETED',
github Human-Connection / API / server / services / comments / comments.hooks.js View on Github external
),
      createExcerpt({ length: 180 }),
      setNow('updatedAt'),
      // SoftDelete uses patch to delete items
      // Make changes to deleted items here
      patchDeletedData({
        data: {
          content: 'DELETED',
          contentExcerpt: 'DELETED'
        }
      })
    ],
    remove: [
      authenticate('jwt'),
      unless(isProvider('server'),
        unless(isModerator(),
          isVerified(),
          restrictToOwner()
        )
      )
    ]
  },

  after: {
    all: [
      xss({ fields: xssFields }),
      keepDeletedDataFields(),
      discard('wasSeeded')
    ],
    find: [
      populate({ schema: userSchema }),
      protect('content', 'badgeIds'),
github Human-Connection / API / server / services / contributions / contributions.hooks.js View on Github external
categoryIds: undefined,
            teaserImg: undefined,
            shoutCount: 0,
            tags: undefined,
            emotions: undefined
          },
          $unset: {
            cando: '',
            meta: ''
          }
        }
      })
    ],
    remove: [
      authenticate('jwt'),
      unless(isModerator(),
        canEditOrganization(),
        excludeDisabled(),
        restrictToOwner()
      )
    ]
  },

  after: {
    all: [
      xss({fields: xssFields}),
      populate({schema: userSchema}),
      populate({schema: categoriesSchema}),
      populate({schema: candosSchema}),
      populate({schema: commentsSchema}),
      keepDeletedDataFields({
        fields: [
github Human-Connection / API / server / services / shouts / shouts.hooks.js View on Github external
const isModerator = require('../../hooks/is-moderator-boolean');
const setShoutCount = require('./hooks/set-shout-count');
const {
  associateCurrentUser,
  restrictToOwner
} = require('feathers-authentication-hooks');
const { isVerified } = require('feathers-authentication-management').hooks;

module.exports = {
  before: {
    all: [],
    find: [],
    get: [],
    create: [
      authenticate('jwt'),
      unless(isProvider('server'),
        isVerified(),
        associateCurrentUser()
      )
    ],
    update: [
      authenticate('jwt'),
      unless(isModerator(),
        restrictToOwner()
      )
    ],
    patch: [
      authenticate('jwt'),
      unless(isModerator(),
        restrictToOwner()
      )
    ],
github Human-Connection / API / server / services / users-candos / users-candos.hooks.js View on Github external
module.exports = {
  before: {
    all: [],
    find: [],
    get: [],
    create: [
      unless(isProvider('server'),
        authenticate('jwt'),
        isVerified(),
        associateCurrentUser()
      ),
      setDoneDate()
    ],
    update: [
      authenticate('jwt'),
      unless(isModerator(),
        restrictToOwner()
      ),
      setDoneDate()
    ],
    patch: [
      authenticate('jwt'),
      unless(isModerator(),
        restrictToOwner()
      ),
      setDoneDate()
    ],
    remove: [
      authenticate('jwt'),
      unless(isModerator(),
        restrictToOwner()
      )
github codingfriend1 / Feathers-Vue / server / services / users / users.hooks.js View on Github external
const isEnabled = require('../../hooks/is-enabled');
const setDefaultRole = require('../../hooks/set-default-role');
const setFirstUserToRole = require('../../hooks/set-first-user-to-role');
const sendVerificationEmail = require('../../hooks/send-verification-email');
const hasPermissionsBoolean = require('../../hooks/has-permissions-boolean');
const preventDisabledAdmin = require('../../hooks/prevent-disabled-admin');
const verifyHooks = require('feathers-authentication-management').hooks;
const loopItems = require('../../hooks/loop-items')


const { hashPassword } = require('feathers-authentication-local').hooks;

const restrict = [
  authenticate('jwt'),
  isEnabled(),
  commonHooks.unless(
    hasPermissionsBoolean('manageUsers'),
    restrictToOwner({
      idField: '_id',
      ownerField: '_id'
    })
  )
];

function setUserInitials(item) {
  if(item.name) {
    item.initials = _.get(item, 'name', '')
      .match(/\b(\w)/g)
      .join('')
      .slice(0, 2)
      .toUpperCase();
  }