Unverified Commit 2e7bc572 authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[Feature][web] added role list for dinky-web (#1799)

* added role list * added todo comment * fix code style * fix code style * fix code style role , rolenamespace * added note hideInSearch: true, * fix i18n tips
parent b5b534ba
...@@ -25,6 +25,7 @@ import org.dinky.model.Role; ...@@ -25,6 +25,7 @@ import org.dinky.model.Role;
import org.dinky.model.UserRole; import org.dinky.model.UserRole;
import org.dinky.service.RoleService; import org.dinky.service.RoleService;
import org.dinky.service.UserRoleService; import org.dinky.service.UserRoleService;
import org.dinky.utils.MessageResolverUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -54,17 +55,31 @@ public class RoleController { ...@@ -54,17 +55,31 @@ public class RoleController {
private final UserRoleService userRoleService; private final UserRoleService userRoleService;
/** /**
* create or update role * create or update role , this method will be {@link Deprecated} in the future, please use
* {@link #addedOrUpdateRole(Role)}
* *
* @return delete result code * @return delete result code
*/ */
@PutMapping @PutMapping
@Deprecated
public Result<Void> saveOrUpdateRole(@RequestBody Role role) { public Result<Void> saveOrUpdateRole(@RequestBody Role role) {
return roleService.saveOrUpdateRole(role); return roleService.saveOrUpdateRole(role);
} }
/** /**
* delete tenant by id * create or update role
*
* @param role {@link Role}
* @return {@link Role} of {@link Void}
*/
@PutMapping("/addedOrUpdateRole")
public Result<Void> addedOrUpdateRole(@RequestBody Role role) {
return roleService.addedOrUpdateRole(role);
}
/**
* delete role by ids , this method will be {@link Deprecated} in the future, please use {@link
* #deleteRoleById(Integer)}
* *
* @return delete result code * @return delete result code
*/ */
...@@ -73,6 +88,16 @@ public class RoleController { ...@@ -73,6 +88,16 @@ public class RoleController {
return roleService.deleteRoles(para); return roleService.deleteRoles(para);
} }
/**
* delete role by id
*
* @return delete result code
*/
@DeleteMapping("/delete")
public Result<Void> deleteRoleById(@RequestParam Integer id) {
return roleService.deleteRoleById(id);
}
/** query role list */ /** query role list */
@PostMapping @PostMapping
public ProTableResult<Role> listRoles(@RequestBody JsonNode para) { public ProTableResult<Role> listRoles(@RequestBody JsonNode para) {
...@@ -90,6 +115,6 @@ public class RoleController { ...@@ -90,6 +115,6 @@ public class RoleController {
userRoleIds.add(userRole.getRoleId()); userRoleIds.add(userRole.getRoleId());
} }
Dict result = Dict.create().set("roles", roleList).set("roleIds", userRoleIds); Dict result = Dict.create().set("roles", roleList).set("roleIds", userRoleIds);
return Result.succeed(result, "获取成功"); return Result.succeed(result, MessageResolverUtils.getMessage("response.get.success"));
} }
} }
...@@ -67,11 +67,13 @@ public class Role implements Serializable { ...@@ -67,11 +67,13 @@ public class Role implements Serializable {
@TableField(fill = FieldFill.INSERT_UPDATE) @TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime; private LocalDateTime updateTime;
/** namespace list */ /** this field is deprecated , it's will be delete in the future namespace list */
@TableField(exist = false) @TableField(exist = false)
@Deprecated
private List<Namespace> namespaces; private List<Namespace> namespaces;
/** namespace namespaceIds */ /** this field is deprecated , it's will be delete in the future namespace namespaceIds */
@Deprecated
@TableField(exist = false) @TableField(exist = false)
private String namespaceIds; private String namespaceIds;
......
...@@ -31,9 +31,11 @@ import com.baomidou.mybatisplus.annotation.TableName; ...@@ -31,9 +31,11 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
/** role namespace , it's deprecated will be removed in the future */
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@TableName("dinky_role_namespace") @TableName("dinky_role_namespace")
@Deprecated
public class RoleNamespace implements Serializable { public class RoleNamespace implements Serializable {
private static final long serialVersionUID = 304808291890721691L; private static final long serialVersionUID = 304808291890721691L;
......
...@@ -24,29 +24,46 @@ import org.dinky.common.result.Result; ...@@ -24,29 +24,46 @@ import org.dinky.common.result.Result;
import org.dinky.db.service.ISuperService; import org.dinky.db.service.ISuperService;
import org.dinky.model.Role; import org.dinky.model.Role;
import java.util.List;
import java.util.Set;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
public interface RoleService extends ISuperService<Role> { public interface RoleService extends ISuperService<Role> {
/** /**
* delete role * delete role by ids , the method will be {@link Deprecated} in the future , please use {@link
* #deleteRoleById(Integer)}
* *
* @param para role id * @param para role id
* @return delete result code * @return delete result code
*/ */
@Deprecated
Result<Void> deleteRoles(JsonNode para); Result<Void> deleteRoles(JsonNode para);
/**
* create or update role , the method will be {@link Deprecated} in the future , please use
* {@link #addedOrUpdateRole(Role)}
*
* @param role
* @return
*/
@Deprecated
Result<Void> saveOrUpdateRole(Role role); Result<Void> saveOrUpdateRole(Role role);
List<Role> getRoleByIds(Set<Integer> roleIds); /**
* create or update role
List<Role> getRoleByTenantIdAndIds(String tenantId, Set<Integer> roleIds); *
* @param role {@link Role}
boolean deleteByIds(List<Integer> ids); * @return {@link Result} of {@link Void}
*/
Result<Void> addedOrUpdateRole(Role role);
@Override @Override
ProTableResult<Role> selectForProTable(JsonNode para); ProTableResult<Role> selectForProTable(JsonNode para);
/**
* get role by id
*
* @param id role id
* @return {@link Result} of {@link Void}
*/
Result<Void> deleteRoleById(Integer id);
} }
...@@ -28,7 +28,9 @@ import java.util.List; ...@@ -28,7 +28,9 @@ import java.util.List;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** role namespace service impl , it's will be deprecated in the future */
@Service @Service
@Deprecated
public class RoleNamespaceServiceImpl extends SuperServiceImpl<RoleNamespaceMapper, RoleNamespace> public class RoleNamespaceServiceImpl extends SuperServiceImpl<RoleNamespaceMapper, RoleNamespace>
implements RoleNamespaceService { implements RoleNamespaceService {
......
...@@ -34,10 +34,10 @@ import org.dinky.service.RoleNamespaceService; ...@@ -34,10 +34,10 @@ import org.dinky.service.RoleNamespaceService;
import org.dinky.service.RoleService; import org.dinky.service.RoleService;
import org.dinky.service.TenantService; import org.dinky.service.TenantService;
import org.dinky.service.UserRoleService; import org.dinky.service.UserRoleService;
import org.dinky.utils.MessageResolverUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -46,6 +46,7 @@ import org.springframework.context.annotation.Lazy; ...@@ -46,6 +46,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
...@@ -102,6 +103,49 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen ...@@ -102,6 +103,49 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen
} }
} }
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Void> addedOrUpdateRole(Role role) {
if (Asserts.isNull(role.getId())) {
Role roleCode =
roleService.getOne(
new LambdaQueryWrapper<Role>()
.eq(Role::getRoleCode, role.getRoleCode()));
if (Asserts.isNotNull(roleCode)) {
return Result.failed(
String.format(
MessageResolverUtils.getMessage("role.code.exist"),
role.getRoleCode()));
}
}
Boolean roleSaveOrUpdate = saveOrUpdate(role);
if (roleSaveOrUpdate) {
return Result.succeed(MessageResolverUtils.getMessage("save.success"));
} else {
return Result.failed(MessageResolverUtils.getMessage("save.failed"));
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Void> deleteRoleById(Integer id) {
Role role = getById(id);
Long selectUserRoleCnt =
userRoleService
.getBaseMapper()
.selectCount(
new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId, id));
if (selectUserRoleCnt > 0) {
return Result.failed(MessageResolverUtils.getMessage("role.binding.user"));
}
Boolean removeById = roleService.removeById(role);
if (removeById) {
return Result.succeed(MessageResolverUtils.getMessage("delete.success"));
} else {
return Result.failed(MessageResolverUtils.getMessage("delete.failed"));
}
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public Result<Void> deleteRoles(JsonNode para) { public Result<Void> deleteRoles(JsonNode para) {
...@@ -131,21 +175,6 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen ...@@ -131,21 +175,6 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen
} }
} }
@Override
public List<Role> getRoleByIds(Set<Integer> roleIds) {
return baseMapper.getRoleByIds(roleIds);
}
@Override
public List<Role> getRoleByTenantIdAndIds(String tenantId, Set<Integer> roleIds) {
return baseMapper.getRoleByTenantIdAndIds(tenantId, roleIds);
}
@Override
public boolean deleteByIds(List<Integer> ids) {
return baseMapper.deleteByIds(ids) > 0;
}
@Override @Override
public ProTableResult<Role> selectForProTable(JsonNode para, boolean isDelete) { public ProTableResult<Role> selectForProTable(JsonNode para, boolean isDelete) {
ProTableResult<Role> roleProTableResult = super.selectForProTable(para, isDelete); ProTableResult<Role> roleProTableResult = super.selectForProTable(para, isDelete);
...@@ -153,10 +182,17 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen ...@@ -153,10 +182,17 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen
.getData() .getData()
.forEach( .forEach(
role -> { role -> {
// todo: namespace will be delete in the future , so next line code will
// be delete too
List<Namespace> namespaceArrayList = new ArrayList<>(); List<Namespace> namespaceArrayList = new ArrayList<>();
List<Integer> idsList = new ArrayList<>(); List<Integer> idsList = new ArrayList<>();
Tenant tenant = Tenant tenant =
tenantService.getBaseMapper().selectById(role.getTenantId()); tenantService.getBaseMapper().selectById(role.getTenantId());
// todo: namespace will be delete in the future , so next some code will
// be delete too
roleNamespaceService roleNamespaceService
.list( .list(
new QueryWrapper<RoleNamespace>() new QueryWrapper<RoleNamespace>()
...@@ -169,7 +205,11 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen ...@@ -169,7 +205,11 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen
namespaceArrayList.add(namespaceServiceById); namespaceArrayList.add(namespaceServiceById);
idsList.add(roleNamespace.getNamespaceId()); idsList.add(roleNamespace.getNamespaceId());
}); });
role.setTenant(tenant); role.setTenant(tenant);
// todo: namespace will be delete in the future , so next some code will
// be delete too
role.setNamespaces(namespaceArrayList); role.setNamespaces(namespaceArrayList);
String result = String result =
idsList.stream() idsList.stream()
...@@ -177,6 +217,7 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen ...@@ -177,6 +217,7 @@ public class RoleServiceImpl extends SuperServiceImpl<RoleMapper, Role> implemen
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
role.setNamespaceIds(result); role.setNamespaceIds(result);
}); });
return roleProTableResult; return roleProTableResult;
} }
} }
...@@ -24,10 +24,11 @@ modify.success=\u4FEE\u6539\u6210\u529F ...@@ -24,10 +24,11 @@ modify.success=\u4FEE\u6539\u6210\u529F
modify.failed=\u4FEE\u6539\u5931\u8D25 modify.failed=\u4FEE\u6539\u5931\u8D25
delete.success=\u5220\u9664\u6210\u529F delete.success=\u5220\u9664\u6210\u529F
delete.failed=\u5220\u9664\u5931\u8D25 delete.failed=\u5220\u9664\u5931\u8D25
delete.partially.success=\u5220\u9664\u90E8\u5206\u6210\u529F\uFF0C\u4F46 {0} \u5220\u9664\u5931\u8D25\uFF0C\u5171 {1} \u6B21\u5931\u8D25\u3002
delete.placeholder=\u8BF7\u9009\u62E9\u8981\u5220\u9664\u7684\u8BB0\u5F55 delete.placeholder=\u8BF7\u9009\u62E9\u8981\u5220\u9664\u7684\u8BB0\u5F55
create.success=\u65B0\u589E\u6210\u529F create.success=\u65B0\u589E\u6210\u529F
create.failed=\u65B0\u589E\u5931\u8D25 create.failed=\u65B0\u589E\u5931\u8D25
save.success=\u4FDD\u5B58\u6210\u529F
save.failed=\u4FDD\u5B58\u5931\u8D25
# response messages # response messages
request.params.error=\u8BF7\u6C42\u53C2\u6570\u9519\u8BEF request.params.error=\u8BF7\u6C42\u53C2\u6570\u9519\u8BEF
...@@ -82,6 +83,11 @@ tenant.assign.user.success=\u5206\u914D\u7528\u6237\u6210\u529F ...@@ -82,6 +83,11 @@ tenant.assign.user.success=\u5206\u914D\u7528\u6237\u6210\u529F
tenant.assign.user.failed=\u5206\u914D\u7528\u6237\u5931\u8D25 tenant.assign.user.failed=\u5206\u914D\u7528\u6237\u5931\u8D25
tenant.binding.user.deleteAll=\u8BE5\u79DF\u6237\u7ED1\u5B9A\u7684\u7528\u6237\u5DF2\u88AB\u5168\u90E8\u5220\u9664 tenant.binding.user.deleteAll=\u8BE5\u79DF\u6237\u7ED1\u5B9A\u7684\u7528\u6237\u5DF2\u88AB\u5168\u90E8\u5220\u9664
# role messages
role.exists=\u89D2\u8272 {0} \u5DF2\u5B58\u5728
role.binding.user= \u8BE5\u89D2\u8272\u5DF2\u7ED1\u5B9A\u7528\u6237\uFF0C\u65E0\u6CD5\u5220\u9664
message.welcome=\u6B22\u8FCE\u4F7F\u7528 Dinky message.welcome=\u6B22\u8FCE\u4F7F\u7528 Dinky
message.task.running=\u4EFB\u52A1\u5DF2\u5728\u8FD0\u884C message.task.running=\u4EFB\u52A1\u5DF2\u5728\u8FD0\u884C
......
...@@ -23,10 +23,11 @@ modify.success=Modify successfully ...@@ -23,10 +23,11 @@ modify.success=Modify successfully
modify.failed=Modification failed modify.failed=Modification failed
delete.success=Delete successfully delete.success=Delete successfully
delete.failed=Delete failed delete.failed=Delete failed
delete.partially.success=Delete was partially successful, but {0} failed to delete out of {1} failures.
delete.placeholder=Please select the record to delete delete.placeholder=Please select the record to delete
create.success=Add successfully create.success=Add successfully
create.failed=Create failed create.failed=Create failed
save.success=Save successfully
save.failed=Save failed
# response messages # response messages
request.params.error=Request parameter error request.params.error=Request parameter error
...@@ -82,6 +83,11 @@ tenant.assign.user.failed = Failed to assign user ...@@ -82,6 +83,11 @@ tenant.assign.user.failed = Failed to assign user
tenant.binding.user.deleteAll=All users bound by this tenant have been deleted tenant.binding.user.deleteAll=All users bound by this tenant have been deleted
# role messages
role.exists=Role {0} already exists
role.binding.user= The role has been bound to the user, delete failed
message.welcome=Welcome to Dinky message.welcome=Welcome to Dinky
message.task.running=Task is already running message.task.running=Task is already running
base.not.exists={0} does not exist base.not.exists={0} does not exist
......
...@@ -24,10 +24,12 @@ modify.success=\u4FEE\u6539\u6210\u529F ...@@ -24,10 +24,12 @@ modify.success=\u4FEE\u6539\u6210\u529F
modify.failed=\u4FEE\u6539\u5931\u8D25 modify.failed=\u4FEE\u6539\u5931\u8D25
delete.success=\u5220\u9664\u6210\u529F delete.success=\u5220\u9664\u6210\u529F
delete.failed=\u5220\u9664\u5931\u8D25 delete.failed=\u5220\u9664\u5931\u8D25
delete.partially.success=\u5220\u9664\u90E8\u5206\u6210\u529F\uFF0C\u4F46 {0} \u5220\u9664\u5931\u8D25\uFF0C\u5171 {1} \u6B21\u5931\u8D25\u3002
delete.placeholder=\u8BF7\u9009\u62E9\u8981\u5220\u9664\u7684\u8BB0\u5F55 delete.placeholder=\u8BF7\u9009\u62E9\u8981\u5220\u9664\u7684\u8BB0\u5F55
create.success=\u65B0\u589E\u6210\u529F create.success=\u65B0\u589E\u6210\u529F
create.failed=\u65B0\u589E\u5931\u8D25 create.failed=\u65B0\u589E\u5931\u8D25
save.success=\u4FDD\u5B58\u6210\u529F
save.failed=\u4FDD\u5B58\u5931\u8D25
# response messages # response messages
request.params.error=\u8BF7\u6C42\u53C2\u6570\u9519\u8BEF request.params.error=\u8BF7\u6C42\u53C2\u6570\u9519\u8BEF
...@@ -82,6 +84,10 @@ tenant.assign.user.success=\u5206\u914D\u7528\u6237\u6210\u529F ...@@ -82,6 +84,10 @@ tenant.assign.user.success=\u5206\u914D\u7528\u6237\u6210\u529F
tenant.assign.user.failed=\u5206\u914D\u7528\u6237\u5931\u8D25 tenant.assign.user.failed=\u5206\u914D\u7528\u6237\u5931\u8D25
tenant.binding.user.deleteAll=\u8BE5\u79DF\u6237\u7ED1\u5B9A\u7684\u7528\u6237\u5DF2\u88AB\u5168\u90E8\u5220\u9664 tenant.binding.user.deleteAll=\u8BE5\u79DF\u6237\u7ED1\u5B9A\u7684\u7528\u6237\u5DF2\u88AB\u5168\u90E8\u5220\u9664
# role messages
role.exists=\u89D2\u8272 {0} \u5DF2\u5B58\u5728
role.binding.user= \u8BE5\u89D2\u8272\u5DF2\u7ED1\u5B9A\u7528\u6237\uFF0C\u65E0\u6CD5\u5220\u9664
message.welcome=\u6B22\u8FCE\u4F7F\u7528 Dinky message.welcome=\u6B22\u8FCE\u4F7F\u7528 Dinky
message.task.running=\u4EFB\u52A1\u5DF2\u5728\u8FD0\u884C message.task.running=\u4EFB\u52A1\u5DF2\u5728\u8FD0\u884C
......
...@@ -177,7 +177,7 @@ export default [ ...@@ -177,7 +177,7 @@ export default [
path: '/auth/role', path: '/auth/role',
name: 'role', name: 'role',
icon: 'TeamOutlined', icon: 'TeamOutlined',
// component: './AuthCenter/Role', component: './AuthCenter/Role',
}, },
{ {
path: '/auth/tenant', path: '/auth/tenant',
......
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
"@types/history": "^5.0.0", "@types/history": "^5.0.0",
"@types/jest": "^29.2.1", "@types/jest": "^29.2.1",
"@types/lodash": "^4.14.186", "@types/lodash": "^4.14.186",
"@types/react-custom-scrollbars": "^4.0.10",
"@types/react": "^18.0.28", "@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11", "@types/react-dom": "^18.0.11",
"@types/react-helmet": "^6.1.5", "@types/react-helmet": "^6.1.5",
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
import {TransferProps} from "antd/es/transfer"; import {TransferProps} from "antd/es/transfer";
import {ColumnsType, TableRowSelection} from "antd/es/table/interface"; import {ColumnsType, TableRowSelection} from "antd/es/table/interface";
import {Table, Transfer} from "antd"; import {Table, Transfer} from "antd";
// @ts-ignore
import {Scrollbars} from "react-custom-scrollbars"; import {Scrollbars} from "react-custom-scrollbars";
import difference from "lodash/difference"; import difference from "lodash/difference";
import {NORMAL_TABLE_OPTIONS, SCROLLBAR_OPTIONS} from "@/services/constants"; import {NORMAL_TABLE_OPTIONS, SCROLLBAR_OPTIONS} from "@/services/constants";
......
...@@ -187,26 +187,7 @@ export default { ...@@ -187,26 +187,7 @@ export default {
'tenant.EnterTenantNote': 'Please enter Tenant Note!', 'tenant.EnterTenantNote': 'Please enter Tenant Note!',
'tenant.delete': 'Delete Tenant', 'tenant.delete': 'Delete Tenant',
'tenant.deleteConfirm': 'Are you sure you want to delete this Tenant?', 'tenant.deleteConfirm': 'Are you sure you want to delete this Tenant?',
'tenant.enable': 'Enable Tenant',
'tenant.enableConfirm': 'Are you sure you want to enable this Tenant?',
'tenant.disable': 'Disable Tenant',
'tenant.disableConfirm': 'Are you sure you want to disable this Tenant?',
'nameSpace.NameSpaceManagement': 'NameSpace Management',
'nameSpace.NameSpaceCode': 'NameSpace Code',
'nameSpace.belongTenant': 'Belong Tenant',
'nameSpace.deleteNameSpace': 'Delete NameSpace',
'nameSpace.deleteNameSpaceConfirm': 'Are you sure you want to delete this NameSpace?',
'nameSpace.enableNameSpace': 'Enable NameSpace',
'nameSpace.enableNameSpaceConfirm': 'Are you sure you want to enable this NameSpace?',
'nameSpace.disableNameSpace': 'Disable NameSpace',
'nameSpace.disableNameSpaceConfirm': 'Are you sure you want to disable this NameSpace?',
'nameSpace.create': 'Create NameSpace',
'nameSpace.update': 'Update NameSpace',
'nameSpace.EnterNameSpaceCode': 'Please enter NameSpace Code!',
'nameSpace.EnterNameSpaceNote': 'Please enter NameSpace Note!',
'nameSpace.disableTotalOf': 'Total Of {total} Namespace Is Disabled',
'role.roleManagement': 'Role Management', 'role.roleManagement': 'Role Management',
'role.roleCode': 'Role Code', 'role.roleCode': 'Role Code',
...@@ -221,13 +202,7 @@ export default { ...@@ -221,13 +202,7 @@ export default {
'role.EnterNote': 'Please enter Role Note!', 'role.EnterNote': 'Please enter Role Note!',
'role.delete': 'Delete Role', 'role.delete': 'Delete Role',
'role.deleteConfirm': 'Are you sure you want to delete this Role?', 'role.deleteConfirm': 'Are you sure you want to delete this Role?',
'role.enable': 'Enable Role',
'role.enableConfirm': 'Are you sure you want to enable this Role?',
'role.disable': 'Disable Role',
'role.disableConfirm': 'Are you sure you want to disable this Role?',
'regist.openAPI': 'OpenAPI Document',
'regist.BusinessComponent': 'Business Component Document',
'metadata.NoDatabaseSelected': 'No database selected', 'metadata.NoDatabaseSelected': 'No database selected',
'metadata.Application': 'Application', 'metadata.Application': 'Application',
......
...@@ -182,31 +182,10 @@ export default { ...@@ -182,31 +182,10 @@ export default {
'tenant.EnterTenantNote': '请输入租户备注/描述信息!', 'tenant.EnterTenantNote': '请输入租户备注/描述信息!',
'tenant.delete': '删除租户', 'tenant.delete': '删除租户',
'tenant.deleteConfirm': '您确定要删除此租户吗?', 'tenant.deleteConfirm': '您确定要删除此租户吗?',
'tenant.enable': '启用租户',
'tenant.enableConfirm': '您确定要启用此租户吗?',
'tenant.disable': '禁用租户',
'tenant.disableConfirm': '您确定要禁用此租户吗?',
'nameSpace.NameSpaceManagement': '命名空间管理',
'nameSpace.NameSpaceCode': '命名空间编码',
'nameSpace.belongTenant': '所属租户',
'nameSpace.deleteNameSpace': '删除命名空间',
'nameSpace.deleteNameSpaceConfirm': '您确定要删除此命名空间吗?',
'nameSpace.enableNameSpace': '启用命名空间',
'nameSpace.enableNameSpaceConfirm': '您确定要启用此命名空间吗?',
'nameSpace.disableNameSpace': '禁用命名空间',
'nameSpace.disableNameSpaceConfirm': '您确定要禁用此命名空间吗?',
'nameSpace.create': '创建命名空间',
'nameSpace.update': '修改命名空间',
'nameSpace.EnterNameSpaceCode': '请输入命名空间编码!',
'nameSpace.EnterNameSpaceNote': '请输入命名空间的备注/描述信息!',
'nameSpace.disableTotalOf': '被禁用的命名空间共 {total} 个',
'role.roleManagement': '角色管理', 'role.roleManagement': '角色管理',
'role.roleCode': '角色编码', 'role.roleCode': '角色编码',
'role.roleName': '角色名称', 'role.roleName': '角色名称',
'role.namespaceIds': '命名空间',
'role.belongTenant': '所属租户', 'role.belongTenant': '所属租户',
'role.create': '创建角色', 'role.create': '创建角色',
'role.update': '修改角色', 'role.update': '修改角色',
...@@ -216,14 +195,6 @@ export default { ...@@ -216,14 +195,6 @@ export default {
'role.EnterNote': '请输入角色的备注/描述信息!', 'role.EnterNote': '请输入角色的备注/描述信息!',
'role.delete': '删除角色', 'role.delete': '删除角色',
'role.deleteConfirm': '您确定要删除此角色吗?', 'role.deleteConfirm': '您确定要删除此角色吗?',
'role.enable': '启用角色',
'role.enableConfirm': '您确定要启用此角色吗?',
'role.disable': '禁用角色',
'role.disableConfirm': '您确定要禁用此角色吗?',
'regist.openAPI': 'OpenAPI 文档',
'regist.BusinessComponent': '业务组件文档',
'metadata.NoDatabaseSelected': '未选择数据源', 'metadata.NoDatabaseSelected': '未选择数据源',
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import React, {useState} from 'react';
import {Button, Form, Input, Modal, Select, Tag} from 'antd';
import {l} from "@/utils/intl";
import {FORM_LAYOUT_PUBLIC, NORMAL_MODAL_OPTIONS} from "@/services/constants";
import {ProForm, ProFormText, ProFormTextArea} from "@ant-design/pro-components";
export type TenantFormProps = {
onCancel: (flag?: boolean) => void;
onSubmit: (values: Partial<UserBaseInfo.Role>) => void;
modalVisible: boolean;
values: Partial<UserBaseInfo.Role>;
};
const RoleForm: React.FC<TenantFormProps> = (props) => {
const [form] = Form.useForm();
const [formVals, setFormVals] = useState<Partial<UserBaseInfo.Role>>({
id: props.values?.id,
tenantId: props.values?.tenantId,
roleCode: props.values?.roleCode,
roleName: props.values?.roleName,
isDelete: props.values?.isDelete,
note: props.values?.note,
createTime: props.values?.createTime,
updateTime: props.values?.updateTime,
});
const {
onSubmit: handleSubmit,
onCancel: handleModalVisible,
modalVisible,
} = props;
/**
* submit form
*/
const submitForm = async () => {
const fieldsValue = await form.validateFields();
// fieldsValue.id = formVals.id;
setFormVals({...formVals, ...fieldsValue});
handleSubmit({...formVals, ...fieldsValue});
};
/**
* construct role form
* @constructor
*/
const ConstructRoleForm = () => {
return (
<>
<ProFormText
name="roleCode"
label={l('role.roleCode')}
placeholder={l('role.EnterRoleCode')}
rules={[{required: true, message: l('role.EnterRoleCode')}]}
/>
<ProFormText
name="roleName"
label={l('role.roleName')}
placeholder={l('role.EnterRoleName')}
rules={[{required: true, message: l('role.EnterRoleName')}]}
/>
<ProFormTextArea
name="note"
label={l('global.table.note')}
placeholder={l('role.EnterNote')}
allowClear
/>
</>
);
};
/**
* render
*/
return (
<Modal
{...NORMAL_MODAL_OPTIONS}
title={formVals.id ? l('role.update') : l('role.create')}
open={modalVisible}
onCancel={() => handleModalVisible(false)}
onOk={() => submitForm()}
>
<ProForm
{...FORM_LAYOUT_PUBLIC}
form={form}
initialValues={formVals}
submitter={false}
layout={'horizontal'}
>
{ConstructRoleForm()}
</ProForm>
</Modal>
);
};
export default RoleForm;
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import React, {useRef, useState} from "react";
import {EditTwoTone, PlusOutlined} from '@ant-design/icons';
import ProTable, {ActionType, ProColumns} from "@ant-design/pro-table";
import {Button, Popconfirm, Tag} from 'antd';
import {PageContainer} from '@ant-design/pro-layout';
import {l} from "@/utils/intl";
import {handleAddOrUpdate, handleRemoveById} from "@/services/BusinessCrud";
import {queryList} from "@/services/api";
import {API_CONSTANTS, PROTABLE_OPTIONS_PUBLIC} from "@/services/constants";
import RoleForm from "./components/RoleForm";
import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
import {getTenantByLocalStorage} from "@/services/function";
const RoleList: React.FC = () => {
/**
* status
*/
const [formValues, setFormValues] = useState<any>();
const [modalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const actionRef = useRef<ActionType>();
/**
* delete role by id
* @param id role id
*/
const handleDeleteSubmit = async (id: number) => {
// TODO: DELETE role interface is use /api/role , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/role (ROLE)
await handleRemoveById(API_CONSTANTS.ROLE_DELETE, id);
actionRef.current?.reloadAndRest?.();
}
const handleAddOrUpdateSubmit = async (value :any ) => {
// TODO: added or update role interface is use /api/role/addedOrUpdateRole , because of the backend interface 'saveOrUpdate' is repeat , in the future, we need to change the interface to /api/role (ROLE)
const success = await handleAddOrUpdate(API_CONSTANTS.ROLE_ADDED_OR_UPDATE, {...value, tenantId: getTenantByLocalStorage()});
if (success) {
handleModalVisible(false);
setFormValues({});
if (actionRef.current) {
actionRef.current.reload();
}
}
}
/**
* columns
*/
const columns: ProColumns<UserBaseInfo.Role>[] = [
{
title: l('role.roleCode'),
dataIndex: 'roleCode',
},
{
title: l('role.roleName'),
dataIndex: 'roleName',
},
{
title: l('role.belongTenant'),
hideInSearch: true,
render: (_, record) => {
return <Tag color="blue">{record.tenant.tenantCode}</Tag>
}
},
{
title: l('global.table.note'),
dataIndex: 'note',
hideInSearch: true,
ellipsis: true,
},
{
title: l('global.table.createTime'),
dataIndex: 'createTime',
sorter: true,
hideInSearch: true,
valueType: 'dateTime',
},
{
title: l('global.table.updateTime'),
dataIndex: 'updateTime',
sorter: true,
hideInSearch: true,
valueType: 'dateTime',
},
{
title: l('global.table.operate'),
valueType: 'option',
width: "20vh",
render: (_, record) => [
<Button
className={"options-button"}
key={"RoleEdit"}
icon={<EditTwoTone/>}
title={l("button.edit")}
onClick={() => {
setFormValues(record);
handleUpdateModalVisible(true);
}}
/>,
<>
{record.id !== 1 &&
<Popconfirm
placement="topRight"
title={l("button.delete")}
description={l("role.deleteConfirm")}
onConfirm={() => {
handleDeleteSubmit(record.id);
}}
okText={l("button.confirm")}
cancelText={l("button.cancel")}
>
<Button key={'deleteRoleIcon'} icon={<DangerDeleteIcon/>}/>
</Popconfirm>
}
</>,
],
},
];
/**
* render
*/
return (
<PageContainer title={false}>
<ProTable<UserBaseInfo.Role>
{...PROTABLE_OPTIONS_PUBLIC}
headerTitle={l('role.roleManagement')}
actionRef={actionRef}
toolBarRender={() => [
<Button type="primary" onClick={() => handleModalVisible(true)}>
<PlusOutlined/> {l('button.create')}
</Button>,
]}
request={(params, sorter, filter: any) => queryList(API_CONSTANTS.ROLE, {...params, sorter, filter})}
columns={columns}
/>
<RoleForm
onSubmit={(value: any) => {handleAddOrUpdateSubmit(value)}}
onCancel={() => {
handleModalVisible(false);
}}
modalVisible={modalVisible}
values={{}}
/>
{formValues && Object.keys(formValues).length ? (
<RoleForm
onSubmit={(value: any) => {handleAddOrUpdateSubmit(value)}}
onCancel={() => {
handleUpdateModalVisible(false);
setFormValues({});
}}
modalVisible={updateModalVisible}
values={formValues}
/>
) : undefined
}
</PageContainer>
);
};
export default RoleList;
...@@ -68,6 +68,7 @@ const TenantFormList: React.FC = () => { ...@@ -68,6 +68,7 @@ const TenantFormList: React.FC = () => {
* @param id tenant id * @param id tenant id
*/ */
const handleDeleteSubmit = async (id : number) => { const handleDeleteSubmit = async (id : number) => {
// TODO: delete tenant interface is use /api/tenant/delete , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/tenant (TENANT)
await handleRemoveById(API_CONSTANTS.TENANT_DELETE, id); await handleRemoveById(API_CONSTANTS.TENANT_DELETE, id);
actionRef.current?.reloadAndRest?.(); actionRef.current?.reloadAndRest?.();
}; };
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import type {ColumnsType} from 'antd/es/table/interface';
import {useEffect, useState} from 'react';
import {l} from "@/utils/intl";
import {getData} from "@/services/api";
import TableTransfer from '@/components/TableTransfer/TableTransfer';
import {API_CONSTANTS} from "@/services/constants";
export type TableTransferFromProps = {
user: Partial<UserBaseInfo.User>;
onChange: (values: string[]) => void;
};
const TableTransferFrom = (props: TableTransferFromProps) => {
/**
* status
*/
const {user, onChange: handleChange} = props;
const [targetKeys, setTargetKeys] = useState<string[]>([]);
const [roleTableList, setRoleTableList] = useState<UserBaseInfo.Role[]>([]);
const [selectedKeys, setSelectedKeys] = useState<string[]>([]);
/**
* select change
* @param sourceSelectedKeys
* @param targetSelectedKeys
*/
const onSelectChange = (
sourceSelectedKeys: string[],
targetSelectedKeys: string[],
) => {
const newSelectedKeys = [...sourceSelectedKeys, ...targetSelectedKeys];
setSelectedKeys(newSelectedKeys);
};
/**
* get data
*/
useEffect(() => {
getData(API_CONSTANTS.GET_ROLES_BY_USERID, {id: user.id}).then(result => {
setRoleTableList(result.datas.roles);
setTargetKeys(result.datas.roleIds);
handleChange(result.datas.roleIds);
});
}, []);
/**
* table columns
*/
const columns: ColumnsType<UserBaseInfo.Role> = [
{
dataIndex: 'roleCode',
title: l('role.roleCode'),
},
{
dataIndex: 'roleName',
title: l('role.roleName'),
},
{
dataIndex: 'note',
title: l('global.table.note'),
ellipsis: true,
},
];
/**
* transfer change
* @param nextTargetKeys
*/
const onChange = (nextTargetKeys: string[]) => {
setTargetKeys(nextTargetKeys);
handleChange(nextTargetKeys);
};
/**
* render
*/
return (<>
<TableTransfer
dataSource={roleTableList}
targetKeys={targetKeys}
selectedKeys={selectedKeys}
rowKey={item => item.id as any}
onChange={onChange}
onSelectChange={onSelectChange}
filterOption={(inputValue, item) =>
item.roleCode!.indexOf(inputValue) !== -1 || item.roleName!.indexOf(inputValue) !== -1
}
leftColumns={columns}
rightColumns={columns}
/>
</>
);
};
export default TableTransferFrom;
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
/** /**
* the interface api constants * the interface api constants
*/ */
...@@ -58,6 +56,11 @@ export const API_CONSTANTS = { ...@@ -58,6 +56,11 @@ export const API_CONSTANTS = {
// get user list by tenantId // get user list by tenantId
GET_USER_LIST_BY_TENANTID: "/api/user/getUserListByTenantId", GET_USER_LIST_BY_TENANTID: "/api/user/getUserListByTenantId",
// --- role ---
// role list
ROLE: "/api/role",
ROLE_ADDED_OR_UPDATE: "/api/role/addedOrUpdateRole",
ROLE_DELETE: "/api/role/delete",
}; };
......
...@@ -53,22 +53,9 @@ declare namespace UserBaseInfo { ...@@ -53,22 +53,9 @@ declare namespace UserBaseInfo {
tenant: Tenant; tenant: Tenant;
roleCode?: string; roleCode?: string;
roleName?: string; roleName?: string;
namespaceIds?: string;
namespaces?: NameSpace[];
isDelete: boolean; isDelete: boolean;
note?: string; note?: string;
createTime?: Date; createTime?: Date;
updateTime?: Date; updateTime?: Date;
}; };
export type NameSpace = {
id: number;
tenantId: number;
tenant: Tenant;
namespaceCode?: string;
enabled: boolean;
note?: string;
createTime?: Date;
updateTime?: Date;
};
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment