Atlassian has restricted the functionality that user macro’s can use, now some of my user macro’s stopped working. I now want to provide them in a plugin. One of them I can’t get to work.
I think the ac:structured-macro tag can’t be rendered. How do get this to work? Is there a work-around?
Any help will be appreciated.
macro:
package com.atlassian.tutorial.myPlugin.macro;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.confluence.renderer.radeox.macros.MacroUtils;
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.confluence.user.ConfluenceUser;
import com.atlassian.confluence.util.velocity.VelocityUtils;
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.sal.api.user.UserKey;
import java.util.Map;
@Scanned
public class CurrentUserTaskReport implements Macro {
@Override
public String execute(Map<String, String> map, String body, ConversionContext conversionContext) throws MacroExecutionException {
// Create the Velocity Context
Map<String, Object> context = MacroUtils.defaultVelocityContext();
ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get();
UserKey userKey = currentUser.getKey();
context.put("currentUser", currentUser);
context.put("userKey", userKey);
currentUser.getFullName();
// Render the Template
String result = VelocityUtils.getRenderedTemplate("templates/CurrentUserTaskReport.vm", context);
return result;
}
@Override
public BodyType getBodyType() {
return BodyType.NONE;
}
@Override
public OutputType getOutputType() {
return OutputType.BLOCK;
}
}
template:
<ac:structured-macro ac:name="tasks-report-macro" ac:schema-version="1">
<ac:parameter ac:name="assignees">
<ri:user ri:userkey="${userKey}"/>
</ac:parameter>
</ac:structured-macro>
<h1>Hi there! $currentUser.fullName</h1>
atlassian-plugin.xml:
<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}" />
<param name="plugin-icon">images/pluginIcon.png</param>
<param name="plugin-logo">images/pluginLogo.png</param>
</plugin-info>
<!-- add our i18n resource -->
<resource type="i18n" name="i18n" location="myPlugin"/>
<!-- add our web resources -->
<web-resource key="myPlugin-resources" name="myPlugin Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="velocity" name="template" location="/templates/CurrentUserTaskReport.vm"/>
<resource type="download" name="myPlugin.css" location="/css/myPlugin.css"/>
<resource type="download" name="myPlugin.js" location="/js/myPlugin.js"/>
<resource type="download" name="images/" location="/images"/>
<context>myPlugin</context>
</web-resource>
<xhtml-macro name="current-user-task-report-macro" class="com.atlassian.tutorial.myPlugin.macro.CurrentUserTaskReport" key='current-user-task-report-macro'>
<description key="current-user-task-report.macro.desc"/>
<category name="admin"/>
<parameters/>
</xhtml-macro>
</atlassian-plugin>
Expected result:
A list with open tasks for current user
Result: