Add times_reported integer attribute to RelatedContent
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
class RelatedContent < ActiveRecord::Base
|
class RelatedContent < ActiveRecord::Base
|
||||||
|
RELATED_CONTENTS_REPORT_THRESHOLD = Setting['related_contents_report_threshold'].to_i
|
||||||
|
|
||||||
belongs_to :parent_relationable, polymorphic: true
|
belongs_to :parent_relationable, polymorphic: true
|
||||||
belongs_to :child_relationable, polymorphic: true
|
belongs_to :child_relationable, polymorphic: true
|
||||||
has_one :opposite_related_content, class_name: 'RelatedContent', foreign_key: :related_content_id
|
has_one :opposite_related_content, class_name: 'RelatedContent', foreign_key: :related_content_id
|
||||||
@@ -12,6 +14,12 @@ class RelatedContent < ActiveRecord::Base
|
|||||||
after_create :create_opposite_related_content, unless: proc { opposite_related_content.present? }
|
after_create :create_opposite_related_content, unless: proc { opposite_related_content.present? }
|
||||||
after_destroy :destroy_opposite_related_content, if: proc { opposite_related_content.present? }
|
after_destroy :destroy_opposite_related_content, if: proc { opposite_related_content.present? }
|
||||||
|
|
||||||
|
scope :not_hidden, -> { where('times_reported <= ?', RELATED_CONTENTS_REPORT_THRESHOLD) }
|
||||||
|
|
||||||
|
def hidden_by_reports?
|
||||||
|
times_reported > RELATED_CONTENTS_REPORT_THRESHOLD
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_opposite_related_content
|
def create_opposite_related_content
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ section "Creating Settings" do
|
|||||||
Setting.create(key: 'map_latitude', value: 51.48)
|
Setting.create(key: 'map_latitude', value: 51.48)
|
||||||
Setting.create(key: 'map_longitude', value: 0.0)
|
Setting.create(key: 'map_longitude', value: 0.0)
|
||||||
Setting.create(key: 'map_zoom', value: 10)
|
Setting.create(key: 'map_zoom', value: 10)
|
||||||
|
Setting.create(key: 'related_contents_report_threshold', value: 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
section "Creating Geozones" do
|
section "Creating Geozones" do
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddTimeReportedToRelatedContent < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :related_contents, :times_reported, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20171127171925) do
|
ActiveRecord::Schema.define(version: 20171127230716) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -859,6 +859,7 @@ ActiveRecord::Schema.define(version: 20171127171925) do
|
|||||||
t.integer "related_content_id"
|
t.integer "related_content_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.integer "times_reported", default: 0
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "related_contents", ["child_relationable_type", "child_relationable_id"], name: "index_related_contents_on_child_relationable", using: :btree
|
add_index "related_contents", ["child_relationable_type", "child_relationable_id"], name: "index_related_contents_on_child_relationable", using: :btree
|
||||||
|
|||||||
@@ -116,3 +116,6 @@ Setting['proposal_improvement_path'] = nil
|
|||||||
Setting['map_latitude'] = 51.48
|
Setting['map_latitude'] = 51.48
|
||||||
Setting['map_longitude'] = 0.0
|
Setting['map_longitude'] = 0.0
|
||||||
Setting['map_zoom'] = 10
|
Setting['map_zoom'] = 10
|
||||||
|
|
||||||
|
# Related content
|
||||||
|
Setting['related_contents_report_threshold'] = 5
|
||||||
|
|||||||
Reference in New Issue
Block a user