Due to the format of our page titles, our page URLs always resolve to ../pages/viewpage.action?pageId=########
And people are constantly receiving a URL to a page that results in the error: You don't have permission to view this page.
This results in numerous tickets to our instance admin to determine the space/admins of the page.
It looks like I could possibly write a user macro to get ancestors (which also might not be viewable by the user) so what I really need is to identify the space or the page admins based on the pageId.
Are you looking for a way for your help desk to look up the space based on the page id or are you looking to show that to the user in the permissions message when it shows up?
All the options are interesting, I would like to get the name of the space to grant access to this page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
com.atlassian.confluence.pages.Page page = pageManager.getPage(pageId);
com.atlassian.confluence.spaces.Space space = page.getSpace();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getPage(long id) - Deprecated.
since 7.3.0, we can use ContentService.find(Expansion...) from plugins
com.atlassian.confluence.api.model.content.Content content = contentService.find(new Expansion("space")).withId(ContentId.of(pageId)).fetchOrNull();
com.atlassian.confluence.api.model.content.Space space = content.getSpace();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How can we insert that into a user macro ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
^^^^ 100% this ^^^^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
inside a macro:
long pageId = conversionContext.getEntity().getId();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
gotti_p : A one-line macro... Not really helping at all.
Where do you put the pageID in that ? In the getId(<pageID>) ?
The long pageId variable will contain the space ID ? Not clear or maybe you misread the initial question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thought the rest was clear from the code before
inside the macros execute-method you get the pageId and with that you get the page and the space, etc
public String execute(Map<String, String> params, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException {
String body = conversionContext.getEntity().getBodyAsString();
long pageId = conversionContext.getEntity().getId();
Page page = pageManager.getPage(pageId);
long spaceId = page.getSpace().getId();
....
}
pageManager you get by injection similar to all other components you might need:
constructor:
@Autowired
public MyMacro(@ComponentImport PageManager pageManager,
@ComponentImport SpaceManager spaceManager,
....
) {
this.pageManager = pageManager;
this.spaceManager = spaceManager;
....
}
If the question is about macros in general here is a sample:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you just need to get the Space and the linked page in human readable for one time (without Macro etc.) you just could try to open that page and look into the Audit log, cause a request for a restricted page, where you don´t have the needed rights will result in a audit log listing. In the audit log the space and respective page is linked.
hope that helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.