mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-05 04:38:10 +08:00
PL-9684 Role editor enhancements
This commit is contained in:
parent
fa95d3f32c
commit
1735ab457b
@ -45,7 +45,8 @@ public abstract class BasicPermissionTreeDatasource extends AbstractTreeDatasour
|
||||
if (permissionDs == null)
|
||||
return new Tree<>();
|
||||
|
||||
if (permissionsTree == null) {
|
||||
Boolean filtering = (Boolean) params.get("filtering");
|
||||
if (filtering == null || filtering) {
|
||||
Tree<BasicPermissionTarget> permissions = getPermissions();
|
||||
|
||||
List<Node<BasicPermissionTarget>> nodes = permissions.getRootNodes();
|
||||
|
@ -21,12 +21,13 @@ import com.haulmont.bali.datastruct.Node;
|
||||
import com.haulmont.bali.datastruct.Tree;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.UserSessionSource;
|
||||
import com.haulmont.cuba.gui.config.PermissionConfig;
|
||||
import com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget;
|
||||
import com.haulmont.cuba.gui.config.PermissionConfig;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ScreenPermissionTreeDatasource extends BasicPermissionTreeDatasource {
|
||||
@ -34,6 +35,7 @@ public class ScreenPermissionTreeDatasource extends BasicPermissionTreeDatasourc
|
||||
protected PermissionConfig permissionConfig = AppBeans.get(PermissionConfig.class);
|
||||
protected UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
|
||||
protected UserSessionSource uss = AppBeans.get(UserSessionSource.class);
|
||||
protected Predicate<BasicPermissionTarget> screenFilter;
|
||||
|
||||
@Override
|
||||
public Tree<BasicPermissionTarget> getPermissions() {
|
||||
@ -53,7 +55,14 @@ public class ScreenPermissionTreeDatasource extends BasicPermissionTreeDatasourc
|
||||
Node<BasicPermissionTarget> filteredRootNode = new Node<>(rootNode.getData());
|
||||
rootNode.getChildren().stream()
|
||||
.filter(child -> session.isScreenPermitted(child.getData().getPermissionValue()))
|
||||
.filter(child -> !child.getChildren().isEmpty()
|
||||
|| screenFilter == null
|
||||
|| screenFilter.test(child.getData()))
|
||||
.forEach(child -> filteredRootNode.addChild(filterNode(session, child)));
|
||||
return filteredRootNode;
|
||||
}
|
||||
|
||||
public void setFilter(Predicate<BasicPermissionTarget> filter) {
|
||||
this.screenFilter = filter;
|
||||
}
|
||||
}
|
@ -48,6 +48,8 @@ systemLevel=System level
|
||||
nameMsg=Name isn't specified
|
||||
permissions.remove=Remove
|
||||
|
||||
screenFilter = Screen
|
||||
|
||||
actions.Allow=Allow
|
||||
actions.Disallow=Disallow
|
||||
actions.DropRule=DropRule
|
||||
|
@ -62,6 +62,8 @@ entityFilter=Сущность
|
||||
assignedOnly=Только назначенные
|
||||
systemLevel=Системные
|
||||
|
||||
screenFilter = Экран
|
||||
|
||||
actions.RemoveSelected = Удалить выбранный
|
||||
|
||||
EntityOp.CREATE=Создание
|
||||
|
@ -88,6 +88,6 @@
|
||||
id="uiTabFrame" width="100%" height="100%"/>
|
||||
</tab>
|
||||
</tabSheet>
|
||||
<frame id="windowActions" screen="editWindowActions"/>
|
||||
<frame id="windowActions" screen="extendedEditWindowActions"/>
|
||||
</layout>
|
||||
</window>
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2018 Haulmont.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.gui.app.security.role.edit.tabs;
|
||||
|
||||
import com.haulmont.cuba.gui.app.security.entity.AssignableTarget;
|
||||
import com.haulmont.cuba.gui.components.TextField;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ScreenNameFilter<T extends AssignableTarget> implements Predicate<T> {
|
||||
|
||||
protected final TextField screenFilter;
|
||||
|
||||
public ScreenNameFilter(TextField screenFilter) {
|
||||
this.screenFilter = screenFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(T target) {
|
||||
if (target != null) {
|
||||
String filterTerm = screenFilter.getValue();
|
||||
if (filterTerm == null || filterTerm.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return target.getCaption().toLowerCase()
|
||||
.contains(filterTerm.toLowerCase());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
|
||||
package com.haulmont.cuba.gui.app.security.role.edit.tabs;
|
||||
|
||||
import com.haulmont.bali.util.ParamsMap;
|
||||
import com.haulmont.cuba.core.global.Metadata;
|
||||
import com.haulmont.cuba.core.global.Security;
|
||||
import com.haulmont.cuba.gui.app.security.ds.ScreenPermissionTreeDatasource;
|
||||
@ -74,7 +75,10 @@ public class ScreenPermissionsFrame extends AbstractFrame {
|
||||
protected Companion companion;
|
||||
|
||||
@Inject
|
||||
private GroupBoxLayout screensEditPane;
|
||||
protected GroupBoxLayout screensEditPane;
|
||||
|
||||
@Inject
|
||||
protected TextField screenFilter;
|
||||
|
||||
protected boolean itemChanging = false;
|
||||
|
||||
@ -122,6 +126,9 @@ public class ScreenPermissionsFrame extends AbstractFrame {
|
||||
}
|
||||
});
|
||||
|
||||
screenPermissionsTreeDs.setFilter(new ScreenNameFilter<>(screenFilter));
|
||||
screenFilter.addEnterPressListener(e -> applyFilter());
|
||||
|
||||
allowCheckBox.addValueChangeListener(e -> {
|
||||
if (!itemChanging) {
|
||||
itemChanging = true;
|
||||
@ -216,4 +223,8 @@ public class ScreenPermissionsFrame extends AbstractFrame {
|
||||
// trigger generated column update
|
||||
screenPermissionsTree.repaint();
|
||||
}
|
||||
|
||||
public void applyFilter() {
|
||||
screenPermissionsTreeDs.refresh(ParamsMap.of("filtering", true));
|
||||
}
|
||||
}
|
@ -42,8 +42,19 @@
|
||||
|
||||
<layout margin="true">
|
||||
<split width="100%" height="100%" pos="80" orientation="horizontal">
|
||||
<vbox height="100%" margin="false;true;false;false">
|
||||
<treeTable id="screenPermissionsTree" width="100%" height="100%" multiselect="true">
|
||||
<vbox expand="screenPermissionsTree"
|
||||
height="100%"
|
||||
margin="false;true;false;false">
|
||||
<hbox margin="false;false,true;false"
|
||||
spacing="true">
|
||||
<label align="MIDDLE_LEFT"
|
||||
value="msg://screenFilter"/>
|
||||
<textField id="screenFilter"
|
||||
width="theme://cuba.gui.screens-permission-tab.screenFilter.width"/>
|
||||
<button caption="msg://actions.Apply"
|
||||
invoke="applyFilter"/>
|
||||
</hbox>
|
||||
<treeTable id="screenPermissionsTree" width="100%" multiselect="true">
|
||||
<columns>
|
||||
<column id="caption" caption="msg://target"/>
|
||||
<column id="permissionVariant" caption="msg://value"/>
|
||||
|
@ -130,6 +130,7 @@ cuba.gui.scheduled-task-edit.field.width=400px
|
||||
cuba.gui.session-attr-edit.field.width=250px
|
||||
|
||||
cuba.gui.attributes-permission-tab.entityFilter.width=300px
|
||||
cuba.gui.screens-permission-tab.screenFilter.width = 300px
|
||||
|
||||
cuba.gui.entities-permission-tab.entityFilter.width=300px
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user