class Step(ModelWithID): questionnaire_id = Unicode() label = JSON() description = JSON() presentation_order = Int(default=0) triggered_by_score = Int(default=0) unicode_keys = ['questionnaire_id'] int_keys = ['presentation_order', 'triggered_by_score'] localized_keys = ['label', 'description']
class ModelWithID(Model): """ Base class for working the database, already integrating an id. """ __storm_table__ = None id = Unicode(primary=True, default_factory=uuid4) @classmethod def get(cls, store, obj_id): return store.find(cls, cls.id == obj_id).one()
class User(Storm): """A user of Fluidinfo. @param username: The username of the user. @param passwordHash: The hashed password of the user. @param fullname: The name of the user. @param email: The email address for the user. @param role: The L{Role} for the user. """ __storm_table__ = 'users' id = Int('id', primary=True, allow_none=False, default=AutoReload) objectID = UUID('object_id', allow_none=False) role = ConstantEnum('role', enum_class=Role, allow_none=False) username = Unicode('username', allow_none=False) passwordHash = RawStr('password_hash', allow_none=False) fullname = Unicode('fullname', allow_none=False) email = Unicode('email', validator=validateEmail) namespaceID = Int('namespace_id') creationTime = DateTime('creation_time', default=AutoReload) namespace = Reference(namespaceID, 'Namespace.id') def __init__(self, username, passwordHash, fullname, email, role): self.objectID = uuid4() self.username = username self.passwordHash = passwordHash self.fullname = fullname self.email = email self.role = role def isAnonymous(self): """Returns C{True} if this user has the anonymous role.""" return self.role == Role.ANONYMOUS def isSuperuser(self): """Returns C{True} if this user has the super user role.""" return self.role == Role.SUPERUSER def isUser(self): """Returns C{True} if this user has the regular user role.""" return self.role == Role.USER
class SharingJob(StormBase): """Base class for jobs related to sharing.""" implements(ISharingJob) __storm_table__ = 'SharingJob' id = Int(primary=True) job_id = Int('job') job = Reference(job_id, Job.id) product_id = Int(name='product') product = Reference(product_id, Product.id) distro_id = Int(name='distro') distro = Reference(distro_id, Distribution.id) grantee_id = Int(name='grantee') grantee = Reference(grantee_id, Person.id) job_type = EnumCol(enum=SharingJobType, notNull=True) _json_data = Unicode('json_data') @property def metadata(self): return simplejson.loads(self._json_data) def __init__(self, job_type, pillar, grantee, metadata): """Constructor. :param job_type: The BranchMergeProposalJobType of this job. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(SharingJob, self).__init__() json_data = simplejson.dumps(metadata) self.job = Job() self.job_type = job_type self.grantee = grantee self.product = self.distro = None if IProduct.providedBy(pillar): self.product = pillar else: self.distro = pillar # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring, # but the DB representation is unicode. self._json_data = json_data.decode('utf-8') def destroySelf(self): Store.of(self).remove(self) def makeDerived(self): return SharingJobDerived.makeSubclass(self)
class StatusLine(object): """A representation of a status line from a log file.""" __storm_table__ = 'status_lines' id = Int(primary=True) time = DateTime(allow_none=False) code = Int(allow_none=False) method = Unicode(allow_none=False) endpoint = Unicode(allow_none=False) contentLength = Int('content_length', allow_none=False) agent = Unicode() def __init__(self, time, code, method, endpoint, contentLength, agent): self.time = time self.code = code self.method = unicode(method) self.endpoint = unicode(endpoint) self.contentLength = contentLength self.agent = unicode(agent)
class InternalTip_v_22(Model): __storm_table__ = 'internaltip' creation_date = DateTime() context_id = Unicode() wb_steps = JSON() preview = JSON() progressive = Int() tor2web = Bool() expiration_date = DateTime() last_activity = DateTime() new = Int()
class InternalFile(ModelWithID): """ This model keeps track of files before they are packaged for specific receivers. """ creation_date = DateTime(default_factory=datetime_now) internaltip_id = Unicode() name = Unicode(validator=longtext_v) file_path = Unicode() content_type = Unicode() size = Int() new = Int(default=True) submission = Int(default=False) processing_attempts = Int(default=0)
class User(Storm): """ I am a website user. I can browse the site, view boards, and potentially modify other User objects. @ivar username: A unique name to identify me @ivar email: The email address tied to me @ivar first_name: My first name @ivar last_name: My surname @ReferenceSet board_perms: A storm ReferenceSet of all my Board permissions """ __storm_table__ = 'users' id = Int(primary=True) username = Unicode(validator=unicoder) email = Unicode(validator=unicoder) first_name = Unicode(validator=unicoder) last_name = Unicode(validator=unicoder) board_perms = ReferenceSet(id, _LinkUserBoardPerms.user_id, _LinkUserBoardPerms.perm_id, BoardPerms.id)
class ReceiverTip(Model): """ This is the table keeping track of ALL the receivers activities and date in a Tip, Tip core data are stored in StoredTip. The data here provide accountability of Receiver accesses, operations, options. """ internaltip_id = Unicode() receiver_id = Unicode() last_access = DateTime(default_factory=datetime_null) access_counter = Int(default=0) label = Unicode(default=u'') can_access_whistleblower_identity = Bool(default=False) new = Int(default=True) unicode_keys = ['label']
class ReceiverTip(Model): """ This is the table keeping track of ALL the receivers activities and date in a Tip, Tip core data are stored in StoredTip. The data here provide accountability of Receiver accesses, operations, options. """ internaltip_id = Unicode() receiver_id = Unicode() # internaltip = Reference(ReceiverTip.internaltip_id, InternalTip.id) # receiver = Reference(ReceiverTip.receiver_id, Receiver.id) last_access = DateTime(default_factory=datetime_null) access_counter = Int(default=0) notification_date = DateTime() label = Unicode(default=u"") new = Int(default=True) unicode_keys = ['label']
class ArchiveAuthToken(Storm): """See `IArchiveAuthToken`.""" __storm_table__ = 'ArchiveAuthToken' id = Int(primary=True) archive_id = Int(name='archive', allow_none=False) archive = Reference(archive_id, 'Archive.id') person_id = Int(name='person', allow_none=True) person = Reference(person_id, 'Person.id') date_created = DateTime(name='date_created', allow_none=False, tzinfo=pytz.UTC) date_deactivated = DateTime(name='date_deactivated', allow_none=True, tzinfo=pytz.UTC) token = Unicode(name='token', allow_none=False) name = Unicode(name='name', allow_none=True) def deactivate(self): """See `IArchiveAuthTokenSet`.""" self.date_deactivated = UTC_NOW @property def archive_url(self): """Return a custom archive url for basic authentication.""" normal_url = URI(self.archive.archive_url) if self.name: name = '+' + self.name else: name = self.person.name auth_url = normal_url.replace(userinfo="%s:%s" % (name, self.token)) return str(auth_url) def asDict(self): return {"token": self.token, "archive_url": self.archive_url}
class SnapBase(Storm): """See `ISnapBase`.""" __storm_table__ = "SnapBase" id = Int(primary=True) date_created = DateTime( name="date_created", tzinfo=pytz.UTC, allow_none=False) registrant_id = Int(name="registrant", allow_none=False) registrant = Reference(registrant_id, "Person.id") name = Unicode(name="name", allow_none=False) display_name = Unicode(name="display_name", allow_none=False) distro_series_id = Int(name="distro_series", allow_none=False) distro_series = Reference(distro_series_id, "DistroSeries.id") build_channels = JSON(name="build_channels", allow_none=False) is_default = Bool(name="is_default", allow_none=False) def __init__(self, registrant, name, display_name, distro_series, build_channels, date_created=DEFAULT): super(SnapBase, self).__init__() self.registrant = registrant self.name = name self.display_name = display_name self.distro_series = distro_series self.build_channels = build_channels self.date_created = date_created self.is_default = False def destroySelf(self): """See `ISnapBase`.""" # Guard against unfortunate accidents. if self.is_default: raise CannotDeleteSnapBase("Cannot delete the default base.") Store.of(self).remove(self)
class DummyModelTwo(Model): """Dummy Model for testing purposes""" __storm_table__ = 'dummy_two' id = Int(primary=True, auto_increment=True, unsigned=True) name = Unicode(size=64, allow_none=False) def __init__(self, name=None): super(DummyModelTwo, self).__init__() if name is not None: self.name = unicode(name)
class PersonTransferJob(StormBase): """Base class for team membership and person merge jobs.""" __storm_table__ = 'PersonTransferJob' id = Int(primary=True) job_id = Int(name='job') job = Reference(job_id, Job.id) major_person_id = Int(name='major_person') major_person = Reference(major_person_id, Person.id) minor_person_id = Int(name='minor_person') minor_person = Reference(minor_person_id, Person.id) job_type = EnumCol(enum=PersonTransferJobType, notNull=True) _json_data = Unicode('json_data') @property def metadata(self): return simplejson.loads(self._json_data) def __init__(self, minor_person, major_person, job_type, metadata, requester=None): """Constructor. :param minor_person: The person or team being added to or removed from the major_person. :param major_person: The person or team that is receiving or losing the minor person. :param job_type: The specific membership action being performed. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(PersonTransferJob, self).__init__() self.job = Job(requester=requester) self.job_type = job_type self.major_person = major_person self.minor_person = minor_person json_data = simplejson.dumps(metadata) # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring, # but the DB representation is unicode. self._json_data = json_data.decode('utf-8') def makeDerived(self): return PersonTransferJobDerived.makeSubclass(self)
class Network(object): __storm_table__ = 'networks' bssid = Unicode(primary=True) essid = Unicode() key = Unicode() on_remote = Bool() def __init__(self, bssid, essid, key=None, on_remote=False): self.bssid = bssid self.essid = essid self.key = key self.on_remote = on_remote def __str__(self): return u'{}::{}::{}'.format(self.bssid, self.essid, self.key) def __eq__(self, n): return self.bssid == n.bssid and self.essid == n.essid and self.key == n.key and self.on_remote == n.on_remote def __ne__(self, n): return not self == n
class Comment(Model): """ This table handle the comment collection, has an InternalTip referenced """ __storm_table__ = 'comment' internaltip_id = Unicode() author = Unicode() content = Unicode(validator=longtext_v) # In case of system_content usage, content has repr() equiv system_content = Pickle() type = Unicode() _types = [u'receiver', u'whistleblower', u'system'] mark = Unicode() _marker = [ u'not notified', u'notified', u'unable to notify', u'disabled', u'skipped' ]
class Notification_v_16(Model): __storm_table__ = 'notification' server = Unicode() port = Int() username = Unicode() password = Unicode() source_name = Unicode() source_email = Unicode() security = Unicode() admin_anomaly_template = JSON() encrypted_tip_template = JSON() encrypted_tip_mail_title = JSON() plaintext_tip_template = JSON() plaintext_tip_mail_title = JSON() encrypted_file_template = JSON() encrypted_file_mail_title = JSON() plaintext_file_template = JSON() plaintext_file_mail_title = JSON() encrypted_comment_template = JSON() encrypted_comment_mail_title = JSON() plaintext_comment_template = JSON() plaintext_comment_mail_title = JSON() encrypted_message_template = JSON() encrypted_message_mail_title = JSON() plaintext_message_template = JSON() plaintext_message_mail_title = JSON() pgp_expiration_alert = JSON() pgp_expiration_notice = JSON() zip_description = JSON() ping_mail_template = JSON() ping_mail_title = JSON() disable_admin_notification_emails = Bool() disable_receivers_notification_emails = Bool()
class Notification_v_14(Model): __storm_table__ = 'notification' server = Unicode() port = Int() username = Unicode() password = Unicode() source_name = Unicode() source_email = Unicode() security = Unicode() encrypted_tip_template = Pickle() encrypted_tip_mail_title = Pickle() plaintext_tip_template = Pickle() plaintext_tip_mail_title = Pickle() encrypted_file_template = Pickle() encrypted_file_mail_title = Pickle() plaintext_file_template = Pickle() plaintext_file_mail_title = Pickle() encrypted_comment_template = Pickle() encrypted_comment_mail_title = Pickle() plaintext_comment_template = Pickle() plaintext_comment_mail_title = Pickle() encrypted_message_template = Pickle() encrypted_message_mail_title = Pickle() plaintext_message_template = Pickle() plaintext_message_mail_title = Pickle() zip_description = Pickle()
class Receiver_version_7(Model): __storm_table__ = 'receiver' user_id = Unicode() name = Unicode() description = Pickle() gpg_key_info = Unicode() gpg_key_fingerprint = Unicode() gpg_key_status = Unicode() gpg_key_armor = Unicode() gpg_enable_notification = Bool() gpg_enable_files = Bool() receiver_level = Int() last_update = DateTime() tags = Pickle() tip_notification = Bool() file_notification = Bool() comment_notification = Bool() # + is added # message_notification = Bool() # this is going to be removed notification_fields = Pickle() # + and substituted without being a dict # mail_address = Unicode() can_delete_submission = Bool()
class InternalTip(ModelWithID): """ This is the internal representation of a Tip that has been submitted to the GlobaLeaks node. It has a not associated map for keep track of Receivers, Tips, Comments and WhistleblowerTip. All of those element has a Storm Reference with the InternalTip.id, never vice-versa """ creation_date = DateTime(default_factory=datetime_now) update_date = DateTime(default_factory=datetime_now) context_id = Unicode() questionnaire_hash = Unicode() preview = JSON() progressive = Int(default=0) tor2web = Bool(default=False) total_score = Int(default=0) expiration_date = DateTime() identity_provided = Bool(default=False) identity_provided_date = DateTime(default_factory=datetime_null) enable_two_way_comments = Bool(default=True) enable_two_way_messages = Bool(default=True) enable_attachments = Bool(default=True) enable_whistleblower_identity = Bool(default=False) wb_last_access = DateTime(default_factory=datetime_now) wb_access_counter = Int(default=0) def wb_revoke_access_date(self): revoke_date = self.wb_last_access + timedelta( days=GLSettings.memory_copy.wbtip_timetolive) return revoke_date def is_wb_access_revoked(self): return self.whistleblowertip is None
class Field_v_20(Model): __storm_table__ = 'field' label = JSON() description = JSON() hint = JSON() multi_entry = Bool() required = Bool() preview = Bool() stats_enabled = Bool() is_template = Bool() x = Int() y = Int() type = Unicode()
class Category(Storm): """ A thread category """ __storm_table__ = "category" id = Int(primary=True) name = Unicode() threads = ReferenceSet(id, Thread.category_id) def __init__(self, name): self.name = unicode(name)
class DummyInvalidModel(Model): """Dummy Model without primary key for testing purposes """ __storm_table__ = 'dummy' id = Int(auto_increment=True, unigned=True) name = Unicode(size=64, allow_none=False) def __init__(self, name=None): super(DummyInvalidModel, self).__init__() if name is not None: self.name = unicode(name)
class Context_v_34(models.ModelWithID): __storm_table__ = 'context' show_small_receiver_cards = Bool(default=False) show_context = Bool(default=True) show_recipients_details = Bool(default=False) allow_recipients_selection = Bool(default=False) maximum_selectable_receivers = Int(default=0) select_all_receivers = Bool(default=True) enable_comments = Bool(default=True) enable_messages = Bool(default=False) enable_two_way_comments = Bool(default=True) enable_two_way_messages = Bool(default=True) enable_attachments = Bool(default=True) tip_timetolive = Int(default=15) name = JSON(validator=shortlocal_v) description = JSON(validator=longlocal_v) recipients_clarification = JSON() status_page_message = JSON() show_receivers_in_alphabetical_order = Bool(default=False) presentation_order = Int(default=0) questionnaire_id = Unicode() img_id = Unicode()
class DBSourceForgeIssueExt(object): """ Maps elements from X{issues_ext_sf} table. @param category: category of the issue @type category: C{str} @param group: group of the issue @type group: C{str} @param issue_id: identifier of the issue @type issue_id: C{int} @ivar __storm_table__: Name of the database table. @type __storm_table__: C{str} @ivar id: Extra issue fields identifier. @type id: L{storm.locals.Int} @ivar category: Category of the issue. @type category: L{storm.locals.Unicode} @ivar group_sf: Group of the issue. @type group_sf: L{storm.locals.Unicode} @ivar issue_id: Issue identifier. @type issue_id: L{storm.locals.Int} @ivar issue: Reference to L{DBIssue} object. @type issue: L{storm.locals.Reference} """ __storm_table__ = 'issues_ext_sf' id = Int(primary=True) category = Unicode() group_sf = Unicode() issue_id = Int() issue = Reference(issue_id, DBIssue.id) #def __init__(self, category, group, issue_id): def __init__(self, issue_id): #self.category = unicode(category) #self.group_sf = unicode(group) self.issue_id = issue_id
class Node(Storm): """A PubSub node.""" __storm_table__ = u'nodes' node = Unicode(primary=True, allow_none=False) config = ReferenceSet(node, 'NodeConfig.node') items = ReferenceSet(node, 'Item.node') subscriptions = ReferenceSet(node, 'Subscription.node') affiliations = ReferenceSet(node, 'Affiliation.node') def __init__(self, node): super(Node, self).__init__() self.node = unicode(node)
class Context(Model): """ This model keeps track of contexts settings. """ show_small_cards = Bool(default=False) show_context = Bool(default=True) show_recipients_details = Bool(default=False) allow_recipients_selection = Bool(default=False) maximum_selectable_receivers = Int(default=0) select_all_receivers = Bool(default=False) enable_comments = Bool(default=True) enable_messages = Bool(default=False) enable_two_way_comments = Bool(default=True) enable_two_way_messages = Bool(default=True) enable_attachments = Bool(default=True) tip_timetolive = Int() # localized strings name = JSON(validator=shortlocal_v) description = JSON(validator=longlocal_v) recipients_clarification = JSON(validator=longlocal_v) status_page_message = JSON(validator=longlocal_v) show_receivers_in_alphabetical_order = Bool(default=False) presentation_order = Int(default=0) questionnaire_id = Unicode() unicode_keys = ['questionnaire_id'] localized_keys = [ 'name', 'description', 'recipients_clarification', 'status_page_message' ] int_keys = [ 'tip_timetolive', 'maximum_selectable_receivers', 'presentation_order', 'steps_navigation_requires_completion' ] bool_keys = [ 'select_all_receivers', 'show_small_cards', 'show_context', 'show_recipients_details', 'show_receivers_in_alphabetical_order', 'allow_recipients_selection', 'enable_comments', 'enable_messages', 'enable_two_way_comments', 'enable_two_way_messages', 'enable_attachments' ]
class DBJiraIssuesLog(DBIssuesLog): """ """ __storm_table__ = 'issues_log_jira' issue_key = Unicode() link = Unicode() environment = Unicode() security = Unicode() updated = DateTime() version = Unicode() component = Unicode() votes = Int() project = Unicode() project_id = Int project_key = Unicode()
class BugTrackerComponent(StormBase): """The software component in the remote bug tracker. Most bug trackers organize bug reports by the software 'component' they affect. This class provides a mapping of this upstream component to the corresponding source package in the distro. """ __storm_table__ = 'BugTrackerComponent' id = Int(primary=True) name = Unicode(allow_none=False) component_group_id = Int('component_group') component_group = Reference( component_group_id, 'BugTrackerComponentGroup.id') is_visible = Bool(allow_none=False) is_custom = Bool(allow_none=False) distribution_id = Int('distribution') distribution = Reference( distribution_id, 'Distribution.id') source_package_name_id = Int('source_package_name') source_package_name = Reference( source_package_name_id, 'SourcePackageName.id') def _get_distro_source_package(self): """Retrieves the corresponding source package""" if self.distribution is None or self.source_package_name is None: return None return self.distribution.getSourcePackage( self.source_package_name) def _set_distro_source_package(self, dsp): """Links this component to its corresponding source package""" if dsp is None: self.distribution = None self.source_package_name = None else: self.distribution = dsp.distribution self.source_package_name = dsp.sourcepackagename distro_source_package = property( _get_distro_source_package, _set_distro_source_package, None, """The distribution's source package for this component""")
class Node_v_18(Model): __storm_table__ = 'node' name = Unicode() public_site = Unicode() hidden_service = Unicode() email = Unicode() receipt_salt = Unicode() last_update = DateTime() receipt_regexp = Unicode() languages_enabled = JSON() default_language = Unicode() default_timezone = Int() description = JSON() presentation = JSON() footer = JSON() security_awareness_title = JSON() security_awareness_text = JSON() stats_update_time = Int() maximum_namesize = Int() maximum_textsize = Int() maximum_filesize = Int() tor2web_admin = Bool() tor2web_submission = Bool() tor2web_receiver = Bool() tor2web_unauth = Bool() allow_unencrypted = Bool() allow_iframes_inclusion = Bool() postpone_superpower = Bool() can_delete_submission = Bool() ahmia = Bool() wizard_done = Bool() disable_privacy_badge = Bool() disable_security_awareness_badge = Bool() disable_security_awareness_questions = Bool() whistleblowing_question = JSON() whistleblowing_button = JSON() enable_custom_privacy_badge = Bool() custom_privacy_badge_tor = JSON() custom_privacy_badge_none = JSON() header_title_homepage = JSON() header_title_submissionpage = JSON() landing_page = Unicode() exception_email = Unicode()