diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 01066c8ad..a948948a2 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -9,6 +9,7 @@ module CommentableActions @resources = @resources.tagged_with(@tag_filter) if @tag_filter @resources = @resources.page(params[:page]).for_render.send("sort_by_#{@current_order}") index_customization if index_customization.present? + featured_debates if featured_debates.present? @tag_cloud = tag_cloud set_resource_votes(@resources) @@ -152,4 +153,9 @@ module CommentableActions def index_customization nil end + + def featured_debates + nil + end + end diff --git a/app/controllers/debate_links_controller.rb b/app/controllers/debate_links_controller.rb deleted file mode 100644 index f6f7c3af8..000000000 --- a/app/controllers/debate_links_controller.rb +++ /dev/null @@ -1,31 +0,0 @@ -class DebateLinksController < ApplicationController - include FeatureFlags - include CommentableActions - - before_action :authenticate_user!, except: [:show] - - load_and_authorize_resource class: "Debate" - - feature_flag :debates - - respond_to :html, :js - - private - - def create_params - params.require(:debate).permit(:title, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key).merge(link_required: true) - end - - def debate_params - params.require(:debate).permit(:title, :external_link, :tag_list, :terms_of_service, :captcha, :captcha_key).merge(link_required: true) - end - - def after_create_path - debate_path(@resource) - end - - def resource_model - Debate - end - -end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 4a22d2e3e..c743d58a7 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -28,16 +28,20 @@ class DebatesController < ApplicationController set_debate_votes(@debate) end - def remove_feature + def unmark_featured @debate.update_attribute(:featured_at, nil) redirect_to request.query_parameters.merge(action: :index) end - def feature + def mark_featured @debate.update_attribute(:featured_at, Time.now) redirect_to request.query_parameters.merge(action: :index) end + def featured_debates + @featured_debates = @debates.featured + end + private def debate_params diff --git a/app/helpers/debates_helper.rb b/app/helpers/debates_helper.rb index d12db7f78..3c1aa02a7 100644 --- a/app/helpers/debates_helper.rb +++ b/app/helpers/debates_helper.rb @@ -1,6 +1,6 @@ module DebatesHelper - def has_featured + def has_featured? Debate.all.featured.count > 0 end end \ No newline at end of file diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 9727e8e35..55759959e 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -30,9 +30,8 @@ module Abilities can :confirm_hide, User cannot :confirm_hide, User, hidden_at: nil - can :feature, Debate - - can :remove_feature, Debate + can :mark_featured, Debate + can :unmark_featured, Debate can :comment_as_administrator, [Debate, Comment, Proposal] diff --git a/app/models/debate.rb b/app/models/debate.rb index 249ae0c44..cdae527f7 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -134,7 +134,7 @@ class Debate < ActiveRecord::Base end def featured? - ! self.featured_at.nil? + self.featured_at.present? end end diff --git a/app/views/debates/_actions.html.erb b/app/views/debates/_actions.html.erb index b88d4830c..1b61e045b 100644 --- a/app/views/debates/_actions.html.erb +++ b/app/views/debates/_actions.html.erb @@ -9,13 +9,13 @@ method: :put, data: { confirm: t('admin.actions.confirm') } %> <% end %> -<% if can? :feature, debate %> - | +<% if can? :mark_featured, debate %> + | <% if debate.featured? %> - <%= link_to t("admin.actions.remove_feature").capitalize, remove_feature_debate_path(debate), + <%= link_to t("admin.actions.unmark_featured").capitalize, unmark_featured_debate_path(debate), method: :put, data: { confirm: t('admin.actions.confirm') } %> <% else %> - <%= link_to t("admin.actions.feature").capitalize, feature_debate_path(debate), + <%= link_to t("admin.actions.mark_featured").capitalize, mark_featured_debate_path(debate), method: :put, data: { confirm: t('admin.actions.confirm') } %> <% end %> <% end %> diff --git a/app/views/debates/_featured_debates.html.erb b/app/views/debates/_featured_debates.html.erb index e678e2da8..577a6da77 100644 --- a/app/views/debates/_featured_debates.html.erb +++ b/app/views/debates/_featured_debates.html.erb @@ -4,7 +4,7 @@