refactor(editor): Refactor utils files and mixins (#4654)
* ✨ Added `utils` module. Moved `canvasHelpers` and old `utils.ts` file to it * ✨ Moved rest of utils and helpers * ⚡ Fixing sytax errors * 🔨 Refactoring new utils files * 🔨 Organizing imports, adding comments and a bit more refactoring * ✔️ Fixing tests * 🔨 Moving mixins to `src`
This commit is contained in:
committed by
GitHub
parent
67983e8f94
commit
5059c57f4a
30
packages/editor-ui/src/mixins/userHelpers.ts
Normal file
30
packages/editor-ui/src/mixins/userHelpers.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { IPermissions, IUser } from '@/Interface';
|
||||
import { isAuthorized } from '@/utils';
|
||||
import { useUsersStore } from '@/stores/users';
|
||||
import Vue from 'vue';
|
||||
import { Route } from 'vue-router';
|
||||
|
||||
export const userHelpers = Vue.extend({
|
||||
methods: {
|
||||
canUserAccessRouteByName(name: string): boolean {
|
||||
const {route} = this.$router.resolve({name});
|
||||
|
||||
return this.canUserAccessRoute(route);
|
||||
},
|
||||
|
||||
canUserAccessCurrentRoute(): boolean {
|
||||
return this.canUserAccessRoute(this.$route);
|
||||
},
|
||||
|
||||
canUserAccessRoute(route: Route): boolean {
|
||||
const permissions: IPermissions = route.meta && route.meta.permissions;
|
||||
const usersStore = useUsersStore();
|
||||
const currentUser = usersStore.currentUser;
|
||||
|
||||
if (permissions && isAuthorized(permissions, currentUser)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user