1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +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:
Real-Gecko 2020-05-27 18:46:37 +06:00
parent 2a0d240038
commit a62daad87b
6 changed files with 90 additions and 13 deletions

View 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': (),
},
),
]

View 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),
]

View file

@ -1,10 +1,11 @@
from django.db.models import Model, BooleanField, IntegerField, CharField
from django.db.models import ForeignKey, OneToOneField
from django.db.models import CASCADE, DO_NOTHING
from django.contrib.auth.models import User
from django.conf import settings
from instances.models import Instance
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator
from django.db.models import (CASCADE, DO_NOTHING, BooleanField, CharField,
ForeignKey, IntegerField, Model, OneToOneField)
from django.utils.translation import ugettext_lazy as _
from instances.models import Instance
class UserInstance(Model):
@ -30,10 +31,26 @@ class UserSSHKey(Model):
class UserAttributes(Model):
user = OneToOneField(User, on_delete=CASCADE)
can_clone_instances = BooleanField(default=True)
max_instances = IntegerField(default=1, help_text="-1 for unlimited. Any integer value", validators=[MinValueValidator(-1), ])
max_cpus = IntegerField(default=1, help_text="-1 for unlimited. Any integer value", validators=[MinValueValidator(-1)])
max_memory = IntegerField(default=2048, help_text="-1 for unlimited. Any integer value", validators=[MinValueValidator(-1)])
max_disk_size = IntegerField(default=20, help_text="-1 for unlimited. Any integer value", validators=[MinValueValidator(-1)])
max_instances = IntegerField(default=1,
help_text="-1 for unlimited. Any integer value",
validators=[
MinValueValidator(-1),
])
max_cpus = IntegerField(
default=1,
help_text="-1 for unlimited. Any integer value",
validators=[MinValueValidator(-1)],
)
max_memory = IntegerField(
default=2048,
help_text="-1 for unlimited. Any integer value",
validators=[MinValueValidator(-1)],
)
max_disk_size = IntegerField(
default=20,
help_text="-1 for unlimited. Any integer value",
validators=[MinValueValidator(-1)],
)
@staticmethod
def create_missing_userattributes(user):
@ -59,3 +76,16 @@ class UserAttributes(Model):
def __unicode__(self):
return self.user.username
class PermissionSet(Model):
"""
Dummy model for holding set of permissions we need to be automatically added by Django
"""
class Meta:
default_permissions = ()
permissions = (
('change_password', _('Can change password')),
)
managed = False

View file

@ -41,7 +41,7 @@
</div>
</div>
</form>
{% if show_profile_edit_password %}
{% if perms.accounts.change_password %}
<h3 class="page-header">{% trans "Edit Password" %}</h3>
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
<div class="form-group">

View file

@ -20,7 +20,6 @@ def profile(request):
error_messages = []
# user = User.objects.get(id=request.user.id)
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
show_profile_edit_password = settings.SHOW_PROFILE_EDIT_PASSWORD
if request.method == 'POST':
if 'username' in request.POST:

View file

@ -171,7 +171,6 @@ QUOTA_DEBUG = True
ALLOW_EMPTY_PASSWORD = True
SHOW_ACCESS_ROOT_PASSWORD = False
SHOW_ACCESS_SSH_KEYS = False
SHOW_PROFILE_EDIT_PASSWORD = False
# available list style: default (grouped), nongrouped
VIEW_INSTANCES_LIST_STYLE = 'grouped'