Merge pull request #830 from AjuntamentdeBarcelona/feature_flags
Feature flags
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
class Admin::DebatesController < Admin::BaseController
|
||||
include FeatureFlags
|
||||
|
||||
feature_flag :debates
|
||||
|
||||
has_filters %w{without_confirmed_hide all with_confirmed_hide}, only: :index
|
||||
|
||||
before_action :load_debate, only: [:confirm_hide, :restore]
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
class Admin::SpendingProposalsController < Admin::BaseController
|
||||
include FeatureFlags
|
||||
|
||||
has_filters %w{unresolved accepted rejected}, only: :index
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
feature_flag :spending_proposals
|
||||
|
||||
def index
|
||||
@spending_proposals = @spending_proposals.includes([:geozone]).send(@current_filter).order(created_at: :desc).page(params[:page])
|
||||
end
|
||||
|
||||
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
|
||||
include FeatureFlags
|
||||
include CommentableActions
|
||||
include FlagActions
|
||||
|
||||
@@ -8,6 +9,8 @@ class DebatesController < ApplicationController
|
||||
before_action :set_search_order, only: :index
|
||||
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{most_voted newest oldest}, only: :show
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
class Moderation::DebatesController < Moderation::BaseController
|
||||
include ModerateActions
|
||||
include FeatureFlags
|
||||
|
||||
has_filters %w{pending_flag_review all with_ignored_flag}, only: :index
|
||||
has_orders %w{flags created_at}, only: :index
|
||||
|
||||
feature_flag :debates
|
||||
|
||||
before_action :load_resources, only: [:index, :moderate]
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
class SpendingProposalsController < ApplicationController
|
||||
include FeatureFlags
|
||||
|
||||
before_action :authenticate_user!, except: [:index]
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
feature_flag :spending_proposals
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
@@ -29,4 +33,4 @@ class SpendingProposalsController < ApplicationController
|
||||
params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :terms_of_service, :captcha, :captcha_key)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user