Created
April 3, 2013 13:02
-
-
Save wbrady/5301020 to your computer and use it in GitHub Desktop.
Fix confluence space names
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| | |
user_groups = client.getUserGroups(token, user) | |
next if !user_groups.include?(employees_group) | |
next if !(space = spaces.find{|space| space['name'] == user }) | |
full_name = client.getUser(token, user)['fullname'] | |
full_space = client.getSpace(token, space['key']) | |
puts "Updating #{full_name}'s space '#{full_space['name']}' to '#{full_name}'" | |
full_space['name'] = full_name | |
client.storeSpace(token, full_space); | |
end | |
puts "Done correcting 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