Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created September 28, 2016 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jechlin/cf096c1da6ad5b5e44a8a803bd6fcaa5 to your computer and use it in GitHub Desktop.
Save jechlin/cf096c1da6ad5b5e44a8a803bd6fcaa5 to your computer and use it in GitHub Desktop.
import com.atlassian.jira.bc.project.ProjectAction
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserProjectHistoryManager
import com.atlassian.jira.util.I18nHelper
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory
import com.atlassian.plugin.web.api.model.WebFragmentBuilder
def historyManager = ComponentAccessor.getComponent(UserProjectHistoryManager)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
if (user) {
def historyItems = historyManager.getProjectHistoryWithPermissionChecks(ProjectAction.VIEW_ISSUES, user)
def velocityRequestContextFactory = ComponentAccessor.getComponent(VelocityRequestContextFactory)
def requestContext = velocityRequestContextFactory.getJiraVelocityRequestContext()
def baseUrl = requestContext.getBaseUrl()
def beanFactory = ComponentAccessor.getComponent(I18nHelper.BeanFactory)
def i18n = beanFactory.getInstance(user)
return historyItems.findAll { project ->
project.projectCategory?.name == "CAT1" // modify project category name to suit
}.collect { project ->
String iconUrl = null
if (project.getAvatar())
{
def avatar = project.getAvatar()
iconUrl = baseUrl + "/secure/projectavatar?pid=" + project.id + "&avatarId=" + avatar.id + "&size=small"
}
new WebFragmentBuilder(50).
id("project-cat-web-item-${project.key.toLowerCase()}").
label(project.name + " (" + project.key + ")").
title(i18n.getText("tooltip.browseproject.specified", project.name)).
styleClass("").
addParam("iconUrl", iconUrl).
webItem("").
url(baseUrl + "/browse/" + project.key).
build()
}
}
[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment