diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /app/serializers/feature_flag_entity.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'app/serializers/feature_flag_entity.rb')
-rw-r--r-- | app/serializers/feature_flag_entity.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/app/serializers/feature_flag_entity.rb b/app/serializers/feature_flag_entity.rb new file mode 100644 index 00000000000..80cf869a389 --- /dev/null +++ b/app/serializers/feature_flag_entity.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class FeatureFlagEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :iid + expose :active + expose :created_at + expose :updated_at + expose :name + expose :description + expose :version + + expose :edit_path, if: -> (feature_flag, _) { can_update?(feature_flag) } do |feature_flag| + edit_project_feature_flag_path(feature_flag.project, feature_flag) + end + + expose :update_path, if: -> (feature_flag, _) { can_update?(feature_flag) } do |feature_flag| + project_feature_flag_path(feature_flag.project, feature_flag) + end + + expose :destroy_path, if: -> (feature_flag, _) { can_destroy?(feature_flag) } do |feature_flag| + project_feature_flag_path(feature_flag.project, feature_flag) + end + + expose :scopes, with: FeatureFlagScopeEntity do |feature_flag| + feature_flag.scopes.sort_by(&:id) + end + + expose :strategies, with: FeatureFlags::StrategyEntity do |feature_flag| + feature_flag.strategies.sort_by(&:id) + end + + private + + def can_update?(feature_flag) + can?(current_user, :update_feature_flag, feature_flag) + end + + def can_destroy?(feature_flag) + can?(current_user, :destroy_feature_flag, feature_flag) + end + + def current_user + request.current_user + end +end |