Sha256: a5ac7411aa145ad03ebfd459515e1409c37540959ea90c130b99a0ec25b285e6

Contents?: true

Size: 1.58 KB

Versions: 54

Compression:

Stored size: 1.58 KB

Contents

require 'flipper/api/action'
require 'flipper/api/v1/decorators/feature'

module Flipper
  module Api
    module V1
      module Actions
        class GroupsGate < Api::Action
          include FeatureNameFromRoute

          route %r{\A/features/(?<feature_name>.*)/groups/?\Z}

          def post
            ensure_valid_params
            feature = flipper[feature_name]
            feature.enable_group(group_name)
            decorated_feature = Decorators::Feature.new(feature)
            json_response(decorated_feature.as_json, 200)
          end

          def delete
            ensure_valid_params
            feature = flipper[feature_name]
            feature.disable_group(group_name)
            decorated_feature = Decorators::Feature.new(feature)
            json_response(decorated_feature.as_json, 200)
          end

          private

          def ensure_valid_params
            if group_name.nil? || group_name.empty?
              json_error_response(:name_invalid)
            end

            return if allow_unregistered_groups?
            return if Flipper.group_exists?(group_name)

            json_error_response(:group_not_registered)
          end

          def allow_unregistered_groups?
            allow_unregistered_groups = params['allow_unregistered_groups']
            allow_unregistered_groups && allow_unregistered_groups == 'true'
          end

          def disallow_unregistered_groups?
            !allow_unregistered_groups?
          end

          def group_name
            @group_name ||= params['name']
          end
        end
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
flipper-api-1.3.2 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.3.1 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.3.0 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.3.0.pre lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.2.2 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.2.1 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.2.0 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.1.2 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.1.1 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.1.0 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.0.0 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-1.0.0.pre lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-0.28.3 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-0.28.2 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-0.28.1 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-0.28.0 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-0.27.1 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-0.27.0 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-0.26.2 lib/flipper/api/v1/actions/groups_gate.rb
flipper-api-0.26.1 lib/flipper/api/v1/actions/groups_gate.rb