Merge lp:~sis-ma/dhis2/SISMA-84 into lp:dhis2

Proposed by Leandro Soares
Status: Merged
Merged at revision: 12354
Proposed branch: lp:~sis-ma/dhis2/SISMA-84
Merge into: lp:dhis2
Diff against target: 232 lines (+60/-7)
8 files modified
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java (+5/-0)
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java (+1/-0)
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java (+10/-3)
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java (+3/-1)
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml (+1/-1)
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java (+2/-2)
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java (+37/-0)
dhis-2/pom.xml (+1/-0)
To merge this branch: bzr merge lp:~sis-ma/dhis2/SISMA-84
Reviewer Review Type Date Requested Status
DHIS 2 core developers Pending
Review via email: mp+186329@code.launchpad.net

Description of the change

Changes for allowing user metadata import.

dhis-2\dhis-api\src\main\java\org\hisp\dhis\common\SharingUtils.java
dhis-2\dhis-api\src\main\java\org\hisp\dhis\user\User.java
dhis-2\dhis-api\src\main\java\org\hisp\dhis\user\UserCredentials.java
dhis-2\dhis-api\src\main\java\org\hisp\dhis\mapping\MapView.java
dhis-2\dhis-services\dhis-service-dxf2\src\main\java\org\hisp\dhis\dxf2\metadata\ExchangeClasses.java
dhis-2\dhis-services\dhis-service-dxf2\src\main\java\org\hisp\dhis\dxf2\DefaultIdentifiableObjectImporter.java
dhis-2\dhis-services\dhis-service-core\src\main\java\org\hisp\dhis\startup\TableAlteror.java
dhis-2\dhis-services\dhis-service-core\src\main\resources\org\hisp\dhis\user\hibernate\UserCredentials.hbm.xml

To post a comment you must log in.
lp:~sis-ma/dhis2/SISMA-84 updated
12140. By Leandro Soares

Merge from trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java 2013-08-25 21:44:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java 2013-09-30 13:57:58 +0000
@@ -209,9 +209,14 @@
209 */209 */
210 public static boolean canWrite( User user, IdentifiableObject object )210 public static boolean canWrite( User user, IdentifiableObject object )
211 {211 {
212 Set<String> authorities = user != null ? user.getUserCredentials().getAllAuthorities() : new HashSet<String>();
213
214 //TODO ( (object instanceof User) && canCreatePrivate( user, object ) ): review possible security breaches and best way to give update access upon user import
212 if ( sharingOverrideAuthority( user )215 if ( sharingOverrideAuthority( user )
213 || (object.getUser() == null && canCreatePublic( user, object ) && PRIVATE_AUTHORITIES.get( object.getClass() ) != null)216 || (object.getUser() == null && canCreatePublic( user, object ) && PRIVATE_AUTHORITIES.get( object.getClass() ) != null)
214 || user.equals( object.getUser() )217 || user.equals( object.getUser() )
218 //|| authorities.contains( PRIVATE_AUTHORITIES.get( object.getClass() ) )
219 || ( (object instanceof User) && canCreatePrivate( user, object ) )
215 || AccessStringHelper.canWrite( object.getPublicAccess() ) )220 || AccessStringHelper.canWrite( object.getPublicAccess() ) )
216 {221 {
217 return true;222 return true;
218223
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2013-09-30 13:57:58 +0000
@@ -97,6 +97,7 @@
9797
98 private Date lastCheckedInterpretations;98 private Date lastCheckedInterpretations;
9999
100 @Scanned
100 private UserCredentials userCredentials;101 private UserCredentials userCredentials;
101102
102 private Set<UserGroup> groups = new HashSet<UserGroup>();103 private Set<UserGroup> groups = new HashSet<UserGroup>();
103104
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2013-09-30 13:57:58 +0000
@@ -37,6 +37,7 @@
37import org.hisp.dhis.common.BaseIdentifiableObject;37import org.hisp.dhis.common.BaseIdentifiableObject;
38import org.hisp.dhis.common.DxfNamespaces;38import org.hisp.dhis.common.DxfNamespaces;
39import org.hisp.dhis.common.IdentifiableObjectUtils;39import org.hisp.dhis.common.IdentifiableObjectUtils;
40import org.hisp.dhis.common.annotation.Scanned;
40import org.hisp.dhis.common.view.DetailedView;41import org.hisp.dhis.common.view.DetailedView;
41import org.hisp.dhis.common.view.ExportView;42import org.hisp.dhis.common.view.ExportView;
42import org.hisp.dhis.dataset.DataSet;43import org.hisp.dhis.dataset.DataSet;
@@ -53,19 +54,19 @@
53 */54 */
54@JacksonXmlRootElement( localName = "userCredentials", namespace = DxfNamespaces.DXF_2_0)55@JacksonXmlRootElement( localName = "userCredentials", namespace = DxfNamespaces.DXF_2_0)
55public class UserCredentials56public class UserCredentials
56 implements Serializable57 extends BaseIdentifiableObject implements Serializable
57{58{
58 /**59 /**
59 * Determines if a de-serialized file is compatible with this class.60 * Determines if a de-serialized file is compatible with this class.
60 */61 */
61 private static final long serialVersionUID = -8919501679702302098L;62 private static final long serialVersionUID = -8919501679702302098L;
6263
63 private int id;64 //private int id;
6465
65 /**66 /**
66 * Required and unique.67 * Required and unique.
67 */68 */
68 private User user;69 //private User user;
6970
70 /**71 /**
71 * Required and unique.72 * Required and unique.
@@ -80,6 +81,7 @@
80 /**81 /**
81 * Set of user roles.82 * Set of user roles.
82 */83 */
84 @Scanned
83 private Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>();85 private Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>();
8486
85 /**87 /**
@@ -286,6 +288,11 @@
286 return user != null ? user.getName() : username;288 return user != null ? user.getName() : username;
287 }289 }
288290
291 public String getCode()
292 {
293 return username;
294 }
295
289 /**296 /**
290 * Tests whether the given input arguments can perform a valid restore of the297 * Tests whether the given input arguments can perform a valid restore of the
291 * user account for these credentials. Returns false if any of the input arguments298 * user account for these credentials. Returns false if any of the input arguments
292299
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-09-30 10:39:35 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-09-30 13:57:58 +0000
@@ -623,7 +623,7 @@
623 executeSql( "ALTER TABLE dataelement ALTER COLUMN domaintype SET NOT NULL" );623 executeSql( "ALTER TABLE dataelement ALTER COLUMN domaintype SET NOT NULL" );
624 executeSql( "update dataelementcategory set datadimension = false where datadimension is null" );624 executeSql( "update dataelementcategory set datadimension = false where datadimension is null" );
625 625
626 executeSql( "UPDATE dataset SET dataelementdecoration=false WHERE dataelementdecoration is null" );626 executeSql( "UPDATE dataset SET dataelementdecoration=false WHERE dataelementdecoration is null" );
627627
628 executeSql( "alter table validationrulegroup rename column validationgroupid to validationrulegroupid" );628 executeSql( "alter table validationrulegroup rename column validationgroupid to validationrulegroupid" );
629 executeSql( "alter table sqlview rename column viewid to sqlviewid" );629 executeSql( "alter table sqlview rename column viewid to sqlviewid" );
@@ -640,6 +640,8 @@
640 executeSql( "ALTER TABLE interpretation ALTER COLUMN userid DROP NOT NULL" );640 executeSql( "ALTER TABLE interpretation ALTER COLUMN userid DROP NOT NULL" );
641641
642 upgradeMapViewsToAnalyticalObject();642 upgradeMapViewsToAnalyticalObject();
643
644 executeSql( "ALTER TABLE users ALTER COLUMN password DROP NOT NULL" );
643 645
644 log.info( "Tables updated" );646 log.info( "Tables updated" );
645 }647 }
646648
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml 2012-12-13 11:53:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml 2013-09-30 13:57:58 +0000
@@ -21,7 +21,7 @@
21 </property>21 </property>
2222
23 <property name="password">23 <property name="password">
24 <column name="password" not-null="true" />24 <column name="password" not-null="false" />
25 </property>25 </property>
2626
27 <set name="userAuthorityGroups" table="userrolemembers" cascade="save-update">27 <set name="userAuthorityGroups" table="userrolemembers" cascade="save-update">
2828
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-09-27 10:43:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-09-30 13:57:58 +0000
@@ -153,9 +153,9 @@
153 allExportClasses.put( MapView.class, "mapViews" );153 allExportClasses.put( MapView.class, "mapViews" );
154 allExportClasses.put( org.hisp.dhis.mapping.Map.class, "maps" );154 allExportClasses.put( org.hisp.dhis.mapping.Map.class, "maps" );
155155
156 allExportClasses.put( UserAuthorityGroup.class, "userRoles" );
156 allExportClasses.put( User.class, "users" );157 allExportClasses.put( User.class, "users" );
157 allExportClasses.put( UserGroup.class, "userGroups" );158 allExportClasses.put( UserGroup.class, "userGroups" );
158 allExportClasses.put( UserAuthorityGroup.class, "userRoles" );
159159
160 allExportClasses.put( MessageConversation.class, "messageConversations" );160 allExportClasses.put( MessageConversation.class, "messageConversations" );
161 allExportClasses.put( Interpretation.class, "interpretations" );161 allExportClasses.put( Interpretation.class, "interpretations" );
@@ -173,7 +173,7 @@
173 importClasses = new LinkedHashMap<Class<? extends IdentifiableObject>, String>( allExportClasses );173 importClasses = new LinkedHashMap<Class<? extends IdentifiableObject>, String>( allExportClasses );
174174
175 // for now, do not allow user/userGroup to be imported175 // for now, do not allow user/userGroup to be imported
176 importClasses.remove( User.class );176 //importClasses.remove( User.class );
177 importClasses.remove( UserGroup.class );177 importClasses.remove( UserGroup.class );
178178
179 // this is considered data, and is not available for meta-data export/import179 // this is considered data, and is not available for meta-data export/import
180180
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-08-28 12:33:54 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2013-09-30 13:57:58 +0000
@@ -62,6 +62,7 @@
62import org.hisp.dhis.system.util.functional.Function1;62import org.hisp.dhis.system.util.functional.Function1;
63import org.hisp.dhis.user.User;63import org.hisp.dhis.user.User;
64import org.hisp.dhis.user.UserAuthorityGroup;64import org.hisp.dhis.user.UserAuthorityGroup;
65import org.hisp.dhis.user.UserCredentials;
65import org.hisp.dhis.user.UserGroup;66import org.hisp.dhis.user.UserGroup;
66import org.springframework.beans.factory.annotation.Autowired;67import org.springframework.beans.factory.annotation.Autowired;
6768
@@ -409,6 +410,11 @@
409 NonIdentifiableObjects nonIdentifiableObjects = new NonIdentifiableObjects();410 NonIdentifiableObjects nonIdentifiableObjects = new NonIdentifiableObjects();
410 nonIdentifiableObjects.extract( object );411 nonIdentifiableObjects.extract( object );
411412
413 UserCredentials userCredentials = null;
414 if (object instanceof User) {
415 userCredentials = ((User)object).getUserCredentials();
416 }
417
412 Map<Field, Object> fields = detachFields( object );418 Map<Field, Object> fields = detachFields( object );
413 Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );419 Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );
414420
@@ -422,6 +428,23 @@
422428
423 objectBridge.updateObject( object );429 objectBridge.updateObject( object );
424430
431 if (object instanceof User) {
432 userCredentials.setUser((User)object);
433 userCredentials.setId( ((User)object).getId());
434
435 Map<Field, Collection<Object>> collectionFieldsUserCredentials = detachCollectionFields( userCredentials );
436
437 sessionFactory.getCurrentSession().save(userCredentials);
438
439 reattachCollectionFields( userCredentials, collectionFieldsUserCredentials );
440
441 sessionFactory.getCurrentSession().saveOrUpdate(userCredentials);
442
443 ((User) object).setUserCredentials(userCredentials);
444
445 objectBridge.updateObject( (User)object );
446 }
447
425 if ( !options.isDryRun() )448 if ( !options.isDryRun() )
426 {449 {
427 nonIdentifiableObjects.save( object );450 nonIdentifiableObjects.save( object );
@@ -462,6 +485,11 @@
462 nonIdentifiableObjects.extract( object );485 nonIdentifiableObjects.extract( object );
463 nonIdentifiableObjects.delete( persistedObject );486 nonIdentifiableObjects.delete( persistedObject );
464487
488 UserCredentials userCredentials = null;
489 if (object instanceof User) {
490 userCredentials = ((User)object).getUserCredentials();
491 }
492
465 Map<Field, Object> fields = detachFields( object );493 Map<Field, Object> fields = detachFields( object );
466 Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );494 Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );
467495
@@ -477,6 +505,15 @@
477505
478 objectBridge.updateObject( persistedObject );506 objectBridge.updateObject( persistedObject );
479507
508 if (object instanceof User) {
509
510 Map<Field, Collection<Object>> collectionFieldsUserCredentials = detachCollectionFields( userCredentials );
511
512 reattachCollectionFields( ((User)persistedObject).getUserCredentials(), collectionFieldsUserCredentials );
513 sessionFactory.getCurrentSession().saveOrUpdate(((User)persistedObject).getUserCredentials());
514
515 }
516
480 if ( !options.isDryRun() )517 if ( !options.isDryRun() )
481 {518 {
482 nonIdentifiableObjects.save( persistedObject );519 nonIdentifiableObjects.save( persistedObject );
483520
=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml 2013-09-26 16:34:42 +0000
+++ dhis-2/pom.xml 2013-09-30 13:57:58 +0000
@@ -26,6 +26,7 @@
26 <module>dhis-api</module>26 <module>dhis-api</module>
27 <module>dhis-services</module>27 <module>dhis-services</module>
28 <module>dhis-support</module>28 <module>dhis-support</module>
29 <module>dhis-web</module>
29 </modules>30 </modules>
3031
31 <licenses>32 <licenses>