-
+
@@ -186,8 +184,8 @@
{
if (userGridRef) {
return userGridRef.getSelectedRows().length > 0;
@@ -205,12 +203,12 @@
return false;
},
click: () => {
- selectRoleDialog.open({ userId: userGridRef.getSelectedRows()[0].id, userGrid: userGridRef, roleGrid: roleGridRef });
+ selectRoleDialog.open({ userId: userGridRef.getSelectedRows()[0].id, roleGrid: roleGridRef });
},
},
{
name: 'addAllRole',
- label: $t('system.role.action.addAllRole'),
+ label: $t('system.user.selectRole.grid.toolbar.addAllRole'),
enableIf: () => {
if (userGridRef) {
return userGridRef.getSelectedRows().length > 0;
@@ -219,27 +217,22 @@
},
click: () => {
const selectedUser = userGridRef.getSelectedRows()[0];
- DialogManager.confirm(
- $t('system.role.action.addAllRole.confirm', { userLoginName: selectedUser.loginName, userName: selectedUser.userName }),
- () => {
- axios
- .post(Environment.apiContextPath('/api/system/user/addAllRoles'), {
- one: selectedUser.id,
- many: [],
- })
- .then((response) => {
- axios.get(Environment.apiContextPath('/api/system/role/queryRolesByUser?userId=') + selectedUser.id).then((response) => {
- roleGridRef.replaceRows(response.data.content);
- });
- });
- },
- );
+ DialogManager.confirm($t('system.user.selectRole.grid.toolbar.addAllRole.tip'), () => {
+ axios
+ .post(Environment.apiContextPath('/api/system/user/addAllRoles'), {
+ one: selectedUser.id,
+ many: [],
+ })
+ .then((response) => {
+ roleGridRef?.refresh();
+ });
+ });
},
},
'separator',
{
name: 'removeRole',
- label: $t('system.role.action.removeRole'),
+ label: $t('system.user.selectRole.grid.toolbar.removeRole'),
enableIf: () => {
if (userGridRef && roleGridRef) {
return userGridRef.getSelectedRows().length > 0 && roleGridRef.getSelectedRows().length > 0;
@@ -249,33 +242,21 @@
click: (selecteds) => {
const selectedUser = userGridRef.getSelectedRows()[0];
const roleIds = Tools.extractProperties(selecteds, 'id');
- const messageKey = roleIds.length > 1 ? 'system.role.action.removeRole.confirms' : 'system.role.action.removeRole.confirm';
- DialogManager.confirm(
- t(messageKey, {
- userLoginName: selectedUser.loginName,
- userName: selectedUser.userName,
- roleCode: selecteds[0].code,
- roleName: selecteds[0].name,
- counter: selecteds.length,
- }),
- () => {
- axios
- .post(Environment.apiContextPath('/api/system/user/removeRoles'), {
- one: selectedUser.id,
- many: roleIds,
- })
- .then((response) => {
- axios.get(Environment.apiContextPath('/api/system/role/queryRolesByUser?userId=') + selectedUser.id).then((response) => {
- roleGridRef.replaceRows(response.data.content);
- });
- });
- },
- );
+ DialogManager.confirm($t('system.user.selectRole.grid.toolbar.removeRole.tip'), () => {
+ axios
+ .post(Environment.apiContextPath('/api/system/user/removeRoles'), {
+ one: selectedUser.id,
+ many: roleIds,
+ })
+ .then((response) => {
+ roleGridRef?.refresh();
+ });
+ });
},
},
{
name: 'removeAllRole',
- label: $t('system.role.action.removeAllRole'),
+ label: $t('system.user.selectRole.grid.toolbar.removeAllRole'),
enableIf: () => {
if (userGridRef && roleGridRef) {
return userGridRef.getSelectedRows().length > 0 && roleGridRef.getRows().length > 0;
@@ -284,21 +265,16 @@
},
click: () => {
const selectedUser = userGridRef.getSelectedRows()[0];
- DialogManager.confirm(
- t('system.role.action.removeAllRole.confirm', { userLoginName: selectedUser.loginName, userName: selectedUser.userName }),
- () => {
- axios
- .post(Environment.apiContextPath('/api/system/user/removeAllRoles'), {
- one: selectedUser.id,
- many: [],
- })
- .then((response) => {
- axios.get(Environment.apiContextPath('/api/system/role/queryRolesByUser?userId=') + selectedUser.id).then((response) => {
- roleGridRef.replaceRows(response.data.content);
- });
- });
- },
- );
+ DialogManager.confirm($t('system.user.selectRole.grid.toolbar.removeAllRole.tip'), () => {
+ axios
+ .post(Environment.apiContextPath('/api/system/user/removeAllRoles'), {
+ one: selectedUser.id,
+ many: [],
+ })
+ .then((response) => {
+ roleGridRef?.refresh();
+ });
+ });
},
},
'separator',
@@ -311,12 +287,7 @@
width: 60,
name: 'status',
label: $t('status'),
- format: (value, row) => {
- return {
- componentType: RoleStatusTag,
- attrs: row,
- };
- },
+ format: Formater.enableTag(),
},
]"
:viewer="{
@@ -346,6 +317,7 @@
:title="$t('system.org.grid.title')"
:data-url="Environment.apiContextPath('/api/system/org/listAllOrgsWithSelectedStatusByUser?userId=') + currentSelectedUserId"
selection="multiple"
+ :pageable="false"
:full-screen-button="false"
:toolbar-configure="{ noIcon: true }"
:toolbar-actions="[
@@ -357,34 +329,18 @@
click: () => {
axios
.post(Environment.apiContextPath('/api/system/user/updateOrgs'), {
- one: currentSelectedUserId,
- many: orgTreeGridRef.value.getTicked(),
+ one: userGridRef.getSelectedRows()[0].id,
+ many: orgTreeGridRef.getTicked(),
})
.then((response) => {});
},
},
'view',
]"
- :pagination="{
- sortBy: 'name',
- descending: false,
- reqPageStart: 0,
- rowsPerPage: 0,
- }"
:columns="[
- { width: 100, name: 'code', label: $t('code') },
+ { width: 80, name: 'code', label: $t('code') },
{ width: 100, name: 'name', label: $t('name') },
- {
- width: 60,
- name: 'status',
- label: $t('status'),
- format: (value, row) => {
- return {
- componentType: RoleStatusTag,
- attrs: row,
- };
- },
- },
+ { width: 60, name: 'status', label: $t('status'), format: Formater.enableTag() },
]"
:viewer="{
panel: {
@@ -415,11 +371,12 @@
diff --git a/io.sc.platform.system/src/main/java/io/sc/platform/system/user/service/impl/UserServiceImpl.java b/io.sc.platform.system/src/main/java/io/sc/platform/system/user/service/impl/UserServiceImpl.java
index f617c4d8..adeabb69 100644
--- a/io.sc.platform.system/src/main/java/io/sc/platform/system/user/service/impl/UserServiceImpl.java
+++ b/io.sc.platform.system/src/main/java/io/sc/platform/system/user/service/impl/UserServiceImpl.java
@@ -37,6 +37,8 @@ import org.springframework.util.StringUtils;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import java.sql.PreparedStatement;
@@ -186,8 +188,19 @@ public class UserServiceImpl extends DaoServiceImpl queryUsersByRole(String roleId, QueryParameter queryParameter) throws Exception {
if(StringUtils.hasText(roleId)) {
Specification specification = (root, query, criteriaBuilder) -> {
- Join join = root.join("roles");
- return criteriaBuilder.equal(join.get("id"), roleId);
+ Subquery subquery =query.subquery(Integer.class);
+ // select 1
+ subquery.select(criteriaBuilder.literal(1));
+
+ // from sys_user_role,sys_role
+ Root subQueryRoot =subquery.correlate(root);
+ Join join = subQueryRoot.join("roles");
+
+ // where sys_user.id_='xxx'
+ subquery.where(criteriaBuilder.equal(join.get("id"), roleId));
+
+ // where exists (...)
+ return criteriaBuilder.exists(subquery);
};
return this.query(specification, queryParameter);
}
@@ -197,12 +210,23 @@ public class UserServiceImpl extends DaoServiceImpl queryOtherUsersByRole(String roleId, QueryParameter queryParameter) throws Exception {
if(StringUtils.hasText(roleId)) {
- Specification specification = (root, query, criteriaBuilder) -> {
- query.distinct(true);
- Join join = root.join("roles", JoinType.LEFT);
- return criteriaBuilder.or(criteriaBuilder.isNull(join.get("id")),criteriaBuilder.notEqual(join.get("id"), roleId));
+ Specification baseSpecification = (root, query, criteriaBuilder) -> {
+ Subquery subquery =query.subquery(Integer.class);
+ // select 1
+ subquery.select(criteriaBuilder.literal(1));
+
+ // from sys_user_role,sys_role
+ Root subQueryRoot =subquery.correlate(root);
+ Join join = subQueryRoot.join("roles");
+
+ // where sys_user.id_='xxx'
+ subquery.where(criteriaBuilder.equal(join.get("id"), roleId));
+
+ // where exists (...)
+ return criteriaBuilder.not(criteriaBuilder.exists(subquery));
};
- return this.query(specification, queryParameter);
+ Specification specification =buildSpecification(queryParameter);
+ return this.query(baseSpecification.and(specification), queryParameter);
}
return QueryResult.emptyPage();
}