#4943 Miscellaneous fixes
Merged 3 years ago by pingou. Opened 3 years ago by pingou.

@@ -180,6 +180,8 @@ 

                  # Install the main hook file

                  target = os.path.join(hookfolder, hooktype)

                  if not os.path.exists(target):

+                     if os.path.islink(target):

+                         os.unlink(target)

                      os.symlink(os.path.join(hook_files, "hookrunner"), target)

  

      @classmethod

file modified
+14 -1
@@ -137,6 +137,9 @@ 

  

      # Build a fake path so we can use get_repo_info_from_path

      path = os.path.join(pagure_config["GIT_FOLDER"], gitdir)

+     _auth_log.info(

+         "%s asks to access %s (path: %s) via ssh" % (remoteuser, gitdir, path)

+     )

      _log.info(

          "%s asks to access %s (path: %s) via ssh" % (remoteuser, gitdir, path)

      )
@@ -146,6 +149,11 @@ 

          namespace,

          repo,

      ) = pagure.lib.git.get_repo_info_from_path(path, hide_notfound=True)

+ 

+     _auth_log.info(

+         "%s asks to access the %s repo of %s/%s from user %s"

+         % (remoteuser, repotype, namespace, repo, project_user)

+     )

      _log.info(

          "%s asks to access the %s repo of %s/%s from user %s"

          % (remoteuser, repotype, namespace, repo, project_user)
@@ -177,6 +185,8 @@ 

          )

          _log.info("Project not found with this path")

          return flask.jsonify({"access": False})

+ 

+     _auth_log.info("Checking ACLs on project: %s" % project.fullname)

      _log.info("Checking ACLs on project: %s" % project.fullname)

  

      if repotype not in ["main", "docs"] and not pagure.utils.is_repo_user(
@@ -186,12 +196,15 @@ 

          # allowed for main and docs repos.

          _log.info("%s is not a contributor to this project" % remoteuser)

          _auth_log.info(

-             "User tried to access a projec they do not have access to -- "

+             "User tried to access a project they do not have access to -- "

              "|user: %s|IP: %s|method: N/A|repo: %s|query: N/A"

              % (remoteuser, flask.request.remote_addr, gitdir)

          )

          return flask.jsonify({"access": False})

  

+     _auth_log.info(

+         "Read access granted to %s on: %s" % (remoteuser, project.fullname)

+     )

      _log.info(

          "Read access granted to %s on: %s" % (remoteuser, project.fullname)

      )

file modified
+4 -2
@@ -1024,7 +1024,8 @@ 

                  key=lambda u: u.user,

              ),

              "collaborator": sorted(

-                 self.get_project_users(access="collaborator", combine=False)

+                 self.get_project_users(access="collaborator", combine=False),

+                 key=lambda u: u.user,

              ),

              "ticket": sorted(

                  self.get_project_users(access="ticket", combine=False),
@@ -1066,7 +1067,8 @@ 

                  key=lambda x: x.group_name,

              ),

              "collaborator": sorted(

-                 self.get_project_groups(access="collaborator", combine=False)

+                 self.get_project_groups(access="collaborator", combine=False),

+                 key=lambda x: x.group_name,

              ),

              "ticket": sorted(

                  self.get_project_groups(access="ticket", combine=False),

file modified
+2
@@ -68,6 +68,8 @@ 

                      # approach above didn't work, the user may still be

                      # using an API token, so we want to check that as well.

                      if not remote_user:

+                         import pagure.lib.query

+ 

                          token = pagure.lib.query.get_api_token(

                              flask.g.session, token_str

                          )

@@ -984,6 +984,79 @@ 

          }

          self.assertDictEqual(data, expected_data)

  

+     def test_api_project_collaborators(self):

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

+         tests.create_projects(self.session)

+         tests.create_user(self.session, "ralph", "Ralph B", ["ralph@b.org"])

+         tests.create_user(self.session, "nils", "Nils P", ["nils@p.net"])

+ 

+         # Add a couple of collaborators

+         project = pagure.lib.query._get_project(self.session, "test")

+         pagure.lib.query.add_user_to_project(

+             self.session,

+             project,

+             new_user="ralph",

+             user="pingou",

+             access="collaborator",

+             branches="f*,epel*",

+         )

+         pagure.lib.query.add_user_to_project(

+             self.session,

+             project,

+             new_user="nils",

+             user="pingou",

+             access="collaborator",

+             branches="epel*",

+         )

+         self.session.commit()

+ 

+         # Existing project

+         output = self.app.get("/api/0/test")

+         self.assertEqual(output.status_code, 200)

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

+         data["date_created"] = "1436527638"

+         data["date_modified"] = "1436527638"

+         expected_data = {

+             "access_groups": {

+                 "admin": [],

+                 "collaborator": [],

+                 "commit": [],

+                 "ticket": [],

+             },

+             "access_users": {

+                 "admin": [],

+                 "collaborator": ["nils", "ralph"],

+                 "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",

+             "url_path": "test",

+             "id": 1,

+             "milestones": {},

+             "name": "test",

+             "namespace": None,

+             "parent": None,

+             "priorities": {},

+             "tags": [],

+             "user": {

+                 "fullname": "PY C",

+                 "name": "pingou",

+                 "url_path": "user/pingou",

+             },

+         }

+         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)

Each commit can be reviewed individually

Thanks!

I'll let jenkins finish and will merge and release 5.11.1 :)

rebased onto bef2320

3 years ago

1 new commit added

  • Log the access_route instead of the remote_addr
3 years ago

4 new commits added

  • import pagure.lib.query before using it, in the code
  • Fix sorting collaborators and groups of collaborators
  • If the target is a link and does not exists, remove it before proceeding
  • Increase logging to the pagure_auth logger
3 years ago

Dropping the last commit for now and going to merge as the tests passed w/o it.

Pull-Request has been merged by pingou

3 years ago