#2627 Add the possibility to get the group members when asking the project info
Merged 6 years ago by pingou. Opened 6 years ago by pingou.

file modified
+17 -1
@@ -115,6 +115,7 @@ 

          implicit_watch_users = \

              implicit_watch_users | set(

                  [user.username for user in repo.access_users[access_type]])

+ 

      watching_users_to_watch_level = {}

      for implicit_watch_user in implicit_watch_users:

          user_watch_level = pagure.lib.get_watch_level_on_repo(
@@ -682,10 +683,25 @@ 

      repo = get_authorized_api_project(

          SESSION, repo, user=username, namespace=namespace)

  

+     expand_group = str(

+             flask.request.values.get('expand_group', None)

+         ).lower() in ['1', 't', 'True']

+ 

      if repo is None:

          raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOPROJECT)

  

-     jsonout = flask.jsonify(repo.to_json(api=True, public=True))

+     output = repo.to_json(api=True, public=True)

+ 

+     if expand_group:

+         group_details = {}

+         for grp in repo.projects_groups:

+             group = pagure.lib.search_groups(

+                 SESSION, group_name=grp.group.group_name)

+             group_details[grp.group.group_name] = [

+                 user.username for user in grp.group.users]

+         output['group_details'] = group_details

+ 

+     jsonout = flask.jsonify(output)

      return jsonout

  

  

@@ -852,6 +852,161 @@ 

          }

          self.assertDictEqual(data, expected_data)

  

+     def test_api_project_group(self):

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

+         tests.create_projects(self.session)

+         repo = pagure.get_authorized_project(self.session, 'test')

+ 

+         # Adding a tag

+         output = pagure.lib.update_tags(

+             self.session, repo, 'infra', 'pingou',

+             ticketfolder=None)

+         self.assertEqual(output, ['Issue tagged with: infra'])

+ 

+         # Check after adding

+         repo = pagure.get_authorized_project(self.session, 'test')

+         self.assertEqual(len(repo.tags), 1)

+         self.assertEqual(repo.tags_text, ['infra'])

+ 

+         # Add a group to the project

+         msg = pagure.lib.add_group(

+             self.session,

+             group_name='some_group',

+             display_name='Some Group',

+             description=None,

+             group_type='bar',

+             user='foo',

+             is_admin=False,

+             blacklist=[],

+         )

+         self.session.commit()

+ 

+         project = pagure.get_authorized_project(self.session, 'test')

+         group = pagure.lib.search_groups(

+             self.session, group_name='some_group')

+ 

+         pagure.lib.add_group_to_project(

+             self.session,

+             project,

+             new_group='some_group',

+             user='pingou',

+             access='commit',

+             create=False,

+             is_admin=True

+         )

+         self.session.commit()

+ 

+         # Check the API

+ 

+         # Existing project

+         output = self.app.get('/api/0/test?expand_group=1')

+         self.assertEqual(output.status_code, 200)

+         data = json.loads(output.data)

+         data['date_created'] = "1436527638"

+         data['date_modified'] = "1436527638"

+         expected_data ={

+             "access_groups": {

+                 "admin": [],

+                 "commit": ["some_group"],

+                 "ticket": []

+             },

+             "access_users": {

+                 "admin": [],

+                 "commit": [],

+                 "owner": ["pingou"],

+                 "ticket": []},

+             "close_status": [

+                 "Invalid",

+                 "Insufficient data",

+                 "Fixed",

+                 "Duplicate"

+             ],

+             "custom_keys": [],

+             "date_created": "1436527638",

+             "date_modified": "1436527638",

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

+             "fullname": "test",

+             "group_details": {

+               "some_group": [

+                 "foo"

+               ]

+             },

+             "id": 1,

+             "milestones": {},

+             "name": "test",

+             "namespace": None,

+             "parent": None,

+             "priorities": {},

+             "tags": ["infra"],

+             "user": {

+                 "fullname": "PY C",

+                 "name": "pingou"

+             }

+         }

+         self.assertDictEqual(data, expected_data)

+ 

+     def test_api_project_group_but_no_group(self):

+         """ Test the api_project method of the flask api when asking for

+         group details while there are none associated.

+         """

+         tests.create_projects(self.session)

+         repo = pagure.get_authorized_project(self.session, 'test')

+ 

+         # Adding a tag

+         output = pagure.lib.update_tags(

+             self.session, repo, 'infra', 'pingou',

+             ticketfolder=None)

+         self.assertEqual(output, ['Issue tagged with: infra'])

+ 

+         # Check after adding

+         repo = pagure.get_authorized_project(self.session, 'test')

+         self.assertEqual(len(repo.tags), 1)

+         self.assertEqual(repo.tags_text, ['infra'])

+ 

+         # Check the API

+ 

+         # Existing project

+         output = self.app.get('/api/0/test?expand_group=0')

+         self.assertEqual(output.status_code, 200)

+         data = json.loads(output.data)

+         data['date_created'] = "1436527638"

+         data['date_modified'] = "1436527638"

+         expected_data ={

+             "access_groups": {

+                 "admin": [],

+                 "commit": [],

+                 "ticket": []

+             },

+             "access_users": {

+                 "admin": [],

+                 "commit": [],

+                 "owner": ["pingou"],

+                 "ticket": []},

+             "close_status": [

+                 "Invalid",

+                 "Insufficient data",

+                 "Fixed",

+                 "Duplicate"

+             ],

+             "custom_keys": [],

+             "date_created": "1436527638",

+             "date_modified": "1436527638",

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

+             "fullname": "test",

+             "id": 1,

+             "milestones": {},

+             "name": "test",

+             "namespace": None,

+             "parent": None,

+             "priorities": {},

+             "tags": ["infra"],

+             "user": {

+                 "fullname": "PY C",

+                 "name": "pingou"

+             }

+         }

+         self.assertDictEqual(data, expected_data)

+ 

      def test_api_projects_pagination(self):

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

          tests.create_projects(self.session)
@@ -1742,6 +1897,7 @@ 

                  self.session, project, 'pingou', '-1')

              pagure.lib.update_watch_status(

                  self.session, project, 'foo', '2')

+             self.session.commit()

  

              output = self.app.get('/api/0/test/watchers')

              self.assertEqual(output.status_code, 200)

With this commit the /api/0/<project> API endpoint may include a
group_details entry in its returned JSON blob which lists all the
members of the groups linked to this project.

Relates to: https://pagure.io/fedora-infrastructure/issue/6357
Relates to: https://github.com/fedora-infra/bodhi/issues/1810

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

This looks reasonable to me. :thumbsup:

rebased onto fd37015

6 years ago

Pull-Request has been merged by pingou

6 years ago