It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Limit plugin web-item visibility in project tab panel Edited

Hi colleagues.

I have webwork with web-item  that inserted in project tab panel. How can i restrict this web-item appereance in project tab panel for target project?

 

Thanks in advice.

1 answer

1 accepted

Solution is in using conditions setting of web-item. And impelement Condition class. 

public class ConditionCheck implements Condition
{
    private static final Logger log = Logger.getLogger(ConditionCheck.class);
    private SettingsStorageService settingsStorageService;
    private String projectId;
    public ConditionCheck(PluginSettingsFactory pluginSettingsFactory)
    {
        this.settingsStorageService = new SettingsStorageService(pluginSettingsFactory);
    }
    @Override
    public void init(Map<String, String> map) throws PluginParseException {
    }

    @Override
    public boolean shouldDisplay(Map context) {
        final JiraHelper jiraHelper = (JiraHelper)context.get(JiraWebInterfaceManager.CONTEXT_KEY_HELPER);
        List<Project> projects = Utils.getInquirerProjects(settingsStorageService, "key");
        String state = settingsStorageService.getSetting("enebled");
        if(state.equals("Disabled"))
        {
            return true;
        }
        if(state.equals("Enabled(All projects)"))
        {
            return false;
        }
        try
        {
            String projectId = jiraHelper.getProject().getId().toString();
            for(Project project: projects)
            {
                if(project.getProjectId().equals(projectId))
                {
                    return !project.isSelected();
                }
            }
        }
        catch (Exception e)
        {
            return true;
        }
        return true;
    }
}

 

Hi Александр Верзаков,

Could you elaborate the solution. I am kind of new to Jira development, so, any help would be appreciated.

PFA my code snippet for atlassian-plugin.xml



<project-blueprint
key="my-project-template" weight="90">
<label key="my.project.template.name"/>
<projectTypeKey>business</projectTypeKey>
<!--<projectTypeKey>software</projectTypeKey>-->
<description key="my.project.template.description"/>
<longDescription key="my.project.template.description.long"/>
<infoPage soy-template="JIRA.Templates.ProjectTemplates.Tutorial.renderMyProjectTemplateExplanation"/>
<icon location="images/icon.jpg"/>
<backgroundIcon location="images/background.jpg"/>
<add-project>
<hook class="com.example.plugins.tutorial.MyAddProjectHook"/>
<descriptor file="/config/my-project-template-config.json"/>
</add-project>
</project-blueprint>


<web-item name="project-web-item" i18n-name-key="project--web--item.name" key="project--web--item"
section="jira.project.sidebar.plugins.navigation" weight="300">
<description key="project--web--item.description">The project-web-item Plugin</description>
<label key="project--web--item.label"/>
<!--This web item links to a servlet-->
<link linkId="project--web--item-link">/plugins/servlet/issuecrud</link>
<param name="iconClass" value="aui-icon-large icon-sidebar-release"/>
</web-item>

I want the web-item above to be displayed only when someone creates a project using my custom project blueprint only.

---------------------------

Also, PFA my code for MyAddProjectHook.java for the custom project template/blueprint.

package com.example.plugins.tutorial;

import com.atlassian.jira.project.template.hook.AddProjectHook;
import com.atlassian.jira.project.template.hook.ValidateData;
import com.atlassian.jira.project.template.hook.ValidateResponse;
import com.atlassian.jira.project.template.hook.ConfigureData;
import com.atlassian.jira.project.template.hook.ConfigureResponse;


public class MyAddProjectHook implements AddProjectHook
{
@Override
public ValidateResponse validate(final ValidateData validateData) {
ValidateResponse validateResponse = ValidateResponse.create();

//projectKey
if (validateData.projectName().equals("TEST")) {
validateResponse.addErrorMessage("Invalid Project Name");
}

return validateResponse;
}

@Override
public ConfigureResponse configure(final ConfigureData configureData)
{
return ConfigureResponse.create();
}
}

 

 Regards and thanks in advance!

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted Oct 09, 2018 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

509 views 6 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you