From 29dff20db95e8f692c4c8ceafb72ad8ca30456ca Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sun, 26 Jun 2022 21:30:45 -0700 Subject: [PATCH] Add django-guardian for object-level permissions Signed-off-by: Alek Ratzloff --- Pipfile | 1 + Pipfile.lock | 22 +++++++++++++++------- board/models.py | 7 +++++++ threadchat/settings.py | 6 ++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Pipfile b/Pipfile index 167f8d4..d6e7cfe 100644 --- a/Pipfile +++ b/Pipfile @@ -8,6 +8,7 @@ django = "*" pillow = "*" django-hcaptcha = "*" django-environ = "*" +django-guardian = "*" [dev-packages] mypy = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 5ee02a8..736e5c5 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "6b614acd169f2a3bcb689616de53fb77e5c97e078c338b86806b7bc7cdf9b48d" + "sha256": "a71e0de66e9b1b37118b78315b96e0469e01b88a3fb67e86b78686500e178c54" }, "pipfile-spec": 6, "requires": { @@ -26,19 +26,27 @@ }, "django": { "hashes": [ - "sha256:815b1c3e1c1379cca1c54cc7202ee86df006f52b94560b46ea0b19f162c9474a", - "sha256:91980d3b327e38e44c2bef0af86d624a57adbd5f1c96f43acf150396770caf01" + "sha256:55ea3e07df2eb3994b7261d743c111e4c27a56ca1285eb762dba07432ebe4039", + "sha256:ec22c3e909af402281ef1dea69cbbc42b43b9ac9379df2914e0a7b85597242d6" ], "index": "pypi", - "version": "==4.1a1" + "version": "==4.1b1" }, "django-environ": { "hashes": [ - "sha256:42593bee519a527602a467c7b682aee1a051c2597f98c45f4f4f44169ecdb6e5", - "sha256:6f0bc902b43891656b20486938cba0861dc62892784a44919170719572a534cb" + "sha256:bff5381533056328c9ac02f71790bd5bf1cea81b1beeb648f28b81c9e83e0a21", + "sha256:f21a5ef8cc603da1870bbf9a09b7e5577ab5f6da451b843dbcc721a7bca6b3d9" ], "index": "pypi", - "version": "==0.8.1" + "version": "==0.9.0" + }, + "django-guardian": { + "hashes": [ + "sha256:440ca61358427e575323648b25f8384739e54c38b3d655c81d75e0cd0d61b697", + "sha256:c58a68ae76922d33e6bdc0e69af1892097838de56e93e78a8361090bcd9f89a0" + ], + "index": "pypi", + "version": "==2.4.0" }, "django-hcaptcha": { "hashes": [ diff --git a/board/models.py b/board/models.py index 9c0be28..7c4a74c 100644 --- a/board/models.py +++ b/board/models.py @@ -331,3 +331,10 @@ class BanTemplate(models.Model): return f"/{self.board.url}/ - {self.name}" else: return self.name + + +class Capcode(models.Model): + # Content to display *before* the capcoded user's name. + prefix = models.CharField(max_length=100) + # Content to display *after* the capcoded user's name. + suffix = models.CharField(max_length=100) diff --git a/threadchat/settings.py b/threadchat/settings.py index 35ce7f2..f424dcd 100644 --- a/threadchat/settings.py +++ b/threadchat/settings.py @@ -42,6 +42,7 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "guardian", "board", ] @@ -75,6 +76,11 @@ TEMPLATES = [ WSGI_APPLICATION = "threadchat.wsgi.application" +AUTHENTICATION_BACKENDS = ( + "django.contrib.auth.backends.ModelBackend", + "guardian.backends.ObjectPermissionBackend", +) + # Database # https://docs.djangoproject.com/en/4.0/ref/settings/#databases