xlawrence    2005/06/06 17:03:05 CEST

  Modified files:
    core/src/java/org/jahia/engines/shared BigText_Field.java 
  Log:
  Added method for retreiving the list of groupID a given page does not have 
access to
  
  Revision  Changes    Path
  1.6       +102 -39   
jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java.diff?r1=1.5&r2=1.6&f=h
  
  
  
  Index: BigText_Field.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BigText_Field.java        31 May 2005 11:22:34 -0000      1.5
  +++ BigText_Field.java        6 Jun 2005 15:03:05 -0000       1.6
  @@ -20,6 +20,7 @@
   package org.jahia.engines.shared;
   
   import java.util.HashMap;
  +import java.util.Collection;
   import java.util.Vector;
   import java.util.StringTokenizer;
   import org.jahia.data.containers.JahiaContainer;
  @@ -51,6 +52,8 @@
   import java.util.HashSet;
   import org.jahia.utils.I18n;
   
  +import org.jahia.services.acl.JahiaACLEntry;
  +
   import javax.servlet.ServletConfig;
   
   import org.jahia.content.ContentObject;
  @@ -506,59 +509,119 @@
           return result;
       }
       
  -    /** 
  -     * Checks if a field has the same rights as a page given by its ID.
  -     * 
  -     * @param pageID The ID of the page to check the righes 
  -     * @param field The BigText field where the URL to the Jahia page is 
coded
  -     *
  -     * @return True if the Target page has the same rights as the field
  +    /**
  +     * Returns a Collection of the GroupIDs not having Read Access on the 
given page
        */
  -    public static boolean checkReadAccess(int pageID, JahiaField field) 
  -    throws JahiaException {
  -        ContentPage page = ContentPage.getPage(pageID);
  -        if (page == null) return false;
  +    public Collection getFieldGroupsNotHavingAccessOnPage(int pageID,
  +            JahiaField field, ParamBean jParams, HashMap engineMap) throws 
JahiaException {
  +        logger.debug("Comparing ACLs of field "+field.getID()+ " and page "+
  +                pageID);
  +        final ContentPage page = ContentPage.getPage(pageID);   
  +        final ContentObject aclObject = getFieldACLObject(field, jParams, 
engineMap);
  +        
  +        // Define an ACLEntry for "Read" Rights
  +        final JahiaACLEntry aclEntry = new JahiaACLEntry();
  +        aclEntry.setPermission(JahiaBaseACL.READ_RIGHTS, 
JahiaACLEntry.ACL_YES);
           
  -        Vector fieldACLGroups = field.getACL().getGroupnameList(null);
  +        // Get all the groups which can see the field
  +        final Vector fieldACLGroups = 
aclObject.getACL().getGroupnameListNoAdmin(aclEntry);
           logger.debug("fieldACLGroups: "+fieldACLGroups);
           
  -        Vector pageACLGroups = page.getACL().getGroupnameList(null);
  -        logger.debug("pageACLGroups: "+pageACLGroups);
  +        if (page == null) { return fieldACLGroups; }
           
  -        if (fieldACLGroups.size() > pageACLGroups.size()) {
  -            return false;
  -        }
  +        // Get all the groups which can see the target page
  +        final Vector pageACLGroups = 
page.getACL().getGroupnameListNoAdmin(aclEntry);
  +        logger.debug("pageACLGroups: "+pageACLGroups);
  +              
  +        Vector result = new Vector(fieldACLGroups.size());
           
           Iterator ite = fieldACLGroups.iterator();
  -        boolean result = true;
  -        
  -        while (ite.hasNext() && result) {
  -            final String groupID = (String)ite.next();
  -            JahiaGroup group = ServicesRegistry.getInstance().
  -                    getJahiaGroupManagerService().lookupGroup(groupID);
  -            
  -            // Check that the target page has also got Read rights for that
  -            // group
  -            result = page.getACL().getPermission(group, 
field.getACL().READ_RIGHTS);
  +        while (ite.hasNext()) {
  +            String groupID = (String)ite.next();
  +            
  +            if (!pageACLGroups.contains(groupID)) {
  +                // get rid of the site ID
  +                groupID = groupID.split(":")[0];
  +                
  +                // only add the group name once
  +                if (!result.contains(groupID)) {
  +                    result.addElement(groupID);
  +                    logger.debug("Adding group "+groupID+ " to result");
  +                }
  +            }
           }
           
           return result;
       }
       
       /**
  -     *
  +     * Returns a String of comma separated GroupIDs not having Read Access 
on the given page
        */
  -    public static boolean checkReadAccess(int pageID, ParamBean jParams) 
  -    throws JahiaException {
  -        ContentPage page = ContentPage.getPage(pageID);
  -        if (page == null) return false;
  +    public String getFieldGroupsNotHavingAccessOnPageAsString(int pageID,
  +            JahiaField field, ParamBean jParams, HashMap engineMap) throws 
JahiaException {
           
  -        JahiaUserManagerService userMgr = ServicesRegistry.getInstance().
  -                getJahiaUserManagerService();
  -        if (userMgr == null) return false;
  +        Collection c = getFieldGroupsNotHavingAccessOnPage(pageID, field, 
jParams, engineMap);
  +        StringBuffer result = new StringBuffer();
  +        Iterator ite = c.iterator();
  +        
  +        while (ite.hasNext()) {
  +            String groupID = (String)ite.next();
  +            result.append(groupID).append(",");
  +        }
  +        
  +        if (result.length() > 0) {
  +            result = result.deleteCharAt(result.length() - 1);
  +        }
           
  -        return page.checkReadAccess(userMgr.lookupUser(jParams.getSiteID(),
  -                JahiaUserManagerService.GUEST_USERNAME));
  +        return result.toString();
  +    }
  +    
  +    /**
  +     * Returns the ContentObject of the given field or its closest parent.
  +     */
  +    private ContentObject getFieldACLObject(JahiaField field, ParamBean 
jParams,
  +            HashMap engineMap) throws JahiaException {
  +        if (field.getID() <= 0) {  // this means the field has not yet been 
saved
  +            // fetch the parent container ACL entry instead...
  +            JahiaContainer container = 
(JahiaContainer)engineMap.get("theContainer");
  +            logger.debug("Trying to use parent Container ACL instead: ID = " 
+
  +                    container.getID());
  +            
  +            if (container.getID() <= 0) { // this means the container has 
not yet been saved
  +                // fetch the parent container list ACL entry instead...
  +                final int ctnListID = container.getListID();
  +                logger.debug("Trying to use parent ContainerList ACL 
instead: ID = " +
  +                        ctnListID);
  +
  +                if (ctnListID <= 0) { // this means the containerList is 
empty
  +                    // fetch the page ACL entry instead          
  +                    ContentPage fieldPage = 
ContentPage.getPage(field.getPageID());
  +                    logger.debug("Trying to use parent ContentPage ACL 
instead: ID = " +
  +                            field.getPageID());
  +                    
  +                    if (fieldPage == null) {
  +                        logger.error("Field ContentPage is null !!!");
  +                        throw new JahiaException("Field ContentPage is null 
!!!", 
  +                                "Field ContentPage is null !!!", 
  +                                JahiaException.APPLICATION_ERROR,
  +                                JahiaException.ERROR_SEVERITY);
  +                    }
  +                    
  +                    return fieldPage;
  +                    
  +                } else {
  +                    return 
ServicesRegistry.getInstance().getJahiaContainersService().
  +                            loadContainerList(ctnListID, LoadFlags.ALL, 
jParams).
  +                            getContentContainerList();
  +                }
  +                
  +            } else {
  +                return container.getContentContainer();
  +            }
  +            
  +        } else {
  +            return field.getContentField();
  +        }
       }
       
       /**
  @@ -566,7 +629,7 @@
        */
       public String cleanUpHardCodedLinks( JahiaField field, 
HttpServletRequest req ) {
           String content = field.getValue();
  -        if (content.toLowerCase().indexOf("href") < 0) { 
  +        if (content.toLowerCase().indexOf("href") < 0) {
               // BigText does not contain any link
               return content;
           }
  @@ -612,7 +675,7 @@
                   }
                   
                   // Get rid of the '/op/.../'
  -                if (link.indexOf("/op/") > -1) {               
  +                if (link.indexOf("/op/") > -1) {
                       if (link.indexOf("/op/edit") > -1) {
                           link = StringUtils.replace(link, "/op/edit", "");
                           
  

Reply via email to