Skip to content

Commit

Permalink
Renames the "archive" action to "ignore_flag" (+)
Browse files Browse the repository at this point in the history
* archived_at -> ignored_flag_at
* archived? -> ignored_flag?
* archive -> ignore_flag
* pending -> pending_flag_review
* archived (scope) -> with_ignored_flag
* I18n changes
  • Loading branch information
kikito committed Aug 27, 2015
1 parent 17b33f1 commit cd98276
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 106 deletions.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ body.admin {
font-size: rem-calc(12);
}

.ignored {
color: $text-medium;
font-size: rem-calc(12);
}

.rejected {
color: $delete;
}
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/moderation/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def hide_in_moderation_screen
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

Expand All @@ -31,7 +31,7 @@ def load_comments
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
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/moderation/debates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def hide_in_moderation_screen
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

Expand All @@ -31,7 +31,7 @@ def load_debates
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
Expand Down
8 changes: 4 additions & 4 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def initialize(user)
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
Expand Down
16 changes: 8 additions & 8 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -65,8 +65,12 @@ def not_visible?
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?
Expand All @@ -77,10 +81,6 @@ def as_moderator?
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
Expand Down
12 changes: 6 additions & 6 deletions app/models/debate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -75,12 +75,12 @@ def tags_count_out_of_limit(limit = nil)
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
Expand Down
10 changes: 5 additions & 5 deletions app/views/moderation/comments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
<td>
<%= link_to t("moderation.comments.index.hide"), hide_in_moderation_screen_moderation_comment_path(comment, request.query_parameters), method: :put, class: "delete" %>
</td>
<% if can? :archive, comment %>
<% if can? :ignore_flag, comment %>
<td>
<%= 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" %>
</td>
<% end %>
<% if comment.archived? %>
<td class="archived">
<%= t("moderation.comments.index.archived") %>
<% if comment.ignored_flag? %>
<td class="ignored">
<%= t("moderation.comments.index.ignored_flag") %>
</td>
<% end %>
</tr>
Expand Down
10 changes: 5 additions & 5 deletions app/views/moderation/debates/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
<td>
<%= link_to t("moderation.debates.index.hide"), hide_in_moderation_screen_moderation_debate_path(debate, request.query_parameters), method: :put, class: "delete" %>
</td>
<% if can? :archive, debate %>
<% if can? :ignore_flag, debate %>
<td>
<%= 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" %>
</td>
<% end %>
<% if debate.archived? %>
<td class="archived">
<%= t("moderation.debates.index.archived") %>
<% if debate.ignored_flag? %>
<td class="ignored">
<%= t("moderation.debates.index.ignored_flag") %>
</td>
<% end %>
</tr>
Expand Down
16 changes: 8 additions & 8 deletions config/locales/moderation.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
16 changes: 8 additions & 8 deletions config/locales/moderation.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@
member do
put :hide
put :hide_in_moderation_screen
put :archive
put :ignore_flag
end
end

resources :comments, only: :index do
member do
put :hide
put :hide_in_moderation_screen
put :archive
put :ignore_flag
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
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
Expand Down Expand Up @@ -51,8 +51,8 @@
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
Expand Down
40 changes: 20 additions & 20 deletions spec/features/moderation/comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,57 +104,57 @@
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

Expand All @@ -172,7 +172,7 @@
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

Expand All @@ -187,18 +187,18 @@
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
Expand Down
Loading

0 comments on commit cd98276

Please sign in to comment.