[seam-commits] Seam SVN: r8152 - trunk/examples/seamspace/src/org/jboss/seam/example/seamspace.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat May 10 09:48:52 EDT 2008


Author: shane.bryzak at jboss.com
Date: 2008-05-10 09:48:52 -0400 (Sat, 10 May 2008)
New Revision: 8152

Modified:
   trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/ImagePermission.java
Log:
fixed permission editing

Modified: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/ImagePermission.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/ImagePermission.java	2008-05-10 13:34:54 UTC (rev 8151)
+++ trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/ImagePermission.java	2008-05-10 13:48:52 UTC (rev 8152)
@@ -31,6 +31,8 @@
    private List<Member> selectedFriends;
    private List<String> selectedActions;
    
+   private List<String> originalActions;
+   
    private List<Member> availableFriends;   
    
    @In IdentityManager identityManager;
@@ -66,7 +68,7 @@
             
       List<Permission> permissions = permissionManager.listPermissions(target);
       
-      selectedActions = new ArrayList<String>();
+      selectedActions = new ArrayList<String>();      
       
       for (Permission permission : permissions)
       {
@@ -78,6 +80,8 @@
             }
          }
       }
+      
+      originalActions = new ArrayList<String>(selectedActions);
    }
 
    public List<String> getSelectedRoles()
@@ -112,33 +116,60 @@
    
    public void applyPermissions()
    {
-      List<Permission> permissions = new ArrayList<Permission>();
-
-      for (String role : selectedRoles)
+      if (recipient != null)
       {
-         Principal r = new Role(role);
+         List<Permission> grantedPermissions = new ArrayList<Permission>();
+         List<Permission> revokedPermissions = new ArrayList<Permission>();
+         
          for (String action : selectedActions)
-         {            
-            permissions.add(new Permission(target, action, r));
+         {
+            if (!originalActions.contains(action)) 
+            {
+               grantedPermissions.add(new Permission(target, action, recipient));
+            }
          }
+         
+         for (String action : originalActions)
+         {
+            if (!selectedActions.contains(action))
+            {
+               revokedPermissions.add(new Permission(target, action, recipient));
+            }
+         }
+         
+         if (!grantedPermissions.isEmpty()) permissionManager.grantPermissions(grantedPermissions);
+         if (!revokedPermissions.isEmpty()) permissionManager.revokePermissions(revokedPermissions);
       }
-      
-      for (Member friend : selectedFriends)
+      else
       {
-         MemberAccount acct = (MemberAccount) entityManager.createQuery(
-               "select a from MemberAccount a where a.member = :member")
-               .setParameter("member", friend)
-               .getSingleResult();
+         List<Permission> permissions = new ArrayList<Permission>();
+   
+         for (String role : selectedRoles)
+         {
+            Principal r = new Role(role);
+            for (String action : selectedActions)
+            {            
+               permissions.add(new Permission(target, action, r));
+            }
+         }
          
-         Principal p = new SimplePrincipal(acct.getUsername());
-         
-         for (String action : selectedActions)
+         for (Member friend : selectedFriends)
          {
-            permissions.add(new Permission(target, action, p));
+            MemberAccount acct = (MemberAccount) entityManager.createQuery(
+                  "select a from MemberAccount a where a.member = :member")
+                  .setParameter("member", friend)
+                  .getSingleResult();
+            
+            Principal p = new SimplePrincipal(acct.getUsername());
+            
+            for (String action : selectedActions)
+            {
+               permissions.add(new Permission(target, action, p));
+            }
          }
+         
+         permissionManager.grantPermissions(permissions);
       }
-      
-      permissionManager.grantPermissions(permissions);
       Conversation.instance().endBeforeRedirect();
    }
    




More information about the seam-commits mailing list