From 8a70989f7f70e98446c482501a80deca85ce0d17 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 20:23:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/messages/_message.json.jbuilder | 3 ++- db/migrate/20190720121537_add_is_md_for_messages.rb | 5 +++++ db/migrate/20190720122123_modify_is_md_for_messages.rb | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190720121537_add_is_md_for_messages.rb create mode 100644 db/migrate/20190720122123_modify_is_md_for_messages.rb diff --git a/app/views/messages/_message.json.jbuilder b/app/views/messages/_message.json.jbuilder index bff2413cd..c3ab6c6e3 100644 --- a/app/views/messages/_message.json.jbuilder +++ b/app/views/messages/_message.json.jbuilder @@ -1 +1,2 @@ -json.extract! message, :id, :parent_id, :subject, :created_on, :total_replies_count, :total_praises_count, :praises_count, :visits, :sticky, :is_hidden, :is_public +json.extract! message, :id, :parent_id, :subject, :created_on, :total_replies_count, :total_praises_count, + :is_md, :praises_count, :visits, :sticky, :is_hidden, :is_public diff --git a/db/migrate/20190720121537_add_is_md_for_messages.rb b/db/migrate/20190720121537_add_is_md_for_messages.rb new file mode 100644 index 000000000..a801fb387 --- /dev/null +++ b/db/migrate/20190720121537_add_is_md_for_messages.rb @@ -0,0 +1,5 @@ +class AddIsMdForMessages < ActiveRecord::Migration[5.2] + def change + add_column :messages, :is_md, :boolean, :default => true + end +end diff --git a/db/migrate/20190720122123_modify_is_md_for_messages.rb b/db/migrate/20190720122123_modify_is_md_for_messages.rb new file mode 100644 index 000000000..4137fc8af --- /dev/null +++ b/db/migrate/20190720122123_modify_is_md_for_messages.rb @@ -0,0 +1,7 @@ +class ModifyIsMdForMessages < ActiveRecord::Migration[5.2] + def change + Message.find_each do |m| + m.update_column(:is_md, false) + end + end +end From 82f2bf1b0b655b1f4a88e6c21acbf0fc5692cd17 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 20:30:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0md=E7=9A=84=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 5bdc3e053..90da7d8e5 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -102,7 +102,9 @@ class MessagesController < ApplicationController return normal_status(403, "您没有权限进行该操作") if current_user != @message.author && !current_user.teacher_of_course?(@message.board.course) begin - @message.update_attributes(message_params) + h = {is_md: true} + m_params = message_params.merge(h) + @message.update_attributes(m_params) Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) @message.update_content(params[:content]) rescue Exception => e