Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
cxt 5 years ago
commit 5665d95816

@ -9,15 +9,18 @@ class DiscussesController < ApplicationController
# 总数,分页使用
if current_user.admin?
@disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count
@discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s,
:root_id => nil).includes(:user, :praise_treads).offset(offset)
disscusses = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s,
:root_id => nil).joins(challenge: :games)
.where("discusses.user_id = games.user_id").select("discusses.*, games.identifier")
else
disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and
(hidden = :hidden or user_id = :user_id)",
(discusses.hidden = :hidden or discusses.user_id = :user_id)",
{dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id})
@disscuss_count = disscusses.count
@discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset)
.joins(challenge: :games).where("discusses.user_id = games.user_id").select("discusses.*, games.identifier")
@disscuss_count = disscusses.count("discusses.id")
end
@discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset)
@manger = @container.has_manager?(current_user)
@current_user = current_user
end

@ -16,6 +16,8 @@ class Challenge < ApplicationRecord
# 参考答案
has_many :challenge_answers, :dependent => :destroy
has_many :exercise_bank_shixun_challenges, :dependent => :destroy
# 回复
has_many :discusses, :dependent => :destroy
# acts_as_attachable

@ -9,6 +9,7 @@ class Discuss < ApplicationRecord
has_many :tidings, as: :container, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy
belongs_to :challenge
after_create :send_tiding
scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder(created_at: :asc) }

@ -9,7 +9,8 @@ json.shixun_id discuss.dis_id
json.hidden discuss.hidden
json.manage current_user.manager_of_shixun?(container)
json.reward discuss.reward
json.game_url discuss.game_url(container, current_user)
#json.game_url discuss.game_url(container, current_user)
json.game_url "/tasks/#{discuss.identifier}" if @manger
# 主贴和回复有一些不同点
if discuss.parent_id
json.can_delete discuss.can_deleted?(current_user)

@ -0,0 +1,11 @@
class ModifyChallengeIdForDiscusses < ActiveRecord::Migration[5.2]
def change
discusses = Discuss.where(challenge_id: nil)
discusses.each do |dis|
challenge_id = Shixun.find(dis.dis_id).challenges.first.id
dis.update_column(:challenge_id, challenge_id)
end
add_index :discusses, :challenge_id
end
end
Loading…
Cancel
Save