提交 d9ee8e40 编写于 作者: C Captain.B

hasRoles

上级 0fd99a4d
import {TokenKey} from "./constants";
export function hasRole(role) {
let user = JSON.parse(localStorage.getItem(TokenKey));
let roles = user.roles.map(r => r.id);
return roles.indexOf(role) > -1;
}
export function hasRoles(...roles) {
let user = JSON.parse(localStorage.getItem(TokenKey));
let rs = user.roles.map(r => r.id);
for (let item of roles) {
if (rs.indexOf(item) > -1) {
return true;
}
}
return false;
}
<template>
<el-row class="settings" type="flex" justify="end" align="middle">
<router-link to="/content">
<font-awesome-icon :icon="['fas', 'user-plus']" size="lg"/>
</router-link>
<router-link to="/setting">
<font-awesome-icon :icon="['fas', 'cog']" size="lg"/>
</router-link>
</el-row>
</template>
<script>
export default {
name: "MsSetting"
}
</script>
<style scoped>
.settings > * {
padding-left: 15px;
cursor: pointer;
line-height: 40px;
color: inherit;
}
.settings > * :hover {
opacity: 0.7;
}
.settings > * :active {
opacity: 0.8;
}
</style>
......@@ -42,7 +42,8 @@
</template>
<script>
import {ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER, TokenKey} from '../../common/constants';
import {ROLE_ORG_ADMIN, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER, TokenKey} from '../../common/constants';
import {hasRoles} from "../../common/utils";
export default {
name: "MsUser",
......@@ -89,18 +90,17 @@
}
},
initMenuData() {
let roles = this.currentUser.roles.map(r => r.id);
// if (roles.indexOf(ROLE_ORG_ADMIN) > -1) {
this.$get("/organization/list/userorg/" + this.currentUserId, response => {
let data = response.data;
this.organizationList = data;
let org = data.filter(r => r.id === this.currentUser.lastOrganizationId);
if (org.length > 0) {
this.currentOrganizationName = org[0].name;
}
});
// }
if (roles.indexOf(ROLE_TEST_MANAGER) > -1 || roles.indexOf(ROLE_TEST_USER) > -1 || roles.indexOf(ROLE_TEST_VIEWER) > -1) {
if (hasRoles(ROLE_ORG_ADMIN, ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
this.$get("/organization/list/userorg/" + this.currentUserId, response => {
let data = response.data;
this.organizationList = data;
let org = data.filter(r => r.id === this.currentUser.lastOrganizationId);
if (org.length > 0) {
this.currentOrganizationName = org[0].name;
}
});
}
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
if (!this.currentUser.lastOrganizationId) {
return false;
}
......
......@@ -15,14 +15,13 @@
<script>
import {ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "../../../common/constants";
import {hasRoles} from "../../../common/utils";
export default {
name: "MsRecentProject",
mounted() {
const rolesString = localStorage.getItem("roles");
const roles = rolesString.split(',');
if (roles.indexOf(ROLE_TEST_MANAGER) > -1 || roles.indexOf(ROLE_TEST_USER) > -1 || roles.indexOf(ROLE_TEST_VIEWER) > -1) {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
this.$get('/project/recent/5', (response) => {
this.recentProjects = response.data;
});
......
......@@ -13,14 +13,13 @@
<script>
import {ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "../../../common/constants";
import {hasRoles} from "../../../common/utils";
export default {
name: "MsRecentReport",
mounted() {
const rolesString = localStorage.getItem("roles");
const roles = rolesString.split(',');
if (roles.indexOf(ROLE_TEST_MANAGER) > -1 || roles.indexOf(ROLE_TEST_USER) > -1 || roles.indexOf(ROLE_TEST_VIEWER) > -1) {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
this.$get('/report/recent/5', (response) => {
this.recentReports = response.data;
});
......
......@@ -12,14 +12,13 @@
<script>
import {ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "../../../common/constants";
import {hasRoles} from "../../../common/utils";
export default {
name: "MsRecentTestPlan",
mounted() {
const rolesString = localStorage.getItem("roles");
const roles = rolesString.split(',');
if (roles.indexOf(ROLE_TEST_MANAGER) > -1 || roles.indexOf(ROLE_TEST_USER) > -1 || roles.indexOf(ROLE_TEST_VIEWER) > -1) {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
this.$get('/testplan/recent/5', (response) => {
this.recentTestPlans = response.data;
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册