From 5afa84ee19853e71d70e431b38ece7c3f1bd23ba Mon Sep 17 00:00:00 2001 From: Real-Gecko Date: Wed, 27 May 2020 18:46:37 +0600 Subject: [PATCH] Added change password permission Replaces SHOW_PROFILE_EDIT_PASSWORD option Can be set on per user or per group basis --- ...602_1004.py => 0002_auto_20200602_1004.py} | 2 +- ...permissionset.py => 0003_permissionset.py} | 4 +-- .../migrations/0004_apply_change_password.py | 25 +++++++++++++++++++ accounts/templates/profile.html | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) rename accounts/migrations/{0003_auto_20200602_1004.py => 0002_auto_20200602_1004.py} (95%) rename accounts/migrations/{0002_permissionset.py => 0003_permissionset.py} (90%) create mode 100644 accounts/migrations/0004_apply_change_password.py diff --git a/accounts/migrations/0003_auto_20200602_1004.py b/accounts/migrations/0002_auto_20200602_1004.py similarity index 95% rename from accounts/migrations/0003_auto_20200602_1004.py rename to accounts/migrations/0002_auto_20200602_1004.py index 72338b1..91dd8ce 100644 --- a/accounts/migrations/0003_auto_20200602_1004.py +++ b/accounts/migrations/0002_auto_20200602_1004.py @@ -7,7 +7,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('accounts', '0002_permissionset'), + ('accounts', '0001_initial'), ] operations = [ diff --git a/accounts/migrations/0002_permissionset.py b/accounts/migrations/0003_permissionset.py similarity index 90% rename from accounts/migrations/0002_permissionset.py rename to accounts/migrations/0003_permissionset.py index 5b36210..15fd77b 100644 --- a/accounts/migrations/0002_permissionset.py +++ b/accounts/migrations/0003_permissionset.py @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('accounts', '0001_initial'), + ('accounts', '0002_auto_20200602_1004'), ] operations = [ @@ -16,7 +16,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ], options={ - 'permissions': (('change_password', 'Can change password'), ), + 'permissions': (('change_password', 'Can change password'),), 'managed': False, 'default_permissions': (), }, diff --git a/accounts/migrations/0004_apply_change_password.py b/accounts/migrations/0004_apply_change_password.py new file mode 100644 index 0000000..f313b7e --- /dev/null +++ b/accounts/migrations/0004_apply_change_password.py @@ -0,0 +1,25 @@ +from django.db import migrations + + +def apply_change_password(apps, schema_editor): + from django.conf import settings + from django.contrib.auth.models import User, Permission + + if hasattr(settings, 'SHOW_PROFILE_EDIT_PASSWORD'): + if settings.SHOW_PROFILE_EDIT_PASSWORD: + permission = Permission.objects.get(codename='change_password') + users = User.objects.all() + user: User + for user in users: + user.user_permissions.add(permission) + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0003_permissionset'), + ] + + operations = [ + migrations.RunPython(apply_change_password), + ] diff --git a/accounts/templates/profile.html b/accounts/templates/profile.html index 848fae6..1c00314 100644 --- a/accounts/templates/profile.html +++ b/accounts/templates/profile.html @@ -64,7 +64,7 @@
-
+