summaryrefslogtreecommitdiff
path: root/app/serializers/feature_flag_entity.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/serializers/feature_flag_entity.rb')
-rw-r--r--app/serializers/feature_flag_entity.rb48
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