dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19875
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8852: Including system setting for which org unit should be assigned to self registered users
------------------------------------------------------------
revno: 8852
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-11-04 11:37:25 +0300
message:
Including system setting for which org unit should be assigned to self registered users
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetAccessSettingsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetAccessSettingsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemAccessSettings.vm
--
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-api/src/main/java/org/hisp/dhis/configuration/Configuration.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java 2012-10-23 10:26:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java 2012-11-04 08:37:25 +0000
@@ -30,6 +30,7 @@
import java.io.Serializable;
import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.period.YearlyPeriodType;
@@ -61,6 +62,8 @@
private UserAuthorityGroup selfRegistrationRole;
+ private OrganisationUnit selfRegistrationOrgUnit;
+
public Configuration()
{
}
@@ -76,7 +79,8 @@
public boolean selfRegistrationAllowed()
{
- return selfRegistrationRole != null && selfRegistrationRole instanceof UserAuthorityGroup;
+ return selfRegistrationRole != null && selfRegistrationRole instanceof UserAuthorityGroup &&
+ selfRegistrationOrgUnit != null && selfRegistrationOrgUnit instanceof OrganisationUnit;
}
// -------------------------------------------------------------------------
@@ -142,4 +146,14 @@
{
this.selfRegistrationRole = selfRegistrationRole;
}
+
+ public OrganisationUnit getSelfRegistrationOrgUnit()
+ {
+ return selfRegistrationOrgUnit;
+ }
+
+ public void setSelfRegistrationOrgUnit( OrganisationUnit selfRegistrationOrgUnit )
+ {
+ this.selfRegistrationOrgUnit = selfRegistrationOrgUnit;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml 2012-10-23 08:01:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml 2012-11-04 08:37:25 +0000
@@ -25,7 +25,10 @@
column="infrastructuralperiodtypeid" foreign-key="fk_configuration_infrastructural_periodtype" />
<many-to-one name="selfRegistrationRole" class="org.hisp.dhis.user.UserAuthorityGroup"
- column="selfregistrationrole" foreign-key="fk_configuration_selfregistrationrole" unique="true" />
+ column="selfregistrationrole" foreign-key="fk_configuration_selfregistrationrole" />
+
+ <many-to-one name="selfRegistrationOrgUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit"
+ column="selfRegistrationOrgUnit" foreign-key="fk_configuration_selfregistrationorgunit" />
</class>
</hibernate-mapping>
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java 2012-11-03 20:19:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AccountController.java 2012-11-04 08:37:25 +0000
@@ -39,6 +39,7 @@
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.configuration.ConfigurationService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.security.PasswordManager;
import org.hisp.dhis.security.SecurityService;
import org.hisp.dhis.setting.SystemSettingManager;
@@ -300,6 +301,7 @@
// ---------------------------------------------------------------------
UserAuthorityGroup userRole = configurationService.getConfiguration().getSelfRegistrationRole();
+ OrganisationUnit orgUnit = configurationService.getConfiguration().getSelfRegistrationOrgUnit();
User user = new User();
user.setFirstName( firstName );
@@ -307,6 +309,7 @@
user.setEmail( email );
user.setPhoneNumber( phoneNumber );
user.setEmployer( employer );
+ user.getOrganisationUnits().add( orgUnit );
credentials = new UserCredentials();
credentials.setUsername( username );
@@ -315,8 +318,6 @@
credentials.getUserAuthorityGroups().add( userRole );
user.setUserCredentials( credentials );
-
- // TODO org unit
userService.addUser( user );
userService.addUserCredentials( credentials );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetAccessSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetAccessSettingsAction.java 2012-10-23 08:01:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetAccessSettingsAction.java 2012-11-04 08:37:25 +0000
@@ -32,6 +32,8 @@
import java.util.List;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.user.UserAuthorityGroup;
import org.hisp.dhis.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +48,9 @@
{
@Autowired
private UserService userService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
// -------------------------------------------------------------------------
// Output
@@ -57,6 +62,13 @@
{
return userRoles;
}
+
+ private List<OrganisationUnit> selfRegistrationOrgUnits = new ArrayList<OrganisationUnit>();
+
+ public List<OrganisationUnit> getSelfRegistrationOrgUnits()
+ {
+ return selfRegistrationOrgUnits;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -68,6 +80,9 @@
Collections.sort( userRoles, IdentifiableObjectNameComparator.INSTANCE );
+ selfRegistrationOrgUnits.addAll( organisationUnitService.getOrganisationUnitsAtLevel( 1 ) );
+ selfRegistrationOrgUnits.addAll( organisationUnitService.getOrganisationUnitsAtLevel( 2 ) );
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetAccessSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetAccessSettingsAction.java 2012-10-29 20:17:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetAccessSettingsAction.java 2012-11-04 08:37:25 +0000
@@ -30,6 +30,8 @@
import org.hisp.dhis.configuration.Configuration;
import org.hisp.dhis.configuration.ConfigurationService;
import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.user.UserAuthorityGroup;
import org.hisp.dhis.user.UserService;
@@ -53,6 +55,9 @@
@Autowired
private UserService userService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
// -------------------------------------------------------------------------
// Input
@@ -64,14 +69,21 @@
{
this.selfRegistrationRole = selfRegistrationRole;
}
-
+
+ private Integer selfRegistrationOrgUnit;
+
+ public void setSelfRegistrationOrgUnit( Integer selfRegistrationOrgUnit )
+ {
+ this.selfRegistrationOrgUnit = selfRegistrationOrgUnit;
+ }
+
private Boolean accountRecovery;
public void setAccountRecovery( Boolean accountRecovery )
{
this.accountRecovery = accountRecovery;
}
-
+
// -------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------
@@ -97,14 +109,21 @@
public String execute()
{
UserAuthorityGroup group = null;
+ OrganisationUnit unit = null;
if ( selfRegistrationRole != null )
{
group = userService.getUserAuthorityGroup( selfRegistrationRole );
}
+ if ( selfRegistrationOrgUnit != null )
+ {
+ unit = organisationUnitService.getOrganisationUnit( selfRegistrationOrgUnit );
+ }
+
Configuration config = configurationService.getConfiguration();
config.setSelfRegistrationRole( group );
+ config.setSelfRegistrationOrgUnit( unit );
configurationService.setConfiguration( config );
systemSettingManager.saveSystemSetting( KEY_ACCOUNT_RECOVERY, accountRecovery );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2012-10-29 20:17:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2012-11-04 08:37:25 +0000
@@ -107,5 +107,7 @@
access_settings=Access settings
do_not_allow_self_registration=Do not allow self registration
self_registration_account_user_role=Self registration account user role
+self_registration_account_organisation_unit=Self registration account organisation unit
access=Access
-enable_user_account_recovery=Enable user account recovery
\ No newline at end of file
+enable_user_account_recovery=Enable user account recovery
+select_organisation_unit=Select organisation unit
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemAccessSettings.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemAccessSettings.vm 2012-10-29 20:17:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemAccessSettings.vm 2012-11-04 08:37:25 +0000
@@ -3,6 +3,7 @@
jQuery( "input[type=button]" ).click( function() {
jQuery.postUTF8( "setSystemAccessSettings.action", {
selfRegistrationRole: jQuery( "#selfRegistrationRole" ).val(),
+ selfRegistrationOrgUnit: jQuery( "#selfRegistrationOrgUnit" ).val(),
accountRecovery: jQuery( '#accountRecovery' ).is( ':checked' )
}, function( json ) {
if ( json.response == "success" ) {
@@ -14,6 +15,7 @@
</script>
#set( $curRole = $keyConfig.selfRegistrationRole )
+#set( $curUnit = $keyConfig.selfRegistrationOrgUnit )
<h3>$i18n.getString( "access_settings" )</h3>
@@ -24,7 +26,18 @@
<option>$i18n.getString( "do_not_allow_self_registration" )</option>
<option>---</option>
#foreach( $role in $userRoles )
- <option value="$role.id" #if( $curRole && $role.id == $curRole.id )selected="selected"#end>$i18n.getString( $role.name )</option>
+ <option value="$role.id" #if( $curRole && $role.id == $curRole.id )selected="selected"#end>$encoder.htmlEncode( $role.name )</option>
+ #end
+</select>
+</div>
+
+<div class="settingLabel">$i18n.getString( "self_registration_account_organisation_unit" )</div>
+
+<div class="setting">
+<select id="selfRegistrationOrgUnit" name="selfRegistrationOrgUnit">
+ <option value="">[ $i18n.getString( "select_organisation_unit" ) ]</option>
+ #foreach( $unit in $selfRegistrationOrgUnits )
+ <option value="$unit.id" #if( $curUnit && $unit.id == $curUnit.id )selected="selected"#end>$encoder.htmlEncode( $unit.name )</option>
#end
</select>
</div>