#148 Extend take_orphan endpoint to accept fas username in POST data
Closed 3 years ago by humaton. Opened 3 years ago by humaton.
humaton/pagure-dist-git extend_take_orphan  into  master

file modified
+4 -2
@@ -342,9 +342,11 @@ 

  

      repo = _get_repo(repo, namespace=namespace)

      _check_token(repo, project_token=False)

- 

+     # check the POST data for fas_username to assign package to

+     # if not present use current users fas

+     fas_user_params = flask.request.args.get('fas_username')

      user_obj = pagure.lib.query.get_user(

-         flask.g.session, flask.g.fas_user.username

+         flask.g.session, flask.g.fas_user.username if fas_user_params is None else fas_user_params

      )

      if not user_obj:

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

@@ -375,6 +375,37 @@ 

          assert repo.orphan_reason.reason == "reason"

          output = self.app.post(

              "/_dg/take_orphan/rpms/test4",

+             headers=headers, 

+             json={'fas_username': 'jednorozec'}, 

+         )

+         assert output.status_code == 200

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

+         self.assertDictEqual(data, {"point_of_contact": "jednorozec"})

+ 

+         # refresh the repo object, so we have the current state

+         self.session.refresh(repo)

+         assert repo.user.user == "jednorozec"

+         assert not repo.orphan_reason

+ 

+         assert mock_log.call_count == 1

+ 

+     @patch("pagure_distgit.plugin._is_active_in_pdc")

+     @patch("pagure_distgit.plugin.pagure.lib.notify.log")

+     def test_take_orphan_specify_fas(self, mock_log, mock_pdc):

+         """

+         Assert that package is correctly adopted.

+         By user specified in the POST data

+         """

+         mock_pdc.return_value = True

+         headers = {"Authorization": "token aaabbbcccddd"}

+         repo = pagure.lib.query.get_authorized_project(

+             self.session,

+             "test4",

+             namespace="rpms",

+         )

+         assert repo.orphan_reason.reason == "reason"

+         output = self.app.post(

+             "/_dg/take_orphan/rpms/test4",

              headers=headers,

          )

          assert output.status_code == 200
@@ -388,6 +419,7 @@ 

  

          assert mock_log.call_count == 1

  

+ 

      @patch.dict("pagure.config.config", {"PDC_URL": "invalid://"})

      @patch("pagure_distgit.plugin.requests")

      @patch("pagure_distgit.plugin.pagure.lib.notify.log")

rebased onto 0f770d5a5d239495b21885817de982af177ac7f5

3 years ago

if fas_username is not passed onto the request, args.get() above will return None and Non.exists will not work.

Could you expand on the use-case for this change?

Currently, when releng is un-retiring packages we do it using the PATCH HTTP method to set the projects main_admin. As mentioned in the issue I have linked this is causing to leave orphan_reason in the database. By updating this endpoint and releng scripts this should be fixed.

rebased onto 45bbf86e2372a38f47f6e976c67ef9359cbfe971

3 years ago

rebased onto 1b25269

3 years ago

if fas_username is not passed onto the request, args.get() above will return None and Non.exists will not work.

Ups, it should be fixed now.

Don't we want that only rel-eng and admin users are able to assign a package to others?

I started to write a separate endpoint for this, but then I stopped due to lack of time trying to make test works:
https://pagure.io/fork/mattia/pagure-dist-git/c/a0d34d5160ad77dd4736b41f762713caf7736fda?branch=unretire

@mattia I have troubles with getting tests running as well, let me pick up your new endpoint and get the tests running.

Pull-Request has been closed by humaton

3 years ago