JiriChara / vue-kindergarten

Modular security for Vue, Vuex, Vue-Router and Nuxt
MIT License
312 stars 24 forks source link

Is there a way to create custom perimeter for custom roles #45

Open kavin404 opened 4 years ago

kavin404 commented 4 years ago

I have a nuxt application where a user can create custom roles. e.g CustomRoleA , CustomRoleB etc. Is there a way to handle this using vue-kindergarten. Is there a way to generate the perimeters dynamically?

import { Perimeter } from 'vue-kindergarten'
export default class BasePerimeter extends Perimeter {
  isSuperAdmin () {
    return this.child === 'SuperAdministrator'
  }

  isPartyAdmin () {
    return this.child === 'PartyAdministrator'
  }

  isTeamAdmin () {
    return this.child === 'TeamAdministrator'
  }

  isPartyUser () {
    return this.child === 'PartyUser'
  }
}

import BasePerimeter from './base'

    export default new BasePerimeter({
      purpose: 'user',

      can: {
        read: () => true,

        add () {
          return this.isSuperAdmin() || this.isPartyAdmin() || this.isTeamAdmin()
        },

        update () {
          return this.isSuperAdmin() || this.isPartyAdmin() || this.isTeamAdmin()
        },

        allowDelete () {
          return this.isSuperAdmin() || this.isPartyAdmin() || this.isTeamAdmin()
        },
        changePassword () {
          return this.isSuperAdmin() || this.isPartyAdmin() || this.isTeamAdmin()
        }
      }
    })