Rizwan Pochi
Rizwan Pochi

Reputation: 11

Custom Jira Project Settings Button Navigating to a New Page Instead of Rendering in the Same Page, How to resolve this?

Description:

We have implemented a custom button in Jira project settings that, when clicked, should display content on the right side of the project settings page (similar to other project settings like "Users and Roles"). However, the current behavior is that clicking the button navigates to a completely new page instead of rendering the content on the same page.

Here's the current setup:

Web section and web item: We have added a custom section and item in the project settings:

<web-section key="custom-project-settings-section" location="atl.jira.proj.config">
<label key="custom.project.settings.section.label"/>
</web-section>

<web-item key="custom-project-settings-item" section="atl.jira.proj.config/custom-project-settings-section" weight="1000">
<label key="custom.project.settings.item.label"/>
<link linkId="custom-project-settings-link">/plugins/servlet/project-config/${project.key}/EntryPointServlet?projectKey=$projectKeyEncoded&amp;projectId=$project.id</link>
</web-item>

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException {
ApplicationUser currUser = authenticationContext.getLoggedInUser();
ProjectManager manager = ComponentAccessor.getComponent(ProjectManager.class);
ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class);
ProjectRole role = projectRoleManager.getProjectRole("Administrators");

if (projectRoleManager.isUserInProjectRole(currUser, role, manager.getProjectByCurrentKeyIgnoreCase(projectKey))) {
templateRenderer.render("templates/custom-project-settings.vm", map, response.getWriter());
} else {
redirectToLogin(request, response);
}
}

The Issue: While the servlet and button work as expected in terms of functionality, the button navigates to a new page when clicked instead of rendering the content within the existing project settings screen (like the "Users and Roles" section, which stays on the same page).

The Expected Behavior: Clicking the custom button should load content into the right-hand side of the project settings page, maintaining the user within the current page, rather than redirecting them to a new page, without the project settings buttons from the left side panel.

Upvotes: 1

Views: 34

Answers (1)

ihaveagirlfriend
ihaveagirlfriend

Reputation: 1

You need to provide context to your velocity template which is done by including additional meta tags in template head. In your case the template should look something like this:

$webResourceManager.requireResource("package.artifact:resource-key")
<html>
    <head>
        <meta name="decorator" content="atl.admin"/>
        <meta name="projectKey" content="${projectKey}"/>
        <meta name="admin.active.section" content="atl.jira.proj.config"/>
        <title>Some title</title>
    </head>
    <body>
        whatsoever
    </body>
</html>

Also the web item link defined in atlassian-plugin.xml should contain a project key as a query parameter

<web-item key="item.key" section="section.key">
    <label key="label.key"/>
    <link linkId="link-key">/secure/webwork-alias!default.jspa?projectKey=$projectKeyEncoded</link>
</web-item>

Similar approach works for admin screens, where you could use for example this

<meta name="decorator" content="atl.admin" />
<meta name="admin.active.section" content="plugin-admin-config-link" />

I recommend you to reach out to the atlassian dev community for atlassian related questions - similar question answered here

Upvotes: 0

Related Questions