Просмотр исходного кода

feat(api): Support member query by ID (#49877)

We need this for the frontend to allow for optimistic lookup of members
which may not have already been loaded
Evan Purkhiser 1 год назад
Родитель
Сommit
aeaded9b03

+ 3 - 0
src/sentry/api/endpoints/organization_member/index.py

@@ -141,6 +141,9 @@ class OrganizationMemberIndexEndpoint(OrganizationEndpoint):
                         | Q(user__emails__email__in=value)
                     )
 
+                elif key == "id":
+                    queryset = queryset.filter(id__in=value)
+
                 elif key == "scope":
                     queryset = queryset.filter(role__in=[r.id for r in roles.with_any_scope(value)])
 

+ 11 - 0
tests/sentry/api/endpoints/test_organization_member_index.py

@@ -155,6 +155,17 @@ class OrganizationMemberListTest(OrganizationMemberListTestBase, HybridCloudTest
         assert len(response.data) == 1
         assert response.data[0]["email"] == self.user2.email
 
+    def test_id_query(self):
+        member = OrganizationMember.objects.create(
+            email="billy@localhost", organization=self.organization
+        )
+        response = self.get_success_response(
+            self.organization.slug, qs_params={"query": f"id:{member.id}"}
+        )
+
+        assert len(response.data) == 1
+        assert response.data[0]["email"] == "billy@localhost"
+
     def test_query_null_user(self):
         OrganizationMember.objects.create(email="billy@localhost", organization=self.organization)
         response = self.get_success_response(self.organization.slug, qs_params={"query": "bill"})