#132 WIP Migrate Users
* adds automatic permission group adding depending on old access role * catches error on intervention migration auto-recording * changes default user is_active flag to be true on migration
This commit is contained in:
parent
9cd73aefe1
commit
3c211e6560
@ -229,7 +229,6 @@ class BaseMigrater:
|
||||
is_new = user[1]
|
||||
user = user[0]
|
||||
if is_new:
|
||||
user.is_active = False
|
||||
user.first_name = "MIGRIERT"
|
||||
user.last_name = "MIGRIERT"
|
||||
user.save()
|
||||
|
@ -198,6 +198,7 @@ class InterventionMigrater(BaseMigrater):
|
||||
intervention = self._migrate_documents(intervention, InterventionDocument, eiv)
|
||||
intervention = self._migrate_log(intervention, eiv)
|
||||
intervention = self._migrate_revocation(intervention, eiv)
|
||||
intervention = self._migrate_recorded(intervention, eiv)
|
||||
|
||||
intervention.save()
|
||||
|
||||
@ -266,8 +267,9 @@ class InterventionMigrater(BaseMigrater):
|
||||
|
||||
if recorded_state_result[0] is None:
|
||||
# There are old entries which hold alteintrag=false but are old entries.
|
||||
# This might be due to very poor migration in the past. Therefore, if there is no entry in table vorgang
|
||||
# we act as if this is an old entry anyway, which needs to be recorded
|
||||
# This might be due to problems in the migration process in the past. Therefore,
|
||||
# if there is no entry in table vorgang we act as if this is an old entry anyway,
|
||||
# which needs to be recorded
|
||||
to_be_recorded = True
|
||||
else:
|
||||
to_be_recorded = recorded_state_result[0] or recorded_state_result[1]
|
||||
@ -278,6 +280,10 @@ class InterventionMigrater(BaseMigrater):
|
||||
recorded_on = instance.created.timestamp
|
||||
recorded_by = instance.created.user.username
|
||||
else:
|
||||
if recorded_state_ts_user is None:
|
||||
# This means the entry is not an old entry but has not been recorded in the old system.
|
||||
# Nothing to do here!
|
||||
return instance
|
||||
recorded_on = timezone.make_aware(recorded_state_ts_user[0])
|
||||
recorded_by = recorded_state_ts_user[1]
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
from django.contrib.auth.models import Group
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_REGISTRATION_OFFICE_ID
|
||||
from konova.management.commands.kspMigrater.base_migrater import BaseMigrater
|
||||
from konova.settings import ZB_GROUP, ETS_GROUP
|
||||
from user.models import User
|
||||
|
||||
|
||||
@ -66,6 +68,7 @@ class UserMigrater(BaseMigrater):
|
||||
)
|
||||
team = self._get_team_from_responsible_code(responsible_code=_org, prefix="ZB")
|
||||
user_teams.append(team)
|
||||
self.give_registration_office_permission_for_user(user)
|
||||
elif is_type_ets:
|
||||
_org = KonovaCode.objects.get(
|
||||
atom_id=_org,
|
||||
@ -73,6 +76,7 @@ class UserMigrater(BaseMigrater):
|
||||
)
|
||||
team = self._get_team_from_responsible_code(responsible_code=_org, prefix="ETS")
|
||||
user_teams.append(team)
|
||||
self.give_conservation_office_permission_for_user(user)
|
||||
else:
|
||||
_org = result[5]
|
||||
if company_team is None:
|
||||
@ -90,3 +94,23 @@ class UserMigrater(BaseMigrater):
|
||||
team.users.add(user)
|
||||
num_processed += 1
|
||||
cursor.close()
|
||||
|
||||
def give_registration_office_permission_for_user(self, user: User):
|
||||
""" Gives user registration office group permissions
|
||||
|
||||
"""
|
||||
group = Group.objects.get(
|
||||
name=ZB_GROUP,
|
||||
)
|
||||
user.groups.add(group)
|
||||
return user
|
||||
|
||||
def give_conservation_office_permission_for_user(self, user: User):
|
||||
""" Gives user conservation office group permissions
|
||||
|
||||
"""
|
||||
group = Group.objects.get(
|
||||
name=ETS_GROUP,
|
||||
)
|
||||
user.groups.add(group)
|
||||
return user
|
||||
|
Loading…
Reference in New Issue
Block a user