2015-02-04 11:57:37 +08:00
|
|
|
class CommentService
|
|
|
|
#评论
|
|
|
|
def news_comments params,current_user
|
|
|
|
@news = News.find(params[:id])
|
2015-02-04 14:39:46 +08:00
|
|
|
@course = @news.course
|
|
|
|
if @course.nil?
|
|
|
|
raise 'news in unknown course'
|
|
|
|
end
|
|
|
|
raise Unauthorized unless @news.commentable?(current_user)
|
|
|
|
if current_user.nil? || !(current_user.admin? || @course.is_public == 1 || (@course.is_public == 0 && current_user.member_of_course?(@course)))
|
|
|
|
raise '403'
|
|
|
|
end
|
2015-02-04 11:57:37 +08:00
|
|
|
@comment = Comment.new
|
2015-02-04 14:39:46 +08:00
|
|
|
@comment.send(:safe_attributes=,params[:comment],current_user)
|
2015-02-04 11:57:37 +08:00
|
|
|
@comment.author = current_user
|
|
|
|
@news.comments << @comment
|
|
|
|
@comment
|
|
|
|
end
|
2015-02-05 15:54:50 +08:00
|
|
|
|
|
|
|
#作业留言
|
|
|
|
def homework_message params,current_user
|
|
|
|
@bid = Bid.find(params[:id], :include => [{:homeworks => :user}])
|
|
|
|
if params[:bid_message][:message].size>0
|
|
|
|
if params[:reference_content]
|
|
|
|
message = params[:bid_message][:message] + "\n" + params[:reference_content]
|
|
|
|
else
|
|
|
|
message = params[:bid_message][:message]
|
|
|
|
@m = message
|
|
|
|
end
|
|
|
|
refer_user_id = params[:bid_message][:reference_user_id].to_i
|
2015-02-05 16:11:35 +08:00
|
|
|
jfm = @bid.add_jour(current_user, message, refer_user_id)
|
2015-02-05 15:54:50 +08:00
|
|
|
end
|
|
|
|
#@user = @bid.author
|
|
|
|
#@jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
|
|
|
#@jour = paginateHelper @jours,10
|
|
|
|
@bid.set_commit(@feedback_count)
|
2015-02-05 16:11:35 +08:00
|
|
|
jfm
|
2015-02-05 15:54:50 +08:00
|
|
|
end
|
|
|
|
|
2015-02-04 11:57:37 +08:00
|
|
|
end
|