Feature-flag debates
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
class Admin::DebatesController < Admin::BaseController
|
class Admin::DebatesController < Admin::BaseController
|
||||||
|
include FeatureFlags
|
||||||
|
|
||||||
|
feature_flag :debates
|
||||||
|
|
||||||
has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index
|
has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index
|
||||||
|
|
||||||
before_action :load_debate, only: [:confirm_hide, :restore]
|
before_action :load_debate, only: [:confirm_hide, :restore]
|
||||||
|
|||||||
25
app/controllers/concerns/feature_flags.rb
Normal file
25
app/controllers/concerns/feature_flags.rb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
module FeatureFlags
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
def feature_flag(name, *options)
|
||||||
|
before_filter(*options) do
|
||||||
|
check_feature_flag(name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_feature_flag(name)
|
||||||
|
raise FeatureDisabled, name unless Setting["feature.#{name}"]
|
||||||
|
end
|
||||||
|
|
||||||
|
class FeatureDisabled < Exception
|
||||||
|
def initialize(name)
|
||||||
|
@name = name
|
||||||
|
end
|
||||||
|
|
||||||
|
def message
|
||||||
|
"Feature disabled: #{@name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
class DebatesController < ApplicationController
|
class DebatesController < ApplicationController
|
||||||
|
include FeatureFlags
|
||||||
include CommentableActions
|
include CommentableActions
|
||||||
include FlagActions
|
include FlagActions
|
||||||
|
|
||||||
@@ -7,6 +8,8 @@ class DebatesController < ApplicationController
|
|||||||
before_action :set_search_order, only: :index
|
before_action :set_search_order, only: :index
|
||||||
before_action :authenticate_user!, except: [:index, :show]
|
before_action :authenticate_user!, except: [:index, :show]
|
||||||
|
|
||||||
|
feature_flag :debates
|
||||||
|
|
||||||
has_orders %w{hot_score confidence_score created_at relevance}, only: :index
|
has_orders %w{hot_score confidence_score created_at relevance}, only: :index
|
||||||
has_orders %w{most_voted newest oldest}, only: :show
|
has_orders %w{most_voted newest oldest}, only: :show
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
class Moderation::DebatesController < Moderation::BaseController
|
class Moderation::DebatesController < Moderation::BaseController
|
||||||
include ModerateActions
|
include ModerateActions
|
||||||
|
include FeatureFlags
|
||||||
|
|
||||||
has_filters %w{pending_flag_review all with_ignored_flag}, only: :index
|
has_filters %w{pending_flag_review all with_ignored_flag}, only: :index
|
||||||
has_orders %w{flags created_at}, only: :index
|
has_orders %w{flags created_at}, only: :index
|
||||||
|
|
||||||
|
feature_flag :debates
|
||||||
|
|
||||||
before_action :load_resources, only: [:index, :moderate]
|
before_action :load_resources, only: [:index, :moderate]
|
||||||
|
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|||||||
5
app/helpers/feature_flags_helper.rb
Normal file
5
app/helpers/feature_flags_helper.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module FeatureFlagsHelper
|
||||||
|
def feature?(name)
|
||||||
|
!!Setting["feature.#{name}"]
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,6 +11,7 @@ class Setting < ActiveRecord::Base
|
|||||||
def []=(key, value)
|
def []=(key, value)
|
||||||
setting = where(key: key).first || new(key: key)
|
setting = where(key: key).first || new(key: key)
|
||||||
setting.value = value
|
setting.value = value
|
||||||
|
setting.value = nil if setting.value == false
|
||||||
setting.save!
|
setting.save!
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,12 +18,14 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<% if feature?(:debates) %>
|
||||||
<li <%= "class=active" if controller_name == "debates" %>>
|
<li <%= "class=active" if controller_name == "debates" %>>
|
||||||
<%= link_to admin_debates_path do %>
|
<%= link_to admin_debates_path do %>
|
||||||
<i class="icon-debates"></i>
|
<i class="icon-debates"></i>
|
||||||
<%= t("admin.menu.hidden_debates") %>
|
<%= t("admin.menu.hidden_debates") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<li <%= "class=active" if controller_name == "comments" %>>
|
<li <%= "class=active" if controller_name == "comments" %>>
|
||||||
<%= link_to admin_comments_path do %>
|
<%= link_to admin_comments_path do %>
|
||||||
|
|||||||
@@ -35,7 +35,9 @@
|
|||||||
<section class="subnavigation row">
|
<section class="subnavigation row">
|
||||||
|
|
||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
|
<% if feature?(:debates) %>
|
||||||
<%= link_to t("layouts.header.debates"), debates_path, class: ("active" if controller_name == "debates") %>
|
<%= link_to t("layouts.header.debates"), debates_path, class: ("active" if controller_name == "debates") %>
|
||||||
|
<% end %>
|
||||||
<%= link_to t("layouts.header.proposals"), proposals_path, class: ("active" if controller_name == "proposals") %>
|
<%= link_to t("layouts.header.proposals"), proposals_path, class: ("active" if controller_name == "proposals") %>
|
||||||
<%= link_to t("layouts.header.spending_proposals"), spending_proposals_path, class: ("active" if controller_name == "spending_proposals") %>
|
<%= link_to t("layouts.header.spending_proposals"), spending_proposals_path, class: ("active" if controller_name == "spending_proposals") %>
|
||||||
<%= link_to t("layouts.header.more_information"), page_path('more_information'), class: ("active" if current_page?("/more_information")) %>
|
<%= link_to t("layouts.header.more_information"), page_path('more_information'), class: ("active" if current_page?("/more_information")) %>
|
||||||
|
|||||||
@@ -11,12 +11,14 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<% if feature?(:debates) %>
|
||||||
<li <%= "class=active" if controller_name == "debates" %>>
|
<li <%= "class=active" if controller_name == "debates" %>>
|
||||||
<%= link_to moderation_debates_path do %>
|
<%= link_to moderation_debates_path do %>
|
||||||
<i class="icon-debates"></i>
|
<i class="icon-debates"></i>
|
||||||
<%= t('moderation.menu.flagged_debates') %>
|
<%= t('moderation.menu.flagged_debates') %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<li <%= "class=active" if controller_name == "comments" %>>
|
<li <%= "class=active" if controller_name == "comments" %>>
|
||||||
<%= link_to moderation_comments_path do %>
|
<%= link_to moderation_comments_path do %>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
<%= render "proposals" if @proposals.present? %>
|
<%= render "proposals" if @proposals.present? %>
|
||||||
<%= render "debates" if @debates.present? %>
|
<%= render "debates" if @debates.present? && feature?(:debates) %>
|
||||||
<%= render "comments" if @comments.present? %>
|
<%= render "comments" if @comments.present? %>
|
||||||
|
|||||||
@@ -49,3 +49,6 @@ Setting["org_name"] = "Consul"
|
|||||||
|
|
||||||
# Consul installation place name (City, Country...)
|
# Consul installation place name (City, Country...)
|
||||||
Setting["place_name"] = "Consul-land"
|
Setting["place_name"] = "Consul-land"
|
||||||
|
|
||||||
|
# Feature flags
|
||||||
|
Setting['feature.debates'] = true
|
||||||
|
|||||||
@@ -2,6 +2,14 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature 'Admin debates' do
|
feature 'Admin debates' do
|
||||||
|
|
||||||
|
scenario 'Disabled with a feature flag' do
|
||||||
|
Setting['feature.debates'] = nil
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
|
||||||
|
expect{ visit admin_debates_path }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||||
|
end
|
||||||
|
|
||||||
background do
|
background do
|
||||||
admin = create(:administrator)
|
admin = create(:administrator)
|
||||||
login_as(admin.user)
|
login_as(admin.user)
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature 'Debates' do
|
feature 'Debates' do
|
||||||
|
|
||||||
|
scenario 'Disabled with a feature flag' do
|
||||||
|
Setting['feature.debates'] = nil
|
||||||
|
expect{ visit debates_path }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Index' do
|
scenario 'Index' do
|
||||||
debates = [create(:debate), create(:debate), create(:debate)]
|
debates = [create(:debate), create(:debate), create(:debate)]
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,14 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature 'Moderate debates' do
|
feature 'Moderate debates' do
|
||||||
|
|
||||||
|
scenario 'Disabled with a feature flag' do
|
||||||
|
Setting['feature.debates'] = nil
|
||||||
|
moderator = create(:moderator)
|
||||||
|
login_as(moderator.user)
|
||||||
|
|
||||||
|
expect{ visit moderation_debates_path }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Hide', :js do
|
scenario 'Hide', :js do
|
||||||
citizen = create(:user)
|
citizen = create(:user)
|
||||||
moderator = create(:moderator)
|
moderator = create(:moderator)
|
||||||
|
|||||||
Reference in New Issue
Block a user