NIHVIVO-3523 Handle multiple roles properly when creating or editing user accounts. For a new account, suggest the default roles. Still using only one role, because we have radio buttons instead of checkboxes.
This commit is contained in:
parent
c18e14a106
commit
a75b15d940
4 changed files with 44 additions and 30 deletions
|
@ -2,13 +2,17 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.SelfEditingConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status;
|
||||||
|
@ -55,7 +59,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
private boolean externalAuthOnly;
|
private boolean externalAuthOnly;
|
||||||
private String firstName = "";
|
private String firstName = "";
|
||||||
private String lastName = "";
|
private String lastName = "";
|
||||||
private String selectedRoleUri = "";
|
private Collection<String> selectedRoleUris = Collections.emptyList();
|
||||||
private String associatedProfileUri = "";
|
private String associatedProfileUri = "";
|
||||||
private String newProfileClassUri = "";
|
private String newProfileClassUri = "";
|
||||||
|
|
||||||
|
@ -88,7 +92,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
externalAuthOnly = isFlagOnRequest(PARAMETER_EXTERNAL_AUTH_ONLY);
|
externalAuthOnly = isFlagOnRequest(PARAMETER_EXTERNAL_AUTH_ONLY);
|
||||||
firstName = getStringParameter(PARAMETER_FIRST_NAME, "");
|
firstName = getStringParameter(PARAMETER_FIRST_NAME, "");
|
||||||
lastName = getStringParameter(PARAMETER_LAST_NAME, "");
|
lastName = getStringParameter(PARAMETER_LAST_NAME, "");
|
||||||
selectedRoleUri = getStringParameter(PARAMETER_ROLE, "");
|
selectedRoleUris = getStringParameters(PARAMETER_ROLE);
|
||||||
associatedProfileUri = getStringParameter(
|
associatedProfileUri = getStringParameter(
|
||||||
PARAMETER_ASSOCIATED_PROFILE_URI, "");
|
PARAMETER_ASSOCIATED_PROFILE_URI, "");
|
||||||
newProfileClassUri = getStringParameter(
|
newProfileClassUri = getStringParameter(
|
||||||
|
@ -114,7 +118,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
errorCode = ERROR_NO_FIRST_NAME;
|
errorCode = ERROR_NO_FIRST_NAME;
|
||||||
} else if (lastName.isEmpty()) {
|
} else if (lastName.isEmpty()) {
|
||||||
errorCode = ERROR_NO_LAST_NAME;
|
errorCode = ERROR_NO_LAST_NAME;
|
||||||
} else if (selectedRoleUri.isEmpty()) {
|
} else if (selectedRoleUris.isEmpty()) {
|
||||||
errorCode = ERROR_NO_ROLE;
|
errorCode = ERROR_NO_ROLE;
|
||||||
} else {
|
} else {
|
||||||
errorCode = strategy.additionalValidations();
|
errorCode = strategy.additionalValidations();
|
||||||
|
@ -155,7 +159,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
u.setLoginCount(0);
|
u.setLoginCount(0);
|
||||||
u.setLastLoginTime(0L);
|
u.setLastLoginTime(0L);
|
||||||
u.setStatus(Status.INACTIVE);
|
u.setStatus(Status.INACTIVE);
|
||||||
u.setPermissionSetUris(Collections.singleton(selectedRoleUri));
|
u.setPermissionSetUris(selectedRoleUris);
|
||||||
|
|
||||||
strategy.setAdditionalProperties(u);
|
strategy.setAdditionalProperties(u);
|
||||||
|
|
||||||
|
@ -189,20 +193,29 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
public final ResponseValues showPage() {
|
public final ResponseValues showPage() {
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
body.put(PARAMETER_EMAIL_ADDRESS, emailAddress);
|
if (isSubmit()) {
|
||||||
body.put(PARAMETER_EXTERNAL_AUTH_ID, externalAuthId);
|
body.put(PARAMETER_EMAIL_ADDRESS, emailAddress);
|
||||||
body.put(PARAMETER_FIRST_NAME, firstName);
|
body.put(PARAMETER_EXTERNAL_AUTH_ID, externalAuthId);
|
||||||
body.put(PARAMETER_LAST_NAME, lastName);
|
body.put(PARAMETER_FIRST_NAME, firstName);
|
||||||
body.put("selectedRole", selectedRoleUri);
|
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("roles", buildListOfSelectableRoles());
|
||||||
body.put("profileTypes", buildProfileTypesList());
|
body.put("profileTypes", buildProfileTypesList());
|
||||||
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri);
|
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri);
|
||||||
body.put("formUrls", buildUrlsMap());
|
body.put("formUrls", buildUrlsMap());
|
||||||
|
|
||||||
if (externalAuthOnly) {
|
if (externalAuthOnly) {
|
||||||
body.put(PARAMETER_EXTERNAL_AUTH_ONLY, Boolean.TRUE);
|
body.put(PARAMETER_EXTERNAL_AUTH_ONLY, Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!associatedProfileUri.isEmpty()) {
|
if (!associatedProfileUri.isEmpty()) {
|
||||||
body.put("associatedProfileInfo",
|
body.put("associatedProfileInfo",
|
||||||
buildProfileInfo(associatedProfileUri));
|
buildProfileInfo(associatedProfileUri));
|
||||||
|
@ -221,6 +234,16 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<String> getDefaultRolesForNewUsers() {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
for (PermissionSet ps : userAccountsDao.getAllPermissionSets()) {
|
||||||
|
if (ps.isForNewUsers()) {
|
||||||
|
list.add(ps.getUri());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public UserAccount getAddedAccount() {
|
public UserAccount getAddedAccount() {
|
||||||
return addedAccount;
|
return addedAccount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -64,7 +65,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
private boolean externalAuthOnly;
|
private boolean externalAuthOnly;
|
||||||
private String firstName = "";
|
private String firstName = "";
|
||||||
private String lastName = "";
|
private String lastName = "";
|
||||||
private String selectedRoleUri = "";
|
private Collection<String> selectedRoleUris = new ArrayList<String>();
|
||||||
private String associatedProfileUri = "";
|
private String associatedProfileUri = "";
|
||||||
private String newProfileClassUri = "";
|
private String newProfileClassUri = "";
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
externalAuthOnly = isFlagOnRequest(PARAMETER_EXTERNAL_AUTH_ONLY);
|
externalAuthOnly = isFlagOnRequest(PARAMETER_EXTERNAL_AUTH_ONLY);
|
||||||
firstName = getStringParameter(PARAMETER_FIRST_NAME, "");
|
firstName = getStringParameter(PARAMETER_FIRST_NAME, "");
|
||||||
lastName = getStringParameter(PARAMETER_LAST_NAME, "");
|
lastName = getStringParameter(PARAMETER_LAST_NAME, "");
|
||||||
selectedRoleUri = getStringParameter(PARAMETER_ROLE, "");
|
selectedRoleUris = getStringParameters(PARAMETER_ROLE);
|
||||||
associatedProfileUri = getStringParameter(
|
associatedProfileUri = getStringParameter(
|
||||||
PARAMETER_ASSOCIATED_PROFILE_URI, "");
|
PARAMETER_ASSOCIATED_PROFILE_URI, "");
|
||||||
newProfileClassUri = getStringParameter(
|
newProfileClassUri = getStringParameter(
|
||||||
|
@ -155,7 +156,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
errorCode = ERROR_NO_FIRST_NAME;
|
errorCode = ERROR_NO_FIRST_NAME;
|
||||||
} else if (lastName.isEmpty()) {
|
} else if (lastName.isEmpty()) {
|
||||||
errorCode = ERROR_NO_LAST_NAME;
|
errorCode = ERROR_NO_LAST_NAME;
|
||||||
} else if (!isRootUser() && selectedRoleUri.isEmpty()) {
|
} else if (!isRootUser() && selectedRoleUris.isEmpty()) {
|
||||||
errorCode = ERROR_NO_ROLE;
|
errorCode = ERROR_NO_ROLE;
|
||||||
} else {
|
} else {
|
||||||
errorCode = strategy.additionalValidations();
|
errorCode = strategy.additionalValidations();
|
||||||
|
@ -203,7 +204,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
body.put("externalAuthId", externalAuthId);
|
body.put("externalAuthId", externalAuthId);
|
||||||
body.put("firstName", firstName);
|
body.put("firstName", firstName);
|
||||||
body.put("lastName", lastName);
|
body.put("lastName", lastName);
|
||||||
body.put("selectedRole", selectedRoleUri);
|
body.put("selectedRoles", selectedRoleUris);
|
||||||
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri);
|
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri);
|
||||||
|
|
||||||
if (externalAuthOnly) {
|
if (externalAuthOnly) {
|
||||||
|
@ -219,7 +220,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
body.put("externalAuthId", userAccount.getExternalAuthId());
|
body.put("externalAuthId", userAccount.getExternalAuthId());
|
||||||
body.put("firstName", userAccount.getFirstName());
|
body.put("firstName", userAccount.getFirstName());
|
||||||
body.put("lastName", userAccount.getLastName());
|
body.put("lastName", userAccount.getLastName());
|
||||||
body.put("selectedRole", getExistingRoleUri());
|
body.put("selectedRoles", userAccount.getPermissionSetUris());
|
||||||
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, "");
|
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, "");
|
||||||
|
|
||||||
if (userAccount.isExternalAuthOnly()) {
|
if (userAccount.isExternalAuthOnly()) {
|
||||||
|
@ -254,15 +255,6 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getExistingRoleUri() {
|
|
||||||
Set<String> uris = userAccount.getPermissionSetUris();
|
|
||||||
if (uris.isEmpty()) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return uris.iterator().next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> buildUrlsMapWithEditUrl() {
|
private Map<String, String> buildUrlsMapWithEditUrl() {
|
||||||
Map<String, String> map = buildUrlsMap();
|
Map<String, String> map = buildUrlsMap();
|
||||||
map.put("edit", editAccountUrl(userAccount.getUri()));
|
map.put("edit", editAccountUrl(userAccount.getUri()));
|
||||||
|
@ -287,8 +279,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
userAccount.setPermissionSetUris(Collections.<String> emptySet());
|
userAccount.setPermissionSetUris(Collections.<String> emptySet());
|
||||||
userAccount.setExternalAuthOnly(false);
|
userAccount.setExternalAuthOnly(false);
|
||||||
} else {
|
} else {
|
||||||
userAccount.setPermissionSetUris(Collections
|
userAccount.setPermissionSetUris(selectedRoleUris);
|
||||||
.singleton(selectedRoleUri));
|
|
||||||
userAccount.setExternalAuthOnly(externalAuthOnly);
|
userAccount.setExternalAuthOnly(externalAuthOnly);
|
||||||
}
|
}
|
||||||
strategy.setAdditionalProperties(userAccount);
|
strategy.setAdditionalProperties(userAccount);
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
<p><input id="externalAuthChkBox" type="checkbox" name="externalAuthOnly" <#if externalAuthOnly?? >checked</#if> />Externally Authenticated Only</p>
|
<p><input id="externalAuthChkBox" type="checkbox" name="externalAuthOnly" <#if externalAuthOnly?? >checked</#if> />Externally Authenticated Only</p>
|
||||||
<p>Roles<span class="requiredHint"> *</span></p>
|
<p>Roles<span class="requiredHint"> *</span></p>
|
||||||
<#list roles as role>
|
<#list roles as role>
|
||||||
<input type="radio" name="role" value="${role.uri}" role="radio" <#if selectedRole = role.uri>checked</#if> />
|
<input type="radio" name="role" value="${role.uri}" role="radio" ${selectedRoles?seq_contains(role.uri)?string("checked", "")} />
|
||||||
<label class="inline" for="${role.label}"> ${role.label}</label>
|
<label class="inline" for="${role.label}"> ${role.label}</label>
|
||||||
<br />
|
<br />
|
||||||
</#list>
|
</#list>
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
<#if roles?has_content>
|
<#if roles?has_content>
|
||||||
<p>Roles<span class="requiredHint"> *</span></p>
|
<p>Roles<span class="requiredHint"> *</span></p>
|
||||||
<#list roles as role>
|
<#list roles as role>
|
||||||
<input type="radio" name="role" value="${role.uri}" role="radio" <#if selectedRole = role.uri>checked</#if> />
|
<input type="radio" name="role" value="${role.uri}" role="radio" ${selectedRoles?seq_contains(role.uri)?string("checked", "")} />
|
||||||
<label class="inline" for="${role.label}"> ${role.label}</label>
|
<label class="inline" for="${role.label}"> ${role.label}</label>
|
||||||
<br />
|
<br />
|
||||||
</#list>
|
</#list>
|
||||||
|
|
Loading…
Add table
Reference in a new issue