16 |
16 |
import org.apache.log4j.Logger;
|
17 |
17 |
|
18 |
18 |
import com.vaadin.server.ExternalResource;
|
|
19 |
import com.vaadin.server.FontAwesome;
|
19 |
20 |
import com.vaadin.ui.Button;
|
20 |
21 |
import com.vaadin.ui.Label;
|
21 |
22 |
import com.vaadin.ui.Link;
|
... | ... | |
59 |
60 |
|
60 |
61 |
private List<Label> labels = new ArrayList<>();
|
61 |
62 |
|
|
63 |
private List<ButtonWithUserEditPermission> editButtons = new ArrayList<>();
|
|
64 |
|
62 |
65 |
private Button addTypeDesignationButton;
|
63 |
66 |
|
64 |
67 |
private Label nameLabel = null;
|
65 |
68 |
|
66 |
69 |
private Link identifierLink;
|
67 |
70 |
|
|
71 |
private boolean isRegistrationLocked;
|
|
72 |
|
|
73 |
private boolean isLockOverride;
|
|
74 |
|
68 |
75 |
public RegistrationItemNameAndTypeButtons(RegistrationDTO regDto, ICdmEntityUuidCacher entitiyCacher) {
|
69 |
76 |
|
70 |
|
boolean isRegistrationLocked = EnumSet.of(
|
|
77 |
isRegistrationLocked = EnumSet.of(
|
71 |
78 |
RegistrationStatus.PUBLISHED, RegistrationStatus.REJECTED)
|
72 |
79 |
.contains(regDto.getStatus());
|
73 |
80 |
|
... | ... | |
87 |
94 |
Label nameLabel = new Label(regDto.getNameRef().getLabel());
|
88 |
95 |
nameLabel.setWidthUndefined();
|
89 |
96 |
boolean userHasPermission = userHelper.userHasPermission(regDto.registration().getName(), CRUD.UPDATE);
|
90 |
|
nameButton.setReadOnly(isRegistrationLocked || ! userHasPermission);
|
|
97 |
editButtons.add(new ButtonWithUserEditPermission(nameButton, userHasPermission));
|
91 |
98 |
|
92 |
99 |
addComponent(nameIdButton.getButton());
|
93 |
100 |
PermissionDebugUtils.addGainPerEntityPermissionButton(this, TaxonName.class, regDto.getNameRef().getUuid(),
|
... | ... | |
109 |
116 |
Button tdButton = new Button(buttonLabel + ":");
|
110 |
117 |
tdButton.setDescription("Edit the type designation working set");
|
111 |
118 |
boolean userHasUpdatePermission = userHelper.userHasPermission(baseEntityRef.getType(), baseEntityRef.getUuid(), CRUD.UPDATE, CRUD.DELETE);
|
112 |
|
tdButton.setReadOnly(isRegistrationLocked || !userHasUpdatePermission);
|
|
119 |
editButtons.add(new ButtonWithUserEditPermission(tdButton, userHasUpdatePermission));
|
113 |
120 |
addComponent(tdButton);
|
114 |
121 |
|
115 |
122 |
PermissionDebugUtils.addGainPerEntityPermissionButton(this, SpecimenOrObservationBase.class,
|
... | ... | |
149 |
156 |
}
|
150 |
157 |
|
151 |
158 |
iterator().forEachRemaining(c -> addStyledComponent(c));
|
|
159 |
updateEditorButtonReadonlyStates();
|
152 |
160 |
addDefaultStyles();
|
153 |
161 |
|
154 |
162 |
}
|
155 |
163 |
|
|
164 |
|
|
165 |
private void updateEditorButtonReadonlyStates() {
|
|
166 |
for(ButtonWithUserEditPermission b : editButtons){
|
|
167 |
boolean impossibleToUnlock = !b.userCanEdit && isLockOverride && isRegistrationLocked;
|
|
168 |
b.button.setReadOnly((isRegistrationLocked && !isLockOverride) || !b.userCanEdit);
|
|
169 |
b.button.setEnabled(!impossibleToUnlock);
|
|
170 |
b.button.setDescription(impossibleToUnlock ? "Unlock failed due to missing permissions!" : "");
|
|
171 |
b.button.setIcon(isLockOverride ? FontAwesome.UNLOCK_ALT : null);
|
|
172 |
}
|
|
173 |
|
|
174 |
}
|
|
175 |
|
156 |
176 |
public IdButton<TaxonName> getNameButton() {
|
157 |
177 |
return nameIdButton;
|
158 |
178 |
}
|
... | ... | |
250 |
270 |
|
251 |
271 |
}
|
252 |
272 |
|
|
273 |
public class ButtonWithUserEditPermission {
|
|
274 |
|
|
275 |
Button button;
|
|
276 |
boolean userCanEdit;
|
|
277 |
/**
|
|
278 |
* @param button
|
|
279 |
* @param userCanEdit
|
|
280 |
*/
|
|
281 |
public ButtonWithUserEditPermission(Button button, boolean userCanEdit) {
|
|
282 |
super();
|
|
283 |
this.button = button;
|
|
284 |
this.userCanEdit = userCanEdit;
|
|
285 |
}
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
}
|
|
290 |
public boolean isRegistrationLocked() {
|
|
291 |
return isRegistrationLocked;
|
|
292 |
}
|
|
293 |
|
|
294 |
|
|
295 |
/**
|
|
296 |
* @return the isLockOverride
|
|
297 |
*/
|
|
298 |
public boolean isLockOverride() {
|
|
299 |
return isLockOverride;
|
|
300 |
}
|
|
301 |
|
|
302 |
/**
|
|
303 |
* @param isLockOverride the isLockOverride to set
|
|
304 |
*/
|
|
305 |
public void setLockOverride(boolean isLockOverride) {
|
|
306 |
if(this.isLockOverride != isLockOverride){
|
|
307 |
this.isLockOverride = isLockOverride;
|
|
308 |
updateEditorButtonReadonlyStates();
|
|
309 |
}
|
|
310 |
}
|
|
311 |
|
253 |
312 |
}
|
ref #8192 unlock button to allow curator and admin to edit published Registrations