mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 09:46:32 +01:00
Run migrations! Update all Permissions and Locks to new Permission hierarchy.
This commit is contained in:
parent
0bd47f0c52
commit
2138e4cd70
1 changed files with 47 additions and 0 deletions
47
evennia/typeclasses/migrations/0008_lock_and_perm_rename.py
Normal file
47
evennia/typeclasses/migrations/0008_lock_and_perm_rename.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.11 on 2017-01-25 22:30
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
from django.db import migrations
|
||||
|
||||
def update_perms_and_locks(apps, schema_editor):
|
||||
|
||||
# update all permissions
|
||||
Tag = apps.get_model('typeclasses', 'Tag')
|
||||
perm_map = {"guests": "guest", "players": "player", "playerhelpers":"helper",
|
||||
"builders": "builder", "wizards":"admin", "immortals": "developer"}
|
||||
|
||||
for perm in Tag.objects.filter(db_tagtype="permission"):
|
||||
if perm.db_key in perm_map:
|
||||
perm.db_key = perm_map[perm.db_key]
|
||||
perm.save(update_fields=("db_key",))
|
||||
|
||||
# update all locks on all entities
|
||||
apps_models = [("objects", "ObjectDB"), ("players", "PlayerDB"), ("scripts", "ScriptDB"),
|
||||
("comms", "ChannelDB")]
|
||||
p_reg = re.compile(r"(?<=perm\()(\w+)(?=\))|(?<=perm_above\()(\w+)(?=\))",
|
||||
re.IGNORECASE + re.UNICODE)
|
||||
def _sub(match):
|
||||
perm = match.group(1)
|
||||
return perm_map[perm.lower()].capitalize() if perm.lower() in perm_map else perm
|
||||
|
||||
for app_tuple in apps_models:
|
||||
TClass = apps.get_model(*app_tuple)
|
||||
for obj in TClass.objects.filter(db_lock_storage__icontains="perm"):
|
||||
orig_lock = obj.db_lock_storage
|
||||
repl_lock = p_reg.sub(_sub, orig_lock)
|
||||
if repl_lock != orig_lock:
|
||||
obj.db_lock_storage = repl_lock
|
||||
obj.save(update_fields=('db_lock_storage',))
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('typeclasses', '0007_tag_migrations_may_be_slow'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
||||
migrations.RunPython(update_perms_and_locks)
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue