class SubmissionParticipant(db.Model): """ This table stores information about the reviewers and uploaders of a HEPdata submission """ __tablename__ = "submissionparticipant" id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True) publication_recid = db.Column(db.Integer) full_name = db.Column(db.String(128)) email = db.Column(db.String(128)) affiliation = db.Column(db.String(128)) invitation_cookie = db.Column(UUIDType, default=uuid.uuid4) # when the user logs in with their cookie, # this user_account should be updated. user_account = db.Column(db.Integer, db.ForeignKey(User.id)) # e.g., reviewer or uploader role = db.Column(db.String(32), default='') # e.g. primary or reserve reviewer/uploader status = db.Column(db.String(32), default='reserve') action_date = db.Column(db.DateTime, nullable=True, index=True)
class OAIProvider(db.Model): __tablename__ = "oarepo_oai_provider" id = db.Column(db.Integer, primary_key=True) code = db.Column(db.String(16), nullable=False, unique=True) description = db.Column(db.String(2048), nullable=True) oai_endpoint = db.Column(db.String(2048), nullable=False) set_ = db.Column(db.String(256), name="set") metadata_prefix = db.Column(db.String(32), default="oai_dc") constant_fields = db.Column(db.JSON().with_variant( postgresql.JSONB(none_as_null=True), 'postgresql', ).with_variant( JSONType(), 'sqlite', ).with_variant( JSONType(), 'mysql', ), default=lambda: dict(), nullable=True) def get_parsers(self): return registry.parsers.get(self.code) or {} def get_rules(self, parser_name): return registry.rules.get(parser_name)
class ActivityAction(db.Model, TimestampMixin): """Define Activety.""" __tablename__ = 'workflow_activity_action' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Activity_Action identifier.""" activity_id = db.Column(db.String(24), nullable=False, unique=False, index=True) """activity id of Activity Action.""" action_id = db.Column(db.Integer(), db.ForeignKey(Action.id), nullable=True, unique=False) """action id.""" action_status = db.Column(db.String(1), db.ForeignKey(ActionStatus.action_status_id), nullable=False, unique=False) """action status.""" action_comment = db.Column(db.Text, nullable=True) """action comment."""
class GitSnapshot(db.Model): """Snapshot information for a Git repo.""" __tablename__ = 'git_snapshot' id = db.Column(db.Integer, primary_key=True) # webhook payload / event payload = db.Column(json_type, default={}, nullable=True) # git specifics tag = db.Column(db.String(255), nullable=True) ref = db.Column(db.String(255), nullable=True) # foreign keys (connecting to repo and events) webhook_id = db.Column(db.Integer, db.ForeignKey(GitWebhook.id), nullable=False) webhook = db.relationship(GitWebhook, backref=db.backref("snapshots", cascade="all, delete-orphan")) created = db.Column(db.DateTime, server_default=db.func.now()) @staticmethod def create(webhook, data): snapshot = GitSnapshot(payload=data, webhook_id=webhook.id, tag=data['commit'].get('tag'), ref=data['commit']['id']) db.session.add(snapshot) db.session.commit()
class MailConfig(db.Model): """Mail Config.""" id = db.Column(db.Integer, primary_key=True) mail_server = db.Column(db.String(255), default='localhost') mail_port = db.Column(db.Integer, default=25) mail_use_tls = db.Column(db.Boolean(name='use_tls'), default=False) mail_use_ssl = db.Column(db.Boolean(name='use_ssl'), default=False) mail_username = db.Column(db.String(255), default='') mail_password = db.Column(db.String(255), default='') mail_default_sender = db.Column(db.String(255), default='') @classmethod def get_config(cls): """Get mail Config.""" if len(cls.query.all()) < 1: db.session.add(cls()) db.session.commit() cfg = cls.query.get(1).__dict__ cfg.pop('id') cfg.pop('_sa_instance_state') return cfg @classmethod def set_config(cls, new_config): """Set mail Config.""" cfg = cls.query.get(1) cfg.mail_server = new_config['mail_server'] cfg.mail_port = int(new_config['mail_port']) cfg.mail_use_tls = new_config['mail_use_tls'] cfg.mail_use_ssl = new_config['mail_use_ssl'] cfg.mail_username = new_config['mail_username'] cfg.mail_password = new_config['mail_password'] cfg.mail_default_sender = new_config['mail_default_sender'] db.session.commit()
class SiteLicenseIpAddress(db.Model, Timestamp): """Represent a SiteLicenseIpAddress data. The SiteLicenseIpAddress object contains a ``created`` and a ``updated`` properties that are automatically updated. """ __tablename__ = 'sitelicense_ip_address' organization_id = db.Column(db.Integer(), db.ForeignKey(SiteLicenseInfo.organization_id, ondelete='RESTRICT'), primary_key=True) organization_no = db.Column(db.Integer(), primary_key=True, autoincrement=True) start_ip_address = db.Column(db.String(16), nullable=False) finish_ip_address = db.Column(db.String(16), nullable=False) def __iter__(self): """TODO: __iter__.""" for name in dir(SiteLicenseIpAddress): if not name.startswith('__') and not name.startswith('_'): value = getattr(self, name) if isinstance(value, str): yield (name, value)
class Keyword(db.Model): __tablename__ = "keyword" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(128)) value = db.Column(db.String(128))
class Action(db.Model, TimestampMixin): """define Action.""" __tablename__ = 'workflow_action' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Action identifier.""" action_name = db.Column(db.String(255), nullable=True, unique=False, index=False) """the name of action.""" action_desc = db.Column(db.Text, nullable=True) """the description of action.""" action_endpoint = db.Column(db.String(24), nullable=True, index=False) """the endpoint of action""" action_version = db.Column(db.String(64), nullable=True) """the version of action.""" action_makedate = db.Column(db.DateTime, nullable=False, default=datetime.now) """the create date of action.""" action_lastdate = db.Column(db.DateTime, nullable=False, default=datetime.now) """the last update date of action."""
class DataSubmission(db.Model): __tablename__ = "datasubmission" id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True) publication_recid = db.Column(db.Integer) publication_inspire_id = db.Column(db.String(128)) location_in_publication = db.Column(db.String(256)) name = db.Column(db.String(64)) description = db.Column(db.LargeBinary) keywords = db.relationship("Keyword", secondary="keyword_submission", cascade="all,delete") # the main data file, with the data table data_file = db.Column(db.Integer, db.ForeignKey("dataresource.id")) # supplementary files, such as code, links out to other resources etc. resources = db.relationship("DataResource", secondary="datafile_identifier", cascade="all,delete") doi = db.Column(db.String(128), nullable=True) # the record ID for the resulting record created on finalisation. associated_recid = db.Column(db.Integer) # when a new version is loaded, the version is increased and # maintained so people can go back in time # through a submissions review stages. version = db.Column(db.Integer, default=0)
class GitRepository(db.Model): """Information about a GitHub repository.""" id = db.Column(db.Integer, primary_key=True) external_id = db.Column(db.Integer, unique=False, nullable=False) host = db.Column(db.String(255), nullable=False) owner = db.Column(db.String(255), nullable=False) name = db.Column(db.String(255), nullable=False) __tablename__ = 'git_repository' __table_args__ = db.UniqueConstraint( 'host', 'owner', 'name', name='uq_git_repository_unique_constraint'), @classmethod def create_or_get(cls, external_id, host, owner, name): """.""" try: repo = cls.query.filter_by(host=host, owner=owner, name=name).one() except NoResultFound: repo = cls(external_id=external_id, host=host, owner=owner, name=name) db.session.add(repo) return repo
class OAIHarvestConfig(db.Model): """Represents a OAIHarvestConfig record.""" __tablename__ = 'oaiharvester_configs' id = db.Column(db.Integer, primary_key=True) baseurl = db.Column(db.String(255), nullable=False, server_default='') metadataprefix = db.Column(db.String(255), nullable=False, server_default='oai_dc') comment = db.Column(db.Text, nullable=True) name = db.Column(db.String(255), nullable=False) lastrun = db.Column(db.DateTime, default=datetime.datetime(year=1900, month=1, day=1), nullable=True) setspecs = db.Column(db.Text, nullable=False) def save(self): """Save object to persistent storage.""" with db.session.begin_nested(): db.session.merge(self) def update_lastrun(self, new_date=None): """Update the 'lastrun' attribute of object to now.""" self.lastrun = new_date or datetime.datetime.now()
class DataResource(db.Model): """ Details of a data resource, which could be a data table, an image, a script, a ROOT file, or a link to an external website or GitHub repo. Data resources can be related to submissions in various ways: - Resources relating to a submission (HEPSubmission.resources) are linked via the `data_resource_link` table - Data files belonging to a data table (`DataSubmission.data_file`) are linked via the `data_file` field of `datasubmission` - Resources relating to a data table (`DataSubmission.resources`) are linked via the `datafile_identifier` table """ __tablename__ = "dataresource" id = db.Column(db.Integer, primary_key=True, autoincrement=True) file_location = db.Column(db.String(256)) file_type = db.Column(db.String(64), default="json") file_description = db.Column(LargeBinaryString) file_license = db.Column(db.Integer, db.ForeignKey("hepdata_license.id"), nullable=True) created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, index=True)
class ApiHarvestConfig(RecordIdentifier): """Sequence generator for Document identifiers.""" __tablename__ = 'apiharvester_config' __mapper_args__ = {'concrete': True} id = db.Column(db.Integer, primary_key=True) url = db.Column(db.String(255), nullable=False, server_default='') name = db.Column(db.String(255), nullable=False) mimetype = db.Column(db.String(255), nullable=False) size = db.Column(db.Integer, nullable=False) comment = db.Column(db.Text, nullable=True) default_last_run = datetime.strptime('1900-1-1', '%Y-%m-%d') lastrun = db.Column(db.DateTime, default=pytz.utc.localize(default_last_run), nullable=True) def save(self): """Save object to persistent storage.""" with db.session.begin_nested(): db.session.merge(self) def update_lastrun(self, new_date=None): """Update the 'lastrun' attribute of object to now.""" self.lastrun = new_date or datetime.now(timezone.utc)
class ApiHarvestConfig(RecordIdentifier): """Sequence generator for Document identifiers.""" __tablename__ = 'apiharvest_config' __mapper_args__ = {'concrete': True} id = db.Column(db.Integer, primary_key=True) url = db.Column(db.String(255), nullable=False, server_default='') name = db.Column(db.String(255), nullable=False) classname = db.Column(db.String(255), nullable=False) code = db.Column(db.Text, nullable=True) lastrun = db.Column(db.DateTime, default=datetime.datetime(year=1900, month=1, day=1), nullable=True) def save(self): """Save object to persistent storage.""" with db.session.begin_nested(): db.session.merge(self) def update_lastrun(self, new_date=None): """Update the 'lastrun' attribute of object to now.""" self.lastrun = new_date or datetime.datetime.now() self.save() db.session.commit()
class UserIdentity(db.Model, Timestamp): """Represent a UserIdentity record.""" __tablename__ = "accounts_useridentity" id = db.Column(db.String(255), primary_key=True, nullable=False) method = db.Column(db.String(255), primary_key=True, nullable=False) id_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=False) user = db.relationship(User, backref="external_identifiers") __table_args__ = (db.Index("accounts_useridentity_id_user_method", id_user, method, unique=True), ) @classmethod def get_user(cls, method, external_id): """Get the user for a given identity.""" identity = cls.query.filter_by(id=external_id, method=method).one_or_none() if identity is not None: return identity.user return None @classmethod def create(cls, user, method, external_id): """Link a user to an external id. :param user: A :class:`invenio_accounts.models.User` instance. :param method: The identity source (e.g. orcid, github) :param method: The external identifier. :raises AlreadyLinkedError: Raised if already exists a link. """ try: with db.session.begin_nested(): db.session.add( cls(id=external_id, method=method, id_user=user.id)) except IntegrityError: raise AlreadyLinkedError( # dict used for backward compatibility (came from oauthclient) user, { "id": external_id, "method": method }, ) @classmethod def delete_by_external_id(cls, method, external_id): """Unlink a user from an external id.""" with db.session.begin_nested(): cls.query.filter_by(id=external_id, method=method).delete() @classmethod def delete_by_user(cls, method, user): """Unlink a user from an external id.""" with db.session.begin_nested(): cls.query.filter_by(id_user=user.id, method=method).delete()
class License(db.Model): __tablename__ = "hepdata_license" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(256)) url = db.Column(db.String(256)) description = db.Column(LargeBinaryString)
class TemplateDefinition(db.Model, object): """Representation of a template definition.""" __tablename__ = 'sequencegenerator_template' COUNTER_REGEX = re.compile(r'({counter(!.)?(:.*)?})') """Regular expression matching the counter inside the template string.""" name = db.Column(db.String(255), primary_key=True) """The identifier of the template definition.""" meta_template = db.Column(db.String(255), unique=True) """The template generator.""" parent_name = db.Column( db.ForeignKey(name, name='fk_seqgen_template_parent_name_seqgen_template')) """Indicate that the template depends on another one.""" start = db.Column(db.Integer, default=0) """The starting counter of sequences generated from ``meta_template``.""" step = db.Column(db.Integer, default=1) """The incremental step of sequences generated from ``meta_template``.""" children = db.relationship('TemplateDefinition', backref=db.backref('parent', remote_side=name)) @validates('meta_template') def validate_meta_template(self, key, value): """Validate template string of template definition.""" if not self.COUNTER_REGEX.search(value): raise InvalidTemplate('No counter placeholder') return value def counter(self, **kwargs): """Get counter of this template definition, based on given kwargs.""" meta_template = double_counter(self.meta_template, self.COUNTER_REGEX) counter = Counter.get(meta_template, kwargs) if counter is None: with db.session.begin_nested(): counter = Counter.create( meta_template=meta_template, ctx=kwargs, counter=self.start, template_definition=self, ) db.session.add(counter) return counter def __repr__(self): """Canonical representation of ``TemplateDefinition``.""" return ('TemplateDefinition(' 'name={0.name!r}, ' 'meta_template={0.meta_template!r}, ' 'start={0.start!r}, ' 'step={0.step!r})').format(self)
class Location(db.Model, Timestamp): """Model defining base locations.""" __tablename__ = 'files_location' id = db.Column(db.Integer, primary_key=True) """Internal identifier for locations. The internal identifier is used only used as foreign key for buckets in order to decrease storage requirements per row for buckets. """ name = db.Column(db.String(20), unique=True, nullable=False) """External identifier of the location.""" uri = db.Column(db.String(255), nullable=False) """URI of the location.""" default = db.Column(db.Boolean(name='default'), nullable=False, default=False) """True if the location is the default location. At least one location should be the default location. """ @validates('name') def validate_name(self, key, name): """Validate name.""" if not slug_pattern.match(name) or len(name) > 20: raise ValueError( 'Invalid location name (lower-case alphanumeric + danshes).') return name @classmethod def get_by_name(cls, name): """Fetch a specific location object.""" return cls.query.filter_by( name=name, ).one() @classmethod def get_default(cls): """Fetch the default location object.""" try: return cls.query.filter_by(default=True).one_or_none() except MultipleResultsFound: return None @classmethod def all(cls): """Return query that fetches all locations.""" return Location.query.all() def __repr__(self): """Return representation of location.""" return self.name
class Role(db.Model, RoleMixin): """Role data model.""" __tablename__ = "accounts_role" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255))
class FlowDefine(db.Model, TimestampMixin): """Define Flow.""" __tablename__ = 'workflow_flow_define' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Flow identifier.""" flow_id = db.Column(UUIDType, nullable=False, unique=True, index=True, default=uuid.uuid4()) """the id of flow.""" flow_name = db.Column(db.String(255), nullable=True, unique=True, index=True) """the name of flow.""" flow_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=True, unique=False) """the user who update the flow.""" user_profile = db.relationship(User) """User relationship""" FLOWSTATUSPOLICY = [ (FlowStatusPolicy.AVAILABLE, FlowStatusPolicy.describe(FlowStatusPolicy.AVAILABLE)), (FlowStatusPolicy.INUSE, FlowStatusPolicy.describe(FlowStatusPolicy.INUSE)), (FlowStatusPolicy.MAKING, FlowStatusPolicy.describe(FlowStatusPolicy.MAKING)), ] """Subscription policy choices.""" flow_status = db.Column(ChoiceType(FLOWSTATUSPOLICY, impl=db.String(1)), nullable=False, default=FlowStatusPolicy.MAKING, info=dict( label=_('Subscription Policy'), widget=RadioGroupWidget( FlowStatusPolicy.descriptions), )) """the status of flow.""" flow_actions = db.relationship('FlowAction', backref=db.backref('flow')) """flow action relationship."""
class FlowAction(db.Model, TimestampMixin): """Action list belong to Flow.""" __tablename__ = 'workflow_flow_action' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """FlowAction identifier.""" flow_id = db.Column(UUIDType, db.ForeignKey(FlowDefine.flow_id), nullable=False, unique=False, index=True) """the id of flow.""" action_id = db.Column(db.Integer(), db.ForeignKey(Action.id), nullable=False, unique=False) """the id of action.""" action_version = db.Column(db.String(64), nullable=True) """the version of used action.""" action_order = db.Column(db.Integer(), nullable=False, unique=False) """the order of action.""" action_condition = db.Column(db.String(255), nullable=True, unique=False) """the condition of transition.""" TATUSPOLICY = [ (AvailableStautsPolicy.USABLE, AvailableStautsPolicy.describe(AvailableStautsPolicy.USABLE)), (AvailableStautsPolicy.UNUSABLE, AvailableStautsPolicy.describe(AvailableStautsPolicy.UNUSABLE)), ] """Subscription policy choices.""" action_status = db.Column(ChoiceType(TATUSPOLICY, impl=db.String(1)), nullable=False, default=AvailableStautsPolicy.USABLE) """the status of flow action.""" action_date = db.Column(db.DateTime, nullable=False, default=datetime.now) """the use date of action.""" action = db.relationship(Action, backref=db.backref('flow_action')) """flow action relationship.""" action_roles = db.relationship('FlowActionRole', backref=db.backref('flow_action')) """flow action relationship."""
class ActionStatus(db.Model, TimestampMixin): """define ActionStatus.""" __tablename__ = 'workflow_action_status' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """ActionStatus identifier.""" ACTIONSTATUSPOLICY = [ (ActionStatusPolicy.ACTION_BEGIN, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_BEGIN)), (ActionStatusPolicy.ACTION_DONE, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_DONE)), (ActionStatusPolicy.ACTION_DOING, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_DOING)), (ActionStatusPolicy.ACTION_THROWN_OUT, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_THROWN_OUT)), (ActionStatusPolicy.ACTION_NOT_DONE, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_NOT_DONE)), (ActionStatusPolicy.ACTION_RETRY, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_RETRY)), (ActionStatusPolicy.ACTION_SKIPPED, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_SKIPPED)), (ActionStatusPolicy.ACTION_ERROR, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_ERROR)), (ActionStatusPolicy.ACTION_CANCELED, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_CANCELED)), ] """Subscription policy choices.""" action_status_id = db.Column(ChoiceType(ACTIONSTATUSPOLICY, impl=db.String(1)), default=ActionStatusPolicy.ACTION_BEGIN, nullable=False, unique=True, index=True) """the id of action status.""" action_status_name = db.Column(db.String(32), nullable=True, unique=False, index=False) """the name of action.""" action_status_desc = db.Column(db.Text, nullable=True) """the description of action.""" action_scopes = db.Column(db.String(64), nullable=True) """the scopes of action status(sys,user).""" action_displays = db.Column(db.Text, nullable=True, unique=False) """the display info of action status."""
class Page(db.Model, Timestamp): """Represents a page.""" __versioned__ = {} __tablename__ = 'pages_page' id = db.Column(db.Integer, nullable=False, primary_key=True, autoincrement=True) """Page identifier.""" url = db.Column(db.String(100), unique=True, nullable=False) """Page url.""" title = db.Column(db.String(200), nullable=False, default='') """Page title.""" content = db.Column(db.Text(), nullable=False, default='') """Page content. Default is pages/templates/default.html""" description = db.Column(db.String(200), nullable=False, default='') """Page description.""" template_name = db.Column(db.String(70), nullable=False) """Page template name.""" @classmethod def get_by_url(self, url): """Get a page by URL. :param url: The page URL. :returns: A :class:`invenio_pages.models.Page` instance. """ return Page.query.filter_by(url=url).one() @validates('template_name') def validate_template_name(self, key, value): """Validate template name. :param key: The template path. :param value: The template name. :raises ValueError: If template name is wrong. """ if value not in dict(current_app.config['PAGES_TEMPLATES']): raise ValueError('Template "{0}" does not exist.'.format(value)) return value def __repr__(self): """Page representation. Used on Page admin view in inline model. :returns: unambiguous page representation. """ return "URL: %s, title: %s" % (self.url, self.title)
class OAISet(db.Model, Timestamp): """Information about OAI set.""" __tablename__ = "oaiserver_set" id = db.Column(db.Integer, primary_key=True) spec = db.Column( db.String(255), nullable=False, unique=True, info=dict( label=_("Identifier"), description=_("Identifier of the set."), ), ) """Set identifier.""" name = db.Column( db.String(255), info=dict( label=_("Long name"), description=_("Long name of the set."), ), index=True, ) """Human readable name of the set.""" description = db.Column( db.Text, nullable=True, info=dict( label=_("Description"), description=_("Description of the set."), ), ) """Human readable description.""" search_pattern = db.Column( db.Text, nullable=True, info=dict( label=_("Search pattern"), description=_("Search pattern to select records"), ), ) """Search pattern to get records.""" @validates("spec") def validate_spec(self, key, value): """Forbit updates of set identifier.""" if self.spec and self.spec != value: raise OAISetSpecUpdateError("Updating spec is not allowed.") return value
class Announcement(db.Model, Timestamp): """Defines a message to show to users.""" __tablename__ = 'announcements' id = db.Column(db.Integer, primary_key=True) message = db.Column(db.Text, nullable=False) """The message content.""" path = db.Column(db.String(100), nullable=True) """Define in which /path the message will be visible.""" style = db.Column(db.String(20), nullable=False) """Style of the message, for distinguishing warning or info messages.""" start_date = db.Column(db.DateTime, nullable=False, default=datetime.now()) """Start date and time, can be immediate or delayed.""" end_date = db.Column(db.DateTime, nullable=True) """End date and time, must be after `start` or forever.""" active = db.Column(db.Boolean('active'), nullable=False, default=True) """Defines if the message is active, only one at the same time.""" @classmethod def get_for(cls, current_path): """Return the active message for the given /path or None.""" now = datetime.now() date_match = and_( Announcement.start_date < now, or_(Announcement.end_date.is_(None), now < Announcement.end_date)) match = and_(Announcement.active, date_match) for ann in Announcement.query.filter(match).all(): if ann.path is None or current_path.startswith(ann.path): return ann return None @staticmethod def disable_expired(): """Disable any old message to keep everything clean.""" olds = Announcement.query. \ filter(and_(Announcement.end_date.isnot(None), Announcement.end_date < datetime.now())). \ all() for old in olds: old.active = False db.session.commit()
class User(db.Model, UserMixin): """User data model.""" __tablename__ = "accounts_user" id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) """User email.""" password = db.Column(db.String(255)) """User password.""" active = db.Column(db.Boolean(name='active')) """Flag to say if the user is active or not .""" confirmed_at = db.Column(db.DateTime) """When the user confirmed the email address.""" last_login_at = db.Column(db.DateTime) """When the user logged-in for the last time.""" current_login_at = db.Column(db.DateTime) """When user logged into the current session.""" last_login_ip = db.Column(IPAddressType, nullable=True) """Last user IP address.""" current_login_ip = db.Column(IPAddressType, nullable=True) """Current user IP address.""" login_count = db.Column(db.Integer) """Count how many times the user logged in.""" roles = db.relationship('Role', secondary=userrole, backref=db.backref('users', lazy='dynamic')) """List of the user's roles.""" @validates('last_login_ip', 'current_login_ip') def validate_ip(self, key, value): """Hack untrackable IP addresses.""" # NOTE Flask-Security stores 'untrackable' value to IPAddressType # field. This incorrect value causes ValueError on loading # user object. if value == 'untrackable': # pragma: no cover value = None return value def __str__(self): """Representation.""" return 'User <id={0.id}, email={0.email}>'.format(self)
class GitRepositorySnapshots(db.Model): """Snapshot information for a Git repo.""" __tablename__ = 'git_repository_snapshots' id = db.Column(db.Integer, primary_key=True) # webhook payload / event event_payload = db.Column(json_type, default={}, nullable=True) event_type = db.Column(db.String(255), nullable=False) # git specifics tag = db.Column(db.String(255), nullable=True) ref = db.Column(db.String(255), nullable=True) # foreign keys (connecting to repo and events) repo_id = db.Column(db.Integer, db.ForeignKey(GitRepository.id)) repo = db.relationship(GitRepository) @staticmethod def create(event, data, repo, ref=None): snapshot = GitRepositorySnapshots(event_type=event, event_payload=data, tag=data['commit'].get('tag'), ref=ref, repo=repo) db.session.add(snapshot) db.session.commit() @property def download_url(self): if 'github' in self.repo.host: return 'https://codeload.github.com/{self.repo.owner}/' \ '{self.repo.name}/legacy.tar.gz/{self.ref}'\ .format(self=self) else: token = get_access_token('GITLAB') return 'https://gitlab.cern.ch/api/v4/projects/' \ '{self.repo.git_repo_id}/repository/archive?' \ 'sha={self.ref}&private_token={token}' \ .format(self=self, token=token) def __repr__(self): """Get repository representation.""" return """ <Repository {self.repo.name}: {self.repo.git_repo_id} event:\t{self.event_type} tags:\t{self.tag} url:\t{self.url} """.format(self=self)
class Identifier(db.Model): """ Represent an Identifier. The Identifier object contains a ``created``, a ``updated`` properties that are automatically updated. """ __tablename__ = 'doi_identifier' id = db.Column(db.BigInteger, primary_key=True, unique=True) """ Identifier of the index """ repository = db.Column(db.String(100), nullable=False) """ Repository of the community """ jalc_flag = db.Column(db.Boolean(name='jalc_flag'), default=True) """ Jalc_flag of the Identifier """ jalc_crossref_flag = db.Column(db.Boolean(name='jalc_crossref_flag'), default=True) """ Jalc_crossref_flag of the Identifier """ jalc_datacite_flag = db.Column(db.Boolean(name='jalc_datacite_flag'), default=True) """ Jalc_datacite_flag of the Identifier """ ndl_jalc_flag = db.Column(db.Boolean(name='ndl_jalc_flag'), default=True) """ Ndl_jalc_flag of the Identifier """ jalc_doi = db.Column(db.String(100), nullable=True) """ Jalc_doi of the Identifier """ jalc_crossref_doi = db.Column(db.String(100), nullable=True) """ Jalc_crossref_doi of the Identifier """ jalc_datacite_doi = db.Column(db.String(100), nullable=True) """ Jalc_datacite_doi of the Identifier """ ndl_jalc_doi = db.Column(db.String(100), nullable=True) """ Ndl_jalc_doi of the Identifier """ suffix = db.Column(db.String(100), nullable=True) """ Suffix of the Identifier """ created_userId = db.Column(db.String(50), nullable=False) """ Created by user """ created_date = db.Column(db.DateTime, nullable=False) """ Created date """ updated_userId = db.Column(db.String(50), nullable=False) """ Updated by user """ updated_date = db.Column(db.DateTime, nullable=True) """ Created date """ def __repr__(self): """String representation of the Pidstore Identifier object.""" return '<Identifier {}, Repository: {}>'.format( self.id, self.repository)
class UserIdentity(db.Model, Timestamp): """Represent a UserIdentity record.""" __tablename__ = "accounts_useridentity" id = db.Column(db.String(255), primary_key=True, nullable=False) method = db.Column(db.String(255), primary_key=True, nullable=False) id_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=False) user = db.relationship(User, backref="external_identifiers") __table_args__ = ( db.Index("useridentity_id_user_method", id_user, method, unique=True), )
class CrawlerJob(db.Model): """Keeps track of submitted crawler jobs.""" __tablename__ = 'crawler_job' id = db.Column(db.Integer, primary_key=True, autoincrement=True) job_id = db.Column(UUIDType, index=True) spider = db.Column(db.String(255), index=True) workflow = db.Column(db.String(255), index=True) results = db.Column(db.Text, nullable=True) status = db.Column(ChoiceType(JobStatus, impl=db.String(10)), nullable=False) logs = db.Column(db.Text, nullable=True) scheduled = db.Column(db.DateTime, default=datetime.now, nullable=False, index=True) @classmethod def create(cls, job_id, spider, workflow, results=None, logs=None, status=JobStatus.PENDING): """Create a new entry for a scheduled crawler job.""" obj = cls( job_id=job_id, spider=spider, workflow=workflow, results=results, logs=logs, status=status, ) db.session.add(obj) return obj @classmethod def get_by_job(cls, job_id): """Get a row by Job UUID.""" try: return cls.query.filter_by(job_id=job_id).one() except NoResultFound: raise CrawlerJobNotExistError(job_id) def save(self): """Save object to persistent storage.""" with db.session.begin_nested(): db.session.add(self)