Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
25cefe71df
|
@ -0,0 +1,36 @@
|
||||||
|
package io.metersphere.controller;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.TestResource;
|
||||||
|
import io.metersphere.service.TestResourceService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RequestMapping("testresource")
|
||||||
|
@RestController
|
||||||
|
public class TestResourceController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TestResourceService testResourceService;
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
public TestResource addTestResource(@RequestBody TestResource testResource) {
|
||||||
|
return testResourceService.addTestResource(testResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list/{testResourcePoolId}")
|
||||||
|
public List<TestResource> getTestResourceList(@PathVariable(value = "testResourcePoolId") String testResourcePoolId) {
|
||||||
|
return testResourceService.getTestResourceList(testResourcePoolId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/delete/{testResourceId}")
|
||||||
|
public void deleteTestResource(@PathVariable(value = "testResourceId") String testResourceId) {
|
||||||
|
testResourceService.deleteTestResource(testResourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void updateTestResource(@RequestBody TestResource testResource) {
|
||||||
|
testResourceService.updateTestResource(testResource);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
package io.metersphere.controller;
|
package io.metersphere.controller;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.Role;
|
||||||
import io.metersphere.base.domain.User;
|
import io.metersphere.base.domain.User;
|
||||||
import io.metersphere.dto.UserDTO;
|
import io.metersphere.dto.UserDTO;
|
||||||
|
import io.metersphere.dto.UserOperateDTO;
|
||||||
import io.metersphere.service.UserService;
|
import io.metersphere.service.UserService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -28,4 +30,9 @@ public class UserController {
|
||||||
|
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void updateUser(@RequestBody User user) { userService.updateUser(user); }
|
public void updateUser(@RequestBody User user) { userService.updateUser(user); }
|
||||||
|
|
||||||
|
@GetMapping("/role/list/{userId}")
|
||||||
|
public List<Role> getUserRolesList(@PathVariable(value = "userId") String userId) {
|
||||||
|
return userService.getUserRolesList(userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package io.metersphere.service;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.TestResource;
|
||||||
|
import io.metersphere.base.domain.TestResourceExample;
|
||||||
|
import io.metersphere.base.mapper.TestResourceMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class TestResourceService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TestResourceMapper testResourceMapper;
|
||||||
|
|
||||||
|
public TestResource addTestResource(TestResource testResource) {
|
||||||
|
testResource.setId(UUID.randomUUID().toString());
|
||||||
|
testResource.setStatus("1");
|
||||||
|
testResource.setCreateTime(System.currentTimeMillis());
|
||||||
|
testResource.setUpdateTime(System.currentTimeMillis());
|
||||||
|
testResourceMapper.insertSelective(testResource);
|
||||||
|
return testResource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TestResource> getTestResourceList(String testResourcePoolId) {
|
||||||
|
TestResourceExample testResourceExample = new TestResourceExample();
|
||||||
|
testResourceExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolId);
|
||||||
|
List<TestResource> testResources = testResourceMapper.selectByExampleWithBLOBs(testResourceExample);
|
||||||
|
return testResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteTestResource(String testResourceId) {
|
||||||
|
testResourceMapper.deleteByPrimaryKey(testResourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTestResource(TestResource testResource) {
|
||||||
|
testResource.setUpdateTime(System.currentTimeMillis());
|
||||||
|
testResourceMapper.updateByPrimaryKeySelective(testResource);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import io.metersphere.base.mapper.UserMapper;
|
||||||
import io.metersphere.base.mapper.UserRoleMapper;
|
import io.metersphere.base.mapper.UserRoleMapper;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.dto.UserDTO;
|
import io.metersphere.dto.UserDTO;
|
||||||
|
import io.metersphere.dto.UserOperateDTO;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -102,4 +103,14 @@ public class UserService {
|
||||||
user.setUpdateTime(System.currentTimeMillis());
|
user.setUpdateTime(System.currentTimeMillis());
|
||||||
userMapper.updateByPrimaryKeySelective(user);
|
userMapper.updateByPrimaryKeySelective(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Role> getUserRolesList(String userId) {
|
||||||
|
UserRoleExample userRoleExample = new UserRoleExample();
|
||||||
|
userRoleExample.createCriteria().andUserIdEqualTo(userId);
|
||||||
|
List<UserRole> userRolesList = userRoleMapper.selectByExample(userRoleExample);
|
||||||
|
List<String> roleIds = userRolesList.stream().map(UserRole::getRoleId).collect(Collectors.toList());
|
||||||
|
RoleExample roleExample = new RoleExample();
|
||||||
|
roleExample.createCriteria().andIdIn(roleIds);
|
||||||
|
return roleMapper.selectByExample(roleExample);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
<font-awesome-icon class="icon account" :icon="['far', 'address-card']" size="lg"/>
|
<font-awesome-icon class="icon account" :icon="['far', 'address-card']" size="lg"/>
|
||||||
<span>账号</span>
|
<span>账号</span>
|
||||||
</template>
|
</template>
|
||||||
<el-menu-item index="/setting/user">用户</el-menu-item>
|
<el-menu-item index="/setting/user" v-permission="['admin']">用户</el-menu-item>
|
||||||
<el-menu-item index="/setting/testresourcepool">测试资源池</el-menu-item>
|
<el-menu-item index="/setting/testresourcepool" v-permission="['admin','org_admin']">测试资源池</el-menu-item>
|
||||||
<el-menu-item index="/setting/organization">组织</el-menu-item>
|
<el-menu-item index="/setting/organization" v-permission="['test_user']">组织</el-menu-item>
|
||||||
<el-menu-item index="/setting/workspace">工作空间</el-menu-item>
|
<el-menu-item index="/setting/workspace">工作空间</el-menu-item>
|
||||||
<el-menu-item>API Keys</el-menu-item>
|
<el-menu-item>API Keys</el-menu-item>
|
||||||
</el-submenu>
|
</el-submenu>
|
||||||
|
|
|
@ -6,10 +6,11 @@ import filters from "../common/filter";
|
||||||
import ajax from "../common/ajax";
|
import ajax from "../common/ajax";
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import router from "./components/router/router";
|
import router from "./components/router/router";
|
||||||
import store from './store'
|
|
||||||
import './permission' // permission control
|
import './permission' // permission control
|
||||||
import i18n from "../i18n/i18n";
|
import i18n from "../i18n/i18n";
|
||||||
import timestampFormatDate from "./components/common/filter/TimestampFormatDateFilter";
|
import timestampFormatDate from "./components/common/filter/TimestampFormatDateFilter";
|
||||||
|
import store from "./store";
|
||||||
|
import {permission} from './permission'
|
||||||
|
|
||||||
Vue.config.productionTip = false;
|
Vue.config.productionTip = false;
|
||||||
Vue.use(icon);
|
Vue.use(icon);
|
||||||
|
@ -22,6 +23,9 @@ Vue.use(ajax);
|
||||||
// filter
|
// filter
|
||||||
Vue.filter('timestampFormatDate', timestampFormatDate);
|
Vue.filter('timestampFormatDate', timestampFormatDate);
|
||||||
|
|
||||||
|
// v-permission
|
||||||
|
Vue.directive('permission', permission)
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
router,
|
router,
|
||||||
|
|
|
@ -1,10 +1,29 @@
|
||||||
import router from './components/router/router'
|
import router from './components/router/router'
|
||||||
import Cookies from 'js-cookie' // get token from cookie
|
import Cookies from 'js-cookie' // get token from cookie
|
||||||
import {TokenKey} from '../common/constants';
|
import {TokenKey} from '../common/constants';
|
||||||
|
import store from "./store";
|
||||||
|
|
||||||
const whiteList = ['/login']; // no redirect whitelist
|
const whiteList = ['/login']; // no redirect whitelist
|
||||||
|
|
||||||
|
export const permission = {
|
||||||
|
inserted(el, binding) {
|
||||||
|
const { value } = binding
|
||||||
|
// user role list
|
||||||
|
const roles = store.state.roles
|
||||||
|
if (value && value instanceof Array && value.length > 0) {
|
||||||
|
const permissionRoles = value
|
||||||
|
const hasPermission = roles.some(role => {
|
||||||
|
return permissionRoles.includes(role)
|
||||||
|
})
|
||||||
|
if (!hasPermission) {
|
||||||
|
el.parentNode && el.parentNode.removeChild(el)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(`need roles! Like v-permission="['admin','editor']"`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
|
|
||||||
// determine whether the user has logged in
|
// determine whether the user has logged in
|
||||||
|
@ -16,7 +35,7 @@ router.beforeEach(async (to, from, next) => {
|
||||||
} else {
|
} else {
|
||||||
// const roles = user.roles.filter(r => r.id);
|
// const roles = user.roles.filter(r => r.id);
|
||||||
// TODO 设置路由的权限
|
// TODO 设置路由的权限
|
||||||
|
store.commit("setRoles", user.roles.map(r => r.id))
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,6 +3,17 @@ import Vuex from 'vuex'
|
||||||
|
|
||||||
Vue.use(Vuex);
|
Vue.use(Vuex);
|
||||||
|
|
||||||
export default new Vuex.Store({})
|
const store = new Vuex.Store({
|
||||||
|
state: {
|
||||||
|
roles: []
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
setRoles(state, data) {
|
||||||
|
state.roles = data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default store
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue