From 40e5536300e3947688948d471391ba008c50f30c Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 11 Oct 2021 21:39:34 +1100 Subject: [PATCH 1/3] Handle rare case where user instance has no name assigned --- InvenTree/users/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index 8a417a050d..73a7561153 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -216,7 +216,10 @@ class RuleSet(models.Model): return True # Print message instead of throwing an error - logger.info(f"User '{user.name}' failed permission check for {table}.{permission}") + name = getattr(user, 'name', user.pk) + + logger.info(f"User '{name}' failed permission check for {table}.{permission}") + return False @staticmethod From 75bfdd615e0e76927943ecf53cc973f1d9d35a23 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 12 Oct 2021 11:38:25 +1100 Subject: [PATCH 2/3] Fixes for unit tests --- InvenTree/InvenTree/metadata.py | 5 ++++- InvenTree/InvenTree/test_api.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/InvenTree/InvenTree/metadata.py b/InvenTree/InvenTree/metadata.py index 613983fe94..e7f78554f9 100644 --- a/InvenTree/InvenTree/metadata.py +++ b/InvenTree/InvenTree/metadata.py @@ -72,7 +72,10 @@ class InvenTreeMetadata(SimpleMetadata): # Remove any HTTP methods that the user does not have permission for for method, permission in rolemap.items(): - if method in actions and not check(user, table, permission): + + result = check(user, table, permission) + + if method in actions and not result: del actions[method] # Add a 'DELETE' action if we are allowed to delete diff --git a/InvenTree/InvenTree/test_api.py b/InvenTree/InvenTree/test_api.py index 791f98025b..dfe94c034e 100644 --- a/InvenTree/InvenTree/test_api.py +++ b/InvenTree/InvenTree/test_api.py @@ -296,9 +296,9 @@ class APITests(InvenTreeAPITestCase): actions = self.getActions(url) - # 'add' permission does not apply here! - self.assertEqual(len(actions), 1) + self.assertEqual(len(actions), 2) self.assertIn('PUT', actions.keys()) + self.assertIn('GET', actions.keys()) # Add some other permissions self.assignRole('part.change') From ec24f77da8b1027e02fe882df8ad8fd10afe10ca Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 12 Oct 2021 21:29:55 +1100 Subject: [PATCH 3/3] remove 'repository' arg from docker builds --- .github/workflows/docker_latest.yaml | 1 - .github/workflows/docker_stable.yaml | 1 - .github/workflows/docker_tag.yaml | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/workflows/docker_latest.yaml b/.github/workflows/docker_latest.yaml index 355afa5b87..6b248fe0b9 100644 --- a/.github/workflows/docker_latest.yaml +++ b/.github/workflows/docker_latest.yaml @@ -34,7 +34,6 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true target: production - repository: inventree/inventree tags: inventree/inventree:latest - name: Image Digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/docker_stable.yaml b/.github/workflows/docker_stable.yaml index 1f3c7749c7..65c31dd9dc 100644 --- a/.github/workflows/docker_stable.yaml +++ b/.github/workflows/docker_stable.yaml @@ -37,7 +37,6 @@ jobs: target: production build-args: branch: stable - repository: inventree/inventree tags: inventree/inventree:stable - name: Image Digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/docker_tag.yaml b/.github/workflows/docker_tag.yaml index 90b8f72505..5de27f48be 100644 --- a/.github/workflows/docker_tag.yaml +++ b/.github/workflows/docker_tag.yaml @@ -35,5 +35,4 @@ jobs: target: production build-args: tag: ${{ github.event.release.tag_name }} - repository: inventree/inventree tags: inventree/inventree:${{ github.event.release.tag_name }}