Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public void setValues(UIPage uiPage) throws Exception {
    uiPage_ = uiPage;
    Page page = (Page) PortalDataMapper.buildModelObject(uiPage);
    if (uiPage.getOwnerType().equals(PortalConfig.USER_TYPE)) {
      removeChildById("PermissionSetting");
    } else if (getChildById("PermissionSetting") == null) {
      addUIComponentInput(uiPermissionSetting);
    }
    uiPermissionSetting.getChild(UIPermissionSelector.class).setEditable(true);
    invokeGetBindingBean(page);
    getUIStringInput("name").setEditable(false);
    getUIStringInput("pageId").setValue(uiPage.getPageId());
    getUIStringInput("title").setValue(uiPage.getTitle());
    getUIFormCheckBoxInput("showMaxWindow").setValue(uiPage.isShowMaxWindow());
    getUIFormSelectBox(OWNER_TYPE).setEnable(false).setValue(uiPage.getOwnerType());
    removeChild(UIPageTemplateOptions.class);

    UIFormInputItemSelector uiTemplate = getChild(UIFormInputItemSelector.class);
    if (uiTemplate == null) return;
    if (page.getFactoryId() == null || page.getFactoryId().trim().length() < 1) {
      uiTemplate.setValue("Default");
      return;
    }
    uiTemplate.setValue(uiPage.getFactoryId());
  }
  public String getTitle() throws Exception {
    String title = (String) request_.getAttribute(REQUEST_TITLE);

    //
    if (title == null) {
      UIPortal uiportal = Util.getUIPortal();

      //
      UserNode node = uiportal.getSelectedUserNode();
      if (node != null) {
        ExoContainer container = getApplication().getApplicationServiceContainer();
        container.getComponentInstanceOfType(UserPortalConfigService.class);
        UserPortalConfigService configService =
            (UserPortalConfigService)
                container.getComponentInstanceOfType(UserPortalConfigService.class);
        Page page = configService.getPage(node.getPageRef(), getRemoteUser());

        //
        if (page != null) {
          title = page.getTitle();
          return ExpressionUtil.getExpressionValue(this.getApplicationResourceBundle(), title);
        } else {
          title = node.getResolvedLabel();
        }
      }
    }

    //
    return title;
  }
 public Page getPageFrom(org.exoplatform.portal.config.model.Page portalPage) {
   POMSession session = pomManager.getSession();
   Site site =
       session
           .getWorkspace()
           .getSite(Mapper.parseSiteType(portalPage.getOwnerType()), portalPage.getOwnerId());
   return getPagesFrom(site).getChild(portalPage.getName());
 }
  @Override
  protected void afterSecondBootWithOverride(PortalContainer container) throws Exception {
    //
    RequestLifeCycle.begin(container);

    DataStorage dataStorage = (DataStorage) container.getComponentInstanceOfType(DataStorage.class);
    PortalConfig portal = dataStorage.getPortalConfig("classic");
    Container layout = portal.getPortalLayout();
    assertEquals(1, layout.getChildren().size());
    Application<Portlet> layoutPortlet = (Application<Portlet>) layout.getChildren().get(0);
    assertEquals("site1/layout", dataStorage.getId(layoutPortlet.getState()));

    //
    Page home = dataStorage.getPage("portal::classic::home");
    assertNotNull(home);
    assertEquals("site 1", home.getTitle());

    Page page1 = dataStorage.getPage("portal::classic::page1");
    assertNotNull(page1);
    assertEquals("site 1", page1.getTitle());

    Page page2 = dataStorage.getPage("portal::classic::page2");
    assertNotNull(page2);
    assertEquals("site 2", page2.getTitle());

    Page dashboard1 = dataStorage.getPage("user::root::dashboard1");
    assertNotNull(dashboard1);
    assertEquals("site 2", dashboard1.getTitle());

    RequestLifeCycle.end();
  }
Exemplo n.º 5
0
 public boolean hasPermission(Page page) {
   Identity identity = getIdentity();
   if (PortalConfig.USER_TYPE.equals(page.getOwnerType())) {
     if (page.getOwnerId().equals(identity.getUserId())) {
       page.setModifiable(true);
       return true;
     }
   }
   if (superUser_.equals(identity.getUserId())) {
     page.setModifiable(true);
     return true;
   }
   if (hasEditPermission(page)) {
     page.setModifiable(true);
     return true;
   }
   page.setModifiable(false);
   String[] accessPerms = page.getAccessPermissions();
   if (accessPerms != null) {
     for (String per : accessPerms) {
       if (hasPermission(identity, per)) {
         return true;
       }
     }
   }
   return false;
 }
Exemplo n.º 6
0
  public static void toUIPage(UIPage uiPage, Page model) throws Exception {
    toUIContainer(uiPage, model);
    uiPage.setSiteKey(new SiteKey(model.getOwnerType(), model.getOwnerId()));
    uiPage.setIcon(model.getIcon());
    uiPage.setAccessPermissions(model.getAccessPermissions());
    uiPage.setEditPermission(model.getEditPermission());
    uiPage.setFactoryId(model.getFactoryId());
    uiPage.setPageId(model.getPageId());
    uiPage.setTitle(model.getTitle());
    uiPage.setShowMaxWindow(model.isShowMaxWindow());
    uiPage.setModifiable(model.isModifiable());

    List<UIPortlet> portlets = new ArrayList<UIPortlet>();
    uiPage.findComponentOfType(portlets, UIPortlet.class);
    for (UIPortlet portlet : portlets) {
      portlet.setPortletInPortal(false);
    }
  }
  public void testPageAccessibleByGuests() {
    Page page = new Page();
    page.setOwnerType("group");
    page.setOwnerId("foo");
    page.setAccessPermissions(new String[] {"whatever:/platform/guests"});

    //
    assertTrue(root.hasPermission(page));
    assertFalse(administrator.hasPermission(page));
    assertFalse(manager.hasPermission(page));
    assertFalse(user.hasPermission(page));
    assertTrue(guest.hasPermission(page));

    //
    assertTrue(root.hasEditPermission(page));
    assertFalse(administrator.hasEditPermission(page));
    assertFalse(manager.hasEditPermission(page));
    assertFalse(user.hasEditPermission(page));
    assertFalse(guest.hasEditPermission(page));
  }
  public void testPage() {
    Page page = new Page();
    page.setOwnerType("group");
    page.setOwnerId("foo");
    page.setAccessPermissions(new String[0]);

    //
    assertTrue(root.hasPermission(page));
    assertFalse(administrator.hasPermission(page));
    assertFalse(manager.hasPermission(page));
    assertFalse(user.hasPermission(page));
    assertFalse(guest.hasPermission(page));

    //
    assertTrue(root.hasEditPermission(page));
    assertFalse(administrator.hasEditPermission(page));
    assertFalse(manager.hasEditPermission(page));
    assertFalse(user.hasEditPermission(page));
    assertFalse(guest.hasEditPermission(page));
  }
Exemplo n.º 9
0
  /**
   * Rename page node.
   *
   * @param newNodeLabel
   * @param space
   * @return
   * @since 1.2.8
   */
  private UserNode renamePageNode(String newNodeLabel, Space space) {
    UserPortalConfigService configService = getApplicationComponent(UserPortalConfigService.class);

    DataStorage dataService = getApplicationComponent(DataStorage.class);

    try {

      UserNode renamedNode = SpaceUtils.getSpaceUserNode(space);
      UserNode parentNode = renamedNode.getParent();
      String newNodeName = SpaceUtils.cleanString(newNodeLabel);

      if (parentNode.getChild(newNodeName) != null) {
        newNodeName = newNodeName + "_" + System.currentTimeMillis();
      }

      //
      renamedNode.setLabel(newNodeLabel);
      renamedNode.setName(newNodeName);

      Page page = dataService.getPage(renamedNode.getPageRef().format());
      if (page != null) {
        page.setTitle(newNodeLabel);
        dataService.save(page);
      }

      SpaceUtils.getUserPortal().saveNode(parentNode, null);

      space.setUrl(newNodeName);
      SpaceUtils.changeSpaceUrlPreference(renamedNode, space, newNodeLabel);

      List<UserNode> userNodes = new ArrayList<UserNode>(renamedNode.getChildren());
      for (UserNode childNode : userNodes) {
        SpaceUtils.changeSpaceUrlPreference(childNode, space, newNodeLabel);
      }
      return renamedNode;
    } catch (Exception e) {
      LOG.warn(e.getMessage(), e);
      return null;
    }
  }
Exemplo n.º 10
0
 public boolean hasEditPermission(Page page) {
   Identity identity = getIdentity();
   if (PortalConfig.USER_TYPE.equals(page.getOwnerType())) {
     if (page.getOwnerId().equals(identity.getUserId())) {
       page.setModifiable(true);
       return true;
     }
     return false;
   }
   if (hasPermission(identity, page.getEditPermission())) {
     page.setModifiable(true);
     return true;
   }
   page.setModifiable(false);
   return false;
 }
Exemplo n.º 11
0
  /**
   * Add Application to UiPage
   *
   * @param event
   * @throws Exception
   */
  private static void addApplicationToPage(Event<UIAddNewApplication> event, boolean atStartup)
      throws Exception {
    UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
    UIPortal uiPortal = uiPortalApp.getShowedUIPortal();
    PortalRequestContext pcontext = Util.getPortalRequestContext();

    UIDesktopPage uiDesktopPage = uiPortal.findFirstComponentOfType(UIDesktopPage.class);
    if (uiDesktopPage == null) {
      pcontext.addUIComponentToUpdateByAjax(
          uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID));
      UIMaskWorkspace maskWorkspace = uiPortalApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
      maskWorkspace.createEvent("Close", Event.Phase.DECODE, event.getRequestContext()).broadcast();
      pcontext.setFullRender(true);
      return;
    }

    String applicationId = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);

    Application application = event.getSource().getApplication(applicationId);
    ApplicationType appType = application.getType();

    UIPortlet uiPortlet = uiDesktopPage.createUIComponent(UIPortlet.class, null, null);
    ApplicationState appState;

    // TODO: Check if there 's already a portlet window of this portlet. A CloneApplicationState
    // should be created in such case
    appState = new TransientApplicationState<Object>(application.getContentId());

    uiPortlet.setState(new PortletState(appState, appType));
    uiPortlet.setPortletInPortal(false);

    if (atStartup) {
      uiPortlet.getProperties().setProperty("appStatus", "HIDE");
    }

    String portletName = application.getApplicationName();
    String displayName = application.getDisplayName();
    if (displayName != null) {
      uiPortlet.setTitle(displayName);
    } else if (portletName != null) {
      uiPortlet.setTitle(portletName);
    }
    uiPortlet.setDescription(application.getDescription());
    List<String> accessPers = application.getAccessPermissions();
    String[] accessPermissions = accessPers.toArray(new String[accessPers.size()]);
    uiPortlet.setAccessPermissions(accessPermissions);

    // Add portlet to page
    uiDesktopPage.addChild(uiPortlet);

    if (uiDesktopPage.isModifiable()) {
      Page page = (Page) PortalDataMapper.buildModelObject(uiDesktopPage);
      if (page.getChildren() == null) {
        page.setChildren(new ArrayList<ModelObject>());
      }
      DataStorage dataService = uiPortalApp.getApplicationComponent(DataStorage.class);
      dataService.save(page);

      // Rebuild the uiPage to synchronize (storageId, storageName) mapping
      page = dataService.getPage(page.getPageId());
      page.setModifiable(true);
      uiDesktopPage.getChildren().clear();
      PortalDataMapper.toUIPage(uiDesktopPage, page);
    }

    UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
    pcontext.setFullRender(true);
    pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
  }
Exemplo n.º 12
0
    public void execute(Event<UIPageForm> event) throws Exception {
      UIPageForm uiPageForm = event.getSource();
      UIPortalApplication uiPortalApp = uiPageForm.getAncestorOfType(UIPortalApplication.class);
      PortalRequestContext pcontext = Util.getPortalRequestContext();
      UIMaskWorkspace uiMaskWS = uiPortalApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
      uiMaskWS.setUIComponent(null);
      uiMaskWS.setShow(false);
      pcontext.addUIComponentToUpdateByAjax(uiMaskWS);

      UIPage uiPage = uiPageForm.getUIPage();
      if (uiPage == null) return;
      String storageId = uiPage.getStorageId();
      Page page = new Page();
      page.setPageId(uiPage.getPageId());
      uiPageForm.invokeSetBindingBean(page);
      page.setOwnerType(uiPage.getOwnerType());
      List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>();
      findAllPortlet(uiPortlets, uiPage);
      ArrayList<ModelObject> applications = new ArrayList<ModelObject>();
      for (UIPortlet uiPortlet : uiPortlets) {
        applications.add(PortalDataMapper.buildModelObject(uiPortlet));
      }

      if (Page.DESKTOP_PAGE.equals(uiPage.getFactoryId())
          && !Page.DESKTOP_PAGE.equals(page.getFactoryId())) {
        page.setShowMaxWindow(false);
        uiPage.getChildren().clear();
        page.setChildren(applications);

        PortalDataMapper.toUIPage(uiPage, page);
        //        if(page.getTemplate() == null) page.setTemplate(uiPage.getTemplate()) ;
        if (page.getChildren() == null) page.setChildren(new ArrayList<ModelObject>());

        //        uiEditBar.setUIPage(uiPage);
        //        Class<?> [] childrenToRender = {UIPageEditBar.class,
        //            UIPageNodeSelector.class, UIPageNavigationControlBar.class};
        //        uiManagement.setRenderedChildrenOfTypes(childrenToRender);

        pcontext.setFullRender(true);
        UIWorkingWorkspace uiWorkingWS =
            uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
        pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);

        return;
      }

      if (Page.DESKTOP_PAGE.equals(page.getFactoryId())) {
        uiPage.getChildren().clear();
        page.setChildren(applications);

        PortalDataMapper.toUIPage(uiPage, page);
        //        if(page.getTemplate() == null) page.setTemplate(uiPage.getTemplate()) ;
        if (page.getChildren() == null) page.setChildren(new ArrayList<ModelObject>());

        UIPortalToolPanel toolPanel = Util.getUIPortalToolPanel();
        toolPanel.setShowMaskLayer(true);
        pcontext.setFullRender(true);
        UIWorkingWorkspace uiWorkingWS =
            uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
        pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
        DataStorage dataService = uiPageForm.getApplicationComponent(DataStorage.class);
        dataService.save(page);
        return;
      }

      List<UIComponent> uiChildren = uiPage.getChildren();
      if (uiChildren == null) {
        PortalDataMapper.toUIPage(uiPage, page);
        return;
      }
      ArrayList<ModelObject> children = new ArrayList<ModelObject>();
      for (UIComponent child : uiChildren) {
        ModelObject component = PortalDataMapper.buildModelObject(child);
        if (component != null) children.add(component);
      }
      page.setChildren(children);
      uiPage.getChildren().clear();

      try {
        PortalDataMapper.toUIPage(uiPage, page);
      } catch (NoSuchDataException de) {
        uiPortalApp.addMessage(
            new ApplicationMessage(
                "UIPageForm.msg.notExistOrDeleted", null, ApplicationMessage.ERROR));
        UIPortalComposer uiPortalComposer =
            (UIPortalComposer) uiPortalApp.findComponentById("UIPageEditor");
        if (uiPortalComposer != null) {
          Event aboutEvent =
              new Event<UIPortalComposer>(uiPortalComposer, "Abort", event.getRequestContext());
          uiPortalComposer.broadcast(aboutEvent, event.getExecutionPhase());
        }
      }

      uiPage.setStorageId(storageId);
      //      if(page.getTemplate() == null) page.setTemplate(uiPage.getTemplate()) ;
      if (page.getChildren() == null) page.setChildren(new ArrayList<ModelObject>());
    }
Exemplo n.º 13
0
  public void invokeSetBindingBean(Object bean) throws Exception {
    String ownerType = getUIFormSelectBox("ownerType").getValue();
    String ownerId = getUIStringInput("ownerId").getValue();

    // As ownerId is now normalized, we have to maker sure that owenerId of 'group' type starts with
    // a '/'
    if (PortalConfig.GROUP_TYPE.equals(ownerType) && ownerId.charAt(0) != '/') {
      ownerId = "/" + ownerId;
    }

    Page page = (Page) bean;
    page.setPageId(getUIStringInput("pageId").getValue());
    page.setOwnerType(ownerType);
    page.setOwnerId(ownerId);
    page.setName(getUIStringInput("name").getValue());
    String title = getUIStringInput("title").getValue();
    if (title == null || title.trim().length() < 1) title = page.getName();
    page.setTitle(title);

    if (!page.isShowMaxWindow()) {
      page.setShowMaxWindow((Boolean) getUIFormCheckBoxInput("showMaxWindow").getValue());
    }
    if (!PortalConfig.USER_TYPE.equals(page.getOwnerType())) {
      page.setAccessPermissions(
          uiPermissionSetting.getChild(UIListPermissionSelector.class).getValue());
      page.setEditPermission(uiPermissionSetting.getChild(UIPermissionSelector.class).getValue());
    }
    UserACL userACL = getApplicationComponent(UserACL.class);
    userACL.hasPermission(page);

    UIFormInputItemSelector uiTemplate = getChildById("Template");
    if (uiTemplate != null) {
      SelectItemOption<?> itemOption = uiTemplate.getSelectedItemOption();
      if (itemOption != null) {
        page.setFactoryId(itemOption.getIcon());
        //        page.setTemplate((String)itemOption.getValue());
        if (page.getFactoryId().equals(Page.DESKTOP_PAGE)) page.setShowMaxWindow(true);
      }
    }
    UIPageTemplateOptions uiConfigOptions = getChild(UIPageTemplateOptions.class);
    if (uiConfigOptions == null) return;
    Page selectedPage =
        uiConfigOptions.createPageFromSelectedOption(page.getOwnerType(), page.getOwnerId());
    if (selectedPage == null) return;
    page.setChildren(selectedPage.getChildren());
    page.setFactoryId(selectedPage.getFactoryId());
    if (Page.DESKTOP_PAGE.equals(page.getFactoryId())) page.setShowMaxWindow(true);
  }
Exemplo n.º 14
0
 public static Page toPageModel(UIPage uiPage) {
   Page model = new Page(uiPage.getStorageId());
   toContainer(model, uiPage);
   model.setOwnerId(uiPage.getSiteKey().getName());
   model.setOwnerType(uiPage.getSiteKey().getTypeName());
   model.setIcon(uiPage.getIcon());
   model.setPageId(uiPage.getPageId());
   model.setTitle(uiPage.getTitle());
   model.setAccessPermissions(uiPage.getAccessPermissions());
   model.setEditPermission(uiPage.getEditPermission());
   model.setFactoryId(uiPage.getFactoryId());
   model.setShowMaxWindow(uiPage.isShowMaxWindow());
   model.setModifiable(uiPage.isModifiable());
   return model;
 }