Project

General

Profile

Revision 499f55b2

ID499f55b2f35e00e9752ed13e2ce66382d283d56c
Parent c6de1c09
Child d8b1c9ce

Added by Andreas Kohlbecker over 3 years ago

ref #6867 ref #7026 extending UserHelper to allow creation of authorities with propeties and test button in debug mode

View differences:

src/main/java/eu/etaxonomy/cdm/service/CdmUserHelper.java
186 186
     * @return
187 187
     */
188 188
    @Override
189
    public void createAuthorityFor(String username, Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud) {
189
    public void createAuthorityFor(String username, Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud, String property) {
190 190
        UserDetails userDetails = repo.getUserService().loadUserByUsername(username);
191 191
        if(userDetails != null){
192 192
            User user = (User)userDetails;
193 193
            CdmBase entity = repo.getCommonService().find(cdmType, entitiyId);
194
            CdmAuthority authority = new CdmAuthority(entity, crud);
194
            CdmAuthority authority = new CdmAuthority(entity, property, crud);
195 195
            try {
196 196
                user.getGrantedAuthorities().add(authority.asNewGrantedAuthority());
197 197
            } catch (CdmAuthorityParsingException e) {
......
212 212
     * @return
213 213
     */
214 214
    @Override
215
    public void createAuthorityForCurrentUser(Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud) {
216
        createAuthorityFor(userName(), cdmType, entitiyId, crud);
215
    public void createAuthorityForCurrentUser(Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud, String property) {
216
        createAuthorityFor(userName(), cdmType, entitiyId, crud, property);
217 217
    }
218 218

  
219 219
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItemEditButtonGroup.java
79 79
            nameButton.setEnabled(!isRegistrationLocked && userHasPermission);
80 80

  
81 81
            addComponent(nameIdButton.getButton());
82
            PermissionDebugUtils.fromSession().addGainPerEntityPermissionButton(this, TaxonName.class, regDto.getName().getId(), EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
82
            PermissionDebugUtils.fromSession().addGainPerEntityPermissionButton(this, TaxonName.class, regDto.getName().getId(),
83
                    EnumSet.of(CRUD.UPDATE, CRUD.DELETE), null);
83 84
            addComponent(nameLabel);
84 85
        } else {
85 86
            // no name in the registration! we only show the typified name as label
......
97 98
                tdButton.setEnabled(!isRegistrationLocked && UserHelper.fromSession().userHasPermission(baseEntityRef.getType(), baseEntityRef.getId(), CRUD.UPDATE));
98 99
                addComponent(tdButton);
99 100

  
100
                PermissionDebugUtils.fromSession().addGainPerEntityPermissionButton(this, SpecimenOrObservationBase.class, baseEntityRef.getId(), EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
101
                PermissionDebugUtils.fromSession().addGainPerEntityPermissionButton(this, SpecimenOrObservationBase.class,
102
                        baseEntityRef.getId(), EnumSet.of(CRUD.UPDATE, CRUD.DELETE), RegistrationStatus.PREPARATION.name());
101 103

  
102 104
                typeDesignationButtons.add(new TypeDesignationWorkingSetButton(
103 105
                        typeDesignationWorkingSet.getWorkingsetType(),
src/main/java/eu/etaxonomy/cdm/vaadin/security/PermissionDebugUtils.java
69 69
        return (PermissionDebugUtils)VaadinSession.getCurrent().getAttribute(VADDIN_SESSION_KEY);
70 70
     }
71 71

  
72
    public Button addGainPerEntityPermissionButton(AbstractComponentContainer toContainer, Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud){
73
        Button button = gainPerEntityPermissionButton(cdmType, entitiyId, crud);
72
    public Button addGainPerEntityPermissionButton(AbstractComponentContainer toContainer, Class<? extends CdmBase> cdmType,
73
            Integer entitiyId, EnumSet<CRUD> crud, String property){
74
        Button button = gainPerEntityPermissionButton(cdmType, entitiyId, crud, property);
74 75
        if(button != null){
75 76
            toContainer.addComponent(button);
76 77
        }
77 78
        return button;
78 79
    }
79 80

  
80
    public Button gainPerEntityPermissionButton(Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud){
81
    public Button gainPerEntityPermissionButton(Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud, String property){
81 82

  
82 83
       Button button = new Button(FontAwesome.BOLT);
83
       button.addClickListener(e -> UserHelper.fromSession().createAuthorityFor(UserHelper.fromSession().userName(), cdmType, entitiyId, crud));
84
       button.addClickListener(e -> UserHelper.fromSession().createAuthorityFor(UserHelper.fromSession().userName(), cdmType, entitiyId, crud, property));
84 85
       button.addStyleName(ValoTheme.BUTTON_DANGER);
85 86
       return button;
86 87

  
src/main/java/eu/etaxonomy/cdm/vaadin/security/UserHelper.java
53 53

  
54 54
    boolean userIsAutheticated();
55 55

  
56
    public void createAuthorityFor(String username, Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud);
56
    public void createAuthorityFor(String username, Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud, String property);
57 57

  
58 58
    /**
59 59
     * @param cdmType
60 60
     * @param entitiyId
61 61
     * @param crud
62 62
     */
63
    void createAuthorityForCurrentUser(Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud);
63
    void createAuthorityForCurrentUser(Class<? extends CdmBase> cdmType, Integer entitiyId, EnumSet<CRUD> crud, String property);
64 64

  
65 65

  
66 66
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
220 220
        newTaxonNameForRegistration = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
221 221
        newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationId()));
222 222
        EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration);
223
        UserHelper.fromSession().createAuthorityForCurrentUser(TaxonName.class, nameSaveEvent.getEntityId(), EnumSet.of(CRUD.UPDATE,CRUD.DELETE));
223
        UserHelper.fromSession().createAuthorityForCurrentUser(TaxonName.class, nameSaveEvent.getEntityId(), EnumSet.of(CRUD.UPDATE,CRUD.DELETE), null);
224 224
        newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityId());
225 225
        TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
226 226
        popup.withDeleteButton(true);
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorksetViewBean.java
10 10

  
11 11
import java.util.ArrayList;
12 12
import java.util.Collection;
13
import java.util.EnumSet;
13 14
import java.util.List;
14 15
import java.util.UUID;
15 16

  
......
36 37
import com.vaadin.ui.Window;
37 38
import com.vaadin.ui.themes.ValoTheme;
38 39

  
40
import eu.etaxonomy.cdm.model.name.Registration;
41
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
39 42
import eu.etaxonomy.cdm.model.name.TaxonName;
43
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
40 44
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
41 45
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup;
42 46
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup.TypeDesignationWorkingSetButton;
......
53 57
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
54 58
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
55 59
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
60
import eu.etaxonomy.cdm.vaadin.security.PermissionDebugUtils;
56 61
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
57 62
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
58 63
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
......
126 131
     */
127 132
    @Override
128 133
    public void setWorkingset(RegistrationWorkingSet workingset) {
134

  
129 135
        if(workingsetHeader != null){
130 136
            getLayout().removeComponent(workingsetHeader);
131 137
            getLayout().removeComponent(registrationListPanel);
132 138
        }
133

  
134
        registrationListPanel = createRegistrationsList(workingset);
135
        registrationListPanel.setStyleName("registration-list");
136
        registrationListPanel.setCaption("Registrations");
137

  
138 139
        workingsetHeader = new RegistrationItem(workingset, this);
139 140
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
140 141
            workingsetHeader.getSubmitterLabel().setVisible(true);
141 142
        }
142 143
        addContentComponent(workingsetHeader, null);
144

  
145
        registrationListPanel = createRegistrationsList(workingset);
146
        registrationListPanel.setStyleName("registration-list");
147
        registrationListPanel.setCaption("Registrations");
143 148
        addContentComponent(registrationListPanel, 1.0f);
144 149

  
145 150
    }
......
257 262
            buttonGroup.addComponent(editRegistrationButton);
258 263
        }
259 264

  
265
        PermissionDebugUtils.fromSession().addGainPerEntityPermissionButton(buttonGroup, Registration.class, dto.getId(),
266
                EnumSet.of(CRUD.UPDATE), RegistrationStatus.PREPARATION.name());
267

  
260 268
        Component regItem;
261 269

  
262 270
        RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)