leonardovilarinho / vue-acl

Access Control List plugin for VueJS 2.0
375 stars 76 forks source link

load globalRules dynamically and after initialization #70

Closed 3ynm closed 4 years ago

3ynm commented 5 years ago

I would like to do something as the following:

const globalRules = {};
axios.get('/available-permissions').then((response) => {
  response.data.forEach((permission) => {
    rules[`can${capitalize(permission)}] = new AclRule(permission).generate();
  });
});

how could I?

ErickZH commented 5 years ago

Define your globalRules in a file...


import Vue from 'vue'

import { AclInstaller, AclCreate, AclRule } from 'vue-acl'

import router from './router'

Vue.use(AclInstaller)

export default new AclCreate({
    initial: 'public',
    router,
    acceptLocalRules: true,
    globalRules: {
        isAdmin: new AclRule('admin').generate(),
        isDeveloper: new AclRule('developer').generate(),
    }
})
3ynm commented 5 years ago

I'm actually doing it. I want to know how to do it dynamically (after a successful remote request).

ErickZH commented 5 years ago

When accessing your app you want to make a GET request to obey the permissions and be able to load them in the request?

You can try


const globalRules = {};
axios.get('/available-permissions').then((response) => {
  response.data.forEach((permission) => {
    new AclRule(permission).generate();
  });
});
leonardovilarinho commented 4 years ago

Try use local rules: https://github.com/leonardovilarinho/vue-acl#use-in-components

leonardovilarinho commented 4 years ago

Closed due to lack of response