diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsAddPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsAddPage.java index ac4c450e7..2f0dcb3ae 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsAddPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsAddPage.java @@ -2,13 +2,17 @@ package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import edu.cornell.mannlib.vitro.webapp.beans.PermissionSet; import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status; @@ -55,7 +59,7 @@ public class UserAccountsAddPage extends UserAccountsPage { private boolean externalAuthOnly; private String firstName = ""; private String lastName = ""; - private String selectedRoleUri = ""; + private Collection selectedRoleUris = Collections.emptyList(); private String associatedProfileUri = ""; private String newProfileClassUri = ""; @@ -88,7 +92,7 @@ public class UserAccountsAddPage extends UserAccountsPage { externalAuthOnly = isFlagOnRequest(PARAMETER_EXTERNAL_AUTH_ONLY); firstName = getStringParameter(PARAMETER_FIRST_NAME, ""); lastName = getStringParameter(PARAMETER_LAST_NAME, ""); - selectedRoleUri = getStringParameter(PARAMETER_ROLE, ""); + selectedRoleUris = getStringParameters(PARAMETER_ROLE); associatedProfileUri = getStringParameter( PARAMETER_ASSOCIATED_PROFILE_URI, ""); newProfileClassUri = getStringParameter( @@ -114,7 +118,7 @@ public class UserAccountsAddPage extends UserAccountsPage { errorCode = ERROR_NO_FIRST_NAME; } else if (lastName.isEmpty()) { errorCode = ERROR_NO_LAST_NAME; - } else if (selectedRoleUri.isEmpty()) { + } else if (selectedRoleUris.isEmpty()) { errorCode = ERROR_NO_ROLE; } else { errorCode = strategy.additionalValidations(); @@ -155,7 +159,7 @@ public class UserAccountsAddPage extends UserAccountsPage { u.setLoginCount(0); u.setLastLoginTime(0L); u.setStatus(Status.INACTIVE); - u.setPermissionSetUris(Collections.singleton(selectedRoleUri)); + u.setPermissionSetUris(selectedRoleUris); strategy.setAdditionalProperties(u); @@ -189,20 +193,29 @@ public class UserAccountsAddPage extends UserAccountsPage { public final ResponseValues showPage() { Map body = new HashMap(); - body.put(PARAMETER_EMAIL_ADDRESS, emailAddress); - body.put(PARAMETER_EXTERNAL_AUTH_ID, externalAuthId); - body.put(PARAMETER_FIRST_NAME, firstName); - body.put(PARAMETER_LAST_NAME, lastName); - body.put("selectedRole", selectedRoleUri); + if (isSubmit()) { + body.put(PARAMETER_EMAIL_ADDRESS, emailAddress); + body.put(PARAMETER_EXTERNAL_AUTH_ID, externalAuthId); + body.put(PARAMETER_FIRST_NAME, firstName); + body.put(PARAMETER_LAST_NAME, lastName); + body.put("selectedRoles", selectedRoleUris); + } else { + body.put(PARAMETER_EMAIL_ADDRESS, ""); + body.put(PARAMETER_EXTERNAL_AUTH_ID, ""); + body.put(PARAMETER_FIRST_NAME, ""); + body.put(PARAMETER_LAST_NAME, ""); + body.put("selectedRoles", getDefaultRolesForNewUsers()); + } + body.put("roles", buildListOfSelectableRoles()); body.put("profileTypes", buildProfileTypesList()); body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri); body.put("formUrls", buildUrlsMap()); - + if (externalAuthOnly) { body.put(PARAMETER_EXTERNAL_AUTH_ONLY, Boolean.TRUE); } - + if (!associatedProfileUri.isEmpty()) { body.put("associatedProfileInfo", buildProfileInfo(associatedProfileUri)); @@ -221,6 +234,16 @@ public class UserAccountsAddPage extends UserAccountsPage { return new TemplateResponseValues(TEMPLATE_NAME, body); } + private Collection getDefaultRolesForNewUsers() { + List list = new ArrayList(); + for (PermissionSet ps : userAccountsDao.getAllPermissionSets()) { + if (ps.isForNewUsers()) { + list.add(ps.getUri()); + } + } + return list; + } + public UserAccount getAddedAccount() { return addedAccount; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsEditPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsEditPage.java index e81be8bf7..672d2883f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsEditPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/admin/UserAccountsEditPage.java @@ -2,11 +2,12 @@ package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -64,7 +65,7 @@ public class UserAccountsEditPage extends UserAccountsPage { private boolean externalAuthOnly; private String firstName = ""; private String lastName = ""; - private String selectedRoleUri = ""; + private Collection selectedRoleUris = new ArrayList(); private String associatedProfileUri = ""; private String newProfileClassUri = ""; @@ -101,7 +102,7 @@ public class UserAccountsEditPage extends UserAccountsPage { externalAuthOnly = isFlagOnRequest(PARAMETER_EXTERNAL_AUTH_ONLY); firstName = getStringParameter(PARAMETER_FIRST_NAME, ""); lastName = getStringParameter(PARAMETER_LAST_NAME, ""); - selectedRoleUri = getStringParameter(PARAMETER_ROLE, ""); + selectedRoleUris = getStringParameters(PARAMETER_ROLE); associatedProfileUri = getStringParameter( PARAMETER_ASSOCIATED_PROFILE_URI, ""); newProfileClassUri = getStringParameter( @@ -155,7 +156,7 @@ public class UserAccountsEditPage extends UserAccountsPage { errorCode = ERROR_NO_FIRST_NAME; } else if (lastName.isEmpty()) { errorCode = ERROR_NO_LAST_NAME; - } else if (!isRootUser() && selectedRoleUri.isEmpty()) { + } else if (!isRootUser() && selectedRoleUris.isEmpty()) { errorCode = ERROR_NO_ROLE; } else { errorCode = strategy.additionalValidations(); @@ -203,7 +204,7 @@ public class UserAccountsEditPage extends UserAccountsPage { body.put("externalAuthId", externalAuthId); body.put("firstName", firstName); body.put("lastName", lastName); - body.put("selectedRole", selectedRoleUri); + body.put("selectedRoles", selectedRoleUris); body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri); if (externalAuthOnly) { @@ -219,7 +220,7 @@ public class UserAccountsEditPage extends UserAccountsPage { body.put("externalAuthId", userAccount.getExternalAuthId()); body.put("firstName", userAccount.getFirstName()); body.put("lastName", userAccount.getLastName()); - body.put("selectedRole", getExistingRoleUri()); + body.put("selectedRoles", userAccount.getPermissionSetUris()); body.put(PARAMETER_NEW_PROFILE_CLASS_URI, ""); if (userAccount.isExternalAuthOnly()) { @@ -254,15 +255,6 @@ public class UserAccountsEditPage extends UserAccountsPage { return new TemplateResponseValues(TEMPLATE_NAME, body); } - private String getExistingRoleUri() { - Set uris = userAccount.getPermissionSetUris(); - if (uris.isEmpty()) { - return ""; - } else { - return uris.iterator().next(); - } - } - private Map buildUrlsMapWithEditUrl() { Map map = buildUrlsMap(); map.put("edit", editAccountUrl(userAccount.getUri())); @@ -287,8 +279,7 @@ public class UserAccountsEditPage extends UserAccountsPage { userAccount.setPermissionSetUris(Collections. emptySet()); userAccount.setExternalAuthOnly(false); } else { - userAccount.setPermissionSetUris(Collections - .singleton(selectedRoleUri)); + userAccount.setPermissionSetUris(selectedRoleUris); userAccount.setExternalAuthOnly(externalAuthOnly); } strategy.setAdditionalProperties(userAccount); diff --git a/webapp/web/templates/freemarker/body/accounts/userAccounts-add.ftl b/webapp/web/templates/freemarker/body/accounts/userAccounts-add.ftl index bb0a3c5f1..bd425ab88 100644 --- a/webapp/web/templates/freemarker/body/accounts/userAccounts-add.ftl +++ b/webapp/web/templates/freemarker/body/accounts/userAccounts-add.ftl @@ -67,7 +67,7 @@

checked />Externally Authenticated Only

Roles *

<#list roles as role> - checked /> +
diff --git a/webapp/web/templates/freemarker/body/accounts/userAccounts-edit.ftl b/webapp/web/templates/freemarker/body/accounts/userAccounts-edit.ftl index d1a826042..afc68e1ed 100644 --- a/webapp/web/templates/freemarker/body/accounts/userAccounts-edit.ftl +++ b/webapp/web/templates/freemarker/body/accounts/userAccounts-edit.ftl @@ -68,7 +68,7 @@ <#if roles?has_content>

Roles *

<#list roles as role> - checked /> +