dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34602
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17735: Invite, validating that username is not already taken
------------------------------------------------------------
revno: 17735
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-12-19 12:12:59 +0100
message:
Invite, validating that username is not already taken
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityService.java
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-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java 2014-12-19 10:38:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/DefaultSecurityService.java 2014-12-19 11:12:59 +0000
@@ -160,7 +160,7 @@
if ( credentials == null || credentials.getUser() == null )
{
- log.warn( "Could not send restore/invite message as user does not exist: " + credentials );
+ log.warn( "Could not send restore/invite message as user is null: " + credentials );
return "no_user_credentials";
}
@@ -179,6 +179,23 @@
return null;
}
+ public String validateInvite( UserCredentials credentials )
+ {
+ if ( credentials == null )
+ {
+ log.warn( "Could not send invite message as user does is null: " + credentials );
+ return "no_user_credentials";
+ }
+
+ if ( credentials.getUsername() != null && userService.getUserCredentialsByUsername( credentials.getUsername() ) != null )
+ {
+ log.warn( "Could not send invite message as username is already taken: " + credentials );
+ return "username_taken";
+ }
+
+ return validateRestore( credentials );
+ }
+
@Override
public boolean sendRestoreMessage( UserCredentials credentials, String rootPath, RestoreOptions restoreOptions )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityService.java 2014-10-19 20:07:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityService.java 2014-12-19 11:12:59 +0000
@@ -57,10 +57,24 @@
* <li>user_has_critical_authorities</li>
* </ul>
*
- * @param credentials
+ * @param credentials the user credentials.
* @return a string if restore cannot be performed, null otherwise.
*/
String validateRestore( UserCredentials credentials );
+
+ /**
+ * Indicates whether an invite is allowed for the given user. Delegates to
+ * validateRestore( UserCredentials ). The requirements are.
+ *
+ * <ul>
+ * <li>no_user_credentials</li>
+ * <li>username_taken</li>
+ * </ul>
+ *
+ * @param credentials the user credentials.
+ * @return a string if invite cannot be performed, null otherwise.
+ */
+ String validateInvite( UserCredentials credentials );
/**
* Invokes the initRestore method and dispatches email messages with
=== 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 10:38:55 +0000
+++ 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
@@ -318,7 +318,7 @@
}
}
- String valid = securityService.validateRestore( user.getUserCredentials() );
+ String valid = securityService.validateInvite( user.getUserCredentials() );
if ( valid != null )
{