first commit
This commit is contained in:
54
resources/frontend/core/plugins/gate.js
Normal file
54
resources/frontend/core/plugins/gate.js
Normal file
@@ -0,0 +1,54 @@
|
||||
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);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
21
resources/frontend/core/plugins/sentry.js
Normal file
21
resources/frontend/core/plugins/sentry.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as Sentry from '@sentry/browser';
|
||||
import * as Integrations from '@sentry/integrations';
|
||||
import Vue from 'vue';
|
||||
|
||||
if (
|
||||
process.env.NODE_ENV !== 'development' &&
|
||||
'VUE_APP_SENTRY_DSN' in process.env &&
|
||||
process.env.VUE_APP_SENTRY_DSN !== 'undefined'
|
||||
) {
|
||||
Sentry.init({
|
||||
release: process.env.VUE_APP_VERSION,
|
||||
environment: process.env.NODE_ENV,
|
||||
dsn: process.env.VUE_APP_SENTRY_DSN,
|
||||
integrations: [
|
||||
new Integrations.Vue({
|
||||
Vue,
|
||||
attachProps: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
16
resources/frontend/core/plugins/vee-validate.js
Normal file
16
resources/frontend/core/plugins/vee-validate.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { extend, configure } from 'vee-validate';
|
||||
import i18n from '@/i18n';
|
||||
import * as validationRules from 'vee-validate/dist/rules';
|
||||
import isEmail from 'validator/lib/isEmail';
|
||||
|
||||
for (const rule in validationRules) {
|
||||
extend(rule, validationRules[rule]);
|
||||
}
|
||||
|
||||
configure({
|
||||
defaultMessage: (field, values) => {
|
||||
return i18n.t(`validation.${values._rule_}`, values);
|
||||
},
|
||||
});
|
||||
|
||||
extend('email', value => isEmail(String(value), { require_tld: false }));
|
||||
Reference in New Issue
Block a user