Skip to content

Commit

Permalink
Address issue #295
Browse files Browse the repository at this point in the history
  • Loading branch information
evilaliv3 committed Dec 21, 2014
1 parent 5c640e0 commit b868ef3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 deletions.
11 changes: 6 additions & 5 deletions backend/globaleaks/db/base_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from storm.locals import create_database, Store
from storm.properties import PropertyColumn
from storm.variables import BoolVariable, DateTimeVariable
from storm.variables import EnumVariable, IntVariable, RawStrVariable
from storm.variables import UnicodeVariable, JSONVariable, PickleVariable
from storm.variables import EnumVariable, IntVariable, RawStrVariable, PickleVariable
from storm.variables import UnicodeVariable, JSONVariable

from globaleaks import DATABASE_VERSION, models
from globaleaks.settings import GLSetting
Expand Down Expand Up @@ -132,7 +132,8 @@ def __init__(self, old_db_file, new_db_file, start_ver):
from globaleaks.db.update_12_13 import Node_version_12, Context_version_12
from globaleaks.db.update_13_14 import Node_version_13, Context_version_13
from globaleaks.db.update_14_15 import Node_version_14, User_version_14, Context_version_14, Receiver_version_14, \
InternalTip_version_14, Notification_version_14, Stats_version_14
InternalTip_version_14, Notification_version_14, Stats_version_14, ApplicationData_version_14, \
Comment_version_14

self.old_db_file = old_db_file
self.new_db_file = new_db_file
Expand All @@ -148,7 +149,7 @@ def __init__(self, old_db_file, new_db_file, start_ver):
'Receiver': [ Receiver_version_7, None, None, Receiver_version_8, Receiver_version_9, Receiver_version_14, None, None, None, None, models.Receiver],
'ReceiverFile' : [ models.ReceiverFile, None, None, None, None, None, None, None, None, None, None],
'Notification': [ Notification_version_7, None, None, Notification_version_8, Notification_version_14, None, None, None, None, None, models.Notification],
'Comment': [ Comment_version_5, models.Comment, None, None, None, None, None, None, None, None, None],
'Comment': [ Comment_version_5, Comment_version_14, None, None, None, None, None, None, None, None, models.Comment],
'InternalTip' : [ InternalTip_version_10, None, None, None, None, None, InternalTip_version_14, None, None, None, models.InternalTip],
'InternalFile' : [ InternalFile_version_7, None, None, InternalFile_version_10, None, None, models.InternalFile, None, None, None, None],
'WhistleblowerTip' : [ models.WhistleblowerTip, None, None, None, None, None, None, None, None, None, None],
Expand All @@ -157,7 +158,7 @@ def __init__(self, old_db_file, new_db_file, start_ver):
'ReceiverContext' : [ models.ReceiverContext, None, None, None, None, None, None, None, None, None, None],
'Message' : [ models.Message, None, None, None, None, None, None, None, None, None, None],
'Stats' : [Stats_version_14, None, None, None, None, None, None, None, None, None, models.Stats],
'ApplicationData' : [ApplicationData_version_10, None, None, None, None, None, None, models.ApplicationData, None, None, None],
'ApplicationData' : [ApplicationData_version_10, None, None, None, None, None, None, ApplicationData_version_14, None, None, models.ApplicationData],
}

for k, v in self.table_history.iteritems():
Expand Down
16 changes: 15 additions & 1 deletion backend/globaleaks/db/update_14_15.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class User_version_14(Model):
last_login = DateTime()

class InternalTip_version_14(Model):
__storm_table__ = "internaltip"
__storm_table__ = 'internaltip'
context_id = Unicode()
wb_fields = Pickle()
pertinence_counter = Int()
Expand Down Expand Up @@ -177,6 +177,20 @@ class Stats_version_14(Model):
__storm_table__ = 'stats'
content = Pickle()

class ApplicationData_version_14(Model):
__storm_table__ = 'applicationdata'
version = Int()
fields = Pickle()

class Comment_version_14(Model):
__storm_table__ = 'comment'
internaltip_id = Unicode()
author = Unicode()
content = Unicode()
system_content = Pickle()
type = Unicode()
mark = Unicode()

class Replacer1415(TableReplacer):

def migrate_Node(self):
Expand Down
69 changes: 34 additions & 35 deletions backend/globaleaks/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import copy

from storm.locals import Bool, DateTime, Int, Pickle, Reference, ReferenceSet, Unicode, Storm, JSON
from storm.locals import Bool, DateTime, Int, Reference, ReferenceSet, Unicode, Storm, JSON

from globaleaks.settings import transact
from globaleaks.utils.utility import datetime_now, uuid4
Expand Down Expand Up @@ -215,9 +215,9 @@ class Context(Model):
last_update = DateTime()

# localized stuff
name = Pickle(validator=shortlocal_v)
description = Pickle(validator=longlocal_v)
receiver_introduction = Pickle(validator=longlocal_v)
name = JSON()
description = JSON()
receiver_introduction = JSON()

This comment has been minimized.

Copy link
@vecna

vecna Dec 22, 2014

Contributor

Validator can be used here too, they were checking that any value in the dict will not overcome textlimit (4096 by default IRC)

This comment has been minimized.

Copy link
@evilaliv3

evilaliv3 Dec 22, 2014

Author Member

sure of this? what do you suggest to write?

# receivers = ReferenceSet(
# Context.id,
Expand Down Expand Up @@ -381,7 +381,7 @@ class Comment(Model):
content = Unicode(validator=longtext_v)

# In case of system_content usage, content has repr() equiv
system_content = Pickle()
system_content = JSON()

type = Unicode()
_types = [u'receiver', u'whistleblower', u'system']
Expand Down Expand Up @@ -435,17 +435,17 @@ class Node(Model):
# this has a dedicated validator in update_node()
receipt_regexp = Unicode()

languages_enabled = Pickle()
languages_enabled = JSON()
default_language = Unicode()
default_timezone = Int()

# localized string
description = Pickle(validator=longlocal_v)
presentation = Pickle(validator=longlocal_v)
footer = Pickle(validator=longlocal_v)
subtitle = Pickle(validator=longlocal_v)
security_awareness_title = Pickle(validator=longlocal_v)
security_awareness_text = Pickle(validator=longlocal_v)
description = JSON()
presentation = JSON()
footer = JSON()
subtitle = JSON()
security_awareness_title = JSON()
security_awareness_text = JSON()

# Here is set the time frame for the stats publicly exported by the node.
# Expressed in hours
Expand Down Expand Up @@ -517,32 +517,32 @@ class Notification(Model):
security = Unicode()
_security_types = [u'TLS', u'SSL']

admin_anomaly_template = Pickle(validator=longlocal_v)
admin_anomaly_template = JSON()

encrypted_tip_template = Pickle(validator=longlocal_v)
encrypted_tip_mail_title = Pickle(validator=longlocal_v)
plaintext_tip_template = Pickle(validator=longlocal_v)
plaintext_tip_mail_title = Pickle(validator=longlocal_v)
encrypted_tip_template = JSON()
encrypted_tip_mail_title = JSON()
plaintext_tip_template = JSON()
plaintext_tip_mail_title = JSON()

encrypted_file_template = Pickle(validator=longlocal_v)
encrypted_file_mail_title = Pickle(validator=longlocal_v)
plaintext_file_template = Pickle(validator=longlocal_v)
plaintext_file_mail_title = Pickle(validator=longlocal_v)
encrypted_file_template = JSON()
encrypted_file_mail_title = JSON()
plaintext_file_template = JSON()
plaintext_file_mail_title = JSON()

encrypted_comment_template = Pickle(validator=longlocal_v)
encrypted_comment_mail_title = Pickle(validator=longlocal_v)
plaintext_comment_template = Pickle(validator=longlocal_v)
plaintext_comment_mail_title = Pickle(validator=longlocal_v)
encrypted_comment_template = JSON()
encrypted_comment_mail_title = JSON()
plaintext_comment_template = JSON()
plaintext_comment_mail_title = JSON()

encrypted_message_template = Pickle(validator=longlocal_v)
encrypted_message_mail_title = Pickle(validator=longlocal_v)
plaintext_message_template = Pickle(validator=longlocal_v)
plaintext_message_mail_title = Pickle(validator=longlocal_v)
encrypted_message_template = JSON()
encrypted_message_mail_title = JSON()
plaintext_message_template = JSON()
plaintext_message_mail_title = JSON()

pgp_expiration_alert = Pickle(validator=longlocal_v)
pgp_expiration_notice = Pickle(validator=longlocal_v)
pgp_expiration_alert = JSON()
pgp_expiration_notice = JSON()

zip_description = Pickle(validator=longlocal_v)
zip_description = JSON()

unicode_keys = [
'server',
Expand Down Expand Up @@ -585,7 +585,7 @@ class Receiver(Model):
name = Unicode(validator=shorttext_v)

# localization string
description = Pickle(validator=longlocal_v)
description = JSON()

configuration = Unicode()

Expand Down Expand Up @@ -765,8 +765,7 @@ class ApplicationData(Model):
had only one big updated blob.
"""
version = Int()
# XXX why is this a Pickle? ~ A.
fields = Pickle()
fields = JSON()


# Follow classes used for Many to Many references
Expand Down

0 comments on commit b868ef3

Please sign in to comment.