#1454 frontend: more understandable permissions errors
Merged 3 years ago by frostyx. Opened 3 years ago by praiskup.
Unknown source nicer-permissions-error  into  master

@@ -221,8 +221,8 @@

              auto_prune=True, use_bootstrap_container=False, follow_fedora_branching=False, **kwargs):

  

          if not flask.g.user.admin and flask.g.user != user:

-             msg = ("You were authorized as `{0}' and don't have permissions to access "

-                    "project of `{1}' user".format(flask.g.user.name, user.name))

+             msg = ("You were authorized as '{0}' user without permissions to access "

+                    "projects of user '{1}'".format(flask.g.user.name, user.name))

              raise exceptions.AccessRestricted(msg)

  

          if not flask.g.user.admin and persistent:

@@ -45,7 +45,7 @@

      def raise_if_not_in_group(cls, user, group):

          if not user.admin and group.fas_name not in user.user_teams:

              raise exceptions.InsufficientRightsException(

-                 "User '{}' doesn't have access to group {}({})"

+                 "User '{}' doesn't have access to the copr group '{}' (fas_name='{}')"

                  .format(user.username, group.name, group.fas_name))

  

      @classmethod

@@ -277,8 +277,8 @@

              with pytest.raises(InsufficientRightsException) as ex:

                  flask.g.user = self.u2

                  CoprsLogic.add(name="foo", user=self.u3, selected_chroots=["fedora-rawhide-x86_64"])

-             assert "You were authorized as `user2'" in ex.value.message

-             assert "don't have permissions to access project of `user3' user" in ex.value.message

+             assert "You were authorized as 'user2'" in ex.value.message

+             assert "without permissions to access projects of user 'user3'" in ex.value.message

  

              # Admin should be allowed to create such project

              flask.g.user = self.u1
@@ -298,7 +298,7 @@

              self.u1.openid_groups = None

              with pytest.raises(AccessRestricted) as ex:

                  CoprsLogic.add(name="p2", group=self.g1, user=self.u1, selected_chroots=["fedora-rawhide-x86_64"])

-             assert "User 'user1' doesn't have access to group group1(fas_1)" in ex.value.message

+             assert "User 'user1' doesn't have access to the copr group 'group1' (fas_name='fas_1')" in ex.value.message

  

              # Admin can create a whatever group project

              self.u1.admin = True

New format is:

Something went wrong:
Error: User 'praiskup' doesn't have access to copr group 'maistra' (fas_name='maistra')
Something went wrong:
Error: You were authorized as 'praiskup' user without permissions to access projects of user 'frostyx'

vs. the old variant:

Something went wrong:
Error: User 'praiskup' doesn't have access to group maistra(maistra)
Something went wrong:
Error: You were authorized as `praiskup' and don't have permissions to access project of `frostyx' user

The CI fails because there are some unit tests checking that error message, so they need to be also updated. Otherwise LGTM.

rebased onto 14dd19a8154b43a31896b02fc2dc968203d734f4

3 years ago

rebased onto 5a11892

3 years ago

Pull-Request has been merged by frostyx

3 years ago