ae54d93442
Section-based portal access, matrix прав по группам, аккаунтинг-портал, управление группами пользователей, справочники, дашборд и общий каркас навигации/стилей. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
# Grant access_recruiting to pharmacy roles; remove recruiting from stubs (code-side).
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
def grant_recruiting(apps, schema_editor):
|
|
Group = apps.get_model('auth', 'Group')
|
|
Permission = apps.get_model('auth', 'Permission')
|
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
|
GroupSectionAccess = apps.get_model('employees', 'GroupSectionAccess')
|
|
|
|
ct = ContentType.objects.filter(app_label='core', model='portalaccess').first()
|
|
if ct is None:
|
|
return
|
|
perm = Permission.objects.filter(content_type=ct, codename='access_recruiting').first()
|
|
if perm is None:
|
|
return
|
|
|
|
for name in ('Фармацевт', 'Заведующий аптекой'):
|
|
group = Group.objects.filter(name=name).first()
|
|
if group is None:
|
|
continue
|
|
group.permissions.add(perm)
|
|
GroupSectionAccess.objects.update_or_create(
|
|
group_id=group.pk,
|
|
section_key='recruiting',
|
|
defaults={
|
|
'can_create': name == 'Заведующий аптекой',
|
|
'can_update': name == 'Заведующий аптекой',
|
|
'can_delete': False,
|
|
},
|
|
)
|
|
|
|
|
|
def revoke_recruiting(apps, schema_editor):
|
|
Group = apps.get_model('auth', 'Group')
|
|
Permission = apps.get_model('auth', 'Permission')
|
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
|
GroupSectionAccess = apps.get_model('employees', 'GroupSectionAccess')
|
|
|
|
ct = ContentType.objects.filter(app_label='core', model='portalaccess').first()
|
|
if ct is None:
|
|
return
|
|
perm = Permission.objects.filter(content_type=ct, codename='access_recruiting').first()
|
|
if perm is None:
|
|
return
|
|
for name in ('Фармацевт', 'Заведующий аптекой'):
|
|
group = Group.objects.filter(name=name).first()
|
|
if group is None:
|
|
continue
|
|
group.permissions.remove(perm)
|
|
GroupSectionAccess.objects.filter(group_id=group.pk, section_key='recruiting').delete()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('core', '0017_rename_databases_section'),
|
|
('employees', '0018_seed_group_section_access'),
|
|
('hiring', '0008_vacancy'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(grant_recruiting, revoke_recruiting),
|
|
]
|