rosa-build/app/controllers/groups/members_controller.rb

51 lines
1.6 KiB
Ruby
Raw Normal View History

class Groups::MembersController < Groups::BaseController
2011-12-05 12:32:18 +00:00
is_related_controller!
belongs_to :group, :finder => 'find_by_insensitive_uname!', :optional => true
2011-12-05 12:32:18 +00:00
before_filter lambda { authorize! :manage_members, @group }
2011-12-05 12:32:18 +00:00
def index
end
def update
params['user'].keys.each do |user_id|
role = params['user'][user_id]
if relation = parent.actors.where(:actor_id => user_id, :actor_type => 'User') #find_by_actor_id_and_actor_type(user_id, 'User')
relation.update_all(:role => role) if parent.owner.id.to_s != user_id
else
relation = parent.actors.build(:actor_id => user_id, :actor_type => 'User', :role => role)
relation.save!
end
end if params['user']
2011-12-05 12:32:18 +00:00
if parent.save
flash[:notice] = t("flash.members.successfully_changed")
else
flash[:error] = t("flash.members.error_in_changing")
end
redirect_to group_members_path(parent)
2011-12-05 12:32:18 +00:00
end
def remove
all_user_ids = []
params['user_remove'].each do |user_id, remove|
2012-10-16 14:42:52 +01:00
all_user_ids << user_id if remove == ["1"]
end if params['user_remove']
2012-10-16 14:42:52 +01:00
User.where(:id => all_user_ids).each do |user|
parent.remove_member(user)
end
redirect_to group_members_path(parent)
2011-12-05 12:32:18 +00:00
end
def add
2012-11-13 14:29:59 +00:00
@user = User.find_by_uname(params[:user_uname])
if !@user
2012-11-13 14:29:59 +00:00
flash[:error] = t("flash.collaborators.wrong_user", :uname => params[:user_uname])
elsif parent.add_member(@user, params[:role])
flash[:notice] = t("flash.members.successfully_added")
else
flash[:error] = t("flash.members.error_in_adding")
end
redirect_to group_members_path(parent)
end
2011-12-05 12:32:18 +00:00
end