MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/snap.cafsinfotech.in/resources/frontend/core/plugins/gate.js
import { store } from '@/store';

/**
 * Gate Class
 */
class Gate {
    /**
     * @param {any} user
     */
    auth(user) {
        this.user = user;
    }

    /**
     * @param action
     * @param type
     * @param model
     * @returns {boolean|*}
     */
    allow(action, type, model = null) {
        if (!store.state['policies']['policies'][type]) {
            throw new Error(`Cannot find policy ${type}`);
        }

        return store.state['policies']['policies'][type][action](this.user, model);
    }

    /**
     * @param {*} action
     * @param {*} type
     * @param {*} model
     */
    deny(action, type, model = null) {
        return !this.allow(action, type, model);
    }
}

export default {
    install(Vue) {
        Vue.prototype._gate = new Gate();

        Object.defineProperty(Vue.prototype, '$gate', {
            get() {
                return Vue.prototype._gate;
            },
        });

        Object.defineProperty(Vue.prototype, '$can', {
            get() {
                return this.$gate.allow.bind(this.$gate);
            },
        });
    },
};