From b9dce31a4d5528599c8ab6616e78b90ab0751e8b Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 10:11:45 +0200
Subject: [PATCH 01/18] Adds migrations for renaming and new flagging field
* inappropiate_flags table becomes flags
* [comments|debates].archived_at becomes flag_ignored_at
* Add new [comments|debates].hide_reviewed_at
---
...0624_rename_inappropiate_flags_as_flags.rb | 5 +++
...flag_ignored_at_in_comments_and_debates.rb | 6 +++
...ide_reviewed_at_to_comments_and_debates.rb | 6 +++
db/schema.rb | 42 ++++++++++---------
4 files changed, 39 insertions(+), 20 deletions(-)
create mode 100644 db/migrate/20150827080624_rename_inappropiate_flags_as_flags.rb
create mode 100644 db/migrate/20150827080641_rename_archived_at_to_flag_ignored_at_in_comments_and_debates.rb
create mode 100644 db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
diff --git a/db/migrate/20150827080624_rename_inappropiate_flags_as_flags.rb b/db/migrate/20150827080624_rename_inappropiate_flags_as_flags.rb
new file mode 100644
index 000000000..26058bde0
--- /dev/null
+++ b/db/migrate/20150827080624_rename_inappropiate_flags_as_flags.rb
@@ -0,0 +1,5 @@
+class RenameInappropiateFlagsAsFlags < ActiveRecord::Migration
+ def change
+ rename_table :inappropiate_flags, :flags
+ end
+end
diff --git a/db/migrate/20150827080641_rename_archived_at_to_flag_ignored_at_in_comments_and_debates.rb b/db/migrate/20150827080641_rename_archived_at_to_flag_ignored_at_in_comments_and_debates.rb
new file mode 100644
index 000000000..7328ca79b
--- /dev/null
+++ b/db/migrate/20150827080641_rename_archived_at_to_flag_ignored_at_in_comments_and_debates.rb
@@ -0,0 +1,6 @@
+class RenameArchivedAtToFlagIgnoredAtInCommentsAndDebates < ActiveRecord::Migration
+ def change
+ rename_column :comments, :archived_at, :flag_ignored_at
+ rename_column :debates, :archived_at, :flag_ignored_at
+ end
+end
diff --git a/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb b/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
new file mode 100644
index 000000000..dfcef9f06
--- /dev/null
+++ b/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
@@ -0,0 +1,6 @@
+class AddHideReviewedAtToCommentsAndDebates < ActiveRecord::Migration
+ def change
+ add_column :debates, :hide_reviewed_at, :datetime
+ add_column :comments, :hide_reviewed_at, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ad2a412ff..29084fe08 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150826112500) do
+ActiveRecord::Schema.define(version: 20150827080701) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -41,7 +41,7 @@ ActiveRecord::Schema.define(version: 20150826112500) do
t.string "title"
t.text "body"
t.string "subject"
- t.integer "user_id", null: false
+ t.integer "user_id", null: false
t.integer "parent_id"
t.integer "lft"
t.integer "rgt"
@@ -51,12 +51,13 @@ ActiveRecord::Schema.define(version: 20150826112500) do
t.datetime "hidden_at"
t.datetime "flagged_as_inappropiate_at"
t.integer "inappropiate_flags_count", default: 0
- t.datetime "archived_at"
+ t.datetime "flag_ignored_at"
t.integer "moderator_id"
t.integer "administrator_id"
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
+ t.datetime "hide_reviewed_at"
end
add_index "comments", ["cached_votes_down"], name: "index_comments_on_cached_votes_down", using: :btree
@@ -70,8 +71,8 @@ ActiveRecord::Schema.define(version: 20150826112500) do
t.string "title", limit: 80
t.text "description"
t.integer "author_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
t.datetime "hidden_at"
t.string "visit_id"
t.datetime "flagged_as_inappropiate_at"
@@ -79,8 +80,9 @@ ActiveRecord::Schema.define(version: 20150826112500) do
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
- t.datetime "archived_at"
+ t.datetime "flag_ignored_at"
t.integer "comments_count", default: 0
+ t.datetime "hide_reviewed_at"
end
add_index "debates", ["cached_votes_down"], name: "index_debates_on_cached_votes_down", using: :btree
@@ -88,6 +90,18 @@ ActiveRecord::Schema.define(version: 20150826112500) do
add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
+ create_table "flags", force: :cascade do |t|
+ t.integer "user_id"
+ t.string "flaggable_type"
+ t.integer "flaggable_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "flags", ["flaggable_type", "flaggable_id"], name: "index_flags_on_flaggable_type_and_flaggable_id", using: :btree
+ add_index "flags", ["user_id", "flaggable_type", "flaggable_id"], name: "access_inappropiate_flags", using: :btree
+ add_index "flags", ["user_id"], name: "index_flags_on_user_id", using: :btree
+
create_table "identities", force: :cascade do |t|
t.integer "user_id"
t.string "provider"
@@ -98,18 +112,6 @@ ActiveRecord::Schema.define(version: 20150826112500) do
add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree
- create_table "inappropiate_flags", force: :cascade do |t|
- t.integer "user_id"
- t.string "flaggable_type"
- t.integer "flaggable_id"
- t.datetime "created_at"
- t.datetime "updated_at"
- end
-
- add_index "inappropiate_flags", ["flaggable_type", "flaggable_id"], name: "index_inappropiate_flags_on_flaggable_type_and_flaggable_id", using: :btree
- add_index "inappropiate_flags", ["user_id", "flaggable_type", "flaggable_id"], name: "access_inappropiate_flags", using: :btree
- add_index "inappropiate_flags", ["user_id"], name: "index_inappropiate_flags_on_user_id", using: :btree
-
create_table "moderators", force: :cascade do |t|
t.integer "user_id"
end
@@ -237,8 +239,8 @@ ActiveRecord::Schema.define(version: 20150826112500) do
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
add_foreign_key "administrators", "users"
+ add_foreign_key "flags", "users"
add_foreign_key "identities", "users"
- add_foreign_key "inappropiate_flags", "users"
add_foreign_key "moderators", "users"
add_foreign_key "organizations", "users"
-end
\ No newline at end of file
+end
From b640fcb398f032c89afe26abced9ecf88147485b Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 10:18:31 +0200
Subject: [PATCH 02/18] Rename inappropiate_flags_count field to flags_count
---
...te_flags_count_to_flags_count_in_debates_and_comments.rb | 6 ++++++
db/schema.rb | 6 +++---
2 files changed, 9 insertions(+), 3 deletions(-)
create mode 100644 db/migrate/20150827081657_rename_inappropiate_flags_count_to_flags_count_in_debates_and_comments.rb
diff --git a/db/migrate/20150827081657_rename_inappropiate_flags_count_to_flags_count_in_debates_and_comments.rb b/db/migrate/20150827081657_rename_inappropiate_flags_count_to_flags_count_in_debates_and_comments.rb
new file mode 100644
index 000000000..2f2a9285d
--- /dev/null
+++ b/db/migrate/20150827081657_rename_inappropiate_flags_count_to_flags_count_in_debates_and_comments.rb
@@ -0,0 +1,6 @@
+class RenameInappropiateFlagsCountToFlagsCountInDebatesAndComments < ActiveRecord::Migration
+ def change
+ rename_column :debates, :inappropiate_flags_count, :flags_count
+ rename_column :comments, :inappropiate_flags_count, :flags_count
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 29084fe08..c7db25360 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150827080701) do
+ActiveRecord::Schema.define(version: 20150827081657) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -50,7 +50,7 @@ ActiveRecord::Schema.define(version: 20150827080701) do
t.integer "children_count", default: 0
t.datetime "hidden_at"
t.datetime "flagged_as_inappropiate_at"
- t.integer "inappropiate_flags_count", default: 0
+ t.integer "flags_count", default: 0
t.datetime "flag_ignored_at"
t.integer "moderator_id"
t.integer "administrator_id"
@@ -76,7 +76,7 @@ ActiveRecord::Schema.define(version: 20150827080701) do
t.datetime "hidden_at"
t.string "visit_id"
t.datetime "flagged_as_inappropiate_at"
- t.integer "inappropiate_flags_count", default: 0
+ t.integer "flags_count", default: 0
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
From a3e983f15488736979663c11e94c32b9d2f1f317 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 10:35:13 +0200
Subject: [PATCH 03/18] remove unused flagged_as_inappropiate_at column from
debates and comments
---
...appropiate_at_from_comments_and_debates.rb | 6 ++++
db/schema.rb | 32 +++++++++----------
2 files changed, 21 insertions(+), 17 deletions(-)
create mode 100644 db/migrate/20150827083232_remove_flagged_as_inappropiate_at_from_comments_and_debates.rb
diff --git a/db/migrate/20150827083232_remove_flagged_as_inappropiate_at_from_comments_and_debates.rb b/db/migrate/20150827083232_remove_flagged_as_inappropiate_at_from_comments_and_debates.rb
new file mode 100644
index 000000000..c226ecb3f
--- /dev/null
+++ b/db/migrate/20150827083232_remove_flagged_as_inappropiate_at_from_comments_and_debates.rb
@@ -0,0 +1,6 @@
+class RemoveFlaggedAsInappropiateAtFromCommentsAndDebates < ActiveRecord::Migration
+ def change
+ remove_column :debates, :flagged_as_inappropiate_at
+ remove_column :comments, :flagged_as_inappropiate_at
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c7db25360..de3339365 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150827081657) do
+ActiveRecord::Schema.define(version: 20150827083232) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -41,22 +41,21 @@ ActiveRecord::Schema.define(version: 20150827081657) do
t.string "title"
t.text "body"
t.string "subject"
- t.integer "user_id", null: false
+ t.integer "user_id", null: false
t.integer "parent_id"
t.integer "lft"
t.integer "rgt"
t.datetime "created_at"
t.datetime "updated_at"
- t.integer "children_count", default: 0
+ t.integer "children_count", default: 0
t.datetime "hidden_at"
- t.datetime "flagged_as_inappropiate_at"
- t.integer "flags_count", default: 0
+ t.integer "flags_count", default: 0
t.datetime "flag_ignored_at"
t.integer "moderator_id"
t.integer "administrator_id"
- t.integer "cached_votes_total", default: 0
- t.integer "cached_votes_up", default: 0
- t.integer "cached_votes_down", default: 0
+ t.integer "cached_votes_total", default: 0
+ t.integer "cached_votes_up", default: 0
+ t.integer "cached_votes_down", default: 0
t.datetime "hide_reviewed_at"
end
@@ -68,20 +67,19 @@ ActiveRecord::Schema.define(version: 20150827081657) do
add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree
create_table "debates", force: :cascade do |t|
- t.string "title", limit: 80
+ t.string "title", limit: 80
t.text "description"
t.integer "author_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
t.datetime "hidden_at"
t.string "visit_id"
- t.datetime "flagged_as_inappropiate_at"
- t.integer "flags_count", default: 0
- t.integer "cached_votes_total", default: 0
- t.integer "cached_votes_up", default: 0
- t.integer "cached_votes_down", default: 0
+ t.integer "flags_count", default: 0
+ t.integer "cached_votes_total", default: 0
+ t.integer "cached_votes_up", default: 0
+ t.integer "cached_votes_down", default: 0
t.datetime "flag_ignored_at"
- t.integer "comments_count", default: 0
+ t.integer "comments_count", default: 0
t.datetime "hide_reviewed_at"
end
From 909dfb4ce3d6b78e99fb5836f99e00d0cd648e35 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 10:48:49 +0200
Subject: [PATCH 04/18] Several renamings
InappropiateFlag -> Flag
x.flag_as_inappropiate -> x.flag
x.undo_flag_as_inappropiate -> x.unflag
X.flagged_as_inappropiate -> x.flagged
flag-as-inappropiate-actions views & css -> flag-actions views & css
---
app/controllers/comments_controller.rb | 12 ++++----
app/controllers/debates_controller.rb | 12 ++++----
.../moderation/comments_controller.rb | 2 +-
.../moderation/debates_controller.rb | 2 +-
app/models/ability.rb | 16 +++++-----
app/models/comment.rb | 6 ++--
app/models/debate.rb | 6 ++--
app/models/{inappropiate_flag.rb => flag.rb} | 8 ++---
app/models/user.rb | 2 +-
app/views/comments/_actions.html.erb | 4 +--
...ctions.html.erb => _flag_actions.html.erb} | 12 ++++----
.../comments/_refresh_flag_actions.js.erb | 1 +
...efresh_flag_as_inappropiate_actions.js.erb | 1 -
...ctions.html.erb => _flag_actions.html.erb} | 12 ++++----
.../debates/_refresh_flag_actions.js.erb | 1 +
...efresh_flag_as_inappropiate_actions.js.erb | 1 -
app/views/debates/show.html.erb | 4 +--
app/views/moderation/comments/index.html.erb | 2 +-
app/views/moderation/debates/index.html.erb | 2 +-
config/locales/en.yml | 4 +--
config/locales/es.yml | 4 +--
config/routes.rb | 8 ++---
spec/factories.rb | 8 ++---
spec/features/comments_spec.rb | 6 ++--
spec/features/debates_spec.rb | 10 +++----
spec/features/moderation/comments_spec.rb | 10 +++----
spec/features/moderation/debates_spec.rb | 10 +++----
spec/models/ability_spec.rb | 30 +++++++++----------
...inappropiate_flag_spec.rb => flag_spec.rb} | 26 ++++++----------
29 files changed, 107 insertions(+), 115 deletions(-)
rename app/models/{inappropiate_flag.rb => flag.rb} (72%)
rename app/views/comments/{_flag_as_inappropiate_actions.html.erb => _flag_actions.html.erb} (65%)
create mode 100644 app/views/comments/_refresh_flag_actions.js.erb
delete mode 100644 app/views/comments/_refresh_flag_as_inappropiate_actions.js.erb
rename app/views/debates/{_flag_as_inappropiate_actions.html.erb => _flag_actions.html.erb} (63%)
create mode 100644 app/views/debates/_refresh_flag_actions.js.erb
delete mode 100644 app/views/debates/_refresh_flag_as_inappropiate_actions.js.erb
rename spec/models/{inappropiate_flag_spec.rb => flag_spec.rb} (65%)
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 798196ca0..c342b8d10 100644
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -22,14 +22,14 @@ class CommentsController < ApplicationController
respond_with @comment
end
- def flag_as_inappropiate
- InappropiateFlag.flag!(current_user, @comment)
- respond_with @comment, template: 'comments/_refresh_flag_as_inappropiate_actions'
+ def flag
+ Flag.flag!(current_user, @comment)
+ respond_with @comment, template: 'comments/_refresh_flag_actions'
end
- def undo_flag_as_inappropiate
- InappropiateFlag.unflag!(current_user, @comment)
- respond_with @comment, template: 'comments/_refresh_flag_as_inappropiate_actions'
+ def unflag
+ Flag.unflag!(current_user, @comment)
+ respond_with @comment, template: 'comments/_refresh_flag_actions'
end
private
diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb
index cf6d14f65..6bea23ffd 100644
--- a/app/controllers/debates_controller.rb
+++ b/app/controllers/debates_controller.rb
@@ -51,14 +51,14 @@ class DebatesController < ApplicationController
set_debate_votes(@debate)
end
- def flag_as_inappropiate
- InappropiateFlag.flag!(current_user, @debate)
- respond_with @debate, template: 'debates/_refresh_flag_as_inappropiate_actions'
+ def flag
+ Flag.flag!(current_user, @debate)
+ respond_with @debate, template: 'debates/_refresh_flag_actions'
end
- def undo_flag_as_inappropiate
- InappropiateFlag.unflag!(current_user, @debate)
- respond_with @debate, template: 'debates/_refresh_flag_as_inappropiate_actions'
+ def unflag
+ Flag.unflag!(current_user, @debate)
+ respond_with @debate, template: 'debates/_refresh_flag_actions'
end
private
diff --git a/app/controllers/moderation/comments_controller.rb b/app/controllers/moderation/comments_controller.rb
index 8a4d3768e..0570ab5d3 100644
--- a/app/controllers/moderation/comments_controller.rb
+++ b/app/controllers/moderation/comments_controller.rb
@@ -27,7 +27,7 @@ class Moderation::CommentsController < Moderation::BaseController
private
def load_comments
- @comments = Comment.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation.includes(:commentable)
+ @comments = Comment.accessible_by(current_ability, :hide).flagged.sorted_for_moderation.includes(:commentable)
end
def set_valid_filters
diff --git a/app/controllers/moderation/debates_controller.rb b/app/controllers/moderation/debates_controller.rb
index 3492ee423..fdc09b61d 100644
--- a/app/controllers/moderation/debates_controller.rb
+++ b/app/controllers/moderation/debates_controller.rb
@@ -27,7 +27,7 @@ class Moderation::DebatesController < Moderation::BaseController
private
def load_debates
- @debates = Debate.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation
+ @debates = Debate.accessible_by(current_ability, :hide).flagged.sorted_for_moderation
end
def set_valid_filters
diff --git a/app/models/ability.rb b/app/models/ability.rb
index c8ed63d22..7a682de5a 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -22,20 +22,20 @@ class Ability
can :create, Comment
can :create, Debate
- can :flag_as_inappropiate, Comment do |comment|
- comment.author_id != user.id && !InappropiateFlag.flagged?(user, comment)
+ can :flag, Comment do |comment|
+ comment.author_id != user.id && !Flag.flagged?(user, comment)
end
- can :undo_flag_as_inappropiate, Comment do |comment|
- comment.author_id != user.id && InappropiateFlag.flagged?(user, comment)
+ can :unflag, Comment do |comment|
+ comment.author_id != user.id && Flag.flagged?(user, comment)
end
- can :flag_as_inappropiate, Debate do |debate|
- debate.author_id != user.id && !InappropiateFlag.flagged?(user, debate)
+ can :flag, Debate do |debate|
+ debate.author_id != user.id && !Flag.flagged?(user, debate)
end
- can :undo_flag_as_inappropiate, Debate do |debate|
- debate.author_id != user.id && InappropiateFlag.flagged?(user, debate)
+ can :unflag, Debate do |debate|
+ debate.author_id != user.id && Flag.flagged?(user, debate)
end
unless user.organization?
diff --git a/app/models/comment.rb b/app/models/comment.rb
index bbfeca4f5..9df42b700 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -12,14 +12,14 @@ class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true, counter_cache: true
belongs_to :user, -> { with_hidden }
- has_many :inappropiate_flags, :as => :flaggable
+ has_many :flags, :as => :flaggable
scope :recent, -> { order(id: :desc) }
- scope :sorted_for_moderation, -> { order(inappropiate_flags_count: :desc, updated_at: :desc) }
+ scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
scope :pending, -> { where(archived_at: nil, hidden_at: nil) }
scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") }
- scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") }
+ scope :flagged, -> { where("flags_count > 0") }
scope :for_render, -> { with_hidden.includes(user: :organization) }
diff --git a/app/models/debate.rb b/app/models/debate.rb
index 15590fc60..1c3b63370 100644
--- a/app/models/debate.rb
+++ b/app/models/debate.rb
@@ -12,7 +12,7 @@ class Debate < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
- has_many :inappropiate_flags, :as => :flaggable
+ has_many :flags, :as => :flaggable
validates :title, presence: true
validates :description, presence: true
@@ -23,10 +23,10 @@ class Debate < ActiveRecord::Base
before_validation :sanitize_description
before_validation :sanitize_tag_list
- scope :sorted_for_moderation, -> { order(inappropiate_flags_count: :desc, updated_at: :desc) }
+ scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
scope :pending, -> { where(archived_at: nil, hidden_at: nil) }
scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") }
- scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") }
+ scope :flagged, -> { where("flags_count > 0") }
scope :for_render, -> { includes(:tags) }
# Ahoy setup
diff --git a/app/models/inappropiate_flag.rb b/app/models/flag.rb
similarity index 72%
rename from app/models/inappropiate_flag.rb
rename to app/models/flag.rb
index b60b98618..d2f30d284 100644
--- a/app/models/inappropiate_flag.rb
+++ b/app/models/flag.rb
@@ -1,7 +1,7 @@
-class InappropiateFlag < ActiveRecord::Base
+class Flag < ActiveRecord::Base
belongs_to :user
- belongs_to :flaggable, polymorphic: true, counter_cache: true, touch: :flagged_as_inappropiate_at
+ belongs_to :flaggable, polymorphic: true, counter_cache: true
scope(:by_user_and_flaggable, lambda do |user, flaggable|
where(user_id: user.id,
@@ -12,13 +12,13 @@ class InappropiateFlag < ActiveRecord::Base
class AlreadyFlaggedError < StandardError
def initialize
- super "The flaggable was already flagged as inappropiate by this user"
+ super "The flaggable was already flagged by this user"
end
end
class NotFlaggedError < StandardError
def initialize
- super "The flaggable was not flagged as inappropiate by this user"
+ super "The flaggable was not flagged by this user"
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index d7b77a7e0..27e886b90 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -14,7 +14,7 @@ class User < ActiveRecord::Base
has_one :administrator
has_one :moderator
has_one :organization
- has_many :inappropiate_flags
+ has_many :flags
has_many :identities, dependent: :destroy
validates :username, presence: true, unless: :organization?
diff --git a/app/views/comments/_actions.html.erb b/app/views/comments/_actions.html.erb
index 51a6743e0..c4bb0d072 100644
--- a/app/views/comments/_actions.html.erb
+++ b/app/views/comments/_actions.html.erb
@@ -1,5 +1,5 @@
-
- <%= render 'comments/flag_as_inappropiate_actions', comment: comment %>
+
+ <%= render 'comments/flag_actions', comment: comment %>
diff --git a/app/views/comments/_flag_as_inappropiate_actions.html.erb b/app/views/comments/_flag_actions.html.erb
similarity index 65%
rename from app/views/comments/_flag_as_inappropiate_actions.html.erb
rename to app/views/comments/_flag_actions.html.erb
index 9fba8b5b2..f1557668c 100644
--- a/app/views/comments/_flag_as_inappropiate_actions.html.erb
+++ b/app/views/comments/_flag_actions.html.erb
@@ -1,23 +1,23 @@
-<% if can? :flag_as_inappropiate, comment %>
+<% if can? :flag, comment %>
|
-
+
<% end %>
-<% if can? :undo_flag_as_inappropiate, comment %>
+<% if can? :unflag, comment %>
|
-
+
<% end %>
diff --git a/app/views/comments/_refresh_flag_actions.js.erb b/app/views/comments/_refresh_flag_actions.js.erb
new file mode 100644
index 000000000..01c1dcf76
--- /dev/null
+++ b/app/views/comments/_refresh_flag_actions.js.erb
@@ -0,0 +1 @@
+$("#<%= dom_id(@comment) %> .js-flag-actions").html('<%= j render("comments/flag_actions", comment: @comment) %>');
diff --git a/app/views/comments/_refresh_flag_as_inappropiate_actions.js.erb b/app/views/comments/_refresh_flag_as_inappropiate_actions.js.erb
deleted file mode 100644
index 58f356f2b..000000000
--- a/app/views/comments/_refresh_flag_as_inappropiate_actions.js.erb
+++ /dev/null
@@ -1 +0,0 @@
-$("#<%= dom_id(@comment) %> .js-flag-as-inappropiate-actions").html('<%= j render("comments/flag_as_inappropiate_actions", comment: @comment) %>');
diff --git a/app/views/debates/_flag_as_inappropiate_actions.html.erb b/app/views/debates/_flag_actions.html.erb
similarity index 63%
rename from app/views/debates/_flag_as_inappropiate_actions.html.erb
rename to app/views/debates/_flag_actions.html.erb
index 6c3d34236..07fff9329 100644
--- a/app/views/debates/_flag_as_inappropiate_actions.html.erb
+++ b/app/views/debates/_flag_actions.html.erb
@@ -1,21 +1,21 @@
-<% if can? :flag_as_inappropiate, debate %>
-
+<% if can? :flag, debate %>
+
-
- <%= link_to t('shared.flag_as_inappropiate'), flag_as_inappropiate_debate_path(debate), method: :put, remote: true, id: "flag-debate-#{ debate.id }" %>
+ <%= link_to t('shared.flag'), flag_debate_path(debate), method: :put, remote: true, id: "flag-debate-#{ debate.id }" %>
<% end %>
-<% if can? :undo_flag_as_inappropiate, debate %>
-
+<% if can? :unflag, debate %>
+
-
- <%= link_to t('shared.undo_flag_as_inappropiate'), undo_flag_as_inappropiate_debate_path(debate), method: :put, remote: true, id: "unflag-debate-#{ debate.id }" %>
+ <%= link_to t('shared.unflag'), unflag_debate_path(debate), method: :put, remote: true, id: "unflag-debate-#{ debate.id }" %>
<% end %>
diff --git a/app/views/debates/_refresh_flag_actions.js.erb b/app/views/debates/_refresh_flag_actions.js.erb
new file mode 100644
index 000000000..f511f347f
--- /dev/null
+++ b/app/views/debates/_refresh_flag_actions.js.erb
@@ -0,0 +1 @@
+$("#<%= dom_id(@debate) %> .js-flag-actions").html('<%= j render("debates/flag_actions", debate: @debate) %>');
diff --git a/app/views/debates/_refresh_flag_as_inappropiate_actions.js.erb b/app/views/debates/_refresh_flag_as_inappropiate_actions.js.erb
deleted file mode 100644
index 7be008e35..000000000
--- a/app/views/debates/_refresh_flag_as_inappropiate_actions.js.erb
+++ /dev/null
@@ -1 +0,0 @@
-$("#<%= dom_id(@debate) %> .js-flag-as-inappropiate-actions").html('<%= j render("debates/flag_as_inappropiate_actions", debate: @debate) %>');
diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb
index af25f28b1..8fab71128 100644
--- a/app/views/debates/show.html.erb
+++ b/app/views/debates/show.html.erb
@@ -42,8 +42,8 @@
<%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %>
•
-
- <%= render 'debates/flag_as_inappropiate_actions', debate: @debate %>
+
+ <%= render 'debates/flag_actions', debate: @debate %>
diff --git a/app/views/moderation/comments/index.html.erb b/app/views/moderation/comments/index.html.erb
index f4ce8ec67..c4b9d3ee0 100644
--- a/app/views/moderation/comments/index.html.erb
+++ b/app/views/moderation/comments/index.html.erb
@@ -35,7 +35,7 @@
<%= l comment.updated_at.to_date %>
<%= comment.body %> |
- <%= comment.inappropiate_flags_count %> |
+ <%= comment.flags_count %> |
<%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %>
|
diff --git a/app/views/moderation/debates/index.html.erb b/app/views/moderation/debates/index.html.erb
index ac11d2159..30cd14669 100644
--- a/app/views/moderation/debates/index.html.erb
+++ b/app/views/moderation/debates/index.html.erb
@@ -34,7 +34,7 @@
<%= debate.description %>
- <%= debate.inappropiate_flags_count %> |
+ <%= debate.flags_count %> |
<%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %>
|
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 322cf585f..03e0f900e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -133,8 +133,8 @@ en:
shared:
tags_cloud:
tags: Topics
- flag_as_inappropiate: Flag as inappropriate
- undo_flag_as_inappropiate: Undo flag
+ flag: Flag as inappropriate
+ unflag: Undo flag
collective: Collective
mailer:
comment:
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 5c21c039e..3ef3a5113 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -133,8 +133,8 @@ es:
shared:
tags_cloud:
tags: Temas
- flag_as_inappropiate: Denunciar como inapropiado
- undo_flag_as_inappropiate: Deshacer denuncia
+ flag: Denunciar como inapropiado
+ unflag: Deshacer denuncia
collective: Colectivo
mailer:
comment:
diff --git a/config/routes.rb b/config/routes.rb
index 3a75c8634..c6db2acd9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -28,15 +28,15 @@ Rails.application.routes.draw do
resources :debates do
member do
post :vote
- put :flag_as_inappropiate
- put :undo_flag_as_inappropiate
+ put :flag
+ put :unflag
end
resources :comments, only: :create, shallow: true do
member do
post :vote
- put :flag_as_inappropiate
- put :undo_flag_as_inappropiate
+ put :flag
+ put :unflag
end
end
end
diff --git a/spec/factories.rb b/spec/factories.rb
index ded2e20a0..ed77770a4 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -26,9 +26,9 @@ FactoryGirl.define do
archived_at Time.now
end
- trait :flagged_as_inappropiate do
+ trait :flagged do
after :create do |debate|
- InappropiateFlag.flag!(FactoryGirl.create(:user), debate)
+ Flag.flag!(FactoryGirl.create(:user), debate)
end
end
end
@@ -55,9 +55,9 @@ FactoryGirl.define do
archived_at Time.now
end
- trait :flagged_as_inappropiate do
+ trait :flagged do
after :create do |debate|
- InappropiateFlag.flag!(FactoryGirl.create(:user), debate)
+ Flag.flag!(FactoryGirl.create(:user), debate)
end
end
end
diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb
index 58626b02b..0986412bc 100644
--- a/spec/features/comments_spec.rb
+++ b/spec/features/comments_spec.rb
@@ -148,14 +148,14 @@ feature 'Comments' do
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end
- expect(InappropiateFlag.flagged?(user, comment)).to be
+ expect(Flag.flagged?(user, comment)).to be
end
scenario "Undoing flagging as inappropriate", :js do
user = create(:user)
debate = create(:debate)
comment = create(:comment, commentable: debate)
- InappropiateFlag.flag!(user, comment)
+ Flag.flag!(user, comment)
login_as(user)
visit debate_path(debate)
@@ -167,7 +167,7 @@ feature 'Comments' do
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
- expect(InappropiateFlag.flagged?(user, comment)).to_not be
+ expect(Flag.flagged?(user, comment)).to_not be
end
feature "Moderators" do
diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb
index 22b689308..2fd114adc 100644
--- a/spec/features/debates_spec.rb
+++ b/spec/features/debates_spec.rb
@@ -315,7 +315,7 @@ feature 'Debates' do
end
end
- scenario "Flagging as inappropiate", :js do
+ scenario "Flagging", :js do
user = create(:user)
debate = create(:debate)
@@ -329,13 +329,13 @@ feature 'Debates' do
expect(page).to have_css("#unflag-expand-debate-#{debate.id}")
end
- expect(InappropiateFlag.flagged?(user, debate)).to be
+ expect(Flag.flagged?(user, debate)).to be
end
- scenario "Undoing flagging as inappropiate", :js do
+ scenario "Unflagging", :js do
user = create(:user)
debate = create(:debate)
- InappropiateFlag.flag!(user, debate)
+ Flag.flag!(user, debate)
login_as(user)
visit debate_path(debate)
@@ -347,7 +347,7 @@ feature 'Debates' do
expect(page).to have_css("#flag-expand-debate-#{debate.id}")
end
- expect(InappropiateFlag.flagged?(user, debate)).to_not be
+ expect(Flag.flagged?(user, debate)).to_not be
end
end
diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb
index 2e3d1196e..efc37fc72 100644
--- a/spec/features/moderation/comments_spec.rb
+++ b/spec/features/moderation/comments_spec.rb
@@ -123,9 +123,9 @@ feature 'Moderate Comments' do
end
scenario "Filtering comments" do
- create(:comment, :flagged_as_inappropiate, body: "Pending comment")
- create(:comment, :flagged_as_inappropiate, :hidden, body: "Hidden comment")
- create(:comment, :flagged_as_inappropiate, :archived, body: "Archived comment")
+ create(:comment, :flagged, body: "Pending comment")
+ create(:comment, :flagged, :hidden, body: "Hidden comment")
+ create(:comment, :flagged, :archived, body: "Archived comment")
visit moderation_comments_path(filter: 'all')
expect(page).to have_content('Pending comment')
@@ -145,7 +145,7 @@ feature 'Moderate Comments' do
scenario "Reviewing links remember the pagination setting and the filter" do
per_page = Kaminari.config.default_per_page
- (per_page + 2).times { create(:comment, :flagged_as_inappropiate) }
+ (per_page + 2).times { create(:comment, :flagged) }
visit moderation_comments_path(filter: 'pending', page: 2)
@@ -162,7 +162,7 @@ feature 'Moderate Comments' do
background do
debate = create(:debate, title: 'Democracy')
- @comment = create(:comment, :flagged_as_inappropiate, commentable: debate, body: 'spammy spam')
+ @comment = create(:comment, :flagged, commentable: debate, body: 'spammy spam')
visit moderation_comments_path
end
diff --git a/spec/features/moderation/debates_spec.rb b/spec/features/moderation/debates_spec.rb
index b1234bb1b..ee9f53b7e 100644
--- a/spec/features/moderation/debates_spec.rb
+++ b/spec/features/moderation/debates_spec.rb
@@ -66,9 +66,9 @@ feature 'Moderate debates' do
end
scenario "Filtering debates" do
- create(:debate, :flagged_as_inappropiate, title: "Pending debate")
- create(:debate, :flagged_as_inappropiate, :hidden, title: "Hidden debate")
- create(:debate, :flagged_as_inappropiate, :archived, title: "Archived debate")
+ create(:debate, :flagged, title: "Pending debate")
+ create(:debate, :flagged, :hidden, title: "Hidden debate")
+ create(:debate, :flagged, :archived, title: "Archived debate")
visit moderation_debates_path(filter: 'all')
expect(page).to have_content('Pending debate')
@@ -88,7 +88,7 @@ feature 'Moderate debates' do
scenario "Reviewing links remember the pagination setting and the filter" do
per_page = Kaminari.config.default_per_page
- (per_page + 2).times { create(:debate, :flagged_as_inappropiate) }
+ (per_page + 2).times { create(:debate, :flagged) }
visit moderation_debates_path(filter: 'pending', page: 2)
@@ -104,7 +104,7 @@ feature 'Moderate debates' do
feature 'A flagged debate exists' do
background do
- @debate = create(:debate, :flagged_as_inappropiate, title: 'spammy spam', description: 'buy buy buy')
+ @debate = create(:debate, :flagged, title: 'spammy spam', description: 'buy buy buy')
visit moderation_debates_path
end
diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb
index a7cfd195f..440807603 100644
--- a/spec/models/ability_spec.rb
+++ b/spec/models/ability_spec.rb
@@ -31,38 +31,38 @@ describe Ability do
it { should_not be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) }
- describe 'flagging content as inappropiate' do
- it { should be_able_to(:flag_as_inappropiate, debate) }
- it { should_not be_able_to(:undo_flag_as_inappropiate, debate) }
- it { should be_able_to(:flag_as_inappropiate, comment) }
- it { should_not be_able_to(:undo_flag_as_inappropiate, comment) }
+ describe 'flagging content' do
+ it { should be_able_to(:flag, debate) }
+ it { should_not be_able_to(:unflag, debate) }
+ it { should be_able_to(:flag, comment) }
+ it { should_not be_able_to(:unflag, comment) }
describe "own comments" do
let(:own_comment) { create(:comment, author: user) }
- it { should_not be_able_to(:flag_as_inappropiate, own_comment) }
- it { should_not be_able_to(:undo_flag_as_inappropiate, own_comment) }
+ it { should_not be_able_to(:flag, own_comment) }
+ it { should_not be_able_to(:unflag, own_comment) }
end
describe "own debates" do
let(:own_debate) { create(:debate, author: user) }
- it { should_not be_able_to(:flag_as_inappropiate, own_debate) }
- it { should_not be_able_to(:undo_flag_as_inappropiate, own_debate) }
+ it { should_not be_able_to(:flag, own_debate) }
+ it { should_not be_able_to(:unflag, own_debate) }
end
describe "already-flagged comments" do
- before(:each) { InappropiateFlag.flag!(user, comment) }
+ before(:each) { Flag.flag!(user, comment) }
- it { should_not be_able_to(:flag_as_inappropiate, comment) }
- it { should be_able_to(:undo_flag_as_inappropiate, comment) }
+ it { should_not be_able_to(:flag, comment) }
+ it { should be_able_to(:unflag, comment) }
end
describe "already-flagged debates" do
- before(:each) { InappropiateFlag.flag!(user, debate) }
+ before(:each) { Flag.flag!(user, debate) }
- it { should_not be_able_to(:flag_as_inappropiate, debate) }
- it { should be_able_to(:undo_flag_as_inappropiate, debate) }
+ it { should_not be_able_to(:flag, debate) }
+ it { should be_able_to(:unflag, debate) }
end
end
diff --git a/spec/models/inappropiate_flag_spec.rb b/spec/models/flag_spec.rb
similarity index 65%
rename from spec/models/inappropiate_flag_spec.rb
rename to spec/models/flag_spec.rb
index 0ae831ee0..a5725e7c8 100644
--- a/spec/models/inappropiate_flag_spec.rb
+++ b/spec/models/flag_spec.rb
@@ -1,6 +1,6 @@
require 'rails_helper'
-describe InappropiateFlag do
+describe Flag do
let(:user) { create(:user) }
let(:comment) { create(:comment) }
@@ -8,43 +8,35 @@ describe InappropiateFlag do
describe '.flag!' do
it 'creates a flag when there is none' do
- expect { described_class.flag!(user, comment) }.to change{ InappropiateFlag.count }.by(1)
- expect(InappropiateFlag.last.user).to eq(user)
- expect(InappropiateFlag.last.flaggable).to eq(comment)
+ expect { described_class.flag!(user, comment) }.to change{ Flag.count }.by(1)
+ expect(Flag.last.user).to eq(user)
+ expect(Flag.last.flaggable).to eq(comment)
end
it 'raises an error if the flag has already been created' do
described_class.flag!(user, comment)
- expect { described_class.flag!(user, comment) }.to raise_error(InappropiateFlag::AlreadyFlaggedError)
+ expect { described_class.flag!(user, comment) }.to raise_error(Flag::AlreadyFlaggedError)
end
it 'increases the flag count' do
- expect { described_class.flag!(user, comment) }.to change{ comment.reload.inappropiate_flags_count }.by(1)
- end
-
- it 'updates the flagged_as date' do
- expect { described_class.flag!(user, comment) }.to change{ comment.reload.flagged_as_inappropiate_at }
+ expect { described_class.flag!(user, comment) }.to change{ comment.reload.flags_count }.by(1)
end
end
describe '.unflag!' do
it 'raises an error if the flag does not exist' do
- expect { described_class.unflag!(user, comment) }.to raise_error(InappropiateFlag::NotFlaggedError)
+ expect { described_class.unflag!(user, comment) }.to raise_error(Flag::NotFlaggedError)
end
describe 'when the flag already exists' do
before(:each) { described_class.flag!(user, comment) }
it 'removes an existing flag' do
- expect { described_class.unflag!(user, comment) }.to change{ InappropiateFlag.count }.by(-1)
+ expect { described_class.unflag!(user, comment) }.to change{ Flag.count }.by(-1)
end
it 'decreases the flag count' do
- expect { described_class.unflag!(user, comment) }.to change{ comment.reload.inappropiate_flags_count }.by(-1)
- end
-
- it 'does not update the flagged_as date' do
- expect { described_class.unflag!(user, comment) }.to_not change{ comment.flagged_as_inappropiate_at }
+ expect { described_class.unflag!(user, comment) }.to change{ comment.reload.flags_count }.by(-1)
end
end
From 17b33f103063965fad199bb32e6720dad93ce88b Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 11:08:10 +0200
Subject: [PATCH 05/18] rename flag_ignored_at to ignored_flag_at in migrations
---
...rchived_at_to_flag_ignored_at_in_comments_and_debates.rb | 6 ------
...rchived_at_to_ignored_flag_at_in_comments_and_debates.rb | 6 ++++++
db/schema.rb | 4 ++--
3 files changed, 8 insertions(+), 8 deletions(-)
delete mode 100644 db/migrate/20150827080641_rename_archived_at_to_flag_ignored_at_in_comments_and_debates.rb
create mode 100644 db/migrate/20150827080641_rename_archived_at_to_ignored_flag_at_in_comments_and_debates.rb
diff --git a/db/migrate/20150827080641_rename_archived_at_to_flag_ignored_at_in_comments_and_debates.rb b/db/migrate/20150827080641_rename_archived_at_to_flag_ignored_at_in_comments_and_debates.rb
deleted file mode 100644
index 7328ca79b..000000000
--- a/db/migrate/20150827080641_rename_archived_at_to_flag_ignored_at_in_comments_and_debates.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-class RenameArchivedAtToFlagIgnoredAtInCommentsAndDebates < ActiveRecord::Migration
- def change
- rename_column :comments, :archived_at, :flag_ignored_at
- rename_column :debates, :archived_at, :flag_ignored_at
- end
-end
diff --git a/db/migrate/20150827080641_rename_archived_at_to_ignored_flag_at_in_comments_and_debates.rb b/db/migrate/20150827080641_rename_archived_at_to_ignored_flag_at_in_comments_and_debates.rb
new file mode 100644
index 000000000..5a0c90085
--- /dev/null
+++ b/db/migrate/20150827080641_rename_archived_at_to_ignored_flag_at_in_comments_and_debates.rb
@@ -0,0 +1,6 @@
+class RenameArchivedAtToIgnoredFlagAtInCommentsAndDebates < ActiveRecord::Migration
+ def change
+ rename_column :comments, :archived_at, :ignored_flag_at
+ rename_column :debates, :archived_at, :ignored_flag_at
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index de3339365..e14c97e02 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -50,7 +50,7 @@ ActiveRecord::Schema.define(version: 20150827083232) do
t.integer "children_count", default: 0
t.datetime "hidden_at"
t.integer "flags_count", default: 0
- t.datetime "flag_ignored_at"
+ t.datetime "ignored_flag_at"
t.integer "moderator_id"
t.integer "administrator_id"
t.integer "cached_votes_total", default: 0
@@ -78,7 +78,7 @@ ActiveRecord::Schema.define(version: 20150827083232) do
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
- t.datetime "flag_ignored_at"
+ t.datetime "ignored_flag_at"
t.integer "comments_count", default: 0
t.datetime "hide_reviewed_at"
end
From cd982768f2a526f7faae0e81b902a884462241cd Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 11:43:58 +0200
Subject: [PATCH 06/18] Renames the "archive" action to "ignore_flag" (+)
* archived_at -> ignored_flag_at
* archived? -> ignored_flag?
* archive -> ignore_flag
* pending -> pending_flag_review
* archived (scope) -> with_ignored_flag
* I18n changes
---
app/assets/stylesheets/admin.scss | 5 +++
.../moderation/comments_controller.rb | 6 +--
.../moderation/debates_controller.rb | 6 +--
app/models/ability.rb | 8 ++--
app/models/comment.rb | 16 ++++----
app/models/debate.rb | 12 +++---
app/views/moderation/comments/index.html.erb | 10 ++---
app/views/moderation/debates/index.html.erb | 10 ++---
config/locales/moderation.en.yml | 16 ++++----
config/locales/moderation.es.yml | 16 ++++----
config/routes.rb | 4 +-
spec/factories.rb | 8 ++--
spec/features/moderation/comments_spec.rb | 40 +++++++++----------
spec/features/moderation/debates_spec.rb | 40 +++++++++----------
spec/models/ability_spec.rb | 20 +++++-----
15 files changed, 111 insertions(+), 106 deletions(-)
diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss
index 5afa088d1..08f95cd41 100644
--- a/app/assets/stylesheets/admin.scss
+++ b/app/assets/stylesheets/admin.scss
@@ -164,6 +164,11 @@ body.admin {
font-size: rem-calc(12);
}
+.ignored {
+ color: $text-medium;
+ font-size: rem-calc(12);
+}
+
.rejected {
color: $delete;
}
diff --git a/app/controllers/moderation/comments_controller.rb b/app/controllers/moderation/comments_controller.rb
index 0570ab5d3..3622d02ac 100644
--- a/app/controllers/moderation/comments_controller.rb
+++ b/app/controllers/moderation/comments_controller.rb
@@ -19,8 +19,8 @@ class Moderation::CommentsController < Moderation::BaseController
redirect_to request.query_parameters.merge(action: :index)
end
- def archive
- @comment.archive
+ def ignore_flag
+ @comment.ignore_flag
redirect_to request.query_parameters.merge(action: :index)
end
@@ -31,7 +31,7 @@ class Moderation::CommentsController < Moderation::BaseController
end
def set_valid_filters
- @valid_filters = %w{all pending archived}
+ @valid_filters = %w{all pending_flag_review with_ignored_flag}
end
def parse_filter
diff --git a/app/controllers/moderation/debates_controller.rb b/app/controllers/moderation/debates_controller.rb
index fdc09b61d..abb8e964b 100644
--- a/app/controllers/moderation/debates_controller.rb
+++ b/app/controllers/moderation/debates_controller.rb
@@ -19,8 +19,8 @@ class Moderation::DebatesController < Moderation::BaseController
redirect_to request.query_parameters.merge(action: :index)
end
- def archive
- @debate.archive
+ def ignore_flag
+ @debate.ignore_flag
redirect_to request.query_parameters.merge(action: :index)
end
@@ -31,7 +31,7 @@ class Moderation::DebatesController < Moderation::BaseController
end
def set_valid_filters
- @valid_filters = %w{all pending archived}
+ @valid_filters = %w{all pending_flag_review with_ignored_flag}
end
def parse_filter
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 7a682de5a..3f209d626 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -53,14 +53,14 @@ class Ability
can :hide, Comment, hidden_at: nil
cannot :hide, Comment, user_id: user.id
- can :archive, Comment, archived_at: nil, hidden_at: nil
- cannot :archive, Comment, user_id: user.id
+ can :ignore_flag, Comment, ignored_flag_at: nil, hidden_at: nil
+ cannot :ignore_flag, Comment, user_id: user.id
can :hide, Debate, hidden_at: nil
cannot :hide, Debate, author_id: user.id
- can :archive, Debate, archived_at: nil, hidden_at: nil
- cannot :archive, Debate, author_id: user.id
+ can :ignore_flag, Debate, ignored_flag_at: nil, hidden_at: nil
+ cannot :ignore_flag, Debate, author_id: user.id
can :hide, User
cannot :hide, User, id: user.id
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 9df42b700..58888719f 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -17,8 +17,8 @@ class Comment < ActiveRecord::Base
scope :recent, -> { order(id: :desc) }
scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
- scope :pending, -> { where(archived_at: nil, hidden_at: nil) }
- scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") }
+ scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) }
+ scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") }
scope :flagged, -> { where("flags_count > 0") }
scope :for_render, -> { with_hidden.includes(user: :organization) }
@@ -65,8 +65,12 @@ class Comment < ActiveRecord::Base
hidden? || user.hidden?
end
- def archived?
- archived_at.present?
+ def ignored_flag?
+ ignored_flag_at.present?
+ end
+
+ def ignore_flag
+ update(ignored_flag_at: Time.now)
end
def as_administrator?
@@ -77,10 +81,6 @@ class Comment < ActiveRecord::Base
moderator_id.present?
end
- def archive
- update(archived_at: Time.now)
- end
-
# TODO: faking counter cache since there is a bug with acts_as_nested_set :counter_cache
# Remove when https://github.com/collectiveidea/awesome_nested_set/issues/294 is fixed
# and reset counters using
diff --git a/app/models/debate.rb b/app/models/debate.rb
index 1c3b63370..eed3fb7b5 100644
--- a/app/models/debate.rb
+++ b/app/models/debate.rb
@@ -24,8 +24,8 @@ class Debate < ActiveRecord::Base
before_validation :sanitize_tag_list
scope :sorted_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) }
- scope :pending, -> { where(archived_at: nil, hidden_at: nil) }
- scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") }
+ scope :pending_flag_review, -> { where(ignored_flag_at: nil, hidden_at: nil) }
+ scope :with_ignored_flag, -> { where("ignored_flag_at IS NOT NULL AND hidden_at IS NULL") }
scope :flagged, -> { where("flags_count > 0") }
scope :for_render, -> { includes(:tags) }
@@ -75,12 +75,12 @@ class Debate < ActiveRecord::Base
count < 0 ? 0 : count
end
- def archived?
- archived_at.present?
+ def ignored_flag?
+ ignored_flag_at.present?
end
- def archive
- update(archived_at: Time.now)
+ def ignore_flag
+ update(ignored_flag_at: Time.now)
end
protected
diff --git a/app/views/moderation/comments/index.html.erb b/app/views/moderation/comments/index.html.erb
index c4b9d3ee0..f9c95e9be 100644
--- a/app/views/moderation/comments/index.html.erb
+++ b/app/views/moderation/comments/index.html.erb
@@ -39,14 +39,14 @@
<%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %>
|
- <% if can? :archive, comment %>
+ <% if can? :ignore_flag, comment %>
- <%= link_to t("moderation.comments.index.archive"), archive_moderation_comment_path(comment, request.query_parameters), method: :put, class: "button radius tiny warning" %>
+ <%= link_to t("moderation.comments.index.ignore_flag"), ignore_flag_moderation_comment_path(comment, request.query_parameters), method: :put, class: "button radius tiny warning" %>
|
<% end %>
- <% if comment.archived? %>
-
- <%= t("moderation.comments.index.archived") %>
+ <% if comment.ignored_flag? %>
+ |
+ <%= t("moderation.comments.index.ignored_flag") %>
|
<% end %>
diff --git a/app/views/moderation/debates/index.html.erb b/app/views/moderation/debates/index.html.erb
index 30cd14669..cbd6baa5d 100644
--- a/app/views/moderation/debates/index.html.erb
+++ b/app/views/moderation/debates/index.html.erb
@@ -38,14 +38,14 @@
<%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %>
|
- <% if can? :archive, debate %>
+ <% if can? :ignore_flag, debate %>
- <%= link_to t("moderation.debates.index.archive"), archive_moderation_debate_path(debate, request.query_parameters), method: :put, class: "button radius tiny warning" %>
+ <%= link_to t("moderation.debates.index.ignore_flag"), ignore_flag_moderation_debate_path(debate, request.query_parameters), method: :put, class: "button radius tiny warning" %>
|
<% end %>
- <% if debate.archived? %>
-
- <%= t("moderation.debates.index.archived") %>
+ <% if debate.ignored_flag? %>
+ |
+ <%= t("moderation.debates.index.ignored_flag") %>
|
<% end %>
diff --git a/config/locales/moderation.en.yml b/config/locales/moderation.en.yml
index 3d61c93a2..6e04e8765 100644
--- a/config/locales/moderation.en.yml
+++ b/config/locales/moderation.en.yml
@@ -16,13 +16,13 @@ en:
commentable: Root
comment: Comment
hide: Hide
- archive: Archive
- archived: Archived
+ ignore_flag: Ignore
+ ignored_flag: Ignored
filter: Filter
filters:
all: All
- pending: Pending
- archived: Archived
+ pending_flag_review: Pending
+ with_ignored_flag: Ignored
debates:
index:
title: Debates flagged as inappropriate
@@ -33,10 +33,10 @@ en:
description: Description
actions: Actions
hide: Hide
- archive: Archive
- archived: Archived
+ ignore_flag: Ignore
+ ignored_flag: Ignored
filter: Filter
filters:
all: All
- pending: Pending
- archived: Archived
+ pending_flag_review: Pending
+ with_ignored_flag: Ignored
diff --git a/config/locales/moderation.es.yml b/config/locales/moderation.es.yml
index 73886ddb0..04889d214 100644
--- a/config/locales/moderation.es.yml
+++ b/config/locales/moderation.es.yml
@@ -16,13 +16,13 @@ es:
commentable: Raíz
comment: Comentario
hide: Ocultar
- archive: Archivar
- archived: Archivado
+ ignore_flag: Ignorar
+ ignored_flag: Ignorado
filter: Filtrar
filters:
all: Todos
- pending: Pendientes
- archived: Archivados
+ pending_flag_review: Pendientes
+ with_ignored_flag: Ignorados
debates:
index:
title: Debates denunciados como inapropiados
@@ -33,10 +33,10 @@ es:
description: Descripción
actions: Acciones
hide: Ocultar
- archive: Archivar
- archived: Archivado
+ ignore_flag: Ignorar
+ ignored_flag: Ignorado
filter: Filtrar
filters:
all: Todos
- pending: Pendientes
- archived: Archivados
+ pending_flag_review: Pendientes
+ with_ignored_flag: Ignorados
diff --git a/config/routes.rb b/config/routes.rb
index c6db2acd9..6d2170ffd 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -88,7 +88,7 @@ Rails.application.routes.draw do
member do
put :hide
put :hide_in_moderation_screen
- put :archive
+ put :ignore_flag
end
end
@@ -96,7 +96,7 @@ Rails.application.routes.draw do
member do
put :hide
put :hide_in_moderation_screen
- put :archive
+ put :ignore_flag
end
end
end
diff --git a/spec/factories.rb b/spec/factories.rb
index ed77770a4..38ba6fd16 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -22,8 +22,8 @@ FactoryGirl.define do
hidden_at Time.now
end
- trait :archived do
- archived_at Time.now
+ trait :with_ignored_flag do
+ ignored_flag_at Time.now
end
trait :flagged do
@@ -51,8 +51,8 @@ FactoryGirl.define do
hidden_at Time.now
end
- trait :archived do
- archived_at Time.now
+ trait :with_ignored_flag do
+ ignored_flag_at Time.now
end
trait :flagged do
diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb
index efc37fc72..b78be6967 100644
--- a/spec/features/moderation/comments_spec.rb
+++ b/spec/features/moderation/comments_spec.rb
@@ -104,57 +104,57 @@ feature 'Moderate Comments' do
visit moderation_comments_path
expect(page).to_not have_link('All')
expect(page).to have_link('Pending')
- expect(page).to have_link('Archived')
+ expect(page).to have_link('Ignored')
visit moderation_comments_path(filter: 'all')
expect(page).to_not have_link('All')
expect(page).to have_link('Pending')
- expect(page).to have_link('Archived')
+ expect(page).to have_link('Ignored')
- visit moderation_comments_path(filter: 'pending')
+ visit moderation_comments_path(filter: 'pending_flag_review')
expect(page).to have_link('All')
expect(page).to_not have_link('Pending')
- expect(page).to have_link('Archived')
+ expect(page).to have_link('Ignored')
- visit moderation_comments_path(filter: 'archived')
+ visit moderation_comments_path(filter: 'with_ignored_flag')
expect(page).to have_link('All')
expect(page).to have_link('Pending')
- expect(page).to_not have_link('Archived')
+ expect(page).to_not have_link('Ignored')
end
scenario "Filtering comments" do
create(:comment, :flagged, body: "Pending comment")
create(:comment, :flagged, :hidden, body: "Hidden comment")
- create(:comment, :flagged, :archived, body: "Archived comment")
+ create(:comment, :flagged, :with_ignored_flag, body: "Ignored comment")
visit moderation_comments_path(filter: 'all')
expect(page).to have_content('Pending comment')
expect(page).to_not have_content('Hidden comment')
- expect(page).to have_content('Archived comment')
+ expect(page).to have_content('Ignored comment')
- visit moderation_comments_path(filter: 'pending')
+ visit moderation_comments_path(filter: 'pending_flag_review')
expect(page).to have_content('Pending comment')
expect(page).to_not have_content('Hidden comment')
- expect(page).to_not have_content('Archived comment')
+ expect(page).to_not have_content('Ignored comment')
- visit moderation_comments_path(filter: 'archived')
+ visit moderation_comments_path(filter: 'with_ignored_flag')
expect(page).to_not have_content('Pending comment')
expect(page).to_not have_content('Hidden comment')
- expect(page).to have_content('Archived comment')
+ expect(page).to have_content('Ignored comment')
end
scenario "Reviewing links remember the pagination setting and the filter" do
per_page = Kaminari.config.default_per_page
(per_page + 2).times { create(:comment, :flagged) }
- visit moderation_comments_path(filter: 'pending', page: 2)
+ visit moderation_comments_path(filter: 'pending_flag_review', page: 2)
- click_link('Archive', match: :first, exact: true)
+ click_link('Ignore', match: :first, exact: true)
uri = URI.parse(current_url)
query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys
- expect(query_params[:filter]).to eq('pending')
+ expect(query_params[:filter]).to eq('pending_flag_review')
expect(query_params[:page]).to eq('2')
end
@@ -172,7 +172,7 @@ feature 'Moderate Comments' do
expect(page).to have_content('spammy spam')
expect(page).to have_content('1')
expect(page).to have_link('Hide')
- expect(page).to have_link('Archive')
+ expect(page).to have_link('Ignore')
end
end
@@ -187,18 +187,18 @@ feature 'Moderate Comments' do
expect(@comment.reload).to be_hidden
end
- scenario 'Marking the comment as archived' do
+ scenario 'Marking the comment as ignored' do
within("#comment_#{@comment.id}") do
- click_link('Archive')
+ click_link('Ignore')
end
expect(current_path).to eq(moderation_comments_path)
within("#comment_#{@comment.id}") do
- expect(page).to have_content('Archived')
+ expect(page).to have_content('Ignored')
end
- expect(@comment.reload).to be_archived
+ expect(@comment.reload).to be_ignored_flag
end
end
end
diff --git a/spec/features/moderation/debates_spec.rb b/spec/features/moderation/debates_spec.rb
index ee9f53b7e..8e3e105b5 100644
--- a/spec/features/moderation/debates_spec.rb
+++ b/spec/features/moderation/debates_spec.rb
@@ -47,57 +47,57 @@ feature 'Moderate debates' do
visit moderation_debates_path
expect(page).to_not have_link('All')
expect(page).to have_link('Pending')
- expect(page).to have_link('Archived')
+ expect(page).to have_link('Ignored')
visit moderation_debates_path(filter: 'all')
expect(page).to_not have_link('All')
expect(page).to have_link('Pending')
- expect(page).to have_link('Archived')
+ expect(page).to have_link('Ignored')
- visit moderation_debates_path(filter: 'pending')
+ visit moderation_debates_path(filter: 'pending_flag_review')
expect(page).to have_link('All')
expect(page).to_not have_link('Pending')
- expect(page).to have_link('Archived')
+ expect(page).to have_link('Ignored')
- visit moderation_debates_path(filter: 'archived')
+ visit moderation_debates_path(filter: 'with_ignored_flag')
expect(page).to have_link('All')
expect(page).to have_link('Pending')
- expect(page).to_not have_link('Archived')
+ expect(page).to_not have_link('Ignored')
end
scenario "Filtering debates" do
create(:debate, :flagged, title: "Pending debate")
create(:debate, :flagged, :hidden, title: "Hidden debate")
- create(:debate, :flagged, :archived, title: "Archived debate")
+ create(:debate, :flagged, :with_ignored_flag, title: "Ignored debate")
visit moderation_debates_path(filter: 'all')
expect(page).to have_content('Pending debate')
expect(page).to_not have_content('Hidden debate')
- expect(page).to have_content('Archived debate')
+ expect(page).to have_content('Ignored debate')
- visit moderation_debates_path(filter: 'pending')
+ visit moderation_debates_path(filter: 'pending_flag_review')
expect(page).to have_content('Pending debate')
expect(page).to_not have_content('Hidden debate')
- expect(page).to_not have_content('Archived debate')
+ expect(page).to_not have_content('Ignored debate')
- visit moderation_debates_path(filter: 'archived')
+ visit moderation_debates_path(filter: 'with_ignored_flag')
expect(page).to_not have_content('Pending debate')
expect(page).to_not have_content('Hidden debate')
- expect(page).to have_content('Archived debate')
+ expect(page).to have_content('Ignored debate')
end
scenario "Reviewing links remember the pagination setting and the filter" do
per_page = Kaminari.config.default_per_page
(per_page + 2).times { create(:debate, :flagged) }
- visit moderation_debates_path(filter: 'pending', page: 2)
+ visit moderation_debates_path(filter: 'pending_flag_review', page: 2)
- click_link('Archive', match: :first, exact: true)
+ click_link('Ignore', match: :first, exact: true)
uri = URI.parse(current_url)
query_params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys
- expect(query_params[:filter]).to eq('pending')
+ expect(query_params[:filter]).to eq('pending_flag_review')
expect(query_params[:page]).to eq('2')
end
@@ -114,7 +114,7 @@ feature 'Moderate debates' do
expect(page).to have_content('buy buy buy')
expect(page).to have_content('1')
expect(page).to have_link('Hide')
- expect(page).to have_link('Archive')
+ expect(page).to have_link('Ignore')
end
end
@@ -129,18 +129,18 @@ feature 'Moderate debates' do
expect(@debate.reload).to be_hidden
end
- scenario 'Marking the debate as archived' do
+ scenario 'Marking the debate as ignored' do
within("#debate_#{@debate.id}") do
- click_link('Archive')
+ click_link('Ignore')
end
expect(current_path).to eq(moderation_debates_path)
within("#debate_#{@debate.id}") do
- expect(page).to have_content('Archived')
+ expect(page).to have_content('Ignored')
end
- expect(@debate.reload).to be_archived
+ expect(@debate.reload).to be_ignored_flag
end
end
end
diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb
index 440807603..088516d1a 100644
--- a/spec/models/ability_spec.rb
+++ b/spec/models/ability_spec.rb
@@ -131,8 +131,8 @@ describe Ability do
let(:own_debate) { create(:debate, author: user) }
let(:hidden_comment) { create(:comment, :hidden) }
let(:hidden_debate) { create(:debate, :hidden) }
- let(:archived_comment) { create(:comment, :archived) }
- let(:archived_debate) { create(:debate, :archived) }
+ let(:ignored_comment) { create(:comment, :with_ignored_flag) }
+ let(:ignored_debate) { create(:debate, :with_ignored_flag) }
it { should be_able_to(:hide, comment) }
it { should be_able_to(:hide_in_moderation_screen, comment) }
@@ -144,15 +144,15 @@ describe Ability do
it { should_not be_able_to(:hide, hidden_debate) }
it { should_not be_able_to(:hide, own_debate) }
- it { should be_able_to(:archive, comment) }
- it { should_not be_able_to(:archive, hidden_comment) }
- it { should_not be_able_to(:archive, archived_comment) }
- it { should_not be_able_to(:archive, own_comment) }
+ it { should be_able_to(:ignore_flag, comment) }
+ it { should_not be_able_to(:ignore_flag, hidden_comment) }
+ it { should_not be_able_to(:ignore_flag, ignored_comment) }
+ it { should_not be_able_to(:ignore_flag, own_comment) }
- it { should be_able_to(:archive, debate) }
- it { should_not be_able_to(:archive, hidden_debate) }
- it { should_not be_able_to(:archive, archived_debate) }
- it { should_not be_able_to(:archive, own_debate) }
+ it { should be_able_to(:ignore_flag, debate) }
+ it { should_not be_able_to(:ignore_flag, hidden_debate) }
+ it { should_not be_able_to(:ignore_flag, ignored_debate) }
+ it { should_not be_able_to(:ignore_flag, own_debate) }
it { should_not be_able_to(:hide, user) }
it { should be_able_to(:hide, other_user) }
From 4ab5ab722e62fb741d604e68c1da468a77eae73f Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 12:23:10 +0200
Subject: [PATCH 07/18] hide_reviewed_at -> confirmed_hide_at
---
...7080701_add_confirmed_hide_at_to_comments_and_debates.rb | 6 ++++++
...27080701_add_hide_reviewed_at_to_comments_and_debates.rb | 6 +++---
db/schema.rb | 4 ++--
3 files changed, 11 insertions(+), 5 deletions(-)
create mode 100644 db/migrate/20150827080701_add_confirmed_hide_at_to_comments_and_debates.rb
diff --git a/db/migrate/20150827080701_add_confirmed_hide_at_to_comments_and_debates.rb b/db/migrate/20150827080701_add_confirmed_hide_at_to_comments_and_debates.rb
new file mode 100644
index 000000000..20d2872ac
--- /dev/null
+++ b/db/migrate/20150827080701_add_confirmed_hide_at_to_comments_and_debates.rb
@@ -0,0 +1,6 @@
+class AddConfirmedHideAtToCommentsAndDebates < ActiveRecord::Migration
+ def change
+ add_column :debates, :confirmed_hide_at, :datetime
+ add_column :comments, :confirmed_hide_at, :datetime
+ end
+end
diff --git a/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb b/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
index dfcef9f06..20d2872ac 100644
--- a/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
+++ b/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
@@ -1,6 +1,6 @@
-class AddHideReviewedAtToCommentsAndDebates < ActiveRecord::Migration
+class AddConfirmedHideAtToCommentsAndDebates < ActiveRecord::Migration
def change
- add_column :debates, :hide_reviewed_at, :datetime
- add_column :comments, :hide_reviewed_at, :datetime
+ add_column :debates, :confirmed_hide_at, :datetime
+ add_column :comments, :confirmed_hide_at, :datetime
end
end
diff --git a/db/schema.rb b/db/schema.rb
index e14c97e02..7819be065 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 20150827083232) do
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
- t.datetime "hide_reviewed_at"
+ t.datetime "confirmed_hide_at"
end
add_index "comments", ["cached_votes_down"], name: "index_comments_on_cached_votes_down", using: :btree
@@ -80,7 +80,7 @@ ActiveRecord::Schema.define(version: 20150827083232) do
t.integer "cached_votes_down", default: 0
t.datetime "ignored_flag_at"
t.integer "comments_count", default: 0
- t.datetime "hide_reviewed_at"
+ t.datetime "confirmed_hide_at"
end
add_index "debates", ["cached_votes_down"], name: "index_debates_on_cached_votes_down", using: :btree
From 1770dfd3f6e749ccb7eebfcd035b8783110631d3 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 13:20:12 +0200
Subject: [PATCH 08/18] adds ability to confirm the hiding of comments, debates
or users
---
app/models/ability.rb | 15 +++++++++++++++
spec/factories.rb | 4 ++++
spec/models/ability_spec.rb | 27 +++++++++++++++++++++++----
3 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 3f209d626..e931d037f 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -72,8 +72,23 @@ class Ability
if user.administrator?
can :restore, Comment
+ cannot :restore, Comment, hidden_at: nil
+
can :restore, Debate
+ cannot :restore, Debate, hidden_at: nil
+
can :restore, User
+ cannot :restore, User, hidden_at: nil
+
+ can :confirm_hide, Comment
+ cannot :confirm_hide, Comment, hidden_at: nil
+
+ can :confirm_hide, Debate
+ cannot :confirm_hide, Debate, hidden_at: nil
+
+ can :confirm_hide, User
+ cannot :confirm_hide, User, hidden_at: nil
+
can :comment_as_administrator, [Debate, Comment]
end
end
diff --git a/spec/factories.rb b/spec/factories.rb
index 38ba6fd16..9734b3364 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -4,6 +4,10 @@ FactoryGirl.define do
sequence(:email) { |n| "manuela#{n}@madrid.es" }
password 'judgmentday'
confirmed_at { Time.now }
+
+ trait :hidden do
+ hidden_at Time.now
+ end
end
factory :identity do
diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb
index 088516d1a..06e2a9a62 100644
--- a/spec/models/ability_spec.rb
+++ b/spec/models/ability_spec.rb
@@ -169,15 +169,34 @@ describe Ability do
describe "Administrator" do
let(:user) { create(:user) }
before { create(:administrator, user: user) }
- let(:other_user) { create(:user) }
+
+ let(:other_user) { create(:user) }
+ let(:hidden_user) { create(:user, :hidden) }
+
+ let(:hidden_debate) { create(:debate, :hidden) }
+ let(:hidden_comment) { create(:comment, :hidden) }
+ let(:own_debate) { create(:debate, author: user)}
+ let(:own_comment) { create(:comment, author: user)}
it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) }
- it { should be_able_to(:restore, comment) }
- it { should be_able_to(:restore, debate) }
- it { should be_able_to(:restore, other_user) }
+ it { should_not be_able_to(:restore, comment) }
+ it { should_not be_able_to(:restore, debate) }
+ it { should_not be_able_to(:restore, other_user) }
+
+ it { should be_able_to(:restore, hidden_comment) }
+ it { should be_able_to(:restore, hidden_debate) }
+ it { should be_able_to(:restore, hidden_user) }
+
+ it { should_not be_able_to(:confirm_hide, comment) }
+ it { should_not be_able_to(:confirm_hide, debate) }
+ it { should_not be_able_to(:confirm_hide, other_user) }
+
+ it { should be_able_to(:confirm_hide, hidden_comment) }
+ it { should be_able_to(:confirm_hide, hidden_debate) }
+ it { should be_able_to(:confirm_hide, hidden_user) }
it { should be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) }
From ad3b689a22b0ecd13707107497e67906177b1354 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 27 Aug 2015 16:32:16 +0200
Subject: [PATCH 09/18] remove duplicated migration
---
...27080701_add_hide_reviewed_at_to_comments_and_debates.rb | 6 ------
1 file changed, 6 deletions(-)
delete mode 100644 db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
diff --git a/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb b/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
deleted file mode 100644
index 20d2872ac..000000000
--- a/db/migrate/20150827080701_add_hide_reviewed_at_to_comments_and_debates.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-class AddConfirmedHideAtToCommentsAndDebates < ActiveRecord::Migration
- def change
- add_column :debates, :confirmed_hide_at, :datetime
- add_column :comments, :confirmed_hide_at, :datetime
- end
-end
From 900f00b44320b0a549853e7891ce3b4162df25fb Mon Sep 17 00:00:00 2001
From: Alberto Garcia Cabeza
Date: Thu, 27 Aug 2015 16:46:47 +0200
Subject: [PATCH 10/18] Adds new texts on header, debates and footer
---
app/assets/stylesheets/participacion.scss | 21 ++++++++++
app/views/debates/new.html.erb | 4 +-
app/views/layouts/_admin_header.html.erb | 10 -----
app/views/layouts/_footer.html.erb | 51 +++++++++++------------
app/views/layouts/_header.html.erb | 9 ++--
config/locales/en.yml | 35 +++++++++++++---
config/locales/es.yml | 35 +++++++++++++---
7 files changed, 114 insertions(+), 51 deletions(-)
diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss
index 116b57ff8..ff5a2b13a 100644
--- a/app/assets/stylesheets/participacion.scss
+++ b/app/assets/stylesheets/participacion.scss
@@ -217,6 +217,12 @@ header {
margin: 0;
}
+ p {
+ color: white;
+ font-size: rem-calc(18);
+ line-height: $line-height;
+ }
+
.button {
color: white;
font-family: inherit;
@@ -431,6 +437,11 @@ footer {
.logo {
@include logo;
+
+ a {
+ line-height: rem-calc(36);
+ padding-left: 0;
+ }
}
h4 {
@@ -446,6 +457,16 @@ footer {
opacity: .5;
}
}
+
+ .footer-description {
+ a {
+ text-decoration: underline;
+
+ &:hover {
+ color: rgba(255,255,255,.6);
+ }
+ }
+ }
}
.subfooter {
diff --git a/app/views/debates/new.html.erb b/app/views/debates/new.html.erb
index 7987265bd..f9fe689da 100644
--- a/app/views/debates/new.html.erb
+++ b/app/views/debates/new.html.erb
@@ -16,6 +16,8 @@
<%= t("debates.new.recommendation_one") %>
<%= t("debates.new.recommendation_two") %>
<%= t("debates.new.recommendation_three") %>
+ <%= t("debates.new.recommendation_four") %>
+ <%= t("debates.new.recommendation_five") %>
-
\ No newline at end of file
+
diff --git a/app/views/layouts/_admin_header.html.erb b/app/views/layouts/_admin_header.html.erb
index 13424e5e8..fdc1d6c6e 100644
--- a/app/views/layouts/_admin_header.html.erb
+++ b/app/views/layouts/_admin_header.html.erb
@@ -23,14 +23,4 @@
-
- <% if home_page? %>
-
-
-
<%= t("layouts.header.open_city") %>
- <%= t("layouts.header.open_city_slogan") %>
- <%= link_to t("layouts.header.see_all_debates"), debates_path, class: 'button radius' %>
-
-
- <% end %>
diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb
index 64d6fe8a4..5ad0e6c8b 100644
--- a/app/views/layouts/_footer.html.erb
+++ b/app/views/layouts/_footer.html.erb
@@ -1,36 +1,35 @@
- <%= link_to t("admin.users.show.restore"), restore_admin_user_path(@user),
- method: :put, data: { confirm: t('admin.actions.confirm') }, class: "button radius tiny" %>
<%= link_to t("admin.users.show.back"), admin_users_path,
class: "button radius tiny secondary" %>
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 3190eedb7..7a7f8f342 100644
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -37,7 +37,6 @@ en:
restore: Restore
confirm: 'Are you sure?'
confirm_hide: Confirm
- archive: Archive
tags:
index:
title: 'Debate topics'
@@ -49,14 +48,10 @@ en:
comments:
index:
title: Hidden comments
- show_debate: Show debate
filter: Filter
- restore:
- success: The comment has been restored
- filters:
- all: All
- pending: Pending
- archived: Archived
+ filters:
+ all: All
+ with_confirmed_hide: Confirmed
debates:
index:
title: Hidden debates
@@ -67,16 +62,16 @@ en:
users:
index:
title: Banned users
- restore: Restore user
+ filter: Filter
+ filters:
+ all: All
+ with_confirmed_hide: Confirmed
show:
title: "User activity from %{user}"
- restore: Restore user
back: Back
email: "Email:"
registered_at: "Registered at:"
hidden_at: "Hidden at:"
- restore:
- success: The user has been restored
officials:
level_0: Level 0
level_1: Level 1
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 18dfc06b0..2e9dffe03 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -37,7 +37,6 @@ es:
restore: Volver a mostrar
confirm: '¿Estás seguro?'
confirm_hide: Confirmar
- archive: Archivar
tags:
index:
title: 'Temas de debate'
@@ -49,14 +48,10 @@ es:
comments:
index:
title: Comentarios ocultos
- show_debate: Ver debate
- filter: Filtro
- restore:
- success: El comentario ha sido permitido
- filters:
- all: Todos
- pending: Pendientes
- archived: Archivados
+ filter: Firar
+ filters:
+ all: Todos
+ with_confirmed_hide: Confirmados
debates:
index:
title: Debates ocultos
@@ -67,16 +62,16 @@ es:
users:
index:
title: Usuarios bloqueados
- restore: Restaurar usuario
+ filter: Filro
+ filters:
+ all: Todos
+ with_confirmed_hide: Confirmados
show:
title: "Actividad del usuario %{user}"
- restore: Restaurar usuario
back: Volver
email: "Email:"
registered_at: "Fecha de alta:"
hidden_at: "Bloqueado:"
- restore:
- success: El usuario y sus contenidos han sido restaurados
officials:
level_0: Nivel 0
level_1: Nivel 1
diff --git a/spec/features/admin/users_spec.rb b/spec/features/admin/users_spec.rb
index ed5c80f34..84dbccf50 100644
--- a/spec/features/admin/users_spec.rb
+++ b/spec/features/admin/users_spec.rb
@@ -2,60 +2,20 @@ require 'rails_helper'
feature 'Admin users' do
- scenario 'Restore hidden user' do
- citizen = create(:user)
+ background do
admin = create(:administrator)
- create(:moderator, user: admin.user)
-
- debate_previously_hidden = create(:debate, :hidden, author: citizen)
- debate = create(:debate, author: citizen)
- comment_previously_hidden = create(:comment, :hidden, user: citizen, commentable: debate, body: "You have the manners of a beggar")
- comment = create(:comment, user: citizen, commentable: debate, body: 'Not Spam')
-
login_as(admin.user)
- visit debate_path(debate)
-
- within("#debate_#{debate.id}") do
- click_link 'Ban author'
- end
-
- visit debates_path
- expect(page).to_not have_content(debate.title)
- expect(page).to_not have_content(debate_previously_hidden)
-
- click_link "Administration"
- click_link "Hidden users"
- click_link "Restore user"
-
- visit debates_path
- expect(page).to have_content(debate.title)
- expect(page).to_not have_content(debate_previously_hidden)
-
- visit debate_path(debate)
- expect(page).to have_content(comment.body)
- expect(page).to_not have_content(comment_previously_hidden.body)
end
scenario 'Show user activity' do
- citizen = create(:user)
- admin = create(:administrator)
- create(:moderator, user: admin.user)
+ user = create(:user, :hidden)
- debate1 = create(:debate, :hidden, author: citizen)
- debate2 = create(:debate, author: citizen)
- comment1 = create(:comment, :hidden, user: citizen, commentable: debate2, body: "You have the manners of a beggar")
- comment2 = create(:comment, user: citizen, commentable: debate2, body: 'Not Spam')
+ debate1 = create(:debate, :hidden, author: user)
+ debate2 = create(:debate, author: user)
+ comment1 = create(:comment, :hidden, user: user, commentable: debate2, body: "You have the manners of a beggar")
+ comment2 = create(:comment, user: user, commentable: debate2, body: 'Not Spam')
- login_as(admin.user)
- visit debate_path(debate2)
-
- within("#debate_#{debate2.id}") do
- click_link 'Ban author'
- end
-
- click_link "Administration"
- click_link "Hidden users"
- click_link citizen.name
+ visit admin_user_path(user)
expect(page).to have_content(debate1.title)
expect(page).to have_content(debate2.title)
@@ -63,4 +23,66 @@ feature 'Admin users' do
expect(page).to have_content(comment2.body)
end
-end
\ No newline at end of file
+ scenario 'Restore' do
+ user = create(:user, :hidden)
+ visit admin_users_path
+
+ click_link 'Restore'
+
+ expect(page).to_not have_content(user.username)
+
+ expect(user.reload).to_not be_hidden
+ end
+
+ scenario 'Confirm hide' do
+ user = create(:user, :hidden)
+ visit admin_users_path
+
+ click_link 'Confirm'
+
+ expect(page).to have_content(user.username)
+ expect(page).to have_content('Confirmed')
+
+ expect(user.reload).to be_confirmed_hide
+ end
+
+ scenario "Current filter is properly highlighted" do
+ visit admin_users_path
+ expect(page).to_not have_link('All')
+ expect(page).to have_link('Confirmed')
+
+ visit admin_users_path(filter: 'all')
+ expect(page).to_not have_link('All')
+ expect(page).to have_link('Confirmed')
+
+ visit admin_users_path(filter: 'with_confirmed_hide')
+ expect(page).to have_link('All')
+ expect(page).to_not have_link('Confirmed')
+ end
+
+ scenario "Filtering users" do
+ create(:user, :hidden, username: "Unconfirmed")
+ create(:user, :hidden, :with_confirmed_hide, username: "Confirmed user")
+
+ visit admin_users_path(filter: 'all')
+ expect(page).to have_content('Unconfirmed')
+ expect(page).to have_content('Confirmed user')
+
+ visit admin_users_path(filter: 'with_confirmed_hide')
+ expect(page).to_not have_content('Unconfirmed')
+ expect(page).to have_content('Confirmed user')
+ end
+
+ scenario "Action links remember the pagination setting and the filter" do
+ per_page = Kaminari.config.default_per_page
+ (per_page + 2).times { create(:user, :hidden, :with_confirmed_hide) }
+
+ visit admin_users_path(filter: 'with_confirmed_hide', page: 2)
+
+ click_on('Restore', match: :first, exact: true)
+
+ expect(current_url).to include('filter=with_confirmed_hide')
+ expect(current_url).to include('page=2')
+ end
+
+end
From a0592ea16b105536e0bc1f73e8d25fb7b2b99657 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?=
Date: Fri, 28 Aug 2015 12:30:33 +0200
Subject: [PATCH 17/18] adds ckeditor files to asset pipeline
---
config/initializers/assets.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
index 01ef3e663..a6dfa75c0 100644
--- a/config/initializers/assets.rb
+++ b/config/initializers/assets.rb
@@ -9,3 +9,4 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
+Rails.application.config.assets.precompile += %w( ckeditor/* )
From 7053297f09bbfa874e806bce2ac7b9bfbcf32241 Mon Sep 17 00:00:00 2001
From: rgarcia
Date: Fri, 28 Aug 2015 12:30:36 +0200
Subject: [PATCH 18/18] adds missing digest to images
---
app/assets/stylesheets/participacion.scss | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss
index ff5a2b13a..b195899d3 100644
--- a/app/assets/stylesheets/participacion.scss
+++ b/app/assets/stylesheets/participacion.scss
@@ -187,7 +187,7 @@ h1, h2, h3, h4, h5, h6 {
// - - - - - - - - - - - - - - - - - - - - - - - - -
header {
- background: url('home_header_bg.jpg');
+ background: image-url('home_header_bg.jpg');
background-position: 50% 50%;
background-size: cover;
min-height: rem-calc(480);
@@ -587,7 +587,7 @@ form.locale-form {
position: relative;
select {
- background-image: url("language_select.png");
+ background-image: image-url("language_select.png");
&.js-locale-switcher {
background-color: transparent;