mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
Refs #1433 @SystemLevel for Attributes
This commit is contained in:
parent
efd52f8270
commit
d2bce94dbe
@ -2,10 +2,6 @@
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: FIRSTNAME LASTNAME
|
||||
* Created: 06.11.2008 9:49:55
|
||||
* $Id: JPAAnnotationsLoader.java 5981 2011-09-20 07:35:58Z krivopustov $
|
||||
*/
|
||||
package com.haulmont.chile.jpa.loader;
|
||||
|
||||
@ -17,6 +13,7 @@ import com.haulmont.chile.core.model.Range;
|
||||
import com.haulmont.chile.core.model.Session;
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.chile.core.model.impl.MetaClassImpl;
|
||||
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.isBlank;
|
||||
@ -35,6 +32,10 @@ import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author krivopustov
|
||||
* @version $Id$
|
||||
*/
|
||||
public class JPAAnnotationsLoader extends ChileAnnotationsLoader implements ClassMetadataLoader {
|
||||
|
||||
private Log log = LogFactory.getLog(JPAMetadataLoader.class);
|
||||
@ -236,6 +237,11 @@ public class JPAAnnotationsLoader extends ChileAnnotationsLoader implements Clas
|
||||
if (temporal != null) {
|
||||
metaProperty.getAnnotations().put("temporal", temporal.value());
|
||||
}
|
||||
|
||||
SystemLevel systemLevel = field.getAnnotation(SystemLevel.class);
|
||||
if (systemLevel != null) {
|
||||
metaProperty.getAnnotations().put("system", true);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isPersistent(Field field) {
|
||||
@ -246,4 +252,4 @@ public class JPAAnnotationsLoader extends ChileAnnotationsLoader implements Clas
|
||||
|| field.isAnnotationPresent(ManyToMany.class)
|
||||
|| field.isAnnotationPresent(Embedded.class);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,14 +12,15 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that annotated entity is low-level and should not be available for end-user in various entity lists.
|
||||
* Indicates that annotated entity/field is low-level and should not be available for end-user in various entity/field lists.<br/>
|
||||
* For field indicates that attribute should not be available for dynamic filters in UI.
|
||||
*
|
||||
* @author krivopustov
|
||||
* @version $Id$
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface SystemLevel {
|
||||
|
||||
boolean value() default true;
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ import com.haulmont.chile.core.annotations.NamePattern;
|
||||
import com.haulmont.cuba.core.entity.StandardEntity;
|
||||
import com.haulmont.cuba.core.entity.annotation.Listeners;
|
||||
import com.haulmont.cuba.core.entity.annotation.OnDeleteInverse;
|
||||
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
|
||||
import com.haulmont.cuba.core.entity.annotation.TrackEditScreenHistory;
|
||||
import com.haulmont.cuba.core.global.DeletePolicy;
|
||||
import com.haulmont.cuba.core.sys.AppContext;
|
||||
@ -42,9 +43,11 @@ public class User extends StandardEntity {
|
||||
@Column(name = "LOGIN", length = LOGIN_FIELD_LEN, nullable = false)
|
||||
protected String login;
|
||||
|
||||
@SystemLevel
|
||||
@Column(name = "LOGIN_LC", length = LOGIN_FIELD_LEN, nullable = false)
|
||||
protected String loginLowerCase;
|
||||
|
||||
@SystemLevel
|
||||
@Column(name = "PASSWORD", length = 255)
|
||||
protected String password;
|
||||
|
||||
@ -254,4 +257,4 @@ public class User extends StandardEntity {
|
||||
public String getSalt() {
|
||||
return id != null ? id.toString() : "";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2011 Haulmont Technology Ltd. All Rights Reserved.
|
||||
~ Haulmont Technology proprietary and confidential.
|
||||
~ Use is subject to license terms.
|
||||
-->
|
||||
|
||||
<window xmlns="http://schemas.haulmont.com/cuba/4.0/window.xsd">
|
||||
<dsContext>
|
||||
<collectionDatasource
|
||||
id="groups"
|
||||
class="com.haulmont.cuba.security.entity.Group"
|
||||
view="group.lookup"
|
||||
>
|
||||
<query>select g from sec$Group g</query>
|
||||
</collectionDatasource>
|
||||
</dsContext>
|
||||
|
||||
<layout>
|
||||
<vbox expand="expand-box" margin="true">
|
||||
<hbox id="group-box" spacing="true" stylename="edit-area">
|
||||
<label control="name" value="msg://name"/>
|
||||
<textField id="name"/>
|
||||
|
||||
<label control="login" value="msg://login"/>
|
||||
<textField id="login"/>
|
||||
|
||||
<label control="email" value="msg://email"/>
|
||||
<textField id="email"/>
|
||||
|
||||
<label control="group" value="msg://group"/>
|
||||
<lookupField id="group" optionsDatasource="groups" captionProperty="name" required="false"
|
||||
nullName="msg://any"/>
|
||||
</hbox>
|
||||
<hbox align="MIDDLE_LEFT" spacing="true" margin="true;false;false;false">
|
||||
<button id="apply" icon="icons/search.png"/>
|
||||
<button id="clear" icon="icons/clear.png"/>
|
||||
</hbox>
|
||||
<hbox id="expand-box"/>
|
||||
</vbox>
|
||||
</layout>
|
||||
</window>
|
@ -26,7 +26,7 @@
|
||||
|
||||
<layout expand="usersTable" spacing="true">
|
||||
<filter id="genericFilter" datasource="usersDs" applyTo="usersTable">
|
||||
<properties include=".*" exclude="(password)|(loginLowerCase)"/>
|
||||
<properties include=".*"/>
|
||||
<custom name="customByGroup" caption="msg://genericFilter.customByGroup"
|
||||
join="left join u.group.hierarchyList h" paramClass="com.haulmont.cuba.security.entity.Group">
|
||||
(h.parent.id = ? or h.group.id = ?) or (u.group.id = ? and h.parent is null)
|
||||
@ -73,4 +73,4 @@
|
||||
<rows datasource="usersDs"/>
|
||||
</groupTable>
|
||||
</layout>
|
||||
</window>
|
||||
</window>
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.gui.components.filter.addcondition;
|
||||
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.MessageTools;
|
||||
import com.haulmont.cuba.core.global.UserSessionSource;
|
||||
import com.haulmont.cuba.security.entity.EntityAttrAccess;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
|
||||
/**
|
||||
* @author artamonov
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ModelPropertiesFilter {
|
||||
|
||||
private UserSession userSession;
|
||||
private final MessageTools messageTools;
|
||||
|
||||
public ModelPropertiesFilter() {
|
||||
userSession = AppBeans.get(UserSessionSource.class).getUserSession();
|
||||
messageTools = AppBeans.get(MessageTools.class);
|
||||
}
|
||||
|
||||
public boolean isPropertyFilterAllowed(MetaProperty property) {
|
||||
if (userSession.isEntityAttrPermitted(property.getDomain(), property.getName(), EntityAttrAccess.VIEW)) {
|
||||
// exclude system level attributes
|
||||
Boolean systemLevel = (Boolean) property.getAnnotations().get("system");
|
||||
if (!BooleanUtils.isTrue(systemLevel)) {
|
||||
// exclude not localized properties (they are usually not for end user) and ToMany
|
||||
if (messageTools.hasPropertyCaption(property) && !property.getRange().getCardinality().isMany()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -9,10 +9,7 @@ package com.haulmont.cuba.gui.components.filter.addcondition;
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.MessageTools;
|
||||
import com.haulmont.cuba.core.global.UserSessionProvider;
|
||||
import com.haulmont.cuba.gui.components.filter.AbstractConditionDescriptor;
|
||||
import com.haulmont.cuba.security.entity.EntityAttrAccess;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
@ -20,11 +17,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Property node.
|
||||
* <p/>
|
||||
* <p>$Id$</p>
|
||||
* Property node
|
||||
*
|
||||
* @author krivopustov
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PropertyModelItem implements ModelItem {
|
||||
|
||||
@ -64,16 +60,11 @@ public class PropertyModelItem implements ModelItem {
|
||||
if (metaProperty.getRange().isClass()) {
|
||||
List<ModelItem> list = new ArrayList<>();
|
||||
|
||||
UserSession userSession = UserSessionProvider.getUserSession();
|
||||
ModelPropertiesFilter propertiesFilter = new ModelPropertiesFilter();
|
||||
|
||||
for (MetaProperty property : metaProperty.getRange().asClass().getProperties()) {
|
||||
// check permissions
|
||||
if (userSession.isEntityAttrPermitted(property.getDomain(), property.getName(), EntityAttrAccess.VIEW)) {
|
||||
// exclude not localized properties (they are usually not for end user) and ToMany
|
||||
if (AppBeans.get(MessageTools.class).hasPropertyCaption(property) && !property.getRange().getCardinality().isMany()) {
|
||||
list.add(new PropertyModelItem(this, property, null, descriptorBuilder));
|
||||
}
|
||||
}
|
||||
if (propertiesFilter.isPropertyFilterAllowed(property))
|
||||
list.add(new PropertyModelItem(this, property, null, descriptorBuilder));
|
||||
}
|
||||
Collections.sort(list, new ModelItemComparator());
|
||||
return list;
|
||||
|
@ -9,13 +9,11 @@ package com.haulmont.cuba.gui.components.filter.addcondition;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.chile.core.model.MetaPropertyPath;
|
||||
import com.haulmont.cuba.core.global.MessageProvider;
|
||||
import com.haulmont.cuba.core.global.UserSessionProvider;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.Messages;
|
||||
import com.haulmont.cuba.gui.components.filter.AbstractConditionDescriptor;
|
||||
import com.haulmont.cuba.gui.components.filter.AbstractFilterEditor;
|
||||
import com.haulmont.cuba.gui.components.filter.AbstractPropertyConditionDescriptor;
|
||||
import com.haulmont.cuba.security.entity.EntityAttrAccess;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@ -55,7 +53,7 @@ public class RootPropertyModelItem implements ModelItem {
|
||||
public List<ModelItem> getChildren() {
|
||||
List<ModelItem> list = new ArrayList<>();
|
||||
|
||||
UserSession userSession = UserSessionProvider.getUserSession();
|
||||
ModelPropertiesFilter modelPropertiesFilter = new ModelPropertiesFilter();
|
||||
|
||||
for (AbstractConditionDescriptor descriptor : propertyDescriptors) {
|
||||
if (descriptor instanceof AbstractPropertyConditionDescriptor) {
|
||||
@ -65,7 +63,8 @@ public class RootPropertyModelItem implements ModelItem {
|
||||
continue;
|
||||
}
|
||||
MetaProperty metaProperty = mpp.getMetaProperty();
|
||||
if (userSession.isEntityAttrPermitted(metaClass, metaProperty.getName(), EntityAttrAccess.VIEW))
|
||||
|
||||
if (modelPropertiesFilter.isPropertyFilterAllowed(metaProperty))
|
||||
list.add(new PropertyModelItem(null, metaProperty, descriptor, descriptorBuilder));
|
||||
}
|
||||
}
|
||||
@ -76,11 +75,11 @@ public class RootPropertyModelItem implements ModelItem {
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return MessageProvider.getMessage(AbstractFilterEditor.MESSAGES_PACK, "NewConditionDlg.attributes");
|
||||
return AppBeans.get(Messages.class).getMessage(AbstractFilterEditor.MESSAGES_PACK, "NewConditionDlg.attributes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractConditionDescriptor getDescriptor() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user