dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33639
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17207: Use generic collections crud web api.
------------------------------------------------------------
revno: 17207
committer: Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-10-22 10:58:44 +0200
message:
Use generic collections crud web api.
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/GetUserGroupAction.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/GetUserGroupListAction.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/usergroup.js
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/userGroupList.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java 2014-10-21 22:42:27 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/CurrentUserController.java 2014-10-22 08:58:44 +0000
@@ -37,7 +37,6 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -56,7 +55,6 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
-import org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.interpretation.Interpretation;
import org.hisp.dhis.interpretation.InterpretationService;
@@ -69,7 +67,6 @@
import org.hisp.dhis.system.util.TextUtils;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
-import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserGroupService;
import org.hisp.dhis.user.UserService;
import org.hisp.dhis.user.UserSettingService;
@@ -696,83 +693,4 @@
response.setContentType( MediaType.APPLICATION_JSON_VALUE );
JacksonUtils.toJson( response.getOutputStream(), forms );
}
-
- @RequestMapping( method = RequestMethod.POST, value = "/groups" )
- public void joinUserGroup(
- HttpServletResponse response, @RequestParam( value = "groupUid", required = true ) String groupUid )
- throws NotAuthenticatedException
- {
- User currentUser = currentUserService.getCurrentUser();
-
- if ( currentUser == null )
- {
- throw new NotAuthenticatedException();
- }
-
- UserGroup group = manager.get( UserGroup.class, groupUid );
-
- if ( group == null )
- {
- ContextUtils.notFoundResponse( response, "UserGroup does not exist: " + groupUid );
- return;
- }
-
- Collection<UserGroup> userGroups = currentUser.getGroups();
-
- if ( userGroups.contains( group ) )
- {
- ContextUtils.okResponse( response, "Already a member of this group." );
- return;
- }
-
- if ( !aclService.canUpdate( currentUser, group ) )
- {
- throw new UpdateAccessDeniedException( "You don't have permissions modify this group." );
- }
-
- group.addUser( currentUser );
-
- manager.update( group );
-
- ContextUtils.okResponse( response, "Joined group." );
- }
-
- @RequestMapping( method = RequestMethod.DELETE, value = "/groups/{uid}" )
- public void leaveUserGroup( HttpServletResponse response, @PathVariable( "uid" ) String groupUid )
- throws NotAuthenticatedException
- {
- User currentUser = currentUserService.getCurrentUser();
-
- if ( currentUser == null )
- {
- throw new NotAuthenticatedException();
- }
-
- UserGroup group = manager.get( UserGroup.class, groupUid );
-
- if ( group == null )
- {
- ContextUtils.notFoundResponse( response, "UserGroup does not exist: " + groupUid );
- return;
- }
-
- Collection<UserGroup> userGroups = currentUser.getGroups();
-
- if ( !userGroups.contains( group ) )
- {
- ContextUtils.okResponse( response, "Not a member of this UserGroup." );
- return;
- }
-
- if ( !aclService.canUpdate( currentUser, group ) )
- {
- throw new UpdateAccessDeniedException( "You don't have permissions modify this group." );
- }
-
- group.removeUser( currentUser );
-
- manager.update( group );
-
- ContextUtils.okResponse( response, "Left group." );
- }
}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/GetUserGroupAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/GetUserGroupAction.java 2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/GetUserGroupAction.java 2014-10-22 08:58:44 +0000
@@ -84,9 +84,9 @@
@Override
public String execute()
{
- group = userGroupService.getUserGroup(userGroupId );
+ group = userGroupService.getUserGroup( userGroupId );
- memberCount =group.getMembers().size();
+ memberCount = group.getMembers().size();
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/GetUserGroupListAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/GetUserGroupListAction.java 2014-10-21 16:15:25 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/usergroup/action/GetUserGroupListAction.java 2014-10-22 08:58:44 +0000
@@ -91,6 +91,14 @@
{
this.key = key;
}
+
+ private String currentUserUid;
+
+ public String getCurrentUserUid()
+ {
+ return currentUserUid;
+ }
+
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@@ -112,6 +120,8 @@
userGroupList = new ArrayList<>( userGroupService.getUserGroupsBetween( paging.getStartPos(), paging.getPageSize() ) );
}
+ currentUserUid = currentUserService.getCurrentUser().getUid();
+
isCurrentUserMemberMap = populateMemberShipMap( userGroupList );
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/usergroup.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/usergroup.js 2014-10-21 22:37:18 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/usergroup.js 2014-10-22 08:58:44 +0000
@@ -31,8 +31,7 @@
function joinUserGroup( context ) {
$.ajax( {
type: 'POST',
- url: '../api/me/groups',
- data: { 'groupUid' : context.uid },
+ url: '../api/userGroups/' + context.uid + '/users/' + currentUser,
success: function() {
var $userGroup = $( "#tr" + context.id );
$userGroup.find( ".memberIcon" ).show();
@@ -48,7 +47,7 @@
function leaveUserGroup( context ) {
$.ajax( {
type: 'DELETE',
- url: '../api/me/groups/' + context.uid,
+ url: '../api/userGroups/' + context.uid + '/users/' + currentUser,
success: function( data ) {
var $userGroup = $( "#tr" + context.id );
$userGroup.find( ".memberIcon" ).hide();
@@ -59,4 +58,4 @@
console.log( "Failed to leave user group: " + jqXHR.responseText );
}
});
-}
\ No newline at end of file
+}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/userGroupList.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/userGroupList.vm 2014-10-21 23:17:23 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/userGroupList.vm 2014-10-22 08:58:44 +0000
@@ -3,6 +3,7 @@
<script type="text/javascript">
var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete" ) , "'" )';
+ var currentUser = '$encoder.jsEscape( $currentUserUid, "'" )';
</script>
<h3>$i18n.getString( "user_group_management" ) #openHelp( "user_group_management" )</h3>