|
|
|
@ -242,14 +242,56 @@ class SubjectsController < ApplicationController
|
|
|
|
|
memberships = params[:membership][:user_ids]
|
|
|
|
|
memberships.each do |member|
|
|
|
|
|
user = User.find(member)
|
|
|
|
|
SubjectMember.create!(:user_id => member, :subject_id => @subject.id, :role => 2)
|
|
|
|
|
SubjectMember.create!(:user_id => member, :subject_id => @subject.id, :role => 2,
|
|
|
|
|
:position => @subject.subject_members.size + 1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def delete_member
|
|
|
|
|
member = @subject.subject_members.where(:user_id => params[:mem_id]).first
|
|
|
|
|
member.destroy if member
|
|
|
|
|
if User.current.admin?
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
member = @subject.subject_members.where(:id => params[:mem_id]).first
|
|
|
|
|
if member.present? && member.role != 1
|
|
|
|
|
@subject.subject_members.where("position > #{member.position}").update_all("position = position - 1")
|
|
|
|
|
member.destroy
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_403
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def up_member_position
|
|
|
|
|
if User.current.member_of_subject?(@subject)
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
member = @subject.subject_members.where(:id => params[:mem_id]).first
|
|
|
|
|
raise "不能再上移了" if member.position == 1
|
|
|
|
|
up_member = @subject.subject_members.where(:position => member.position - 1).first
|
|
|
|
|
up_member.update_attribute(:position, member.position)
|
|
|
|
|
member.update_attribute(:position, member.position - 1)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_403
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def down_member_position
|
|
|
|
|
if User.current.member_of_subject?(@subject)
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
member = @subject.subject_members.where(:id => params[:mem_id]).first
|
|
|
|
|
raise "不能再下移了" if member.position == @subject.subject_members.count
|
|
|
|
|
down_member = @subject.subject_members.where(:position => member.position + 1).first
|
|
|
|
|
down_member.update_attribute(:position, member.position)
|
|
|
|
|
member.update_attribute(:position, member.position + 1)
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_403
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def statistics
|
|
|
|
|