Source

plugins/rights-plugin.js

import Vue from 'vue'
import store from '../store'
import { hasRight } from '@/services/rights-service.js'
import { getDevOnlyQueryStringValue } from '@/services/env-service.js'

/**
 * Rights related helpers
 * @namespace Plugins
 * @category Plugins
 * @module rights-plugin
 * @name $rights
 */
Vue.use({
  install() {
    Vue.$rights = Vue.prototype.$rights = {
      canUseClientSelectionFeature() {
        return store.getters['auth/canUseClientSelectionFeature']
      },
      hasExternalRight(name) {
        const shouldByPassRights = getDevOnlyQueryStringValue('rights') === '0'
        if (shouldByPassRights) {
          return true
        }
        return store.getters['auth/hasExternalRight'](name)
      },
      hasFeatureRight(code, options = {}) {
        if (getDevOnlyQueryStringValue('feature_rights') === '0') {
          return true
        } else {
          return this.hasRight(code, options)
        }
      },
      hasRight(code, options = {}) {
        return hasRight(
          store.getters['auth/rightsList'],
          code,
          store.getters['auth/loginName'],
          options
        )
      },
    }
  },
})