Project

General

Profile

Revision 35a51c01

ID35a51c0196919d0ef479d0e99620ef7ec1fb3d84
Parent d81bb53b
Child 99741bc0

Added by Andreas Kohlbecker almost 2 years ago

ref #7833 registration start view only shows references for which the user has permissions

View differences:

src/main/java/eu/etaxonomy/cdm/service/TypifiedEntityFilterablePagingProvider.java
11 11
import java.util.ArrayList;
12 12
import java.util.List;
13 13

  
14
import org.hibernate.criterion.Criterion;
14 15
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
15 16
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
16 17

  
......
87 88
        entityPagingProvider.setMatchMode(matchMode);
88 89
    }
89 90

  
91
    /**
92
     * @deprecated criteria should not be used externally from cdmlib-persistence
93
     */
94
    @Deprecated
95
    public List<Criterion> getCriteria() {
96
        return entityPagingProvider.getCriteria();
97
    }
98

  
99
    /**
100
     * @deprecated criteria should not be used externally from cdmlib-persistence
101
     */
102
    @Deprecated
103
    public void addCriterion(Criterion criterion){
104
        entityPagingProvider.addCriterion(criterion);
105
    }
106

  
90 107
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/StartRegistrationPresenter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.registration;
10 10

  
11
import java.util.Collection;
11 12
import java.util.EnumSet;
13
import java.util.Set;
12 14
import java.util.UUID;
15
import java.util.stream.Collectors;
13 16

  
17
import org.hibernate.criterion.Criterion;
18
import org.hibernate.criterion.Restrictions;
14 19
import org.springframework.beans.factory.annotation.Autowired;
15 20
import org.vaadin.spring.events.EventScope;
16 21
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
......
26 31
import eu.etaxonomy.cdm.format.ReferenceEllypsisFormatter;
27 32
import eu.etaxonomy.cdm.model.reference.Reference;
28 33
import eu.etaxonomy.cdm.model.reference.ReferenceType;
29
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
30
import eu.etaxonomy.cdm.persistence.dao.common.Restriction.Operator;
31 34
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
35
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
36
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
32 37
import eu.etaxonomy.cdm.persistence.query.MatchMode;
33 38
import eu.etaxonomy.cdm.ref.TypedEntityReference;
34 39
import eu.etaxonomy.cdm.service.CdmFilterablePagingProviderFactory;
35 40
import eu.etaxonomy.cdm.service.TypifiedEntityFilterablePagingProvider;
41
import eu.etaxonomy.cdm.service.UserHelperAccess;
36 42
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
37 43
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
38 44
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
......
83 89
                ReferenceEllypsisFormatter.INIT_STRATEGY
84 90
                );
85 91
        TypedEntityCaptionGenerator<Reference> titleCacheGenrator = new TypedEntityCaptionGenerator<Reference>();
86
        referencePagingProvider.addRestriction(new Restriction("type", Operator.AND_NOT, null, ReferenceType.Section, ReferenceType.Journal, ReferenceType.PrintSeries));
92
        // referencePagingProvider.addRestriction(new Restriction("type", Operator.AND_NOT, null, ReferenceType.Section, ReferenceType.Journal, ReferenceType.PrintSeries));
93
        Criterion criterion = Restrictions.not(Restrictions.or(Restrictions.in("type", new ReferenceType[]{ReferenceType.Section, ReferenceType.Journal, ReferenceType.PrintSeries})));
94

  
95
        if(!UserHelperAccess.userHelper().userIsAdmin()){
96
            Collection<CdmAuthority> referencePermissions = UserHelperAccess.userHelper().findUserPermissions(Reference.class, Operation.UPDATE);
97
            boolean generalUpdatePermission = referencePermissions.stream().anyMatch(p -> p.getTargetUUID() == null);
98
            if(!generalUpdatePermission){
99
                // restrict by allowed reference uuids
100
                Set<UUID> allowedUuids = referencePermissions.stream().filter(p -> p.getTargetUUID() != null).map(CdmAuthority::getTargetUUID).collect(Collectors.toSet());
101
                Criterion uuidRestriction = Restrictions.in("uuid", allowedUuids);
102
                criterion = Restrictions.and(criterion, uuidRestriction);
103
            }
104
        }
105
        referencePagingProvider.addCriterion(criterion);
87 106
        getView().getReferenceCombobox().setCaptionGenerator(titleCacheGenrator);
88 107
        getView().getReferenceCombobox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
89 108
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)