dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34608
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17741: Invite, validation for bulk invites
------------------------------------------------------------
revno: 17741
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-12-19 13:59:07 +0100
message:
Invite, validation for bulk invites
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java 2014-12-19 11:12:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java 2014-12-19 12:59:07 +0000
@@ -207,6 +207,14 @@
for ( User user : users.getUsers() )
{
+ if ( !validateInviteUser( user, response ) )
+ {
+ return;
+ }
+ }
+
+ for ( User user : users.getUsers() )
+ {
inviteUser( user, request, response );
}
}
@@ -218,6 +226,14 @@
for ( User user : users.getUsers() )
{
+ if ( !validateInviteUser( user, response ) )
+ {
+ return;
+ }
+ }
+
+ for ( User user : users.getUsers() )
+ {
inviteUser( user, request, response );
}
}
@@ -284,25 +300,14 @@
// Supportive methods
// -------------------------------------------------------------------------
- /**
- * Creates a user invitation and invites the user
- *
- * @param user user object parsed from the POST request
- * @param response response for created user invitation
- * @throws Exception
- */
- private void inviteUser( User user, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ private boolean validateInviteUser( User user, HttpServletResponse response )
{
UserCredentials credentials = user.getUserCredentials();
- // ---------------------------------------------------------------------
- // Validation
- // ---------------------------------------------------------------------
-
if ( credentials == null )
{
ContextUtils.conflictResponse( response, "User credentials is not present" );
- return;
+ return false;
}
credentials.setUser( user );
@@ -314,7 +319,7 @@
if ( role != null && role.hasCriticalAuthorities() )
{
ContextUtils.conflictResponse( response, "User cannot be invited with user role which has critical authorities: " + role );
- return;
+ return false;
}
}
@@ -323,13 +328,25 @@
if ( valid != null )
{
ContextUtils.conflictResponse( response, valid );
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Creates a user invitation and invites the user
+ *
+ * @param user user object parsed from the POST request
+ * @param response response for created user invitation
+ */
+ private void inviteUser( User user, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ {
+ if ( !validateInviteUser( user, response ) )
+ {
return;
}
-
- // ---------------------------------------------------------------------
- // Prepare, create and invite user
- // ---------------------------------------------------------------------
-
+
RestoreOptions restoreOptions = user.getUsername() == null || user.getUsername().isEmpty() ?
RestoreOptions.INVITE_WITH_USERNAME_CHOICE : RestoreOptions.INVITE_WITH_DEFINED_USERNAME;
@@ -344,9 +361,8 @@
/**
* Creates a user
*
- * @param user user object parsed from the POST request
+ * @param user user object parsed from the POST request
* @param response response for created user
- * @throws Exception
*/
private void createUser( User user, HttpServletResponse response ) throws Exception
{