[Edited with optimized variable creation for {{viewers}} and {{editors}}]
So when people start messing with Restrictions in Confluence, they often ask why Edit Restrictions are not inherited by child pages.
And as I was explaining this limitation today to one of my users, I thought, ok in some cases, it might be helpful if say, for a certain space, or certain pages, all child pages would inherit Edit restrictions via an Automation rule copying them from the parent.
So, I spent a little time and figured out how to do it. It's entirely possible I've missed something, so I welcome your feedback!
In testing, my rule is triggered when a page is moved. As tested it runs on every page in a single space. More on this at the end under "Building on this"
We're going to clear all restrictions since we will be copying everything from the parent. So I'm setting Restrictions to "Anyone in the space can view and edit"
We using the Get restrictions API call to get all of the Restrictions of the Parent Page. That call is:
https://boomaster.atlassian.net/wiki/rest/api/content/{{page.parent.id}}/restriction
From the response to the API call, we're extracting all of the Users and Groups with read permission, and formatting them into a JSON excerpt that we are storing in a variable named {{viewers}}.
This "code" is a bit complex and was what took the longest time:
{{#webResponse.body.results}}{{#if(equals(operation, "read"))}}"user": {{restrictions.user.results.asJsonObjectArray("accountId")}}
,"group": {{restrictions.group.results.asJsonObjectArray("id")}}
{{/}}{{/}}
From the response to the API call, we're extracting all of the Users and Groups with update permission, and formatting them into a JSON excerpt that we are storing in a variable named {{editors}}. It's the same as above, but is looking for the "update" operation instead of "read":
{{#webResponse.body.results}}{{#if(equals(operation, "update"))}}"user": {{restrictions.user.results.asJsonObjectArray("accountId")}}
,"group": {{restrictions.group.results.asJsonObjectArray("id")}}
{{/}}{{/}}
We use the Add restrictions API call to apply the parent permissions that we've extracted above.
Custom data:
{ "results": [
{
"operation": "read",
"restrictions": {
{{viewers}}
}
},
{
"operation": "update",
"restrictions": {
{{editors}}
}
}
]
}
And welp, that's basically it.
If you don't want this behavior on every page in your space, you could add conditions to restrict it to specific Parent pages by doing a smart values condition to see if {{page.parent.id}} matches regular expression "^(1234|456|789)$".
Also, this rule only triggers on page moves. You could also implement it when a page is published, adding a condition to check if there is a parent page.
As I said, people have been asking about this forever.
From 2020's Is there a way to inherit editing permissions? I learned about Edit Permission Inheritance which is a paid app that adds a feature to toggle Inheritance of Edit Restrictions on specific pages. All descendants of those pages will have the same Edit Restrictions.
But then in Nov 2022 @Alexandra Astor said that:
We tried Edit Permission Inheritance by Purde Software, however, once the edit permissions are inherited it is not possible to turn them off.
And @Nic Brough -Adaptavist- responded:
Inheriting edit restrictions does not make a lot of sense, it's incredibly limiting.
However, setting them down through a tree can be useful. Not inheriting, the way view restrictions do it automatically, but a one-off "parse the tree, set edit restriction on all pages automatically". This would leave people with the flexibility to change the restrictions later.
Welp, here you go, Nic. :-} That's kind of what my Automation does, when you Move a page under page with restrictions.
You could take the core logic of the rule and create a manually triggered Rule that would copy the current page's restrictions to all descendants. (I believe this CQL would work: ancestor = {{page.id}})
Darryl Lee
Sr. Atlassian Systems Engineer
Roku, Inc.
San Jose, CA
203 accepted answers
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
4 comments