[seam-commits] Seam SVN: r8159 - in trunk/examples/seamspace: src/org/jboss/seam/example/seamspace and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon May 12 04:18:28 EDT 2008


Author: shane.bryzak at jboss.com
Date: 2008-05-12 04:18:28 -0400 (Mon, 12 May 2008)
New Revision: 8159

Modified:
   trunk/examples/seamspace/resources/META-INF/security-rules.drl
   trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/PictureSearch.java
   trunk/examples/seamspace/view/pictures.xhtml
Log:
implemented delete image feature

Modified: trunk/examples/seamspace/resources/META-INF/security-rules.drl
===================================================================
--- trunk/examples/seamspace/resources/META-INF/security-rules.drl	2008-05-12 08:17:42 UTC (rev 8158)
+++ trunk/examples/seamspace/resources/META-INF/security-rules.drl	2008-05-12 08:18:28 UTC (rev 8159)
@@ -28,6 +28,19 @@
   check.grant();
 end
 
+# This rule allows a member to delete their own images
+
+rule DeleteImage
+  no-loop
+  activation-group "permissions"
+when
+  acct: MemberAccount()
+  image: MemberImage(mbr : member -> (mbr.memberId.equals(acct.member.memberId)))
+  check: PermissionCheck(target == image, action == "delete", granted == false)
+then
+  check.grant();
+end
+
 # This rule allows members to revoke permissions on their images to other users/roles
 
 rule RevokeImagePermissions

Modified: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/PictureSearch.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/PictureSearch.java	2008-05-12 08:17:42 UTC (rev 8158)
+++ trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/PictureSearch.java	2008-05-12 08:18:28 UTC (rev 8159)
@@ -11,6 +11,7 @@
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.security.Delete;
 import org.jboss.seam.annotations.web.RequestParameter;
 import org.jboss.seam.security.Identity;
 
@@ -41,6 +42,11 @@
       this.memberName = memberName;
    }
    
+   public void delete(@Delete MemberImage image)
+   {
+      entityManager.remove(image);
+   }
+   
    public MemberImage lookupImage()
    {
       return entityManager.find(MemberImage.class, imageId);
@@ -50,7 +56,7 @@
    public void loadMemberPictures()
    {
       memberImages = (List<MemberImage>) entityManager.createQuery(
-            "select i from MemberImage i where i.member.memberName = :name")
+            "select i from MemberImage i where i.member.memberName = :name and not i = i.member.picture")
             .setParameter("name", memberName)
             .getResultList();      
       Identity.instance().filterByPermission(memberImages, "view");

Modified: trunk/examples/seamspace/view/pictures.xhtml
===================================================================
--- trunk/examples/seamspace/view/pictures.xhtml	2008-05-12 08:17:42 UTC (rev 8158)
+++ trunk/examples/seamspace/view/pictures.xhtml	2008-05-12 08:18:28 UTC (rev 8159)
@@ -14,6 +14,13 @@
     </ui:define>
   
     <ui:define name="content">
+    
+      <script type="text/javascript">
+        function confirmDelete()
+        {
+          return confirm("Are you sure you wish to delete this image? This action cannot be undone.");
+        }
+      </script>    
       
       <div class="errors"><h:messages globalOnly="true"/></div>     
 
@@ -45,10 +52,18 @@
               <a href="content/images?id=#{img.imageId}" rel="lightbox[pictureset]" title="#{img.caption}">
                 <h:graphicImage value="/content/images?id=#{img.imageId}&amp;width=90" border="0"/>
               </a>
-              <s:button view="/imagepermissions.seam" action="#{permissionSearch.search(pictureSearch.lookupImage())}" styleClass="padlock">
+              <s:button view="/imagepermissions.seam" 
+                action="#{permissionSearch.search(pictureSearch.lookupImage())}" 
+                styleClass="padlock"
+                rendered="#{s:hasPermission(img, 'seam.grant-permission')}">
                 <f:param name="imageId" value="#{img.imageId}"/>
               </s:button>
-              <s:button styleClass="trash"/>
+              <s:button styleClass="trash" 
+                action="#{pictureSearch.delete(pictureSearch.lookupImage())}"
+                rendered="#{s:hasPermission(img, 'delete')}"
+                onclick="if (!confirmDelete()) return false">
+                <f:param name="imageId" value="#{img.imageId}"/>
+              </s:button>
             </div>
               
           </ui:repeat> 




More information about the seam-commits mailing list