mass subscribe to a group?

18 views
Skip to first unread message

Trevor

unread,
Oct 4, 2010, 7:38:56 PM10/4/10
to Gitorious
hi, is there a way to mass subscribe a bunch of users to a group,
outside of SQL? The interface only lets me add one at a time, which
will take forever.

Cheers,
Trevor

Marius Mårnes Mathiesen

unread,
Oct 5, 2010, 2:03:13 AM10/5/10
to gito...@googlegroups.com
Trevor,
As you mentioned above, there is no UI for mass subscribing users to a team. The application console, however, should be helpful:

user_logins = ["john","jane","billy"] # Usernames for users being invited
team_name = "core-dev" # The name of the team
inviter = User.find_by_login!("trevor") # "Remember" who added the members
role = Role.member # Regular members, for admin members use Role.admin

group = Group.find_by_name!(team_name)
user_logins.each do | login | 
  user = User.find_by_login!(login)
  membership = Membership.build_invitation(inviter, :group => group, :user => user, :role => role)
  membership.save!     
end

This is pretty much the same that the controller used in the UI will do, run it by going to the application root and enter

  ruby script/console <RAILS_ENV>

If this is something that needs to be done on a regular basis, id could be an idea to put it into a script (the script directory is well suited for this), perhaps prompting interactively for user names, team names and roles...

Happy hacking!
- Marius

Trevor

unread,
Oct 5, 2010, 7:39:31 PM10/5/10
to Gitorious
Thanks as always Marius, that did the trick!

Trevor

On Oct 4, 11:03 pm, Marius Mårnes Mathiesen
Reply all
Reply to author
Forward
0 new messages