#4346 Add support for !owner to the API listing projects
Merged 5 years ago by pingou. Opened 5 years ago by pingou.

file modified
+8 -1
@@ -2271,7 +2271,14 @@ 

              "as parameters in the `search_projects` function"

          )

      elif owner is not None:

-         projects = projects.join(model.User).filter(model.User.user == owner)

+         if owner.startswith("!"):

+             projects = projects.join(model.User).filter(

+                 model.User.user != owner[1:]

+             )

+         else:

+             projects = projects.join(model.User).filter(

+                 model.User.user == owner

+             )

      elif username is not None:

          projects = projects.filter(

              # User created the project

@@ -362,6 +362,77 @@ 

          self.maxDiff = None

          self.assertDictEqual(data, expected_data)

  

+     def test_api_projects_owner(self):

+         """ Test the api_projects method of the flask api. """

+         tests.create_projects(self.session)

+ 

+         output = self.app.get('/api/0/projects?owner=foo')

+         self.assertEqual(output.status_code, 200)

+         data = json.loads(output.get_data(as_text=True))

+         del data['pagination']

+         expected_data = {

+           "args": {

+             "fork": None,

+             "namespace": None,

+             "owner": "foo",

+             "page": 1,

+             "pattern": None,

+             "per_page": 20,

+             "short": False,

+             "tags": [],

+             "username": None

+           },

+           "projects": [],

+           "total_projects": 0

+         }

+         self.maxDiff = None

+         self.assertDictEqual(data, expected_data)

+ 

+     def test_api_projects_not_owner(self):

+         """ Test the api_projects method of the flask api. """

+         tests.create_projects(self.session)

+ 

+         output = self.app.get('/api/0/projects?owner=!foo&short=1')

+         self.assertEqual(output.status_code, 200)

+         data = json.loads(output.get_data(as_text=True))

+         del data['pagination']

+         expected_data = {

+           "args": {

+             "fork": None,

+             "namespace": None,

+             "owner": "!foo",

+             "page": 1,

+             "pattern": None,

+             "per_page": 20,

+             "short": True,

+             "tags": [],

+             "username": None

+           },

+           "projects": [

+             {

+               "description": "test project #1",

+               "fullname": "test",

+               "name": "test",

+               "namespace": None

+             },

+             {

+               "description": "test project #2",

+               "fullname": "test2",

+               "name": "test2",

+               "namespace": None

+             },

+             {

+               "description": "namespaced test project",

+               "fullname": "somenamespace/test3",

+               "name": "test3",

+               "namespace": "somenamespace"

+             }

+           ],

+           "total_projects": 3

+         }

+         self.maxDiff = None

+         self.assertDictEqual(data, expected_data)

+ 

      def test_api_projects(self):

          """ Test the api_projects method of the flask api. """

          tests.create_projects(self.session)

When querying the list of projects one can filter the projects returned
by their main maintainer, using the filter argument owner. With this commit, if the filter argument starts with the!`, instead
of filtering for project having this person as maintainer, it will allow
to filter for project not having this person as main maintainer.

Fixes https://pagure.io/pagure/issue/4312

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

rebased onto fd71367

5 years ago

Pull-Request has been merged by pingou

5 years ago