Skip to content

Commit

Permalink
Added the user setup privilege to user/update.
Browse files Browse the repository at this point in the history
The user/update call and its corresponding field in EasyPost have now been updated to allow admin users to change ones ability to setup users.

References #568
  • Loading branch information
John Jenkins committed May 31, 2013
1 parent 2d2c157 commit 0e2a248
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/org/ohmage/annotator/Annotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 5 additions & 0 deletions src/org/ohmage/query/IUserQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ public QueryResultsList<UserInformation> 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.
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 31 additions & 1 deletion src/org/ohmage/query/impl/UserQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/org/ohmage/request/InputKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/org/ohmage/request/user/UserSetupRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ public void service() {
null,
null,
null,
null,
null,
null,
personalInfo.getFirstName(),
personalInfo.getLastName(),
personalInfo.getOrganization(),
Expand Down
16 changes: 16 additions & 0 deletions src/org/ohmage/request/user/UserUpdateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -325,6 +339,7 @@ else if(t.length == 1) {
newAccount = tNewAccount;
campaignCreationPrivilege = tCampaignCreationPrivilege;
classCreationPrivilege = tClassCreationPrivilege;
userSetupPrivilege = tUserSetupPrivilege;

firstName = tFirstName;
lastName = tLastName;
Expand Down Expand Up @@ -369,6 +384,7 @@ public void service() {
newAccount,
campaignCreationPrivilege,
classCreationPrivilege,
userSetupPrivilege,
firstName,
lastName,
organization,
Expand Down
6 changes: 6 additions & 0 deletions src/org/ohmage/service/UserServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,10 @@ public Map<String, UserPersonal> 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.
Expand Down Expand Up @@ -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,
Expand All @@ -1476,6 +1481,7 @@ public void updateUser(
newAccount,
campaignCreationPrivilege,
classCreationPrivilege,
userSetupPrivilege,
firstName,
lastName,
organization,
Expand Down
43 changes: 42 additions & 1 deletion src/org/ohmage/validator/UserValidators.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions web/EasyPost.html
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@
<input type="text" name="campaign_creation_privilege">
<label>Class Creation Privilege</label>
<input type="text" name="class_creation_privilege">
<label>User Setup Privilege</label>
<input type="text" name="user_setup_privilege">
<label>First Name</label>
<input type="text" name="first_name">
<label>Last Name</label>
Expand Down

0 comments on commit 0e2a248

Please sign in to comment.