2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-02 10:18:07 +01:00
|
|
|
class Groups::MembersController < Groups::BaseController
|
2011-12-05 12:32:18 +00:00
|
|
|
is_related_controller!
|
2012-05-03 15:08:02 +01:00
|
|
|
belongs_to :group, :finder => 'find_by_insensitive_uname!', :optional => true
|
2011-12-05 12:32:18 +00:00
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
before_filter lambda { authorize! :manage_members, @group }
|
2011-12-05 12:32:18 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-05-03 15:08:02 +01:00
|
|
|
params['user'].keys.each do |user_id|
|
2012-03-01 15:41:40 +00:00
|
|
|
role = params['user'][user_id]
|
2012-04-26 02:38:33 +01:00
|
|
|
if relation = parent.actors.where(:actor_id => user_id, :actor_type => 'User') #find_by_actor_id_and_actor_type(user_id, 'User')
|
2012-05-03 13:23:19 +01:00
|
|
|
relation.update_all(:role => role) if parent.owner.id.to_s != user_id
|
2012-03-01 15:41:40 +00:00
|
|
|
else
|
2012-04-26 02:38:33 +01:00
|
|
|
relation = parent.actors.build(:actor_id => user_id, :actor_type => 'User', :role => role)
|
2012-03-01 15:41:40 +00:00
|
|
|
relation.save!
|
|
|
|
end
|
2012-05-03 15:08:02 +01:00
|
|
|
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
|
2012-05-02 10:18:07 +01:00
|
|
|
redirect_to group_members_path(parent)
|
2011-12-05 12:32:18 +00:00
|
|
|
end
|
|
|
|
|
2012-03-01 14:23:26 +00:00
|
|
|
def remove
|
2012-05-02 10:18:07 +01:00
|
|
|
all_user_ids = []
|
2012-05-03 15:43:23 +01:00
|
|
|
params['user_remove'].each do |user_id, remove|
|
|
|
|
all_user_ids << user_id if remove == ["1"] && parent.owner.id.to_s != user_id
|
2012-05-03 15:08:02 +01:00
|
|
|
end if params['user_remove']
|
2012-05-02 10:18:07 +01:00
|
|
|
all_user_ids.each do |user_id|
|
|
|
|
u = User.find(user_id)
|
|
|
|
Relation.by_actor(u).by_target(parent).each {|r| r.destroy}
|
2012-03-01 15:41:40 +00:00
|
|
|
end
|
2012-05-02 10:18:07 +01:00
|
|
|
redirect_to group_members_path(parent)
|
2011-12-05 12:32:18 +00:00
|
|
|
end
|
|
|
|
|
2011-12-09 23:40:13 +00:00
|
|
|
def add
|
|
|
|
if params['user_id'] and !params['user_id'].empty?
|
|
|
|
@user = User.find_by_uname(params['user_id'])
|
2012-04-26 02:38:33 +01:00
|
|
|
unless parent.actors.exists? :actor_id => @user.id, :actor_type => 'User'
|
|
|
|
relation = parent.actors.build(:actor_id => @user.id, :actor_type => 'User', :role => params[:role])
|
2011-12-10 17:26:57 +00:00
|
|
|
if relation.save
|
|
|
|
flash[:notice] = t("flash.members.successfully_added")
|
|
|
|
else
|
|
|
|
flash[:error] = t("flash.members.error_in_adding")
|
|
|
|
end
|
2011-12-09 23:40:13 +00:00
|
|
|
else
|
2011-12-10 17:26:57 +00:00
|
|
|
flash[:error] = t("flash.members.already_added")
|
2011-12-09 23:40:13 +00:00
|
|
|
end
|
|
|
|
end
|
2012-05-02 10:18:07 +01:00
|
|
|
redirect_to group_members_path(parent)
|
2011-12-09 23:40:13 +00:00
|
|
|
end
|
2011-12-05 12:32:18 +00:00
|
|
|
end
|