debian-mirror-gitlab/app/services/feature_flags/create_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.1 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module FeatureFlags
class CreateService < FeatureFlags::BaseService
def execute
return error('Access Denied', 403) unless can_create?
return error('Version is invalid', :bad_request) unless valid_version?
2021-10-27 15:23:28 +05:30
ApplicationRecord.transaction do
2021-01-03 14:25:43 +05:30
feature_flag = project.operations_feature_flags.new(params)
if feature_flag.save
success(feature_flag: feature_flag)
else
error(feature_flag.errors.full_messages, 400)
end
end
end
private
def audit_message(feature_flag)
2021-07-02 01:05:55 +05:30
message_parts = ["Created feature flag #{feature_flag.name} with description \"#{feature_flag.description}\"."]
2021-01-03 14:25:43 +05:30
2021-11-11 11:23:49 +05:30
message_parts += feature_flag.strategies.map do |strategy|
created_strategy_message(strategy)
2021-01-03 14:25:43 +05:30
end
message_parts.join(" ")
end
def can_create?
Ability.allowed?(current_user, :create_feature_flag, project)
end
def valid_version?
!params.key?(:version) || Operations::FeatureFlag.versions.key?(params[:version])
end
end
end