Created
March 29, 2013 18:54
-
-
Save wbrady/5272811 to your computer and use it in GitHub Desktop.
Ruby script to create Confluence personal spaces for users who don't have one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'xmlrpc/client' | |
puts "Please enter your Confluence base URL:" | |
base = STDIN.gets.chomp | |
puts "Please enter your username:" | |
user_name = STDIN.gets.chomp | |
puts "Please enter your password:" | |
system 'stty -echo' | |
password = STDIN.gets.chomp | |
system 'stty echo' | |
employees_group = 'Employees' | |
client = XMLRPC::Client.new_from_uri(base + '/rpc/xmlrpc') | |
client = client.proxy('confluence2') | |
begin | |
puts "Logging in..." | |
token = client.login(user_name, password) | |
users = client.getActiveUsers(token, true) | |
spaces = client.getSpaces(token) | |
users.each do |user| | |
space_key = "~#{user}" | |
next if spaces.map{|space| space['key'] }.include?(space_key) | |
user_groups = client.getUserGroups(token, user) | |
next if !user_groups.include?(employees_group) | |
full_name = client.getUser(token, user)['fullname'] | |
puts "Creating space for #{full_name}..." | |
new_space = { | |
'key' => space_key, | |
'homePage' => '', | |
'name' => user, | |
'url' => "#{base}/display/#{space_key}" | |
} | |
client.addPersonalSpace(token, new_space, user) | |
puts "Assigning full permissions to #{full_name} for their own space" | |
admin_permissions = client.getSpaceLevelPermissions(token) | |
client.addPermissionsToSpace(token, admin_permissions, user, space_key) | |
puts "Assigning view page and add comment permissions to all employees" | |
user_permissions = ['VIEWSPACE', 'COMMENT'] | |
client.addPermissionsToSpace(token, user_permissions, employees_group, space_key) | |
puts | |
end | |
puts "Done creating new spaces" | |
rescue XMLRPC::FaultException => e | |
puts "Error:" | |
puts e.faultCode | |
puts e.faultString | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment