Project

General

Profile

« Previous | Next » 

Revision 9773ed87

Added by Andreas Kohlbecker almost 7 years ago

ref #6169 displaying the Registration.submitter to curators

  • implementation of a UserHelper

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItem.java
55 55

  
56 56
    private static final String LABEL_CAPTION_RELEASED = "Released";
57 57

  
58
    private static final int GRID_ROWS = 4;
58
    private static final int GRID_ROWS = 5;
59 59

  
60 60
    private static final int GRID_COLS = 3;
61 61

  
......
74 74
    private Button blockedByButton = new Button(FontAwesome.WARNING);
75 75
    private Button messageButton;
76 76
    private Button openButton = new Button(FontAwesome.COGS);
77
    private Label submitterLabel = new Label();
77 78
    private Label createdLabel = new Label();
78 79
    private Label publishedLabel = new Label();
79 80
    private Label releasedLabel = new Label();
......
101 102
        setWidth(100, Unit.PERCENTAGE);
102 103
        addStyleName("registration-list-item");
103 104

  
104
        typeStateLabel.setStyleName(LABEL_NOWRAP);
105
        CssLayout stateUserContainer = new CssLayout();
106
        typeStateLabel.setStyleName(LABEL_NOWRAP + " registration-state");
105 107
        typeStateLabel.setVisible(false);
106
        addComponent(typeStateLabel, 0, 0);
107
        setComponentAlignment(typeStateLabel, Alignment.TOP_LEFT);
108

  
109
        submitterLabel.setStyleName(LABEL_NOWRAP + " submitter");
110
        submitterLabel.setIcon(FontAwesome.USER);
111
        submitterLabel.setContentMode(ContentMode.HTML);
112
        submitterLabel.setVisible(false);
113

  
114
        stateUserContainer.addComponents(typeStateLabel, submitterLabel);
115
        addComponent(stateUserContainer, 0, 0);
116
        setComponentAlignment(stateUserContainer, Alignment.TOP_LEFT);
108 117

  
109 118
        identifierLink.setVisible(false);
110 119
        addComponent(identifierLink, 1, 0);
......
161 170
                );
162 171

  
163 172
        updateUI(regDto.getBibliographicCitationString(), regDto.getCreated(), regDto.getDatePublished(), regDto.getMessages().size(),
164
                navigationEvent, null, regDto);
173
                navigationEvent, null, regDto, regDto.getSubmitterUserName());
165 174
    }
166 175

  
167 176
    public void setWorkingSet(RegistrationWorkingSet workingSet, AbstractView<?> parentView){
......
175 184
        }
176 185
        TimePeriod datePublished = workingSet.getRegistrationDTOs().get(0).getDatePublished();
177 186
        updateUI(workingSet.getCitation(), workingSet.getCreated(), datePublished, workingSet.messagesCount(),
178
                referenceEditorAction, FontAwesome.EDIT, null);
187
                referenceEditorAction, FontAwesome.EDIT, null, workingSet.getRegistrationDTOs().get(0).getSubmitterUserName());
179 188
    }
180 189

  
181 190
    /**
191
     * @param submitterUserName TODO
182 192
     *
183 193
     */
184 194
    private void updateUI(String citationString,  DateTime created, TimePeriod datePublished,  int messagesCount,
185
            Object openButtonEvent, Resource openButtonIcon, RegistrationDTO regDto) {
195
            Object openButtonEvent, Resource openButtonIcon, RegistrationDTO regDto, String submitterUserName) {
186 196

  
187 197
        StringBuffer labelMarkup = new StringBuffer();
188 198
        DateTime registrationDate = null;
......
239 249
            registrationDate = regDto.getRegistrationDate();
240 250
        }
241 251

  
242

  
243 252
        getCitationSummaryLabel().setValue(labelMarkup.toString());
253
        getSubmitterLabel().setValue(submitterUserName);
244 254
        updateDateLabels(created, datePublished, registrationDate);
245 255
    }
246 256

  
247 257

  
248
    /**
249
     *
250
     */
251 258
    private void updateDateLabels(DateTime created, TimePeriod datePublished, DateTime released) {
252 259
        getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED + "</span>&nbsp;" + created.toString(ISODateTimeFormat.yearMonthDay()));
253 260
        if(datePublished != null){
254 261
            getPublishedLabel().setVisible(true);
255

  
256

  
257 262
            getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span>&nbsp;" + timePeriodFormatter.print(datePublished));
258 263
        }
259 264
        if(released != null){
260 265
            getReleasedLabel().setVisible(true);
261 266
            getReleasedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_RELEASED + "</span>&nbsp;" + released.toString(ISODateTimeFormat.yearMonthDay()));
262 267
        }
263
        // LABEL_CAPTION_RELEASED
264 268
    }
265 269

  
266 270

  
267

  
268 271
    private void publishEvent(Object event) {
269 272
        parentView.getEventBus().publishEvent(event);
270 273
    }
......
334 337
        return releasedLabel;
335 338
    }
336 339

  
340
    /**
341
     * @return the submitterLabel
342
     */
343
    public Label getSubmitterLabel() {
344
        return submitterLabel;
345
    }
346

  
347

  
337 348
   /* --------------------------------------- */
338 349

  
339 350
}
src/main/java/eu/etaxonomy/cdm/vaadin/security/AnnotationBasedAccessControlBean.java
22 22
 * @author a.kohlbecker
23 23
 * @since Apr 24, 2017
24 24
 *
25
 *
26
 * FIMXE consider renaming this class and its interface, since it is no longer annotation based!!!!
25 27
 */
26 28
public class AnnotationBasedAccessControlBean implements ViewInstanceAccessControl {
27 29

  
......
60 62
                }
61 63
                return false;
62 64
                // FIMXE implement further checks
65
                // TODO use the UserHelperBean?
63 66
            }
64 67
        }
65 68

  
src/main/java/eu/etaxonomy/cdm/vaadin/security/UserHelper.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.security;
10

  
11
import org.springframework.security.authentication.AnonymousAuthenticationToken;
12
import org.springframework.security.core.Authentication;
13
import org.springframework.security.core.context.SecurityContext;
14
import org.springframework.security.core.context.SecurityContextHolder;
15

  
16
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
17

  
18
/**
19
 * @author a.kohlbecker
20
 * @since May 19, 2017
21
 *
22
 */
23
public class UserHelper {
24

  
25

  
26
    public static boolean userIsAutheticated() {
27
        Authentication authentication = getAuthentication();
28
        if(authentication != null){
29
            return authentication.isAuthenticated();
30
        }
31
        return false;
32
    }
33

  
34

  
35
    public static boolean userIsAnnonymous() {
36
        Authentication authentication = getAuthentication();
37
        return authentication != null
38
                && authentication.isAuthenticated()
39
                && authentication instanceof AnonymousAuthenticationToken;
40
    }
41

  
42
    public static String userName() {
43
        Authentication authentication = getAuthentication();
44
        if(authentication != null) {
45
            return authentication.getName();
46
        }
47
        return null;
48
    }
49

  
50
    public static boolean userIsAdmin() {
51
        Authentication authentication = getAuthentication();
52
        if(authentication != null) {
53
            return authentication.getAuthorities().stream().anyMatch(a -> {
54
                return a.getAuthority().equals(Role.ROLE_ADMIN.getAuthority());
55
            });
56
        }
57
        return false;
58
    }
59

  
60
    public static boolean userIsRegistrationCurator() {
61
        Authentication authentication = getAuthentication();
62
        if(authentication != null) {
63
            return authentication.getAuthorities().stream().anyMatch(a -> {
64
                // doing faster regex check here instreas of using CdmAuthoritiy.fromString()
65
                return a.getAuthority().matches("^Registration\\.\\[.*UPDATE");
66
            });
67
        }
68
        return false;
69
    }
70

  
71
    /**
72
     * @return
73
     *
74
     * FIXME is it ok to use the SecurityContextHolder or do we need to hold the context in the vaadin session?
75
     */
76
    private static SecurityContext currentSecurityContext() {
77
        return SecurityContextHolder.getContext();
78
    }
79

  
80
    /**
81
     * @return
82
     */
83
    private static Authentication getAuthentication() {
84
        return currentSecurityContext().getAuthentication();
85
    }
86

  
87
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListViewBean.java
25 25
import com.vaadin.spring.annotation.SpringView;
26 26
import com.vaadin.ui.Button;
27 27
import com.vaadin.ui.Button.ClickEvent;
28
import com.vaadin.ui.Component;
29 28
import com.vaadin.ui.CssLayout;
30 29
import com.vaadin.ui.Grid;
31 30
import com.vaadin.ui.Grid.Column;
......
37 36

  
38 37
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
39 38
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
39
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
40 40
import eu.etaxonomy.cdm.vaadin.util.converter.JodaDateTimeConverter;
41 41
import eu.etaxonomy.cdm.vaadin.util.converter.UrlStringConverter;
42 42
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
......
206 206
        buttonColumn.setSortable(false);
207 207

  
208 208
        grid.setFrozenColumnCount(1);
209

  
210 209
    }
211 210

  
212

  
213 211
    public void populateList(Collection<RegistrationDTO> registrations) {
214 212

  
213
        boolean isCurator = UserHelper.userIsRegistrationCurator() || UserHelper.userIsAdmin();
215 214
        for(RegistrationDTO regDto : registrations) {
216
            Component item = new RegistrationItem(regDto, this);
215
            RegistrationItem item = new RegistrationItem(regDto, this);
216
            item.getSubmitterLabel().setVisible(isCurator);
217 217
            item.setWidth(100, Unit.PERCENTAGE);
218 218
            listContainer.addComponent(item);
219 219
        }
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationDTO.java
39 39

  
40 40
    private String citationDetail = null;
41 41

  
42
    private String submitterUserName = null;
43

  
42 44
    private Registration reg;
43 45

  
44 46
    private List<String> messages = new ArrayList<>();
......
57 59

  
58 60
         registrationType = RegistrationType.from(reg);
59 61

  
62
         if(reg.getSubmitter() != null ){
63
             submitterUserName = reg.getSubmitter().getUsername();
64
         }
65

  
60 66
        if(hasName(reg)){
61 67
            citation = reg.getName().getNomenclaturalReference();
62 68
            citationDetail = reg.getName().getNomenclaturalMicroReference();
......
175 181
        return summary;
176 182
    }
177 183

  
184
    public String getSubmitterUserName(){
185
        return submitterUserName;
186
    }
187

  
178 188
    /**
179 189
     * @return the registrationType
180 190
     */
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowPresenter.java
166 166
    public void onEntityChangeEvent(EntityChangeEvent event){
167 167
        if(event.getEntityType().isAssignableFrom(Reference.class)){
168 168
            if(workingset.getCitationId().equals(event.getEntityId())){
169
                presentWorkingSet(event.getEntityId());
169
                refreshView();
170 170
            }
171 171
        }
172
        if(event.getEntityType().isAssignableFrom(Registration.class)){
173
            if(workingset.getRegistrations().stream().anyMatch(reg -> reg.getId() == event.getEntityId())){
174
                refreshView();
175
            }
176
        }
177

  
178
    }
172 179

  
180
    /**
181
     * 
182
     */
183
    protected void refreshView() {
184
        presentWorkingSet(workingset.getCitationId());
173 185
    }
174 186

  
175 187
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowViewBean.java
47 47
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
48 48
import eu.etaxonomy.cdm.vaadin.model.registration.WorkflowStep;
49 49
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
50
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
50 51
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
51 52

  
52 53
/**
......
126 127
        registration.setId(DOM_ID_WORKINGSET);
127 128
        registration.setWidth(100, Unit.PERCENTAGE);
128 129

  
129
        Panel namesTypesPanel = createRegistrationsList(workingset);
130
        namesTypesPanel.setStyleName("registration-list");
131
        namesTypesPanel.setCaption("Registrations");
130
        Panel registrationListPanel = createRegistrationsList(workingset);
131
        registrationListPanel.setStyleName("registration-list");
132
        registrationListPanel.setCaption("Registrations");
132 133

  
133 134

  
134 135
        registration.addComponent(createWorkflowTabSheet(workingset, null));
135
        registration.addComponent(new RegistrationItem(workingset, this));
136
        registration.addComponent(namesTypesPanel);
136
        RegistrationItem registrationItem = new RegistrationItem(workingset, this);
137
        if(UserHelper.userIsRegistrationCurator() || UserHelper.userIsAdmin()){
138
            registrationItem.getSubmitterLabel().setVisible(true);
139
        };
140
        registration.addComponent(registrationItem);
141
        registration.addComponent(registrationListPanel);
137 142

  
138 143
        registrations.add(registration);
139 144
        workflow.removeAllComponents();
src/main/webapp/VAADIN/themes/edit-valo/edit-valo.scss
244 244
    .registration-list-item {
245 245
        border-top: valo-border($border: $v-border, $color: $v-background-color, $strength: 0.7);
246 246
        padding-top: 4px; // avoid button group to overlap with border
247
        .v-label-registration-state {
248
            margin-right: round($v-unit-size / 4);
249
        }            
250
        .v-caption-submitter {
251
            margin-right: round($v-unit-size / 8);
252
        }
247 253
    }
248 254

  
249 255
   .registration-workflow-item {

Also available in: Unified diff