diff --git a/src/main/java/edu/harvard/iq/dataverse/ManageRolesPage.java b/src/main/java/edu/harvard/iq/dataverse/ManageRolesPage.java index cd3a166ca52..32a51ebedfc 100644 --- a/src/main/java/edu/harvard/iq/dataverse/ManageRolesPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/ManageRolesPage.java @@ -1,6 +1,7 @@ package edu.harvard.iq.dataverse; import edu.harvard.iq.dataverse.engine.Permission; +import static edu.harvard.iq.dataverse.util.JsfHelper.JH; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -15,6 +16,7 @@ import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; +import sun.security.x509.EDIPartyName; /** * @@ -24,8 +26,11 @@ @Named public class ManageRolesPage implements java.io.Serializable { - public enum PageMode {LIST, VIEW, EDIT }; - + private static final Logger logger = Logger.getLogger(ManageRolesPage.class.getName()); + + public enum Intent { LIST, VIEW, EDIT }; + public enum ObjectType { DATAVERSE, ROLES, USERS }; + @Inject DataverseSession session; @EJB @@ -36,31 +41,32 @@ public enum PageMode {LIST, VIEW, EDIT }; private List selectedPermissions; - private PageMode mode = null; + private Intent intent = null; - private String intent; + private String intentParam; private Long viewRoleId; + private int activeTabIndex; private DataverseRole role; private DataverseRole defaultUserRole; private boolean permissionRoot; + private String objectTypeParam; + private ObjectType objectType; public void init() { - if ( mode != null ) return; + + // decide object type + objectType = JH.enumValue(getObjectTypeParam(), ObjectType.class, ObjectType.DATAVERSE); + setActiveTab(objectType); + setIntent( JH.enumValue(getIntentParam(), Intent.class, Intent.LIST)); + if ( viewRoleId != null ) { // enter view mode setRole( rolesService.find(viewRoleId) ); - if ( role == null ) { - FacesContext.getCurrentInstance().addMessage(null, - new FacesMessage(FacesMessage.SEVERITY_WARN, - "Can't find role with id '" + viewRoleId + "'", - "The role might have existed once, but was deleted")); - mode = PageMode.LIST; - } else { - mode = "edit".equals(getIntent()) ? PageMode.EDIT : PageMode.VIEW; - dataversePage.setDataverse( role.getOwner() ); - } - } else { - mode = PageMode.LIST; + if ( getRole() == null ) { + JH.addMessage(FacesMessage.SEVERITY_WARN, "Can't find role with id '" + viewRoleId + "'", + "The role might have existed once, but was deleted"); + setIntent( Intent.LIST ); + } } } @@ -72,24 +78,24 @@ public List getPermissions() { return Arrays.asList(Permission.values()); } - public boolean hasRoles() { + public boolean isHasRoles() { return ! getRoles().isEmpty(); } public void createNewRole( ActionEvent e ) { - mode = PageMode.EDIT; + setIntent(Intent.EDIT); DataverseRole aRole = new DataverseRole(); - aRole.setName("Untitled Role"); - aRole.setAlias("untitled-role"); setRole( aRole ); + setActiveTab(ObjectType.ROLES); + logger.info("Create new role"); } public void cancelEdit( ActionEvent e ) { - mode = PageMode.LIST; + intent = Intent.LIST; } public void saveDataverse( ActionEvent e ) { - + // TODO do } public void saveRole( ActionEvent e ) { @@ -102,7 +108,7 @@ public void saveRole( ActionEvent e ) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Role '" + role.getName() + "' saved", "")); - mode = PageMode.LIST; + intent = Intent.LIST; } public List getRolePermissions() { @@ -117,12 +123,12 @@ public void setSelectedPermissions(List selectedPermissions) { this.selectedPermissions = selectedPermissions; } - public PageMode getMode() { - return mode; + public Intent getIntent() { + return intent; } - public void setMode(PageMode mode) { - this.mode = mode; + public void setIntent(Intent anIntent) { + this.intent = anIntent; } public DataverseRole getRole() { @@ -138,7 +144,7 @@ public void setRole(DataverseRole role) { } } } - + public Long getViewRoleId() { return viewRoleId; } @@ -147,12 +153,12 @@ public void setViewRoleId(Long viewRoleId) { this.viewRoleId = viewRoleId; } - public String getIntent() { - return intent; + public String getIntentParam() { + return intentParam; } - public void setIntent(String intent) { - this.intent = intent; + public void setIntentParam(String intentParam) { + this.intentParam = intentParam; } public DataverseRole getDefaultUserRole() { @@ -170,5 +176,24 @@ public boolean isPermissionRoot() { public void setPermissionRoot(boolean permissionRoot) { this.permissionRoot = permissionRoot; } - + + public int getActiveTabIndex() { + return activeTabIndex; + } + + public void setActiveTabIndex(int activeTabIndex) { + this.activeTabIndex = activeTabIndex; + } + + public String getObjectTypeParam() { + return objectTypeParam; + } + + public void setObjectTypeParam(String objectTypeParam) { + this.objectTypeParam = objectTypeParam; + } + + public void setActiveTab( ObjectType t ) { + setActiveTabIndex( (t!=null) ? t.ordinal() : 0 ); + } } diff --git a/src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java index f2b5a81c16a..d8a90b4aef9 100644 --- a/src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java @@ -60,6 +60,14 @@ public boolean canIssue( Class cmd ) { return isUserAllowedOn(user, cmd, subject); } + /** + * "Fast and loose" query mechanism, allowing to pass the command class name. + * Command is assumed to live in {@code edu.harvard.iq.dataverse.engine.command.impl.} + * @param commandName + * @return {@code true} iff the user has the permissions required by the command on the + * object. + * @throws ClassNotFoundException + */ public boolean canIssueCommand( String commandName ) throws ClassNotFoundException { return isUserAllowedOn(user, (Class)Class.forName("edu.harvard.iq.dataverse.engine.command.impl." + commandName), subject); @@ -79,7 +87,6 @@ public boolean has( String pName ) { public Set permissionsFor( DataverseUser u, DvObject d ) { Set retVal; - logger.info( "u=" + u.getUserName() + " d=" + d ); if ( perObjectPermissions.containsKey(u.getUserName()) ) { logger.info( "Per object permissions" ); Map> permissions = perObjectPermissions.get(u.getUserName()); @@ -87,7 +94,6 @@ public Set permissionsFor( DataverseUser u, DvObject d ) { : EnumSet.noneOf(Permission.class); } else { - logger.info( "Sample" ); retVal = samplePermissions.containsKey(u.getUserName()) ? samplePermissions.get(u.getUserName()) : EnumSet.noneOf(Permission.class); @@ -95,10 +101,8 @@ public Set permissionsFor( DataverseUser u, DvObject d ) { // Special case for root if ( d.getOwner() == null && !(u.getUserName().equals("GabbiGuest")) ) { - logger.info( "Root special case" ); retVal.add( Permission.UndoableEdit ); } - return retVal; } @@ -113,12 +117,12 @@ public Set permissionsFor( DataverseUser u, DvObject d ) { public boolean isUserAllowedOn( DataverseUser u, Class commandClass, Dataverse d ) { Map> required = CH.permissionsRequired(commandClass); if ( required.isEmpty() || required.get("")==null ) { + logger.info("IsUserAllowedOn: empty-true"); return true; } else { Set grantedUserPermissions = permissionsFor(u, d); - Set neededPermissions = required.get(""); - - return grantedUserPermissions.containsAll(neededPermissions); + Set requiredPermissionSet = required.get(""); + return grantedUserPermissions.containsAll(requiredPermissionSet); } } diff --git a/src/main/java/edu/harvard/iq/dataverse/SampleCommandPage.java b/src/main/java/edu/harvard/iq/dataverse/SampleCommandPage.java index 9213a5b821e..cfe4c46ae26 100644 --- a/src/main/java/edu/harvard/iq/dataverse/SampleCommandPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/SampleCommandPage.java @@ -16,7 +16,6 @@ import static edu.harvard.iq.dataverse.util.JsfHelper.JH; import java.util.ArrayList; -import java.util.EnumSet; import java.util.UUID; import javax.ejb.EJBException; import javax.persistence.EntityManager; diff --git a/src/main/java/edu/harvard/iq/dataverse/util/JsfHelper.java b/src/main/java/edu/harvard/iq/dataverse/util/JsfHelper.java index 064c290c210..e04c87d6dbd 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/JsfHelper.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/JsfHelper.java @@ -1,5 +1,7 @@ package edu.harvard.iq.dataverse.util; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; @@ -8,6 +10,7 @@ * @author michael */ public class JsfHelper { + private static final Logger logger = Logger.getLogger(JsfHelper.class.getName()); public static final JsfHelper JH = new JsfHelper(); @@ -18,4 +21,14 @@ public void addMessage( FacesMessage.Severity s, String summary ) { addMessage(s, summary, ""); } + public > T enumValue( String param, Class enmClass, T defaultValue ) { + if ( param == null ) return defaultValue; + param = param.trim(); + try { + return Enum.valueOf(enmClass, param); + } catch ( IllegalArgumentException iar ) { + logger.log(Level.WARNING, "Illegal value for enum {0}: ''{1}''", new Object[]{enmClass.getName(), param}); + return defaultValue; + } + } } diff --git a/src/main/webapp/WEB-INF/glassfish-web.xml b/src/main/webapp/WEB-INF/glassfish-web.xml index ddd8967a76d..7d4f5ab69e6 100644 --- a/src/main/webapp/WEB-INF/glassfish-web.xml +++ b/src/main/webapp/WEB-INF/glassfish-web.xml @@ -8,5 +8,5 @@ Keep a copy of the generated servlet class' java code. - + diff --git a/src/main/webapp/dataverse.xhtml b/src/main/webapp/dataverse.xhtml index 080aa6149ee..8d30711be8e 100644 --- a/src/main/webapp/dataverse.xhtml +++ b/src/main/webapp/dataverse.xhtml @@ -113,8 +113,9 @@ - + + diff --git a/src/main/webapp/dataverse_template.xhtml b/src/main/webapp/dataverse_template.xhtml index 223e6d91757..379504deb6f 100644 --- a/src/main/webapp/dataverse_template.xhtml +++ b/src/main/webapp/dataverse_template.xhtml @@ -11,6 +11,8 @@ + + diff --git a/src/main/webapp/manage-roles.xhtml b/src/main/webapp/manage-roles.xhtml index 3eef76b853e..2d920de73da 100644 --- a/src/main/webapp/manage-roles.xhtml +++ b/src/main/webapp/manage-roles.xhtml @@ -42,195 +42,185 @@ - + + - - - - - - - - - - - - - - - - - - Create Account - - - - - - Log In - - - - Log Out - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - When a dataverse is defined as a permission root, - it does not honor roles granted to users on its parents dataverses. - Unless this dataverse holds data which is significantly more restricted - than the data in the parent dataverse, you probably want to keep this - box unchecked. - - -
We'll have a list of applicable roles here.
- - Define what guest users can and cannot do on this dataverse. - -
-
- -
-
- - Assign roles to users here! - - - - - - - - - - - - - - - - - - - No roles are defined for Dataverse '#{DataversePage.dataverse.name}'. - - Any roles applied to users at parent dataverses, are valid in this - dataverse as well. - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + When a dataverse is defined as a permission root, + it does not honor roles granted to users on its parents dataverses. + Unless this dataverse holds data which is significantly more restricted + than the data in the parent dataverse, you probably want to keep this + box unchecked. + + +
We'll have a list of applicable roles here.
- - + Define what guest users can and cannot do on this dataverse. - -
-
- - - - - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - #{pmsn.humanName} - - - - - - - - - - - -
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + No roles are defined for Dataverse '#{DataversePage.dataverse.name}'. + + Any roles applied to users at parent dataverses, are valid in this + dataverse as well. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #{pmsn.humanName} + + + + + + + + + + Assign roles to users here! + + + + +
diff --git a/src/main/webapp/resources/css/componentStyles.css b/src/main/webapp/resources/css/componentStyles.css index 6349c158d54..eddd1b54524 100644 --- a/src/main/webapp/resources/css/componentStyles.css +++ b/src/main/webapp/resources/css/componentStyles.css @@ -35,4 +35,28 @@ color: white; margin-right: 4px; padding: 4px; +} + +ul.navigationLinks { + padding: 4px; + border: 1px solid #DDD; + background-color: #EEE; +} + +ul.navigationLinks li { + display: inline-block; + padding: 0; + padding-left: 1em; +} + +ul.navigationLinks li a:hover { + color: blue; +} + +ul.navigationLinks li a:active { + color: red; +} + +ul.navigationLinks li:first-child { + padding-left: 0; } \ No newline at end of file diff --git a/src/test/java/edu/harvard/iq/dataverse/util/JsfHelperTest.java b/src/test/java/edu/harvard/iq/dataverse/util/JsfHelperTest.java new file mode 100644 index 00000000000..9efdf652d94 --- /dev/null +++ b/src/test/java/edu/harvard/iq/dataverse/util/JsfHelperTest.java @@ -0,0 +1,57 @@ +/* + * (C) Michael Bar-Sinai + */ + +package edu.harvard.iq.dataverse.util; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author michael + */ +public class JsfHelperTest { + + enum TestEnum { Lorem, Ipsum, Dolor, Sit, Amet } + + public JsfHelperTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + + /** + * Test of enumValue method, of class JsfHelper. + */ + @Test + public void testEnumValue() { + System.out.println("enumValue"); + JsfHelper instance = new JsfHelper(); + + assertEquals( TestEnum.Lorem, instance.enumValue("Lorem", TestEnum.class, TestEnum.Dolor) ); + assertEquals( TestEnum.Lorem, instance.enumValue("Lorem ", TestEnum.class, TestEnum.Dolor) ); + assertEquals( TestEnum.Dolor, instance.enumValue(null, TestEnum.class, TestEnum.Dolor) ); + assertEquals( TestEnum.Dolor, instance.enumValue("THIS IS A BAD VALUE", TestEnum.class, TestEnum.Dolor) ); + + } + +}