Search in sources :

Example 1 with RedirectPage

use of org.apache.wicket.markup.html.pages.RedirectPage in project wicket by apache.

the class RestartResponseAtInterceptPageExceptionTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            super.init();
            getSecuritySettings().setAuthorizationStrategy(new AbstractPageAuthorizationStrategy() {

                @Override
                protected <T extends Page> boolean isPageAuthorized(Class<T> pageClass) {
                    if (pageClass != RedirectPage.class) {
                        RedirectPage intercept = new RedirectPage("http://example.com/path");
                        throw new RestartResponseAtInterceptPageException(intercept);
                    }
                    return true;
                }
            });
        }
    };
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) AbstractPageAuthorizationStrategy(org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy) RedirectPage(org.apache.wicket.markup.html.pages.RedirectPage)

Example 2 with RedirectPage

use of org.apache.wicket.markup.html.pages.RedirectPage in project gitblit by gitblit.

the class TicketPage method createDeletePatchsetLink.

private Link<Void> createDeletePatchsetLink(final RepositoryModel repositoryModel, final Patchset patchset) {
    Link<Void> deleteLink = new Link<Void>("deleteRevision") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            Repository r = app().repositories().getRepository(repositoryModel.name);
            UserModel user = GitBlitWebSession.get().getUser();
            if (r == null) {
                if (app().repositories().isCollectingGarbage(repositoryModel.name)) {
                    error(MessageFormat.format(getString("gb.busyCollectingGarbage"), repositoryModel.name));
                } else {
                    error(MessageFormat.format("Failed to find repository {0}", repositoryModel.name));
                }
                return;
            }
            // Construct the ref name based on the patchset
            String ticketShard = String.format("%02d", ticket.number);
            ticketShard = ticketShard.substring(ticketShard.length() - 2);
            final String refName = String.format("%s%s/%d/%d", Constants.R_TICKETS_PATCHSETS, ticketShard, ticket.number, patchset.number);
            Ref ref = null;
            boolean success = true;
            try {
                ref = r.getRef(refName);
                if (ref != null) {
                    success = JGitUtils.deleteBranchRef(r, ref.getName());
                } else {
                    success = false;
                }
                if (success) {
                    // clear commit cache
                    CommitCache.instance().clear(repositoryModel.name, refName);
                    // optionally update reflog
                    if (RefLogUtils.hasRefLogBranch(r)) {
                        RefLogUtils.deleteRef(user, r, ref);
                    }
                    TicketModel updatedTicket = app().tickets().deletePatchset(ticket, patchset, user.username);
                    if (updatedTicket == null) {
                        success = false;
                    }
                }
            } catch (IOException e) {
                logger().error("failed to determine ticket from ref", e);
                success = false;
            } finally {
                r.close();
            }
            if (success) {
                getSession().info(MessageFormat.format(getString("gb.deletePatchsetSuccess"), patchset.number));
                logger().info(MessageFormat.format("{0} deleted patchset {1} from ticket {2}", user.username, patchset.number, ticket.number));
            } else {
                getSession().error(MessageFormat.format(getString("gb.deletePatchsetFailure"), patchset.number));
            }
            // Force reload of the page to rebuild ticket change cache
            String relativeUrl = urlFor(TicketsPage.class, getPageParameters()).toString();
            String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
            setResponsePage(new RedirectPage(absoluteUrl));
        }
    };
    WicketUtils.setHtmlTooltip(deleteLink, MessageFormat.format(getString("gb.deletePatchset"), patchset.number));
    deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(getString("gb.deletePatchset"), patchset.number)));
    return deleteLink;
}
Also used : TicketModel(com.gitblit.models.TicketModel) IOException(java.io.IOException) JavascriptEventConfirmation(com.gitblit.wicket.panels.BasePanel.JavascriptEventConfirmation) UserModel(com.gitblit.models.UserModel) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RedirectPage(org.apache.wicket.markup.html.pages.RedirectPage) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) BookmarkablePageLink(org.apache.wicket.markup.html.link.BookmarkablePageLink) SimpleAjaxLink(com.gitblit.wicket.panels.SimpleAjaxLink) Link(org.apache.wicket.markup.html.link.Link) IconAjaxLink(com.gitblit.wicket.panels.IconAjaxLink)

Aggregations

RedirectPage (org.apache.wicket.markup.html.pages.RedirectPage)2 TicketModel (com.gitblit.models.TicketModel)1 UserModel (com.gitblit.models.UserModel)1 JavascriptEventConfirmation (com.gitblit.wicket.panels.BasePanel.JavascriptEventConfirmation)1 IconAjaxLink (com.gitblit.wicket.panels.IconAjaxLink)1 SimpleAjaxLink (com.gitblit.wicket.panels.SimpleAjaxLink)1 IOException (java.io.IOException)1 AbstractPageAuthorizationStrategy (org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy)1 BookmarkablePageLink (org.apache.wicket.markup.html.link.BookmarkablePageLink)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1 Link (org.apache.wicket.markup.html.link.Link)1 MockApplication (org.apache.wicket.mock.MockApplication)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1