Package com.dotmarketing.business

Examples of com.dotmarketing.business.PermissionAPI


    public PermissionableObjectDWR getAsset(String inodeOrIdentifier) throws DotHibernateException {
    UserWebAPI userWebAPI = WebAPILocator.getUserWebAPI();
    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();
    PermissionableObjectDWR asset = new PermissionableObjectDWR();
    PermissionAPI permAPI = APILocator.getPermissionAPI();
    Permissionable p = null;

    asset.setId(inodeOrIdentifier);

    try {
      // Retrieving the current user
      User user = userWebAPI.getLoggedInUser(request);
      Structure hostStrucuture = StructureCache.getStructureByVelocityVarName("Host");

      if (InodeFactory.isInode(inodeOrIdentifier)) {
        Inode inode = InodeFactory.find(inodeOrIdentifier);
        p = inode;
        asset.setType(((Permissionable) inode).getClass().getName());
      } else {
        ContentletAPI contAPI = APILocator.getContentletAPI();
        Contentlet content = contAPI.find(inodeOrIdentifier, user, false);

        if (UtilMethods.isSet(content) && content.getStructureInode().equals(hostStrucuture.getInode())) {
          p = content;
          asset.setType(Host.class.getName());
        }
      }

      if(p==null) return null;

      asset.setIsFolder(p instanceof Folder);
      asset.setIsHost((p instanceof Host) || ((p instanceof Contentlet) && ((Contentlet)p).getStructureInode().equals(hostStrucuture.getInode())));
      asset.setIsParentPermissionable(p.isParentPermissionable());
      asset.setDoesUserHavePermissionsToEdit(permAPI.doesUserHavePermission(p, PermissionAPI.PERMISSION_EDIT_PERMISSIONS, user));
    } catch(DotHibernateException de) {
      throw de;
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here


  public List<Map<String, Object>> getCategoriesTree (String structureName, String filter)
    throws DotDataException, PortalException, SystemException {

    WebContext ctx = WebContextFactory.get();
    HttpServletRequest request = ctx.getHttpServletRequest();
    PermissionAPI perAPI = APILocator.getPermissionAPI();

    //Retrieving the current user
    User user = PortalUtil.getUser(request);
    boolean respectFrontendRoles = false;
    if(user == null) {
      //Assuming is a front-end access
      respectFrontendRoles = true;
      user = (User)request.getSession().getAttribute(WebKeys.CMS_USER);
    }

    Structure st = (Structure) StructureCache.getStructureByName(structureName);
    List<Map<String, Object>> maps = new ArrayList<Map<String,Object>>();


    List<Field> fields = st.getFields();
    for (Field field : fields) {
      if(field.getFieldType().equals(Field.FieldType.CATEGORY.toString())){
        try {
          Category category = categoryAPI.find(field.getValues(), user, respectFrontendRoles);

          if(!perAPI.doesUserHavePermission(category, perAPI.PERMISSION_READ, user))
            continue;

          Map<String, Object> catMap = category.getMap();
          String categoryName = (String) catMap.get("categoryName");
          catMap.put("categoryOrigName", categoryName);
View Full Code Here

  ///// ************** ALL METHODS HERE *************************** ////////

  private void _setupEditTemplatePage(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form, User user) throws Exception {

    //Getting the host that can be assigned to the container
    PermissionAPI perAPI = APILocator.getPermissionAPI();
    Template template = (Template) req.getAttribute(WebKeys.TEMPLATE_EDIT);
        Host templateHost = hostAPI.findParentHost(template, user, false);

    //Getting the host that can be assigned to the template
    List<Host> hosts = APILocator.getHostAPI().findAll(user, false);
    hosts.remove(APILocator.getHostAPI().findSystemHost(user, false));
    hosts = perAPI.filterCollection(hosts, PermissionAPI.PERMISSION_CAN_ADD_CHILDREN, false, user);
    if(templateHost != null && !hosts.contains(templateHost)) {
      hosts.add(templateHost);
    }
    req.setAttribute(WebKeys.TEMPLATE_HOSTS, hosts);

View Full Code Here

        try {
            //get the user
            User user = _getUser( req );

            //Checking if the user can add templates to a host
            PermissionAPI perAPI = APILocator.getPermissionAPI();
            List<Host> hosts = APILocator.getHostAPI().findAll( user, false );
            hosts.remove( APILocator.getHostAPI().findSystemHost( user, false ) );
            hosts = perAPI.filterCollection( hosts, PermissionAPI.PERMISSION_CAN_ADD_CHILDREN, false, user );

            if ( hosts.size() == 0 ) {
                req.setAttribute( WebKeys.TEMPLATE_CAN_ADD, false );
            } else {
                req.setAttribute( WebKeys.TEMPLATE_CAN_ADD, true );
            }

            req.setAttribute( WebKeys.TEMPLATE_CAN_DESIGN, perAPI.doesUserHavePermissions( WebAPILocator.getHostWebAPI().getCurrentHost( req ), "TEMPLATE_LAYOUTS:" + PermissionAPI.PERMISSION_EDIT, user ) );

            _viewWebAssets( req, user, Template.class, "template", WebKeys.TEMPLATES_VIEW_COUNT, WebKeys.TEMPLATES_VIEW, WebKeys.TEMPLATE_QUERY, WebKeys.TEMPLATE_SHOW_DELETED, WebKeys.TEMPLATE_HOST_CHANGED );

            return mapping.findForward( "portlet.ext.templates.view_templates" );
        } catch ( Exception e ) {
View Full Code Here

  private void deleteReport(Report report) throws Exception{
        File f;
        String jrxmlPath;
        String jasperPath;
    HibernateUtil.startTransaction();
    PermissionAPI perAPI = APILocator.getPermissionAPI();
    perAPI.removePermissions(report);
      ReportFactory.deleteReport(report);     
      ReportParameterFactory.deleteReportsParameters(report);           
      WebFormFactory.removeWebFormsByType(report.getReportName());
      if (UtilMethods.isSet(Config.getStringProperty("ASSET_REAL_PATH"))) {
        jrxmlPath = Config.getStringProperty("ASSET_REAL_PATH") + File.separator + Config.getStringProperty("REPORT_PATH") + File.separator + report.getInode() + ".jrxml";
View Full Code Here

  }

    @SuppressWarnings("unchecked")
  public static java.util.List<File> getFilesPerRoleParentAndCondition(Role[] roles,
            com.dotmarketing.portlets.folders.model.Folder folderParent, String condition, User user, String order) {
      PermissionAPI permissionAPI = APILocator.getPermissionAPI();
        java.util.List<File> entries = new java.util.ArrayList<File>();
              
        java.util.List permissions = new ArrayList();
    try {
      permissions = permissionAPI.getPermissionIdsFromRoles(folderParent, roles, user);
    } catch (DotDataException e) {
      Logger.error(FileUtils.class, "Could not load permissions : ",e);
    }
       
        if (permissions.contains(String.valueOf(PERMISSION_READ))) {
View Full Code Here

public class StructureAPIImpl implements StructureAPI {

    @Override
    public void delete(Structure st, User user) throws DotSecurityException, DotDataException, DotStateException {       
        // check for write permissions
        PermissionAPI perAPI=APILocator.getPermissionAPI();
        if(!perAPI.doesUserHavePermission(st, PermissionAPI.PERMISSION_WRITE, user))
            throw new DotSecurityException("User doesn't have permission to delete the structure");

     // checking if there is containers using this structure
         List<Container> containers=APILocator.getContainerAPI().findContainersForStructure(st.getInode());
         Map<String, String> containersInUse = new HashMap<String, String>();
         StringBuilder names=new StringBuilder();
         for(Container c : containers) {
           try {
             String hostTitle = APILocator.getHostAPI().findParentHost(c, user, false).getTitle();
             containersInUse.put(c.getIdentifier(), hostTitle + " : " + c.getTitle() + "</br>");
           } catch (Exception e) {
           }
          }
         for(String title : containersInUse.values()){
           names.append(title).append("</br>");
         }
         if(UtilMethods.isSet(names.toString()))
           throw new DotStateException("Structure " + st.getName() +
                         " can't be deleted because the following containers are using it: " + names);

        // default structure can't be deleted
        if(st.isDefaultStructure())
            throw new DotStateException("Can't delete default structure");

        // deleting fields
        for(Field field : FieldFactory.getFieldsByStructure(st.getInode()))
            FieldFactory.deleteField(field);

        // delete related contentlets
        int limit = 200;
        int offset = 0;
        ContentletAPI conAPI=APILocator.getContentletAPI();
        List<Contentlet> contentlets=null;
        do {
            contentlets = conAPI.findByStructure(st, user, false, limit, offset);
            for(Contentlet contentlet : contentlets){
              contentlet.getMap().put(Contentlet.DONT_VALIDATE_ME, true);
            }
            conAPI.delete(contentlets, user, false);
        } while(contentlets.size()>0);

        //delete bad data contents
        deleteStructureContentlets(st.getInode());
       
        // delete Forms entry if it is a form structure
        if (st.getStructureType() == Structure.STRUCTURE_TYPE_FORM) {
            Structure sf = StructureCache.getStructureByVelocityVarName(
                    FormAPI.FORM_WIDGET_STRUCTURE_NAME_VELOCITY_VAR_NAME);
            if (UtilMethods.isSet(sf) && UtilMethods.isSet(sf.getInode())) {
                Field field = st.getFieldVar(FormAPI.FORM_WIDGET_FORM_ID_FIELD_VELOCITY_VAR_NAME);
                conAPI.delete( conAPI.search(
                        "+structureInode:" + sf.getInode() +
                        " +structureInode:" + st.getInode(), 0, 0,
                        "", user, false), user, false);
            }
        }

        // make sure folders don't refer to this structure as default fileasset structure
        if (st.getStructureType() == Structure.STRUCTURE_TYPE_FILEASSET)
            StructureFactory.updateFolderFileAssetReferences(st);

        // delete relationships where the structure is child or parent
        List<Relationship> relationships = RelationshipFactory.getRelationshipsByParent(st);
        for (Relationship rel : relationships)
            RelationshipFactory.deleteRelationship(rel);
        relationships = RelationshipFactory.getRelationshipsByChild(st);
        for (Relationship rel : relationships)
            RelationshipFactory.deleteRelationship(rel);

        // remove structure permissions
        perAPI.removePermissions(st);

        HibernateUtil.getSession().clear();
       
        // remove structure itself
        StructureFactory.deleteStructure(st);
View Full Code Here

    List<Map<String,String>> resultList = new ArrayList<Map<String,String>>();
    List<ContainerStructure> csList;

    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
    User user = userWebAPI.getLoggedInUser(req);
    PermissionAPI permissionAPI = APILocator.getPermissionAPI();


    try {
      csList = APILocator.getContainerAPI().getContainerStructures(cont);

      for (ContainerStructure cs : csList) {
        Map<String, String> result = new HashMap<String, String>();
        Structure st = StructureCache.getStructureByInode(cs.getStructureId());
        if(permissionAPI.doesUserHavePermission(st, PERMISSION_WRITE, user)){
          result.put("inode", cs.getStructureId());
          result.put("name", st.getName());
          resultList.add(result);
        }
      }
View Full Code Here

      StructureFactory.saveStructure(structure);

      FieldsCache.addFields(structure, structure.getFields());

      //Refreshing permissions
      PermissionAPI perAPI = APILocator.getPermissionAPI();
      if(field.getFieldType().equals("host or folder")) {
        perAPI.resetChildrenPermissionReferences(structure);
      }

        //http://jira.dotmarketing.net/browse/DOTCMS-5178
      if(!isNew && ((!wasIndexed && fieldForm.isIndexed()) || (wasIndexed && !fieldForm.isIndexed()))){
        // rebuild contentlets indexes
View Full Code Here

      StructureCache.removeStructure(structure);
      StructureServices.removeStructureFile(structure);

      //Refreshing permissions
      PermissionAPI perAPI = APILocator.getPermissionAPI();
      if(field.getFieldType().equals("host or folder")) {
        conAPI.cleanHostField(structure, APILocator.getUserAPI().getSystemUser(), false);
        perAPI.resetChildrenPermissionReferences(structure);
      }
      StructureFactory.saveStructure(structure);
      // rebuild contentlets indexes
      conAPI.reindex(structure);
      // remove the file from the cache
View Full Code Here

TOP

Related Classes of com.dotmarketing.business.PermissionAPI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.