This commit is contained in:
Captain.B 2020-03-06 13:56:17 +08:00
parent 0fd99a4dda
commit d9ee8e4085
6 changed files with 37 additions and 55 deletions

View File

@ -0,0 +1,18 @@
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;
}

View File

@ -1,33 +0,0 @@
<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>

View File

@ -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,8 +90,7 @@
}
},
initMenuData() {
let roles = this.currentUser.roles.map(r => r.id);
// if (roles.indexOf(ROLE_ORG_ADMIN) > -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;
@ -99,8 +99,8 @@
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_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
if (!this.currentUser.lastOrganizationId) {
return false;
}

View File

@ -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;
});

View File

@ -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;
});

View File

@ -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;
});