diff --git a/app/controllers/concerns/controller_rescue_handler.rb b/app/controllers/concerns/controller_rescue_handler.rb index dde6c4a8d..f7a12b5a7 100644 --- a/app/controllers/concerns/controller_rescue_handler.rb +++ b/app/controllers/concerns/controller_rescue_handler.rb @@ -24,7 +24,7 @@ module ControllerRescueHandler rescue_from ActiveRecord::RecordInvalid do |ex| render_error(ex.record.errors.full_messages.join(',')) end - rescue_from StandardError do |ex| + rescue_from RuntimeError do |ex| render_error(ex.message) end end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d819b1039..f23be51d5 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -386,6 +386,7 @@ class CoursesController < ApplicationController def destroy if @course.is_delete == 0 @course.delete! + Tiding.where(belong_container: @course).update_all(is_delete: 1) Tiding.create!(user_id: current_user.id, trigger_user_id: current_user.id, container_id: @course.id, container_type: 'DeleteCourse', tiding_type: 'System', belong_container: @course, extra: @course.name) normal_status(0, "成功") diff --git a/app/controllers/tidings_controller.rb b/app/controllers/tidings_controller.rb index 9305046b0..91d6c095d 100644 --- a/app/controllers/tidings_controller.rb +++ b/app/controllers/tidings_controller.rb @@ -5,7 +5,7 @@ class TidingsController < ApplicationController after_action :update_onclick_time!, only: [:index] def index - tidings = current_user.tidings + tidings = current_user.tidings.visible @onclick_time = current_user.click_time tiding_types = @@ -21,7 +21,7 @@ class TidingsController < ApplicationController tidings = tidings.where(container_type: 'JoinCourse', status: 0) if params[:type] == 'course_apply' # @course_apply_count = tidings.where("created_at > '#{@onclick_time}'").where(container_type: 'JoinCourse', status: 0).count - @course_apply_count = tidings.where("created_at > '#{@onclick_time}'").where(container_type: 'JoinCourse', status: 0).count + @course_apply_count = tidings.where(container_type: 'JoinCourse', status: 0).count tidings = tidings.where(container_type: 'ProjectPackage') if params[:type] == 'project_package' diff --git a/app/models/tiding.rb b/app/models/tiding.rb index 02692085a..aa570f5c0 100644 --- a/app/models/tiding.rb +++ b/app/models/tiding.rb @@ -7,6 +7,8 @@ class Tiding < ApplicationRecord has_many :attachments, as: :container + scope :visible, -> { where(is_delete: 0) } + def identifier value = nil diff --git a/db/migrate/20200210111249_add_is_delete_to_tiding.rb b/db/migrate/20200210111249_add_is_delete_to_tiding.rb new file mode 100644 index 000000000..94a53145e --- /dev/null +++ b/db/migrate/20200210111249_add_is_delete_to_tiding.rb @@ -0,0 +1,5 @@ +class AddIsDeleteToTiding < ActiveRecord::Migration[5.2] + def change + add_column :tidings, :is_delete, :boolean, default: 0 + end +end diff --git a/db/migrate/20200210111308_update_tidings_delete_status.rb b/db/migrate/20200210111308_update_tidings_delete_status.rb new file mode 100644 index 000000000..f05e409bd --- /dev/null +++ b/db/migrate/20200210111308_update_tidings_delete_status.rb @@ -0,0 +1,5 @@ +class UpdateTidingsDeleteStatus < ActiveRecord::Migration[5.2] + def change + Tiding.where.not(container_type: 'DeleteCourse').where(belong_container_type: "Course", belong_container_id: Course.where(is_delete: 1).pluck(:id)).update_all(is_delete: 1) + end +end diff --git a/db/migrate/20200210112333_delete_column_tiding.rb b/db/migrate/20200210112333_delete_column_tiding.rb new file mode 100644 index 000000000..1bdc91897 --- /dev/null +++ b/db/migrate/20200210112333_delete_column_tiding.rb @@ -0,0 +1,5 @@ +class DeleteColumnTiding < ActiveRecord::Migration[5.2] + def change + remove_column :tidings, :delete + end +end