From 88397d58d0922901be1e2aedf1a0be5d99e34235 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sun, 6 Sep 2015 17:27:20 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=AE=A8=E8=AE=BA=E5=8C=BA=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E5=B8=96=E5=AD=90=E6=97=B6=E5=A2=9E=E5=8A=A0=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=88=A4=E6=96=AD=202=E3=80=81=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E7=9A=84=E5=8C=BF=E5=90=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=B8=96=E5=AD=90=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 98 ++++++++----------- ...0150906090419_delete_anonymous_feedback.rb | 3 +- ...20150906091723_delete_anonymous_message.rb | 15 +++ 3 files changed, 57 insertions(+), 59 deletions(-) create mode 100644 db/migrate/20150906091723_delete_anonymous_message.rb diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index f71103973..9b0fd56a0 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -89,72 +89,54 @@ class MessagesController < ApplicationController # Create a new topic def new - @message = Message.new - @message.author = User.current - @message.board = @board - @message.safe_attributes = params[:message] - if request.post? - @message.save_attachments(params[:attachments]) - if @message.save - # 更新kindeditor上传的图片资源所有者 - if params[:asset_id] - ids = params[:asset_id].split(',') - update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE - end - # # 与我相关动态的记录add start - # if(@board && @board.course) #项目的先不管 - # teachers = searchTeacherAndAssistant(@board.course) - # for teacher in teachers - # if(teacher.user_id != User.current.id) - # notify = ActivityNotify.new() - # if(@board.course) - # notify.activity_container_id = @board.course_id - # notify.activity_container_type = 'Course' - # else - # notify.activity_container_id = @board.project_id - # notify.activity_container_type = 'Project' - # end - # notify.activity_id = @message.id - # notify.activity_type = 'Message' - # notify.notify_to = teacher.user_id - # notify.is_read = 0 - # notify.save() - # end - # end - # end - # 与我相关动态的记录add end + if User.current.logged? + @message = Message.new + @message.author = User.current + @message.board = @board + @message.safe_attributes = params[:message] + if request.post? + @message.save_attachments(params[:attachments]) + if @message.save + # 更新kindeditor上传的图片资源所有者 + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@message.id,OwnerTypeHelper::MESSAGE + end - call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) - render_attachment_warning_if_needed(@message) - if params[:is_board] - if @project - redirect_to project_boards_path(@project) - elsif @course - redirect_to course_boards_path(@course) + call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) + render_attachment_warning_if_needed(@message) + if params[:is_board] + if @project + redirect_to project_boards_path(@project) + elsif @course + redirect_to course_boards_path(@course) + end + else + redirect_to board_message_url(@board, @message) end else - redirect_to board_message_url(@board, @message) + if params[:is_board] + if @project + redirect_to project_boards_path(@project, :flag => true) + elsif @course + redirect_to course_boards_path(@course, :flag => true) + end + else + layout_file = @project ? 'base_projects' : 'base_courses' + render :action => 'new', :layout => layout_file + end + end else - if params[:is_board] - if @project - redirect_to project_boards_path(@project, :flag => true) - elsif @course - redirect_to course_boards_path(@course, :flag => true) - end - else - layout_file = @project ? 'base_projects' : 'base_courses' - render :action => 'new', :layout => layout_file + respond_to do |format| + format.html { + layout_file = @project ? 'base_projects' : 'base_courses' + render :layout => layout_file + } end - end else - respond_to do |format| - format.html { - layout_file = @project ? 'base_projects' : 'base_courses' - render :layout => layout_file - } - end + redirect_to signin_path end end diff --git a/db/migrate/20150906090419_delete_anonymous_feedback.rb b/db/migrate/20150906090419_delete_anonymous_feedback.rb index a96d6b30d..405cfa7fb 100644 --- a/db/migrate/20150906090419_delete_anonymous_feedback.rb +++ b/db/migrate/20150906090419_delete_anonymous_feedback.rb @@ -1,10 +1,11 @@ class DeleteAnonymousFeedback < ActiveRecord::Migration def up jour_count = JournalsForMessage.all.count / 30 + 2 + puts jour_count transaction do for i in 1 ... jour_count do i JournalsForMessage.page(i).per(30).each do |jour| - jour.destroy if jour.user_id == 2 + jour.destroy if jour.user_id.to_s == "2" end end end diff --git a/db/migrate/20150906091723_delete_anonymous_message.rb b/db/migrate/20150906091723_delete_anonymous_message.rb new file mode 100644 index 000000000..d128f2aff --- /dev/null +++ b/db/migrate/20150906091723_delete_anonymous_message.rb @@ -0,0 +1,15 @@ +class DeleteAnonymousMessage < ActiveRecord::Migration + def up + message_count = Message.all.count / 30 + 2 + transaction do + for i in 1 ... message_count do i + Message.page(i).per(30).each do |message| + message.destroy if jour.author_id.to_s == "2" + end + end + end + end + + def down + end +end