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
1=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java'
2--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java 2013-08-25 21:44:57 +0000
3+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java 2013-09-30 13:57:58 +0000
4@@ -209,9 +209,14 @@
5 */
6 public static boolean canWrite( User user, IdentifiableObject object )
7 {
8+ Set<String> authorities = user != null ? user.getUserCredentials().getAllAuthorities() : new HashSet<String>();
9+
10+ //TODO ( (object instanceof User) && canCreatePrivate( user, object ) ): review possible security breaches and best way to give update access upon user import
11 if ( sharingOverrideAuthority( user )
12 || (object.getUser() == null && canCreatePublic( user, object ) && PRIVATE_AUTHORITIES.get( object.getClass() ) != null)
13 || user.equals( object.getUser() )
14+ //|| authorities.contains( PRIVATE_AUTHORITIES.get( object.getClass() ) )
15+ || ( (object instanceof User) && canCreatePrivate( user, object ) )
16 || AccessStringHelper.canWrite( object.getPublicAccess() ) )
17 {
18 return true;
19
20=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java'
21--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2013-08-23 15:56:19 +0000
22+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2013-09-30 13:57:58 +0000
23@@ -97,6 +97,7 @@
24
25 private Date lastCheckedInterpretations;
26
27+ @Scanned
28 private UserCredentials userCredentials;
29
30 private Set<UserGroup> groups = new HashSet<UserGroup>();
31
32=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java'
33--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2013-08-23 15:56:19 +0000
34+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2013-09-30 13:57:58 +0000
35@@ -37,6 +37,7 @@
36 import org.hisp.dhis.common.BaseIdentifiableObject;
37 import org.hisp.dhis.common.DxfNamespaces;
38 import org.hisp.dhis.common.IdentifiableObjectUtils;
39+import org.hisp.dhis.common.annotation.Scanned;
40 import org.hisp.dhis.common.view.DetailedView;
41 import org.hisp.dhis.common.view.ExportView;
42 import org.hisp.dhis.dataset.DataSet;
43@@ -53,19 +54,19 @@
44 */
45 @JacksonXmlRootElement( localName = "userCredentials", namespace = DxfNamespaces.DXF_2_0)
46 public class UserCredentials
47- implements Serializable
48+ extends BaseIdentifiableObject implements Serializable
49 {
50 /**
51 * Determines if a de-serialized file is compatible with this class.
52 */
53 private static final long serialVersionUID = -8919501679702302098L;
54
55- private int id;
56+ //private int id;
57
58 /**
59 * Required and unique.
60 */
61- private User user;
62+ //private User user;
63
64 /**
65 * Required and unique.
66@@ -80,6 +81,7 @@
67 /**
68 * Set of user roles.
69 */
70+ @Scanned
71 private Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>();
72
73 /**
74@@ -286,6 +288,11 @@
75 return user != null ? user.getName() : username;
76 }
77
78+ public String getCode()
79+ {
80+ return username;
81+ }
82+
83 /**
84 * Tests whether the given input arguments can perform a valid restore of the
85 * user account for these credentials. Returns false if any of the input arguments
86
87=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
88--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-09-30 10:39:35 +0000
89+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-09-30 13:57:58 +0000
90@@ -623,7 +623,7 @@
91 executeSql( "ALTER TABLE dataelement ALTER COLUMN domaintype SET NOT NULL" );
92 executeSql( "update dataelementcategory set datadimension = false where datadimension is null" );
93
94- executeSql( "UPDATE dataset SET dataelementdecoration=false WHERE dataelementdecoration is null" );
95+ executeSql( "UPDATE dataset SET dataelementdecoration=false WHERE dataelementdecoration is null" );
96
97 executeSql( "alter table validationrulegroup rename column validationgroupid to validationrulegroupid" );
98 executeSql( "alter table sqlview rename column viewid to sqlviewid" );
99@@ -640,6 +640,8 @@
100 executeSql( "ALTER TABLE interpretation ALTER COLUMN userid DROP NOT NULL" );
101
102 upgradeMapViewsToAnalyticalObject();
103+
104+ executeSql( "ALTER TABLE users ALTER COLUMN password DROP NOT NULL" );
105
106 log.info( "Tables updated" );
107 }
108
109=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml'
110--- 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
111+++ 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
112@@ -21,7 +21,7 @@
113 </property>
114
115 <property name="password">
116- <column name="password" not-null="true" />
117+ <column name="password" not-null="false" />
118 </property>
119
120 <set name="userAuthorityGroups" table="userrolemembers" cascade="save-update">
121
122=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java'
123--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-09-27 10:43:38 +0000
124+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2013-09-30 13:57:58 +0000
125@@ -153,9 +153,9 @@
126 allExportClasses.put( MapView.class, "mapViews" );
127 allExportClasses.put( org.hisp.dhis.mapping.Map.class, "maps" );
128
129+ allExportClasses.put( UserAuthorityGroup.class, "userRoles" );
130 allExportClasses.put( User.class, "users" );
131 allExportClasses.put( UserGroup.class, "userGroups" );
132- allExportClasses.put( UserAuthorityGroup.class, "userRoles" );
133
134 allExportClasses.put( MessageConversation.class, "messageConversations" );
135 allExportClasses.put( Interpretation.class, "interpretations" );
136@@ -173,7 +173,7 @@
137 importClasses = new LinkedHashMap<Class<? extends IdentifiableObject>, String>( allExportClasses );
138
139 // for now, do not allow user/userGroup to be imported
140- importClasses.remove( User.class );
141+ //importClasses.remove( User.class );
142 importClasses.remove( UserGroup.class );
143
144 // this is considered data, and is not available for meta-data export/import
145
146=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
147--- 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
148+++ 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
149@@ -62,6 +62,7 @@
150 import org.hisp.dhis.system.util.functional.Function1;
151 import org.hisp.dhis.user.User;
152 import org.hisp.dhis.user.UserAuthorityGroup;
153+import org.hisp.dhis.user.UserCredentials;
154 import org.hisp.dhis.user.UserGroup;
155 import org.springframework.beans.factory.annotation.Autowired;
156
157@@ -409,6 +410,11 @@
158 NonIdentifiableObjects nonIdentifiableObjects = new NonIdentifiableObjects();
159 nonIdentifiableObjects.extract( object );
160
161+ UserCredentials userCredentials = null;
162+ if (object instanceof User) {
163+ userCredentials = ((User)object).getUserCredentials();
164+ }
165+
166 Map<Field, Object> fields = detachFields( object );
167 Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );
168
169@@ -422,6 +428,23 @@
170
171 objectBridge.updateObject( object );
172
173+ if (object instanceof User) {
174+ userCredentials.setUser((User)object);
175+ userCredentials.setId( ((User)object).getId());
176+
177+ Map<Field, Collection<Object>> collectionFieldsUserCredentials = detachCollectionFields( userCredentials );
178+
179+ sessionFactory.getCurrentSession().save(userCredentials);
180+
181+ reattachCollectionFields( userCredentials, collectionFieldsUserCredentials );
182+
183+ sessionFactory.getCurrentSession().saveOrUpdate(userCredentials);
184+
185+ ((User) object).setUserCredentials(userCredentials);
186+
187+ objectBridge.updateObject( (User)object );
188+ }
189+
190 if ( !options.isDryRun() )
191 {
192 nonIdentifiableObjects.save( object );
193@@ -462,6 +485,11 @@
194 nonIdentifiableObjects.extract( object );
195 nonIdentifiableObjects.delete( persistedObject );
196
197+ UserCredentials userCredentials = null;
198+ if (object instanceof User) {
199+ userCredentials = ((User)object).getUserCredentials();
200+ }
201+
202 Map<Field, Object> fields = detachFields( object );
203 Map<Field, Collection<Object>> collectionFields = detachCollectionFields( object );
204
205@@ -477,6 +505,15 @@
206
207 objectBridge.updateObject( persistedObject );
208
209+ if (object instanceof User) {
210+
211+ Map<Field, Collection<Object>> collectionFieldsUserCredentials = detachCollectionFields( userCredentials );
212+
213+ reattachCollectionFields( ((User)persistedObject).getUserCredentials(), collectionFieldsUserCredentials );
214+ sessionFactory.getCurrentSession().saveOrUpdate(((User)persistedObject).getUserCredentials());
215+
216+ }
217+
218 if ( !options.isDryRun() )
219 {
220 nonIdentifiableObjects.save( persistedObject );
221
222=== modified file 'dhis-2/pom.xml'
223--- dhis-2/pom.xml 2013-09-26 16:34:42 +0000
224+++ dhis-2/pom.xml 2013-09-30 13:57:58 +0000
225@@ -26,6 +26,7 @@
226 <module>dhis-api</module>
227 <module>dhis-services</module>
228 <module>dhis-support</module>
229+ <module>dhis-web</module>
230 </modules>
231
232 <licenses>