mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Added change password permission
Replaces SHOW_PROFILE_EDIT_PASSWORD option Can be set on per user or per group basis
This commit is contained in:
parent
2a0d240038
commit
a62daad87b
6 changed files with 90 additions and 13 deletions
24
accounts/migrations/0003_permissionset.py
Normal file
24
accounts/migrations/0003_permissionset.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 2.2.12 on 2020-05-27 12:29
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0002_addAdmin'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PermissionSet',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
],
|
||||
options={
|
||||
'permissions': (('change_password', 'Can change password'),),
|
||||
'managed': False,
|
||||
'default_permissions': (),
|
||||
},
|
||||
),
|
||||
]
|
||||
25
accounts/migrations/0004_apply_change_password.py
Normal file
25
accounts/migrations/0004_apply_change_password.py
Normal file
|
|
@ -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),
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue