From 4669b8ed89020ac0965c3817b02c69818ad88151 Mon Sep 17 00:00:00 2001 From: Griatch Date: Wed, 10 Apr 2013 21:45:56 +0200 Subject: [PATCH] Fixed the migrations from a pre-populated database to the many-char-per-player branch. --- .../0014_add_attr__playable_characters.py | 38 ++++++++++++++++--- src/server/initial_setup.py | 3 ++ src/typeclasses/models.py | 2 +- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/players/migrations/0014_add_attr__playable_characters.py b/src/players/migrations/0014_add_attr__playable_characters.py index 0cbe746cb..604f4b45d 100644 --- a/src/players/migrations/0014_add_attr__playable_characters.py +++ b/src/players/migrations/0014_add_attr__playable_characters.py @@ -1,24 +1,43 @@ # -*- coding: utf-8 -*- -import datetime +import datetime, pickle from south.db import db from south.v2 import DataMigration from django.db import models +from src.typeclasses.models import PackedDBobject class Migration(DataMigration): def forwards(self, orm): "Write your forwards methods here." # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..." + + lockstring = "attrread:perm(Admins);attredit:perm(Admins);attrcreate:perm(Admins)" + lockstring2 = "attrread:false();attredit:false();attrcreate:false()" if not db.dry_run: for player in orm['players.PlayerDB'].objects.all(): - attr = orm['players.PlayerAttribute']() - attr.db_obj = player - attr.save() char = player.db_obj - attr.db_obj.value = [char] or [] + if char: + val = pickle.dumps(("iter", [PackedDBobject(char.id, "objectdb", char.db_key)])) + else: + val = pickle.dumps(("iter", [])) + orm['players.PlayerAttribute'].objects.create(db_key="_playable_characters", + db_obj=player, + db_lock_storage=lockstring, + db_value=val) + suser = char and char.id == 1 + if suser: + # move the superuser unmask attribute for the superuser (note that this + # is not a security risk, it only works if player's superuser bit is set too) + val = pickle.dumps(("simple", suser)) + orm['objects.ObjAttribute'].objects.create(db_key="_superuser_character", + db_obj=char, + db_lock_storage=lockstring2, + db_value=val) + def backwards(self, orm): "Write your backwards methods here." + raise RuntimeError("This migration cannot be reverted.") models = { 'auth.group': { @@ -66,6 +85,15 @@ class Migration(DataMigration): 'db_value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) }, + 'objects.objattribute': { + 'Meta': {'object_name': 'ObjAttribute'}, + 'db_date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'db_key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'db_lock_storage': ('django.db.models.fields.CharField', [], {'max_length': '512', 'blank': 'True'}), + 'db_obj': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['objects.ObjectDB']"}), + 'db_value': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) + }, 'objects.objectdb': { 'Meta': {'object_name': 'ObjectDB'}, 'db_cmdset_storage': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), diff --git a/src/server/initial_setup.py b/src/server/initial_setup.py index c35302aab..f85405151 100644 --- a/src/server/initial_setup.py +++ b/src/server/initial_setup.py @@ -60,6 +60,9 @@ def create_objects(): god_character.locks.add("examine:perm(Immortals);edit:false();delete:false();boot:false();msg:all();puppet:false()") god_character.save() + # note that there is no security issue with setting the _superuser_character flag - the system + # will only grant superuser access to a character with this flag if its Player also has the + # superuser bit set. It only marks that the character should not "mask" the superuser privileges. god_character.set_attribute("_superuser_character", True) god_player.set_attribute("_first_login", True) god_player.set_attribute("_last_puppet", god_character) diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index e98000b61..35791ef60 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -297,7 +297,7 @@ class Attribute(SharedMemoryModel): The Attribute class defines the following properties: key - primary identifier mode - which type of data is stored in attribute - permissions - perm strings + lock_storage - perm strings obj - which object the attribute is defined on date_created - when the attribute was created value - the data stored in the attribute