This commit is contained in:
chenjianxing 2020-05-19 18:09:57 +08:00
commit 8c4afc465b
6 changed files with 78 additions and 51 deletions

View File

@ -17,15 +17,14 @@ import io.metersphere.controller.request.member.SetAdminRequest;
import io.metersphere.controller.request.organization.AddOrgMemberRequest; import io.metersphere.controller.request.organization.AddOrgMemberRequest;
import io.metersphere.controller.request.organization.QueryOrgMemberRequest; import io.metersphere.controller.request.organization.QueryOrgMemberRequest;
import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleDTO;
import io.metersphere.service.OrganizationService; import io.metersphere.service.OrganizationService;
import io.metersphere.service.UserService; import io.metersphere.service.UserService;
import io.metersphere.service.WorkspaceService; import io.metersphere.service.WorkspaceService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@ -54,6 +53,12 @@ public class UserController {
return PageUtils.setPageInfo(page, userService.getUserListWithRequest(request)); return PageUtils.setPageInfo(page, userService.getUserListWithRequest(request));
} }
@GetMapping("/special/user/role/{userId}")
@RequiresRoles(RoleConstants.ADMIN)
public UserRoleDTO getUserRole(@PathVariable("userId") String userId) {
return userService.getUserRole(userId);
}
@GetMapping("/special/delete/{userId}") @GetMapping("/special/delete/{userId}")
@RequiresRoles(RoleConstants.ADMIN) @RequiresRoles(RoleConstants.ADMIN)
public void deleteUser(@PathVariable(value = "userId") String userId) { public void deleteUser(@PathVariable(value = "userId") String userId) {

View File

@ -0,0 +1,18 @@
package io.metersphere.dto;
import io.metersphere.base.domain.Role;
import io.metersphere.base.domain.UserRole;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class UserRoleDTO {
private String userId;
private List<Role> roles;
private List<UserRole> userRoles;
private static final long serialVersionUID = 1L;
}

View File

@ -17,13 +17,13 @@ import io.metersphere.controller.request.member.SetAdminRequest;
import io.metersphere.controller.request.organization.AddOrgMemberRequest; import io.metersphere.controller.request.organization.AddOrgMemberRequest;
import io.metersphere.controller.request.organization.QueryOrgMemberRequest; import io.metersphere.controller.request.organization.QueryOrgMemberRequest;
import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleDTO;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
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;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -100,16 +100,24 @@ public class UserService {
} }
UserDTO userDTO = new UserDTO(); UserDTO userDTO = new UserDTO();
BeanUtils.copyProperties(user, userDTO); BeanUtils.copyProperties(user, userDTO);
UserRoleDTO userRole = getUserRole(userId);
userDTO.setUserRoles(userRole.getUserRoles());
userDTO.setRoles(userRole.getRoles());
return userDTO;
}
public UserRoleDTO getUserRole(String userId) {
UserRoleDTO userRoleDTO = new UserRoleDTO();
// //
UserRoleExample userRoleExample = new UserRoleExample(); UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId); userRoleExample.createCriteria().andUserIdEqualTo(userId);
List<UserRole> userRoleList = userRoleMapper.selectByExample(userRoleExample); List<UserRole> userRoleList = userRoleMapper.selectByExample(userRoleExample);
if (CollectionUtils.isEmpty(userRoleList)) { if (CollectionUtils.isEmpty(userRoleList)) {
return userDTO; return userRoleDTO;
} }
// 设置 user_role // 设置 user_role
userDTO.setUserRoles(userRoleList); userRoleDTO.setUserRoles(userRoleList);
List<String> roleIds = userRoleList.stream().map(UserRole::getRoleId).collect(Collectors.toList()); List<String> roleIds = userRoleList.stream().map(UserRole::getRoleId).collect(Collectors.toList());
@ -117,9 +125,9 @@ public class UserService {
roleExample.createCriteria().andIdIn(roleIds); roleExample.createCriteria().andIdIn(roleIds);
List<Role> roleList = roleMapper.selectByExample(roleExample); List<Role> roleList = roleMapper.selectByExample(roleExample);
userDTO.setRoles(roleList); userRoleDTO.setRoles(roleList);
return userDTO; return userRoleDTO;
} }
public List<User> getUserList() { public List<User> getUserList() {

View File

@ -7,7 +7,11 @@
:show-create="false"/> :show-create="false"/>
</template> </template>
<el-table :data="tableData" class="table-content"> <el-table :data="tableData" class="table-content">
<el-table-column prop="name" :label="$t('commons.name')" width="200" show-overflow-tooltip/> <el-table-column :label="$t('commons.name')" width="200" show-overflow-tooltip>
<template v-slot:default="scope">
<el-link type="info" @click="handleView(scope.row)">{{ scope.row.name }}</el-link>
</template>
</el-table-column>
<el-table-column prop="testName" :label="$t('api_report.test_name')" width="200" show-overflow-tooltip/> <el-table-column prop="testName" :label="$t('api_report.test_name')" width="200" show-overflow-tooltip/>
<el-table-column width="250" :label="$t('commons.create_time')"> <el-table-column width="250" :label="$t('commons.create_time')">
<template v-slot:default="scope"> <template v-slot:default="scope">

View File

@ -7,7 +7,10 @@
@create="create" :createTip="$t('load_test.create')"/> @create="create" :createTip="$t('load_test.create')"/>
</template> </template>
<el-table :data="tableData" class="table-content"> <el-table :data="tableData" class="table-content">
<el-table-column prop="name" :label="$t('commons.name')" width="150" show-overflow-tooltip> <el-table-column :label="$t('commons.name')" width="150" show-overflow-tooltip>
<template v-slot:default="scope">
<el-link type="info" @click="handleEdit(scope.row)">{{ scope.row.name }}</el-link>
</template>
</el-table-column> </el-table-column>
<el-table-column prop="projectName" :label="$t('load_test.project_name')" width="150" show-overflow-tooltip> <el-table-column prop="projectName" :label="$t('load_test.project_name')" width="150" show-overflow-tooltip>
</el-table-column> </el-table-column>

View File

@ -1,7 +1,7 @@
<template> <template>
<div v-loading="result.loading"> <div v-loading="result.loading">
<el-card class="table-card"> <el-card class="table-card">
<template v-slot:header> <template v-slot:header>
<ms-table-header :condition.sync="condition" @search="search" @create="create" <ms-table-header :condition.sync="condition" @search="search" @create="create"
:create-tip="$t('user.create')" :title="$t('commons.member')"/> :create-tip="$t('user.create')" :title="$t('commons.member')"/>
@ -9,7 +9,12 @@
<el-table :data="tableData" style="width: 100%"> <el-table :data="tableData" style="width: 100%">
<el-table-column prop="id" label="ID"/> <el-table-column prop="id" label="ID"/>
<el-table-column prop="name" :label="$t('commons.username')"/> <el-table-column prop="name" :label="$t('commons.username')" width="200"/>
<el-table-column :label="$t('commons.role')" width="120">
<template v-slot:default="scope">
<ms-roles-tag :roles="scope.row.roles"/>
</template>
</el-table-column>
<el-table-column prop="email" :label="$t('commons.email')"/> <el-table-column prop="email" :label="$t('commons.email')"/>
<el-table-column prop="status" :label="$t('commons.status')"> <el-table-column prop="status" :label="$t('commons.status')">
<template v-slot:default="scope"> <template v-slot:default="scope">
@ -22,7 +27,7 @@
/> />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="createTime" :label="$t('commons.create_time')" width="180"> <el-table-column prop="createTime" :label="$t('commons.create_time')">
<template v-slot:default="scope"> <template v-slot:default="scope">
<span>{{ scope.row.createTime | timestampFormatDate }}</span> <span>{{ scope.row.createTime | timestampFormatDate }}</span>
</template> </template>
@ -43,21 +48,6 @@
:total="total"/> :total="total"/>
</el-card> </el-card>
<el-dialog :title="$t('commons.verification')" :visible.sync="checkPasswordVisible" width="30%"
@close="closeCheckPassword" :destroy-on-close="true">
<el-form :model="checkPasswordForm" label-position="right" label-width="100px" size="small" :rules="rule"
ref="checkPasswordForm">
<el-form-item :label="$t('commons.password')" prop="password">
<el-input type="password" v-model="checkPasswordForm.password" autocomplete="off" show-password></el-input>
</el-form-item>
</el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="checkPasswordVisible = false"
@confirm="setAdmin('checkPasswordForm')"/>
</template>
</el-dialog>
<!--Create user--> <!--Create user-->
<el-dialog :title="$t('user.create')" :visible.sync="createVisible" width="30%" @closed="handleClose" <el-dialog :title="$t('user.create')" :visible.sync="createVisible" width="30%" @closed="handleClose"
:destroy-on-close="true"> :destroy-on-close="true">
@ -108,7 +98,7 @@
@confirm="updateUser('updateUserForm')"/> @confirm="updateUser('updateUserForm')"/>
</template> </template>
</el-dialog> </el-dialog>
<!--Changing user password in system settings--> <!--Changing user password in system settings-->
<el-dialog :title="$t('member.edit_password')" :visible.sync="editPasswordVisible" width="30%" left> <el-dialog :title="$t('member.edit_password')" :visible.sync="editPasswordVisible" width="30%" left>
<el-form :model="ruleForm" label-position="right" label-width="120px" size="small" :rules="rule" <el-form :model="ruleForm" label-position="right" label-width="120px" size="small" :rules="rule"
ref="editPasswordForm" class="demo-ruleForm"> ref="editPasswordForm" class="demo-ruleForm">
@ -137,10 +127,19 @@
import MsDialogFooter from "../../common/components/MsDialogFooter"; import MsDialogFooter from "../../common/components/MsDialogFooter";
import MsTableOperatorButton from "../../common/components/MsTableOperatorButton"; import MsTableOperatorButton from "../../common/components/MsTableOperatorButton";
import {getCurrentUser} from "../../../../common/js/utils"; import {getCurrentUser} from "../../../../common/js/utils";
import MsRolesTag from "../../common/components/MsRolesTag";
export default { export default {
name: "MsUser", name: "MsUser",
components: {MsCreateBox, MsTablePagination, MsTableHeader, MsTableOperator, MsDialogFooter, MsTableOperatorButton}, components: {
MsCreateBox,
MsTablePagination,
MsTableHeader,
MsTableOperator,
MsDialogFooter,
MsTableOperatorButton,
MsRolesTag
},
data() { data() {
return { return {
queryPath: '/user/special/list', queryPath: '/user/special/list',
@ -152,7 +151,6 @@
createVisible: false, createVisible: false,
updateVisible: false, updateVisible: false,
editPasswordVisible: false, editPasswordVisible: false,
checkPasswordVisible: false,
multipleSelection: [], multipleSelection: [],
currentPage: 1, currentPage: 1,
pageSize: 5, pageSize: 5,
@ -271,9 +269,9 @@
} }
}) })
}, },
editUserPassword(editPasswordForm){ editUserPassword(editPasswordForm) {
this.$refs[editPasswordForm].validate(valid=>{ this.$refs[editPasswordForm].validate(valid => {
if(valid){ if (valid) {
this.result = this.$post(this.editPasswordPath, this.ruleForm, response => { this.result = this.$post(this.editPasswordPath, this.ruleForm, response => {
this.$success(this.$t('commons.modify_success')); this.$success(this.$t('commons.modify_success'));
this.editPasswordVisible = false; this.editPasswordVisible = false;
@ -290,6 +288,15 @@
let data = response.data; let data = response.data;
this.total = data.itemCount; this.total = data.itemCount;
this.tableData = data.listObject; this.tableData = data.listObject;
let url = "/user/special/user/role";
for (let i = 0; i < this.tableData.length; i++) {
this.$get(url + '/' + this.tableData[i].id, result => {
let data = result.data;
let roles = data.roles;
// let userRoles = result.userRoles;
this.$set(this.tableData[i], "roles", roles);
})
}
}) })
}, },
handleClose() { handleClose() {
@ -305,24 +312,6 @@
}, },
handleSelectionChange(val) { handleSelectionChange(val) {
this.multipleSelection = val; this.multipleSelection = val;
},
closeCheckPassword() {
this.checkPasswordForm = {};
},
setAdmin(checkPasswordForm) {
let user = getCurrentUser();
this.$set(this.setAdminParam, 'adminId', user.id);
this.$set(this.setAdminParam, 'password', this.checkPasswordForm.password);
this.$refs[checkPasswordForm].validate(valid => {
if (valid) {
this.$post("/user/set/admin", this.setAdminParam, () => {
this.$success(this.$t('commons.modify_success'));
this.checkPasswordVisible = false;
})
} else {
return false;
}
})
} }
} }
} }