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.permission;
|
10
|
|
11
|
import java.io.Serializable;
|
12
|
import java.util.EnumSet;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import javax.annotation.PostConstruct;
|
16
|
|
17
|
import org.springframework.context.annotation.Profile;
|
18
|
|
19
|
import com.vaadin.server.FontAwesome;
|
20
|
import com.vaadin.spring.annotation.SpringComponent;
|
21
|
import com.vaadin.ui.AbstractComponentContainer;
|
22
|
import com.vaadin.ui.Button;
|
23
|
import com.vaadin.ui.themes.ValoTheme;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
26
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
27
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
28
|
|
29
|
/**
|
30
|
* PermissionDebugUtils provide the following tools:
|
31
|
* <ul>
|
32
|
* <li>{@link #addGainPerEntityPermissionButton(AbstractComponentContainer, Class, Integer, EnumSet)}:
|
33
|
* A button which gives a per entity authority to the current user.</li>
|
34
|
* </ul>
|
35
|
*
|
36
|
*
|
37
|
* To enable the PermissionDebugUtils you need to activate the spring profile <code>debug</code>. You can add
|
38
|
* <code>-Dspring.profiles.active=debug</code> to the command starting the jvm
|
39
|
* or set this as an environment variable.
|
40
|
*
|
41
|
* @author a.kohlbecker
|
42
|
* @since Oct 11, 2017
|
43
|
*
|
44
|
*/
|
45
|
@SpringComponent
|
46
|
@Profile("debug")
|
47
|
public class PermissionDebugUtils implements Serializable {
|
48
|
|
49
|
private static final long serialVersionUID = -210079304170235459L;
|
50
|
|
51
|
private static PermissionDebugUtils bean;
|
52
|
|
53
|
@PostConstruct
|
54
|
public void registerBean() {
|
55
|
PermissionDebugUtils.bean = this;
|
56
|
}
|
57
|
|
58
|
public static PermissionDebugUtils bean() {
|
59
|
return bean;
|
60
|
}
|
61
|
|
62
|
public static Button addGainPerEntityPermissionButton(AbstractComponentContainer toContainer, Class<? extends CdmBase> cdmType,
|
63
|
UUID entitiyUuid, EnumSet<CRUD> crud, String property){
|
64
|
|
65
|
PermissionDebugUtils pu = PermissionDebugUtils.bean();
|
66
|
if(pu != null){
|
67
|
Button button = pu.gainPerEntityPermissionButton(cdmType, entitiyUuid, crud, property);
|
68
|
if(button != null){
|
69
|
toContainer.addComponent(button);
|
70
|
}
|
71
|
return button;
|
72
|
}
|
73
|
return null;
|
74
|
}
|
75
|
|
76
|
public Button gainPerEntityPermissionButton(Class<? extends CdmBase> cdmType, UUID entitiyUuid, EnumSet<CRUD> crud, String property){
|
77
|
|
78
|
Button button = new Button(FontAwesome.BOLT);
|
79
|
button.addClickListener(e -> UserHelperAccess.userHelper().createAuthorityFor(UserHelperAccess.userHelper().userName(), cdmType, entitiyUuid, crud, property));
|
80
|
button.addStyleName(ValoTheme.BUTTON_DANGER);
|
81
|
return button;
|
82
|
|
83
|
}
|
84
|
|
85
|
|
86
|
}
|