Merge branch 'master' into packaging
[pithos-web-client] / src / gr / grnet / pithos / web / client / commands / RemoveUserCommand.java
index d084938..7bc14fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
@@ -72,19 +72,34 @@ public class RemoveUserCommand implements Command {
        public void execute() {
         if (containerPanel != null)
                    containerPanel.hide();
-       final Group group = user.getGroup();
+       final String groupName = user.getGroup();
+       final Group group = app.getAccount().getGroup(groupName);
+       if (group == null)
+               return;
        group.removeMember(user.getName());
        String path = "?update=";
        PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
                        
                        @Override
-                       public void onSuccess(@SuppressWarnings("unused") Resource result) {
-                               app.updateGroupNode(group);
+                       public void onSuccess(Resource result) {
+                               app.fetchAccount(new Command() {
+                                       
+                                       @Override
+                                       public void execute() {
+                                               Group updatedGroup2 = app.getAccount().getGroup(groupName);
+                                               if (updatedGroup2 != null)
+                                                       app.updateGroupNode(updatedGroup2);
+                                               else {
+                                                       app.updateGroupNode(null);
+                                               }
+                                       }
+                               });
                        }
                        
                        @Override
                        public void onError(Throwable t) {
                                GWT.log("", t);
+                               app.setError(t);
                                if (t instanceof RestException) {
                                        app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText());
                                }
@@ -101,7 +116,7 @@ public class RemoveUserCommand implements Command {
                String groupMembers = "";
                if (!group.getMembers().isEmpty()) {
                        for (String u : group.getMembers())
-                               groupMembers += (u + ",");
+                               groupMembers += (URL.encodePathSegment(u) + ",");
                }
                else
                        groupMembers = "~";