Source

mixins/rights-mixin.js

import Vue from 'vue'
import {
  areModulesWhitelisted,
  getWhitelistedModules,
} from '@/services/modules-service.js'
import { rightsTable } from '@/services/rights-service.js'

const methods = {
  /**
   * Module name should be the same as route name (routes.js)
   *
   * events_module, location_module, alerts_module, sensors_module, dashboard_module, objects_module, circuit_module, zones_module, diagnostics_module, events_module, help_module, app_quickmenu_screen
   *
   * Except for external links:
   * citipav, analysis, admin, citifret, help
   * @todo Move to rights-plugin.js
   */
  isModuleEnabled(moduleName) {
    if (areModulesWhitelisted()) {
      return getWhitelistedModules().includes(moduleName)
    }
    return true
  },
  /**
   *
   * @todo Move to rights-plugin.js
   * @returns
   */
  hasExternalRight(name) {
    return Vue.$rights.hasExternalRight(name)
  },
  hasFeatureRight(code, options = {}) {
    return Vue.$rights.hasFeatureRight(code, options)
  },
  hasRight(code = '', options = {}) {
    return Vue.$rights.hasRight(code, options)
  },
}

/**
 * @todo Refactor/Remove: Components can use plugin directly ($rights)
 */
export default {
  methods,
}

/**
 * Composable pattern (Replacement for mixins in Vue 3)
 * @returns
 */
export function useRightsPlugin() {
  return {
    rightsTable,
    ...methods,
  }
}