#!/usr/bin/env ruby ################################################################################ # Copyright 2007 Codehaus Foundation # # # # Licensed under the Apache License, Version 2.0 (the "License"); # # you may not use this file except in compliance with the License. # # You may obtain a copy of the License at # # # # http://www.apache.org/licenses/LICENSE-2.0 # # # # Unless required by applicable law or agreed to in writing, software # # distributed under the License is distributed on an "AS IS" BASIS, # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # # limitations under the License. # ################################################################################ # This script is extremely useful for migrating users from one group to another # where you don't want duplicates; i.e. creating an admin group which has a superset # of the permission of the second group. $: << 'lib' require 'jira4r/jira_tool.rb' # Will if ARGV.length != 5 puts "Usage: subtract-members URL USER PASS GROUP-A GROUP-B" puts " Removes all members from GROUP-A that are in GROUP-B" puts " subtract-members http://jira.example.com jim password clown-developers clown-dev" exit 1 end url, username, password, group_a, group_b = ARGV jira = Jira4R::JiraTool.new(2, url) jira.login(username, password) jira_group_a = jira.getGroup(group_a) jira_group_b = jira.getGroup(group_b) remote_users = {} users_a = jira_group_a.users.collect { |u| remote_users[u.name] = u u.name } users_b = jira_group_b.users.collect { |u| remote_users[u.name] = u u.name } for user in users_a if users_b.include?(user) puts "Removing #{user} from #{group_a}" jira.removeUserFromGroup(jira_group_a, remote_users[user]) end end