diff --git a/src/org/ohmage/annotator/Annotator.java b/src/org/ohmage/annotator/Annotator.java index 9f91a408..1ad4fd05 100644 --- a/src/org/ohmage/annotator/Annotator.java +++ b/src/org/ohmage/annotator/Annotator.java @@ -153,6 +153,7 @@ public static enum ErrorCode { USER_INVALID_REGISTRATION_ID ("1014"), USER_INVALID_DELETE_PERSONAL_INFO ("1015"), USER_INVALID_CLASS_CREATION_PRIVILEGE ("1016"), + USER_INVALID_USER_SETUP_PRIVILEGE ("1017"), DOCUMENT_INVALID_ID ("1100"), DOCUMENT_INVALID_NAME ("1101"), diff --git a/src/org/ohmage/query/IUserQueries.java b/src/org/ohmage/query/IUserQueries.java index 47b319e5..ca31eef2 100644 --- a/src/org/ohmage/query/IUserQueries.java +++ b/src/org/ohmage/query/IUserQueries.java @@ -513,6 +513,10 @@ public QueryResultsList getUserInformation( * Whether or not the user should be allowed to create classes. A * null value indicates that this field should not be updated. * + * @param userSetupPrivilege + * Whether or not the user should be allowed to setup users. A null + * value indicates that this field should not be updated. + * * @param firstName * The user's new first name. A null value indicates that this field * should not be updated. @@ -540,6 +544,7 @@ void updateUser( final Boolean newAccount, final Boolean campaignCreationPrivilege, final Boolean classCreationPrivilege, + final Boolean userSetupPrivilege, final String firstName, final String lastName, final String organization, diff --git a/src/org/ohmage/query/impl/UserQueries.java b/src/org/ohmage/query/impl/UserQueries.java index f54356fa..c844b167 100644 --- a/src/org/ohmage/query/impl/UserQueries.java +++ b/src/org/ohmage/query/impl/UserQueries.java @@ -291,6 +291,12 @@ public class UserQueries extends Query implements IUserQueries { "SET class_creation_privilege = ? " + "WHERE username = ?"; + // Updates a user's user setup privilege. + private static final String SQL_UPDATE_USER_SETUP_PRIVILEGE = + "UPDATE user " + + "SET user_setup_privilege = ? " + + "WHERE username = ?"; + // Updates a user's first name in their personal information record. private static final String SQL_UPDATE_FIRST_NAME = "UPDATE user_personal " + @@ -1777,6 +1783,7 @@ public void updateUser( final Boolean newAccount, final Boolean campaignCreationPrivilege, final Boolean classCreationPrivilege, + final Boolean userSetupPrivilege, final String firstName, final String lastName, final String organization, @@ -1852,7 +1859,7 @@ public void updateUser( } } - // Update the campaign creation privilege value if it's not null. + // Update the class creation privilege value if it's not null. if(classCreationPrivilege != null) { try { getJdbcTemplate() @@ -1875,6 +1882,29 @@ public void updateUser( } } + // Update the user setup privilege value if it's not null. + if(userSetupPrivilege != null) { + try { + getJdbcTemplate() + .update( + SQL_UPDATE_USER_SETUP_PRIVILEGE, + userSetupPrivilege, + username); + } + catch(org.springframework.dao.DataAccessException e) { + transactionManager.rollback(status); + throw + new DataAccessException( + "Error executing the following SQL '" + + SQL_UPDATE_USER_SETUP_PRIVILEGE + + "' with parameters: " + + userSetupPrivilege + + ", " + + username, + e); + } + } + // If we are deleting the user's personal information, then we // won't add new or update existing personal information. if(deletePersonalInfo) { diff --git a/src/org/ohmage/request/InputKeys.java b/src/org/ohmage/request/InputKeys.java index c71a4c4a..e48d8c4c 100644 --- a/src/org/ohmage/request/InputKeys.java +++ b/src/org/ohmage/request/InputKeys.java @@ -133,6 +133,7 @@ private InputKeys() { public static final String NEW_ACCOUNT = "new_account"; public static final String CAMPAIGN_CREATION_PRIVILEGE = "campaign_creation_privilege"; public static final String CLASS_CREATION_PRIVILEGE = "class_creation_privilege"; + public static final String USER_SETUP_PRIVILEGE = "user_setup_privilege"; public static final String FIRST_NAME = "first_name"; public static final String FIRST_NAME_SEARCH = "first_name_search"; public static final String LAST_NAME = "last_name"; diff --git a/src/org/ohmage/request/user/UserSetupRequest.java b/src/org/ohmage/request/user/UserSetupRequest.java index cccac46e..226b2a74 100644 --- a/src/org/ohmage/request/user/UserSetupRequest.java +++ b/src/org/ohmage/request/user/UserSetupRequest.java @@ -235,7 +235,8 @@ public void service() { null, null, null, - null, + null, + null, personalInfo.getFirstName(), personalInfo.getLastName(), personalInfo.getOrganization(), diff --git a/src/org/ohmage/request/user/UserUpdateRequest.java b/src/org/ohmage/request/user/UserUpdateRequest.java index 1c2b5dc5..214413d6 100644 --- a/src/org/ohmage/request/user/UserUpdateRequest.java +++ b/src/org/ohmage/request/user/UserUpdateRequest.java @@ -126,6 +126,7 @@ public class UserUpdateRequest extends UserRequest { private final Boolean newAccount; private final Boolean campaignCreationPrivilege; private final Boolean classCreationPrivilege; + private final Boolean userSetupPrivilege; private final String firstName; private final String lastName; @@ -158,6 +159,7 @@ public UserUpdateRequest(HttpServletRequest httpRequest) throws IOException, Inv Boolean tNewAccount = null; Boolean tCampaignCreationPrivilege = null; Boolean tClassCreationPrivilege = null; + Boolean tUserSetupPrivilege = null; String tFirstName = null; String tLastName = null; @@ -256,6 +258,18 @@ else if(t.length == 1) { t[0]); } + t = getParameterValues(InputKeys.USER_SETUP_PRIVILEGE); + if(t.length > 1) { + throw new ValidationException( + ErrorCode.USER_INVALID_USER_SETUP_PRIVILEGE, + "Multiple user setup privilege parameters were given: " + + InputKeys.USER_SETUP_PRIVILEGE); + } + else if(t.length == 1) { + tUserSetupPrivilege = + UserValidators.validateUserSetupPrivilegeValue(t[0]); + } + t = getParameterValues(InputKeys.FIRST_NAME); if(t.length > 1) { throw new ValidationException( @@ -325,6 +339,7 @@ else if(t.length == 1) { newAccount = tNewAccount; campaignCreationPrivilege = tCampaignCreationPrivilege; classCreationPrivilege = tClassCreationPrivilege; + userSetupPrivilege = tUserSetupPrivilege; firstName = tFirstName; lastName = tLastName; @@ -369,6 +384,7 @@ public void service() { newAccount, campaignCreationPrivilege, classCreationPrivilege, + userSetupPrivilege, firstName, lastName, organization, diff --git a/src/org/ohmage/service/UserServices.java b/src/org/ohmage/service/UserServices.java index b814091e..3a8ae9f6 100644 --- a/src/org/ohmage/service/UserServices.java +++ b/src/org/ohmage/service/UserServices.java @@ -1429,6 +1429,10 @@ public Map gatherPersonalInformation( * Whether or not the user should be allowed to create classes. A * null value indicates that this field should not be updated. * + * @param userSetupPrivilege + * Whether or not the user should be allowed to setup users. A null + * value indicates that this field should not be updated. + * * @param firstName * The user's new first name. A null value indicates that this field * should not be updated. @@ -1459,6 +1463,7 @@ public void updateUser( final Boolean newAccount, final Boolean campaignCreationPrivilege, final Boolean classCreationPrivilege, + final Boolean userSetupPrivilege, final String firstName, final String lastName, final String organization, @@ -1476,6 +1481,7 @@ public void updateUser( newAccount, campaignCreationPrivilege, classCreationPrivilege, + userSetupPrivilege, firstName, lastName, organization, diff --git a/src/org/ohmage/validator/UserValidators.java b/src/org/ohmage/validator/UserValidators.java index f32f0488..d6a39968 100644 --- a/src/org/ohmage/validator/UserValidators.java +++ b/src/org/ohmage/validator/UserValidators.java @@ -470,7 +470,7 @@ public static Boolean validateCampaignCreationPrivilegeValue( } /** - * Validates that a value is a valid campaign class privilege value. If the + * Validates that a value is a valid class class privilege value. If the * value is null or whitespace only, null is returned. If the value is a * valid class creation privilege value, it is returned. If the value is * not null, not whitespace only, and not a valid class creation privilege @@ -511,6 +511,47 @@ public static Boolean validateClassCreationPrivilegeValue( } } + /** + * Validates that a value is a valid user setup privilege value. If the + * value is null or whitespace only, null is returned. If the value is a + * valid user setup privilege value, it is returned. If the value is not + * null, not whitespace only, and not a valid user setup privilege value, + * a ValidationException is thrown. + * + * @param value + * The String representation of the user setup privilege value to be + * validated. + * + * @return Returns null if the value is null or whitespace only; otherwise, + * the value is returned. + * + * @throws ValidationException + * Thrown if the value is not null, not whitespace only, and not a + * valid user setup privilege value. + */ + public static Boolean validateUserSetupPrivilegeValue( + final String value) + throws ValidationException { + + LOGGER + .info( + "Validating that the value is a valid user setup " + + "privilege value."); + + if(StringUtils.isEmptyOrWhitespaceOnly(value)) { + return null; + } + + if(StringUtils.isValidBoolean(value.trim())) { + return StringUtils.decodeBoolean(value.trim()); + } + else { + throw new ValidationException( + ErrorCode.USER_INVALID_USER_SETUP_PRIVILEGE, + "The user setup privilege value is invalid: " + value); + } + } + /** * Validates that the first name value for a user is a valid first name * value. diff --git a/web/EasyPost.html b/web/EasyPost.html index 82cf503f..bc327486 100644 --- a/web/EasyPost.html +++ b/web/EasyPost.html @@ -542,6 +542,8 @@ + +