Permission values
* adds raw permission values for all groups
This commit is contained in:
parent
2757f1b9c1
commit
206d34afbb
@ -7,11 +7,11 @@ Created on: 15.12.20
|
|||||||
"""
|
"""
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User, Group, Permission
|
||||||
from django.core.management import BaseCommand
|
from django.core.management import BaseCommand
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
from konova.management.commands.setup_test_data import TEST_ORGANISATION_DATA
|
from konova.management.commands.setup_data import TEST_ORGANISATION_DATA, GROUPS_DATA
|
||||||
from organisation.models import Organisation
|
from organisation.models import Organisation
|
||||||
|
|
||||||
CREATED_TEMPLATE = "{} created"
|
CREATED_TEMPLATE = "{} created"
|
||||||
@ -23,39 +23,28 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
self.__init_superuser()
|
self._init_superuser()
|
||||||
self.__init_test_organisation()
|
self._init_test_organisation()
|
||||||
|
self._init_default_groups()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.__break_line()
|
self._break_line()
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
def __init_superuser(self):
|
def _init_superuser(self):
|
||||||
""" Create a superuser by user prompt input
|
""" Create a superuser by user prompt input
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.stdout.write(
|
self._write_warning("--- Superuser ---")
|
||||||
self.style.WARNING(
|
|
||||||
"--- Superuser ---",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
username = input("Superuser name: ")
|
username = input("Superuser name: ")
|
||||||
if User.objects.filter(username=username).exists():
|
if User.objects.filter(username=username).exists():
|
||||||
self.stdout.write(
|
self._write_error("Name already taken!")
|
||||||
self.style.ERROR(
|
|
||||||
"Name already taken!"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
exit(-1)
|
exit(-1)
|
||||||
pw = getpass("Password: ")
|
pw = getpass("Password: ")
|
||||||
pw_confirm = getpass("Confirm password : ")
|
pw_confirm = getpass("Confirm password : ")
|
||||||
if pw != pw_confirm:
|
if pw != pw_confirm:
|
||||||
self.stdout.write(
|
self._write_error("Passwords did not match!")
|
||||||
self.style.ERROR(
|
|
||||||
"Passwords did not match!"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
# Create superuser
|
# Create superuser
|
||||||
@ -65,39 +54,75 @@ class Command(BaseCommand):
|
|||||||
superuser.is_staff = True
|
superuser.is_staff = True
|
||||||
superuser.set_password(pw)
|
superuser.set_password(pw)
|
||||||
superuser.save()
|
superuser.save()
|
||||||
self.stdout.write(
|
self._write_success("Superuser {} created".format(username))
|
||||||
self.style.SUCCESS(
|
self._break_line()
|
||||||
"Superuser {} created".format(username)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.__break_line()
|
|
||||||
|
|
||||||
def __init_test_organisation(self):
|
def _init_test_organisation(self):
|
||||||
""" Creates test organisations from predefined data
|
""" Creates test organisations from predefined data
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.stdout.write(
|
self._write_warning("--- Organisations ---")
|
||||||
self.style.WARNING(
|
|
||||||
"--- Organisations ---"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for org in TEST_ORGANISATION_DATA:
|
for org in TEST_ORGANISATION_DATA:
|
||||||
db_org = Organisation.objects.get_or_create(
|
db_org = Organisation.objects.get_or_create(
|
||||||
**org
|
**org
|
||||||
)[0]
|
)[0]
|
||||||
self.stdout.write(
|
self._write_success(CREATED_TEMPLATE.format(db_org.name))
|
||||||
self.style.SUCCESS(
|
self._break_line()
|
||||||
CREATED_TEMPLATE.format(db_org.name)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.__break_line()
|
|
||||||
|
|
||||||
def __break_line(self):
|
def _init_default_groups(self):
|
||||||
|
""" Creates the default groups for konova:
|
||||||
|
* Group default
|
||||||
|
* Group ZB (registration office employees)
|
||||||
|
* Group ETS (conservation office employees)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
self._write_warning("--- Groups ---")
|
||||||
|
for group_data in GROUPS_DATA:
|
||||||
|
name = group_data.get("name")
|
||||||
|
perms_data = group_data.get("permissions")
|
||||||
|
perms_objects = [
|
||||||
|
Permission.objects.get_or_create(
|
||||||
|
codename=perm[0],
|
||||||
|
name=perm[1]
|
||||||
|
)
|
||||||
|
for perm in perms_data
|
||||||
|
]
|
||||||
|
group = Group.objects.get_or_create(
|
||||||
|
name=name,
|
||||||
|
)
|
||||||
|
group.permissions.set(perms_objects)
|
||||||
|
|
||||||
|
self._break_line()
|
||||||
|
|
||||||
|
def _break_line(self):
|
||||||
""" Simply prints a line break
|
""" Simply prints a line break
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.stdout.write("\n")
|
self.stdout.write("\n")
|
||||||
|
|
||||||
|
def _write_warning(self, txt: str):
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.WARNING(
|
||||||
|
txt
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _write_success(self, txt: str):
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.SUCCESS(
|
||||||
|
txt
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _write_error(self, txt: str):
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.ERROR(
|
||||||
|
txt
|
||||||
|
)
|
||||||
|
)
|
61
konova/management/commands/setup_data.py
Normal file
61
konova/management/commands/setup_data.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 15.12.20
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from konova.settings import ADD_INTERVENTION, CREATE_SHARE_LINK, DELETE_ECOACCOUNT, EDIT_ECOACCOUNT, ADD_ECOACCOUNT, \
|
||||||
|
DELETE_COMPENSATION, EDIT_COMPENSATION, ADD_COMPENSATION, DELETE_INTERVENTION, EDIT_INTERVENTION, VALIDITY_CHECK, \
|
||||||
|
DELETE_EMA, EDIT_EMA, ADD_EMA, RECORD_DATA
|
||||||
|
|
||||||
|
TEST_ORGANISATION_DATA = [
|
||||||
|
{
|
||||||
|
"name": "Test_Official_1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test_Official_2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test_NGO_1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Test_Company_1",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
# Groups permissions are declared in konova/settings.py
|
||||||
|
GROUPS_DATA = [
|
||||||
|
{
|
||||||
|
"name": _("Default"),
|
||||||
|
"permissions": [
|
||||||
|
ADD_INTERVENTION,
|
||||||
|
EDIT_INTERVENTION,
|
||||||
|
DELETE_INTERVENTION,
|
||||||
|
ADD_COMPENSATION,
|
||||||
|
EDIT_COMPENSATION,
|
||||||
|
DELETE_COMPENSATION,
|
||||||
|
ADD_ECOACCOUNT,
|
||||||
|
EDIT_ECOACCOUNT,
|
||||||
|
DELETE_ECOACCOUNT,
|
||||||
|
CREATE_SHARE_LINK,
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": _("Registration office"),
|
||||||
|
"permissions": [
|
||||||
|
VALIDITY_CHECK,
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": _("Conservation office"),
|
||||||
|
"permissions": [
|
||||||
|
RECORD_DATA,
|
||||||
|
ADD_EMA,
|
||||||
|
EDIT_EMA,
|
||||||
|
DELETE_EMA,
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
@ -1,49 +0,0 @@
|
|||||||
"""
|
|
||||||
Author: Michel Peltriaux
|
|
||||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
||||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
||||||
Created on: 15.12.20
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
TEST_ORGANISATION_DATA = [
|
|
||||||
{
|
|
||||||
"name": "Test_Official_1",
|
|
||||||
"is_active": True,
|
|
||||||
"is_deleted": False,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test_Official_2",
|
|
||||||
"is_active": True,
|
|
||||||
"is_deleted": False,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test_NGO_1",
|
|
||||||
"is_active": True,
|
|
||||||
"is_deleted": False,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Test_Company_1",
|
|
||||||
"is_active": True,
|
|
||||||
"is_deleted": False,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
TEST_ROLE_GROUPS_DATA = [
|
|
||||||
{
|
|
||||||
"name": "Registration office Test_Official_1",
|
|
||||||
"organisation": "Test_Official_1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Licensing authority Test_Official_1",
|
|
||||||
"organisation": "Test_Official_1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Dataprovider Test_Official_2",
|
|
||||||
"organisation": "Test_Official_2",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Dataprovider Test_Company_1",
|
|
||||||
"organisation": "Test_Company_1",
|
|
||||||
},
|
|
||||||
]
|
|
@ -7,7 +7,7 @@ Created on: 17.11.20
|
|||||||
"""
|
"""
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User, Group
|
||||||
from django.contrib.gis.db.models import MultiPolygonField
|
from django.contrib.gis.db.models import MultiPolygonField
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
@ -43,6 +43,25 @@ class BaseObject(BaseResource):
|
|||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
class KonovaPermission(models.Model):
|
||||||
|
"""
|
||||||
|
Custom permissions for konova
|
||||||
|
|
||||||
|
"""
|
||||||
|
name = models.CharField(max_length=255, blank=False, null=False)
|
||||||
|
description = models.TextField()
|
||||||
|
is_active = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
|
||||||
|
class KonovaGroup(models.Model):
|
||||||
|
"""
|
||||||
|
Custom group model
|
||||||
|
|
||||||
|
"""
|
||||||
|
name = models.CharField(max_length=255, null=False, blank=False)
|
||||||
|
permissions = models.ManyToManyField(KonovaPermission)
|
||||||
|
|
||||||
|
|
||||||
class Deadline(BaseResource):
|
class Deadline(BaseResource):
|
||||||
"""
|
"""
|
||||||
Defines a deadline, which can be used to define dates with a semantic meaning
|
Defines a deadline, which can be used to define dates with a semantic meaning
|
||||||
|
@ -9,6 +9,7 @@ https://docs.djangoproject.com/en/3.1/topics/settings/
|
|||||||
For the full list of settings and their values, see
|
For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/3.1/ref/settings/
|
https://docs.djangoproject.com/en/3.1/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
# Load other settings
|
# Load other settings
|
||||||
from konova.sub_settings.django_settings import *
|
from konova.sub_settings.django_settings import *
|
||||||
@ -51,25 +52,22 @@ DEFAULT_ZOOM = 8.0
|
|||||||
|
|
||||||
# PERMISSION VALUES
|
# PERMISSION VALUES
|
||||||
## Group default
|
## Group default
|
||||||
ADD_INTERVENTION = "add_intervention"
|
ADD_INTERVENTION = ("add_intervention", _("Add new intervention"))
|
||||||
EDIT_INTERVENTION = "edit_intervention"
|
EDIT_INTERVENTION = ("edit_intervention", _("Edit intervention"))
|
||||||
DELETE_INTERVENTION = "delete_intervention"
|
DELETE_INTERVENTION = ("delete_intervention", _("Delete intervention"))
|
||||||
|
ADD_COMPENSATION = ("add_compensation", _("Add new compensation"))
|
||||||
ADD_COMPENSATION = "add_compensation"
|
EDIT_COMPENSATION = ("edit_compensation", _("Edit compensation"))
|
||||||
EDIT_COMPENSATION = "edit_compensation"
|
DELETE_COMPENSATION = ("delete_compensation", _("Delete compensation"))
|
||||||
DELETE_COMPENSATION = "delete_compensation"
|
ADD_ECOACCOUNT = ("add_ecoaccount", _("Add new eco account"))
|
||||||
|
EDIT_ECOACCOUNT = ("edit_ecoaccount", _("Edit eco account"))
|
||||||
ADD_ECOACCOUNT = "add_ecoaccount"
|
DELETE_ECOACCOUNT = ("delete_ecoaccount", _("Delete eco account"))
|
||||||
EDIT_ECOACCOUNT = "edit_ecoaccount"
|
CREATE_SHARE_LINK = ("create_share_link", _("Create share link"))
|
||||||
DELETE_ECOACCOUNT = "delete_ecoaccount"
|
|
||||||
|
|
||||||
CREATE_SHARE_LINK = "create_share_link"
|
|
||||||
|
|
||||||
## Group ZB
|
## Group ZB
|
||||||
VALIDITY_CHECK = "validity_check"
|
VALIDITY_CHECK = ("validity_check", _("Confirm check on data"))
|
||||||
|
|
||||||
## Group ETS
|
## Group ETS
|
||||||
RECORD_DATA = "record_data" # refers to 'verzeichnen'
|
RECORD_DATA = ("record_data", _("Record data")) # refers to 'verzeichnen'
|
||||||
ADD_EMA = "add_ema"
|
ADD_EMA = ("add_ema", _("Add new EMA"))
|
||||||
EDIT_EMA = "edit_ema"
|
EDIT_EMA = ("edit_ema", _("Edit EMA"))
|
||||||
DELETE_EMA = "delete_ema"
|
DELETE_EMA = ("delete_ema", _("Delete EMA"))
|
||||||
|
Loading…
Reference in New Issue
Block a user