This article explains how to replace group permissions with individual permissions in spaces using Confluence Command Line Interface (CLI).
Instructions
Run the below CLI command to get CSV file of all space permissions:
--action runFromSpaceList --common "--action getSpacePermissionList --file permissions.csv --append"
- Import the above "permissions.csv" to SQL database table named "spacepermissions". Be sure to preserve the column names.
Export the below SQL query output to a CSV file (with column headers) named "groups.csv":
select distinct Id as `group` from confluence.spacepermissions where `Id Type` = 'group'
Run the below CLI command to create a list of users for the groups:
--action runFromGroupList --file groups.csv --common "--action getUserList --columns \"1,2,3\" --file spaceusers.csv --append"
- Import the above "spaceusers.csv" to an SQL database table named "spaceusers". Be sure to preserve the column names.
Export the below SQL query output to a CSV (with column headers) file named "spaceuserpermissions.csv":
select distinct space,User as "userId", concat_ws(',', if(`View`='Yes','VIEWSPACE',''), if(`Delete Own`='Yes','REMOVEOWNCONTENT',''), if(`Pages Add`='Yes','EDITSPACE',''), if(`Pages Delete`='Yes','REMOVEPAGE',''), if(`Blog Add`='Yes','EDITBLOG',''), if(`Blog Delete`='Yes','REMOVEBLOG',''), if(`Attachments Add`='Yes','CREATEATTACHMENT',''), if(`Attachments Delete`='Yes','REMOVEATTACHMENT',''), if(`Comments Add`='Yes','COMMENT',''), if(`Comments Remove`='Yes','REMOVECOMMENT',''), if(`Restrictions`='Yes','SETPAGEPERMISSIONS',''), if(`Mail Delete`='Yes','REMOVEMAIL',''), if(`Space Export`='Yes','EXPORTSPACE',''), if(`Admin`='Yes','SETSPACEPERMISSIONS','') ) as "permissions" from confluence.spacepermissions, confluence.spaceusers where confluence.spacepermissions.Id = confluence.spaceusers.User and confluence.spacepermissions.`Id Type` = 'user'
Run the following CLI command to add user permissions:
--action runFromCsv --file "spaceuserpermissions.csv" --common "--action addPermissions"
Export the below SQL query output to a CSV file (with column headers) named "groupspaces.csv":
select distinct Space, Id as "group" from confluence.spacepermissions where `Id Type` = 'group'
Run the following CLI command to remove group permissions:
--action runFromCsv --file groupspaces.csv --common "--action removePermissions --permissions @all"
- It is recommended to test the commands in a non-production environment or run the action with --simulate parameter to verify the behavior before deploying.
- The use of sample or demo SQL databases are recommended for importing CSV files.
- SQL Quires mentioned in article refers to mysql database and modify the queries according to SQL database.