Hey all,
I wanted to jump in here, I hope you're all enjoying some of the enhancements we've made for making it a bit easier to manage guests at scale. While we continue to make progress in this area, I wanted to share a potential short term solution for those of you that are leveraging our Confluence REST APIs.
What I've heard, is that there is a need to assign all guests, within a group, access to the same space. While default space access is a really good start, there may be some edge cases around it (maybe multiple groups needing different sets of space access).
The existing APIs that I wanted to highlight that could be leveraged to build a custom solution around space assignment, would be the following:
Leveraging those APIs we should be able to identify all guest users in a given group, and grant the required space permissions to "assign" space access for a guest (guests by default always be granted read:space, create:page, create:comment, and create:attachment on a given space).
Below is an example of a script that will use the APIs listed above to take a group name, lookup all of the guest users within that group, and assign the correct space permissions if possible (the space permission endpoint will return an error if the guest user already has a space assigned).
#!/bin/bash
groupName="[insert-group-name-here]" # The name of the guest group you want to assign spaces for
spaceKey="[insert-space-key-here]" # The space key of the space you want to assign to your guests
hostname=[insert-confluence-domain-here] # The domain for your Confluence site
result=$(http GET "$hostname/wiki/rest/api/group")
groupId=$(echo $result | jq -r '.results[] | select(.name=="'$groupName'") | .id')
result=$(http GET "$hostname/wiki/rest/api/group/$groupId/membersByGroupId?expand=isExternalCollaborator")
guestIds=$(echo $result | jq '.results[] | select(.isExternalCollaborator==true) | .accountId')
guestIds=($guestIds)
echo "Start assigning space permissions on $spaceKey for ${#guestIds[@]} guests..."
for guestId in "${guestIds[@]}"; do
(
if http --check-status --ignore-stdin POST "$hostname/wiki/rest/api/space/$spaceKey/permission" --raw '{ "subject": { "type": "user", "identifier": '"$guestId"' }, "operation": { "key": "read", "target": "space"}}' &>output.txt:; then
echo "✅ successfully assigned read:space on $spaceKey for $guestId"
if http --check-status --ignore-stdin POST "$hostname/wiki/rest/api/space/$spaceKey/permission" --raw '{ "subject": { "type": "user", "identifier": '"$guestId"' }, "operation": { "key": "create", "target": "page"}}' &>output.txt:; then
echo "✅ successfully assigned create:page on $spaceKey for $guestId"
else
echo "❌ failed to assign create:page on $spaceKey for $guestId"
fi
if http --check-status --ignore-stdin --meta POST "$hostname/wiki/rest/api/space/$spaceKey/permission" --raw '{ "subject": { "type": "user", "identifier": '"$guestId"' }, "operation": { "key": "create", "target": "comment"}}' &>output.txt:; then
echo "✅ successfully assigned create:comment on $spaceKey for $guestId"
else
echo "❌ failed to assign create:comment on $spaceKey for $guestId"
fi
if http --check-status --ignore-stdin --meta POST "$hostname/wiki/rest/api/space/$spaceKey/permission" --raw '{ "subject": { "type": "user", "identifier": '"$guestId"' }, "operation": { "key": "create", "target": "attachment"}}' &>output.txt:; then
echo "✅ successfully assigned create:attachment on $spaceKey for $guestId"
else
echo "❌ failed to assign create:attachment on $spaceKey for $guestId"
fi
else
echo "❌ failed to assign read:space on $spaceKey for $guestId"
fi
)
done
echo "Finished assigning space permissions on $spaceKey for ${#guestIds[@]} guests..."
Hopefully this information is helpful, if there are any questions, please reach out!
Yeah, this would be a needed change for sure.
We also have guests segragated by their respective companies, and obviously they cannot see each others spaces, but when a larger customer has tens of users having to add them as guests one by one is a nightmare.