diff --git a/app/controllers/moderation/comments_controller.rb b/app/controllers/moderation/comments_controller.rb
index e44021e72..03667e286 100644
--- a/app/controllers/moderation/comments_controller.rb
+++ b/app/controllers/moderation/comments_controller.rb
@@ -26,17 +26,17 @@ class Moderation::CommentsController < Moderation::BaseController
private
- def load_comments
- @comments = Comment.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation.includes(:commentable)
- end
+ def load_comments
+ @comments = Comment.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation.includes(:commentable)
+ end
- def set_valid_filters
- @valid_filters = %w{all pending_review reviewed}
- end
+ def set_valid_filters
+ @valid_filters = %w{all pending_review reviewed}
+ end
- def parse_filter
- @filter = params[:filter]
- @filter = 'all' unless @valid_filters.include?(@filter)
- end
+ def parse_filter
+ @filter = params[:filter]
+ @filter = 'all' unless @valid_filters.include?(@filter)
+ end
end
diff --git a/app/controllers/moderation/debates_controller.rb b/app/controllers/moderation/debates_controller.rb
index 622116765..22e4eac6b 100644
--- a/app/controllers/moderation/debates_controller.rb
+++ b/app/controllers/moderation/debates_controller.rb
@@ -1,8 +1,42 @@
class Moderation::DebatesController < Moderation::BaseController
+ before_filter :set_valid_filters, only: :index
+ before_filter :parse_filter, only: :index
+ before_filter :load_debates, only: :index
+
+ load_and_authorize_resource
+
+ def index
+ @debates = @debates.send(@filter)
+ @debates = @debates.page(params[:page])
+ end
def hide
- @debate = Debate.find(params[:id])
@debate.hide
end
-end
\ No newline at end of file
+ def hide_in_moderation_screen
+ @debate.hide
+ redirect_to request.query_parameters.merge(action: :index)
+ end
+
+ def mark_as_reviewed
+ @debate.mark_as_reviewed
+ redirect_to request.query_parameters.merge(action: :index)
+ end
+
+ private
+
+ def load_debates
+ @debates = Debate.accessible_by(current_ability, :hide).flagged_as_inappropiate.sorted_for_moderation
+ end
+
+ def set_valid_filters
+ @valid_filters = %w{all pending_review reviewed}
+ end
+
+ def parse_filter
+ @filter = params[:filter]
+ @filter = 'all' unless @valid_filters.include?(@filter)
+ end
+
+end
diff --git a/app/models/debate.rb b/app/models/debate.rb
index 042c334c7..c16048f70 100644
--- a/app/models/debate.rb
+++ b/app/models/debate.rb
@@ -23,6 +23,11 @@ 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 :pending_review, -> { where(reviewed_at: nil, hidden_at: nil) }
+ scope :reviewed, -> { where("reviewed_at IS NOT NULL AND hidden_at IS NULL") }
+ scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") }
+
# Ahoy setup
visitable # Ahoy will automatically assign visit_id on create
diff --git a/app/views/moderation/comments/index.html.erb b/app/views/moderation/comments/index.html.erb
index 4393f4cb3..0d89114f1 100644
--- a/app/views/moderation/comments/index.html.erb
+++ b/app/views/moderation/comments/index.html.erb
@@ -16,11 +16,11 @@
- | <%= t('moderation.comments.index.flags') %> |
- <%= t('moderation.comments.index.updated_at') %> |
- <%= t('moderation.comments.index.commentable_type') %> |
- <%= t('moderation.comments.index.commentable') %> |
- <%= t('moderation.comments.index.comment') %> |
+ <%= t('moderation.comments.index.headers.flags') %> |
+ <%= t('moderation.comments.index.headers.updated_at') %> |
+ <%= t('moderation.comments.index.headers.commentable_type') %> |
+ <%= t('moderation.comments.index.headers.commentable') %> |
+ <%= t('moderation.comments.index.headers.comment') %> |
<% @comments.each do |comment| %>