Add API support for the user_list of the feature flag strategy

Problem to solve

Currently, it is hard to get the detailed information about user_list from the response of Feature flags API. The example response is as follows:

[
    {
        "name": "feature1",
        "description": "1233211234567",
        "active": true,
        "version": "new_version_flag",
        "created_at": "2023-07-13T03:49:53.469Z",
        "updated_at": "2023-07-13T03:49:53.469Z",
        "scopes": [],
        "strategies": [
            {
                "id": 6,
                "name": "gitlabUserList",
                "parameters": {},
                "scopes": [
                    {
                        "id": 6,
                        "environment_scope": "*"
                    }
                ]
            }
        ]
    }
]

From the response, we can only know that the strategy is associated with a user list. If we want to know the detailed information about the list, we can use the Feature flag user lists API, which requires the internal ID of the project’s feature flag user list. However, it seems that we cannot get the iid from the response of Feature flags API.

Proposal

Add a new field to the response of Feature flags API. Partial example response is as follows:

 "strategies": [
                {
                    "id": 6,
                    "name": "gitlabUserList",
                    "parameters": {},
                    "scopes": [
                        {
                            "id": 6,
                            "environment_scope": "*"
                        }
                    ],
                    "user_list": {
                        "id": 1,
                        "iid": 1,
                        "name": "user-list-1",
                        "user_xids": "123,321"
                    }
                }
            ]

Technical details

diff --git a/lib/api/entities/feature_flag/strategy.rb b/lib/api/entities/feature_flag/strategy.rb
index 621784203702..d565101ef51f 100644
--- a/lib/api/entities/feature_flag/strategy.rb
+++ b/lib/api/entities/feature_flag/strategy.rb
@@ -8,6 +8,10 @@ class Strategy < Grape::Entity
         expose :name, documentation: { type: 'string', example: 'userWithId' }
         expose :parameters, documentation: { type: 'string', example: '{"userIds": "user1"}' }
         expose :scopes, using: FeatureFlag::Scope
+        # TODO: Preload user_list in batch
+        # TODO: Expose only necessary attributes. e.g. id, iid, name, user_xids,
+        #       Avoid exopsing `path` and `edit_path` if unnecessary (because preloading logic will be complicated)
+        expose :user_list, using: FeatureFlag::UserList
       end
     end
   end
Edited Jul 18, 2023 by Shinya Maeda
Assignee Loading
Time tracking Loading