Skip to content
Snippets Groups Projects
Commit 2235371b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

default blobal project privileges options in configuration list

parent e10c72b7
No related branches found
No related tags found
1 merge request!198Resolve "Configurable default permissions"
......@@ -47,4 +47,9 @@ public enum ConfigurationElementEditType {
* Password value.
*/
PASSWORD,
/**
* True/false value.
*/
BOOLEAN,
}
......@@ -150,8 +150,17 @@ public enum ConfigurationElementType {
* Default content of the email when requesting for an account in the system.
*/
REQUEST_ACCOUNT_DEFAULT_CONTENT("Email content used for requesting an account",
"Dear Disease map team,\nI would like to request an account in the system.\nKind regards", ConfigurationElementEditType.TEXT,
false),
"Dear Disease map team,\nI would like to request an account in the system.\nKind regards",
ConfigurationElementEditType.TEXT, false),
DEFAULT_VIEW_PROJECT("Default user privilege for: " + PrivilegeType.VIEW_PROJECT.getCommonName(), "true",
ConfigurationElementEditType.BOOLEAN, false),
DEFAULT_EDIT_COMMENTS_PROJECT("Default user privilege for: " + PrivilegeType.EDIT_COMMENTS_PROJECT.getCommonName(),
"false", ConfigurationElementEditType.BOOLEAN, false),
DEFAULT_LAYOUT_MANAGEMENT("Default user privilege for: " + PrivilegeType.LAYOUT_MANAGEMENT.getCommonName(), "false",
ConfigurationElementEditType.BOOLEAN, false),
;
......
......@@ -11,140 +11,141 @@ import lcsb.mapviewer.model.map.layout.Layout;
*/
public enum PrivilegeType {
/**
* User can browse project.
*/
VIEW_PROJECT(ObjectPrivilege.class, Project.class, "View project"),
/**
* User can add project.
*/
ADD_MAP(BasicPrivilege.class, null, "Add project"),
/**
* User can edit comments in the project.
*/
EDIT_COMMENTS_PROJECT(ObjectPrivilege.class, Project.class, "Manage comments"),
/**
* User can manage projects.
*/
PROJECT_MANAGEMENT(BasicPrivilege.class, null, "Map management"),
/**
* User can manage users.
*/
USER_MANAGEMENT(BasicPrivilege.class, null, "User management"),
/**
* User can have custom layouts (access level defines how many).
*/
CUSTOM_LAYOUTS(BasicPrivilege.class, null, "Custom layouts", true),
/**
* User can view non-public layout.
*/
LAYOUT_VIEW(ObjectPrivilege.class, Layout.class, "View layout"),
/**
* User can manage configuration.
*/
CONFIGURATION_MANAGE(BasicPrivilege.class, null, "Manage configuration"),
/**
* User can manage layouts of all users in the project.
*/
LAYOUT_MANAGEMENT(ObjectPrivilege.class, Project.class, "Manage layouts"), //
/**
* User can manage reference genomes.
*/
MANAGE_GENOMES(BasicPrivilege.class, null, "Manage genomes");
/**
* Type of privilege (basic or privilege to the object).
*/
private Class<? extends BasicPrivilege> privilegeClassType;
/**
* Type of the object to which privilege refers.
*/
private Class<?> privilegeObjectType;
/**
* Name of the privilege.
*/
private String commonName;
/**
* Is the privilege numeric.
*/
private boolean numeric = false;
/**
* Constructor that initialize enum with data.
*
* @param privilegeClazz
* {@link #privilegeClassType}
* @param objectClazz
* {@link #privilegeObjectType}
* @param commonName
* {@link #commonName}
*/
PrivilegeType(Class<? extends BasicPrivilege> privilegeClazz, Class<?> objectClazz, String commonName) {
this.privilegeClassType = privilegeClazz;
this.privilegeObjectType = objectClazz;
this.commonName = commonName;
}
/**
* Constructor that initialize enum with data.
*
* @param privilegeClazz
* {@link #privilegeClassType}
* @param objectClazz
* {@link #privilegeObjectType}
* @param commonName
* {@link #commonName}
* @param numeric
* {@link #numeric}
*/
PrivilegeType(Class<? extends BasicPrivilege> privilegeClazz, Class<?> objectClazz, String commonName, boolean numeric) {
this.privilegeClassType = privilegeClazz;
this.privilegeObjectType = objectClazz;
this.commonName = commonName;
this.numeric = true;
}
/**
*
* @return {@link #privilegeClassType}
*/
public Class<? extends BasicPrivilege> getPrivilegeClassType() {
return privilegeClassType;
}
/**
*
* @return {@link #privilegeObjectType}
*/
public Class<?> getPrivilegeObjectType() {
return privilegeObjectType;
}
/**
*
* @return {@link #commonName}
*/
public String getCommonName() {
return commonName;
}
/**
*
* @return {@link #numeric}
*/
public boolean isNumeric() {
return numeric;
}
/**
* User can browse project.
*/
VIEW_PROJECT(ObjectPrivilege.class, Project.class, "View project"),
/**
* User can add project.
*/
ADD_MAP(BasicPrivilege.class, null, "Add project"),
/**
* User can edit comments in the project.
*/
EDIT_COMMENTS_PROJECT(ObjectPrivilege.class, Project.class, "Manage comments"),
/**
* User can manage projects.
*/
PROJECT_MANAGEMENT(BasicPrivilege.class, null, "Map management"),
/**
* User can manage users.
*/
USER_MANAGEMENT(BasicPrivilege.class, null, "User management"),
/**
* User can have custom layouts (access level defines how many).
*/
CUSTOM_LAYOUTS(BasicPrivilege.class, null, "Custom layouts", true),
/**
* User can view non-public layout.
*/
LAYOUT_VIEW(ObjectPrivilege.class, Layout.class, "View layout"),
/**
* User can manage configuration.
*/
CONFIGURATION_MANAGE(BasicPrivilege.class, null, "Manage configuration"),
/**
* User can manage layouts of all users in the project.
*/
LAYOUT_MANAGEMENT(ObjectPrivilege.class, Project.class, "Manage layouts"), //
/**
* User can manage reference genomes.
*/
MANAGE_GENOMES(BasicPrivilege.class, null, "Manage genomes");
/**
* Type of privilege (basic or privilege to the object).
*/
private Class<? extends BasicPrivilege> privilegeClassType;
/**
* Type of the object to which privilege refers.
*/
private Class<?> privilegeObjectType;
/**
* Name of the privilege.
*/
private String commonName;
/**
* Is the privilege numeric.
*/
private boolean numeric = false;
/**
* Constructor that initialize enum with data.
*
* @param privilegeClazz
* {@link #privilegeClassType}
* @param objectClazz
* {@link #privilegeObjectType}
* @param commonName
* {@link #commonName}
*/
PrivilegeType(Class<? extends BasicPrivilege> privilegeClazz, Class<?> objectClazz, String commonName) {
this.privilegeClassType = privilegeClazz;
this.privilegeObjectType = objectClazz;
this.commonName = commonName;
}
/**
* Constructor that initialize enum with data.
*
* @param privilegeClazz
* {@link #privilegeClassType}
* @param objectClazz
* {@link #privilegeObjectType}
* @param commonName
* {@link #commonName}
* @param numeric
* {@link #numeric}
*/
PrivilegeType(Class<? extends BasicPrivilege> privilegeClazz, Class<?> objectClazz, String commonName,
boolean numeric) {
this.privilegeClassType = privilegeClazz;
this.privilegeObjectType = objectClazz;
this.commonName = commonName;
this.numeric = true;
}
/**
*
* @return {@link #privilegeClassType}
*/
public Class<? extends BasicPrivilege> getPrivilegeClassType() {
return privilegeClassType;
}
/**
*
* @return {@link #privilegeObjectType}
*/
public Class<?> getPrivilegeObjectType() {
return privilegeObjectType;
}
/**
*
* @return {@link #commonName}
*/
public String getCommonName() {
return commonName;
}
/**
*
* @return {@link #numeric}
*/
public boolean isNumeric() {
return numeric;
}
}
......@@ -3,6 +3,7 @@ package lcsb.mapviewer.services.impl;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.EnumUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
......@@ -10,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.common.FrameworkVersion;
import lcsb.mapviewer.model.user.Configuration;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.persist.dao.ConfigurationDao;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.view.ConfigurationView;
......@@ -158,4 +160,14 @@ public class ConfigurationService implements IConfigurationService {
return runtime.maxMemory() / MEGABYTE_SIZE;
}
@Override
public ConfigurationView getValue(PrivilegeType type) {
String name = "DEFAULT_" + type.name();
if (EnumUtils.isValidEnum(ConfigurationElementType.class, name)) {
return getValue(ConfigurationElementType.valueOf(name));
} else {
return null;
}
}
}
......@@ -4,6 +4,7 @@ import java.util.List;
import lcsb.mapviewer.common.FrameworkVersion;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.services.view.ConfigurationView;
/**
......@@ -111,5 +112,7 @@ public interface IConfigurationService {
*/
String getSystemGitVersion(String baseDir);
ConfigurationView getValue(ConfigurationElementType type);
ConfigurationView getValue(ConfigurationElementType type);
ConfigurationView getValue(PrivilegeType type);
}
......@@ -2,6 +2,7 @@ package lcsb.mapviewer.services.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.List;
......@@ -13,93 +14,114 @@ import org.springframework.test.annotation.Rollback;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.FrameworkVersion;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.view.ConfigurationView;
@Rollback(true)
public class ConfigurationServiceTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(ConfigurationServiceTest.class);
@Before
public void setUp() throws Exception {
// clear information about git version
Configuration.getSystemBuildVersion(null, true);
}
@After
public void tearDown() throws Exception {
// clear information about git version
Configuration.getSystemBuildVersion(null, true);
}
@Test
public void testGetUpdate() throws Exception {
try {
String address = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS);
configurationService.deleteConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS);
String newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS);
assertEquals(ConfigurationElementType.EMAIL_ADDRESS.getDefaultValue(), newAddress);
configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, "hello@world");
newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS);
assertEquals("hello@world", newAddress);
configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, address);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testList() throws Exception {
try {
List<ConfigurationView> list = configurationService.getAllValues();
assertEquals(ConfigurationElementType.values().length, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetSystemVersion() throws Exception {
try {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testNormal/");
assertNotNull(view);
assertEquals("100", view.getGitVersion());
assertEquals("202", view.getVersion());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetSystemVersion2() throws Exception {
try {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testModified/");
assertNotNull(view);
assertEquals("100:105", view.getGitVersion());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetSystemVersion3() throws Exception {
try {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testCorrectSvn/");
assertNotNull(view);
assertEquals("117", view.getGitVersion());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
Logger logger = Logger.getLogger(ConfigurationServiceTest.class);
@Before
public void setUp() throws Exception {
// clear information about git version
Configuration.getSystemBuildVersion(null, true);
}
@After
public void tearDown() throws Exception {
// clear information about git version
Configuration.getSystemBuildVersion(null, true);
}
@Test
public void testGetUpdate() throws Exception {
try {
String address = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS);
configurationService.deleteConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS);
String newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS);
assertEquals(ConfigurationElementType.EMAIL_ADDRESS.getDefaultValue(), newAddress);
configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, "hello@world");
newAddress = configurationService.getConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS);
assertEquals("hello@world", newAddress);
configurationService.setConfigurationValue(ConfigurationElementType.EMAIL_ADDRESS, address);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testList() throws Exception {
try {
List<ConfigurationView> list = configurationService.getAllValues();
assertEquals(ConfigurationElementType.values().length, list.size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetSystemVersion() throws Exception {
try {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testNormal/");
assertNotNull(view);
assertEquals("100", view.getGitVersion());
assertEquals("202", view.getVersion());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetSystemVersion2() throws Exception {
try {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testModified/");
assertNotNull(view);
assertEquals("100:105", view.getGitVersion());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetSystemVersion3() throws Exception {
try {
FrameworkVersion view = configurationService.getSystemVersion("testFiles/gitVersionTest/testCorrectSvn/");
assertNotNull(view);
assertEquals("117", view.getGitVersion());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetConfiguratioElemntForPrivilege() throws Exception {
try {
for (PrivilegeType type : PrivilegeType.values()) {
ConfigurationView value = configurationService.getValue(type);
if (Project.class.equals(type.getPrivilegeObjectType())) {
assertNotNull("No default value for privilege " + type.getCommonName(), value);
assertNotNull(value.getValue());
assertNotNull(value.getValueType());
} else {
assertNull(value);
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment