Skip to content

Commit

Permalink
#1668 - Eager tabbed browsing on projects page can lead to IOOBE
Browse files Browse the repository at this point in the history
- Use BookmarkablePageLinks in the project overview
- Allow the ProjectDashboardPage to take a project ID as parameter
- Unmount "welcome.html" thus making the ProjectDashboardPage reachable at the application root
  • Loading branch information
reckart committed Apr 28, 2020
1 parent e4dd00c commit e4ea4c8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ protected void initInceptionResources()
}
});
}

@Override
protected void initDefaultPageMounts()
{
super.initDefaultPageMounts();

// We don't want the project dashboard to be linked as "welcome.html" but rather only under
// its default URL as defined in the ProjectDashboard class
unmount("/welcome.html");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

import static de.tudarmstadt.ukp.clarin.webanno.api.SecurityUtil.annotationEnabeled;
import static de.tudarmstadt.ukp.clarin.webanno.api.SecurityUtil.curationEnabeled;
import static de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PAGE_PARAM_PROJECT_ID;
import static de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_ANNOTATION;
import static de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_AUTOMATION;
import static de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_CORRECTION;
import static de.tudarmstadt.ukp.inception.ui.core.session.SessionMetaData.CURRENT_PROJECT;

import java.util.List;
Expand All @@ -27,11 +31,11 @@
import org.apache.wicket.Session;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.wicketstuff.annotation.mount.MountPath;

import de.tudarmstadt.ukp.clarin.webanno.api.ProjectService;
import de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst;
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.clarin.webanno.security.UserDao;
import de.tudarmstadt.ukp.clarin.webanno.security.model.User;
Expand All @@ -43,14 +47,17 @@
import de.tudarmstadt.ukp.inception.ui.core.dashboard.dashlet.ActivitiesDashlet;
import de.tudarmstadt.ukp.inception.ui.core.dashboard.dashlet.CurrentProjectDashlet;
import de.tudarmstadt.ukp.inception.ui.core.dashboard.projectlist.ProjectsOverviewPage;
import de.tudarmstadt.ukp.inception.ui.core.session.SessionMetaData;

/**
* Project dashboard page
*/
@MountPath(value = "/project.html")
public class ProjectDashboardPage extends ApplicationPageBase
@MountPath(value = "/project/${" + PAGE_PARAM_PROJECT_ID + "}" )
public class ProjectDashboardPage
extends ApplicationPageBase
{
// Page parameters
public static final String PAGE_PARAM_PROJECT_ID = "p";

private static final long serialVersionUID = -2487663821276301436L;

private @SpringBean ProjectService projectService;
Expand All @@ -59,7 +66,36 @@ public class ProjectDashboardPage extends ApplicationPageBase

private DashboardMenu menu;

public ProjectDashboardPage(final PageParameters aPageParameters)
{
super(aPageParameters);

User currentUser = userRepository.getCurrentUser();

// Check if use can access the project
Project project = projectService.listAccessibleProjects(currentUser).stream()
.filter(p -> p.getId().equals(
aPageParameters.get(PAGE_PARAM_PROJECT_ID).toOptionalLong()))
.findFirst()
.orElse(null);

// If the user has no access, send the user back to the overview page
if (project == null) {
setResponsePage(ProjectsOverviewPage.class);
}

// Otherwise make the project the current project
Session.get().setMetaData(CURRENT_PROJECT, project);

commonInit();
}

public ProjectDashboardPage()
{
commonInit();
}

protected void commonInit()
{
setStatelessHint(true);
setVersioned(false);
Expand All @@ -80,9 +116,9 @@ public ProjectDashboardPage()

// if not either a curator or annotator, display warning message
if (
!annotationEnabeled(projectService, user, WebAnnoConst.PROJECT_TYPE_ANNOTATION) &&
!annotationEnabeled(projectService, user, WebAnnoConst.PROJECT_TYPE_AUTOMATION) &&
!annotationEnabeled(projectService, user, WebAnnoConst.PROJECT_TYPE_CORRECTION) &&
!annotationEnabeled(projectService, user, PROJECT_TYPE_ANNOTATION) &&
!annotationEnabeled(projectService, user, PROJECT_TYPE_AUTOMATION) &&
!annotationEnabeled(projectService, user, PROJECT_TYPE_CORRECTION) &&
!curationEnabeled(projectService, user))
{
info("You are not member of any projects to annotate or curate");
Expand All @@ -102,13 +138,12 @@ public ProjectDashboardPage()
*/
private Project getProject()
{
Project project = Session.get().getMetaData(SessionMetaData.CURRENT_PROJECT);
Project project = Session.get().getMetaData(CURRENT_PROJECT);
if (project == null) {
return null;
}
else {
return projectService.getProject(project.getId());
}

return projectService.getProject(project.getId());
}

private List<MenuItem> getMenuItems()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static de.tudarmstadt.ukp.clarin.webanno.security.model.Role.ROLE_ADMIN;
import static de.tudarmstadt.ukp.clarin.webanno.security.model.Role.ROLE_PROJECT_CREATOR;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen;
import static de.tudarmstadt.ukp.inception.ui.core.session.SessionMetaData.CURRENT_PROJECT;
import static java.lang.String.join;
import static java.util.Arrays.asList;
import static org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy.authorize;
Expand All @@ -41,14 +40,14 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.feedback.IFeedback;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -82,7 +81,6 @@
import de.tudarmstadt.ukp.clarin.webanno.support.dialog.ConfirmationDialog;
import de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxLink;
import de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior;
import de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaStatelessLink;
import de.tudarmstadt.ukp.clarin.webanno.ui.core.page.ApplicationPageBase;
import de.tudarmstadt.ukp.clarin.webanno.ui.project.ProjectPage;
import de.tudarmstadt.ukp.inception.ui.core.dashboard.project.ProjectDashboardPage;
Expand Down Expand Up @@ -213,8 +211,10 @@ private WebMarkupContainer createProjectList()
@Override
protected void populateItem(ListItem<Project> aItem)
{
LambdaStatelessLink projectLink = new LambdaStatelessLink(MID_PROJECT_LINK,
() -> selectProject(aItem.getModelObject()));
PageParameters pageParameters = new PageParameters().add(
ProjectDashboardPage.PAGE_PARAM_PROJECT_ID, aItem.getModelObject().getId());
BookmarkablePageLink<Void> projectLink = new BookmarkablePageLink<>(
MID_PROJECT_LINK, ProjectDashboardPage.class, pageParameters);
projectLink.add(new Label(MID_NAME, aItem.getModelObject().getName()));
DateLabel createdLabel = DateLabel.forDatePattern(MID_CREATED,
() -> aItem.getModelObject().getCreated(), "yyyy-MM-dd");
Expand Down Expand Up @@ -348,12 +348,6 @@ private void actionApplyRoleFilter(AjaxRequestTarget aTarget, PermissionLevel aP
aTarget.addChildren(getPage(), IFeedback.class);
}

private void selectProject(Project aProject)
{
Session.get().setMetaData(CURRENT_PROJECT, aProject);
setResponsePage(ProjectDashboardPage.class);
}

private List<Project> listProjects()
{
User currentUser = userRepository.getCurrentUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package de.tudarmstadt.ukp.inception.ui.core.menubar;

import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen;
import static de.tudarmstadt.ukp.inception.ui.core.session.SessionMetaData.CURRENT_PROJECT;

import org.apache.wicket.Session;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
Expand All @@ -28,7 +29,6 @@
import de.tudarmstadt.ukp.inception.ui.core.dashboard.admin.AdminDashboardPage;
import de.tudarmstadt.ukp.inception.ui.core.dashboard.project.ProjectDashboardPage;
import de.tudarmstadt.ukp.inception.ui.core.dashboard.projectlist.ProjectsOverviewPage;
import de.tudarmstadt.ukp.inception.ui.core.session.SessionMetaData;

public class MenuBar
extends de.tudarmstadt.ukp.clarin.webanno.ui.core.page.MenuBar
Expand All @@ -45,8 +45,7 @@ public MenuBar(String aId)
add(new BookmarkablePageLink<>("homeLink", getApplication().getHomePage()));

add(new BookmarkablePageLink<>("dashboardLink", ProjectDashboardPage.class)
.add(visibleWhen(() ->
Session.get().getMetaData(SessionMetaData.CURRENT_PROJECT) != null)));
.add(visibleWhen(() -> Session.get().getMetaData(CURRENT_PROJECT) != null)));

add(new BookmarkablePageLink<>("projectsLink", ProjectsOverviewPage.class)
.add(visibleWhen(() -> userRepository.getCurrentUser() != null)));
Expand Down

0 comments on commit e4ea4c8

Please sign in to comment.