hasRoles
This commit is contained in:
parent
0fd99a4dda
commit
d9ee8e4085
|
@ -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;
|
||||
}
|
|
@ -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>
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue