Esempio n. 1
0
def event_or_shorturl(confId, shorturl_namespace=False, force_overview=False):
    func = None
    event_ = Event.get(int(confId)) if confId.isdigit() else None
    if event_ and event_.is_deleted:
        raise NotFound(_('This event has been deleted.'))
    elif event_:
        # For obvious reasons an event id always comes first.
        # If it's used within the short url namespace we redirect to the event namespace, otherwise
        # we call the RH to display the event
        if shorturl_namespace:
            func = lambda: redirect(event_.url)
        else:
            request.view_args['confId'] = int(request.view_args['confId'])
            func = lambda: RHDisplayEvent().process()
    else:
        shorturl_event = (Event.query.filter(
            db.func.lower(Event.url_shortcut) == confId.lower(),
            ~Event.is_deleted).one_or_none())
        if (shorturl_namespace or config.ROUTE_OLD_URLS) and shorturl_event:
            if shorturl_namespace:
                # Correct namespace => redirect to the event
                func = lambda: redirect(shorturl_event.url)
            else:
                # Old event namespace => 301-redirect to the new shorturl first to get Google etc. to update it
                func = lambda: redirect(shorturl_event.short_url, 301)
        elif is_legacy_id(confId):
            mapping = LegacyEventMapping.find_first(legacy_event_id=confId)
            if mapping is not None:
                url = url_for('events.display', confId=mapping.event_id)
                func = lambda: redirect(url, 301)

    if func is None:
        raise NotFound(_('An event with this ID/shortcut does not exist.'))
    return func()
Esempio n. 2
0
 def _getParams(self):
     super(NoteExportHook, self)._getParams()
     event = self._obj = Event.get(self._pathParams['event_id'],
                                   is_deleted=False)
     if event is None:
         raise HTTPAPIError('No such event', 404)
     session_id = self._pathParams.get('session_id')
     if session_id:
         self._obj = Session.query.with_parent(event).filter_by(
             id=session_id).first()
         if self._obj is None:
             raise HTTPAPIError("No such session", 404)
     contribution_id = self._pathParams.get('contribution_id')
     if contribution_id:
         contribution = self._obj = (
             Contribution.query.with_parent(event).filter_by(
                 id=contribution_id, is_deleted=False).first())
         if contribution is None:
             raise HTTPAPIError("No such contribution", 404)
         subcontribution_id = self._pathParams.get('subcontribution_id')
         if subcontribution_id:
             self._obj = SubContribution.query.with_parent(
                 contribution).filter_by(id=subcontribution_id,
                                         is_deleted=False).first()
             if self._obj is None:
                 raise HTTPAPIError("No such subcontribution", 404)
     self._note = EventNote.get_for_linked_object(self._obj,
                                                  preload_event=False)
     if self._note is None or self._note.is_deleted:
         raise HTTPAPIError("No such note", 404)
Esempio n. 3
0
 def deserialize(self):
     if not self.force and self.data['fossir_version'] != fossir.__version__:
         click.secho(
             'Version mismatch: trying to import event exported with {} to version {}'
             .format(self.data['fossir_version'], fossir.__version__),
             fg='red')
         return None
     self._load_users(self.data)
     for tablename, tabledata in self.data['objects']:
         self._deserialize_object(db.metadata.tables[tablename], tabledata)
     if self.deferred_idrefs:
         # Any reference to an ID that was exported need to be replaced
         # with an actual ID at some point - either immediately (if the
         # referenced row was already imported) or later (usually in case
         # of circular dependencies where one of the IDs is not available
         # when the row is inserted).
         click.secho('BUG: Not all deferred idrefs have been consumed',
                     fg='red')
         for uuid, values in self.deferred_idrefs.iteritems():
             click.secho('{}:'.format(uuid), fg='yellow', bold=True)
             for table, col, pk_value in values:
                 click.secho('  - {}.{} ({})'.format(
                     table.fullname, col, pk_value),
                             fg='yellow')
         raise Exception('Not all deferred idrefs have been consumed')
     event = Event.get(self.event_id)
     event.log(EventLogRealm.event, EventLogKind.other, 'Event',
               'Event imported from another fossir instance')
     self._associate_users_by_email(event)
     db.session.flush()
     return event
Esempio n. 4
0
 def _getParams(self):
     super(AgreementExportHook, self)._getParams()
     type_ = self._pathParams['agreement_type']
     try:
         self._definition = get_agreement_definitions()[type_]
     except KeyError:
         raise HTTPAPIError('No such agreement type', 404)
     self.event = Event.get(self._pathParams['event_id'], is_deleted=False)
     if self.event is None:
         raise HTTPAPIError('No such event', 404)
Esempio n. 5
0
 def validate_entries(self, field):
     if field.errors:
         return
     for entry in field.data:
         if entry['days'] < 0:
             raise ValidationError(_("'Days' must be a positive integer"))
         if entry['type'] not in {'category', 'event'}:
             raise ValidationError(_('Invalid type'))
         if entry['type'] == 'category' and not Category.get(entry['id'], is_deleted=False):
             raise ValidationError(_('Invalid category: {}').format(entry['id']))
         if entry['type'] == 'event' and not Event.get(entry['id'], is_deleted=False):
             raise ValidationError(_('Invalid event: {}').format(entry['id']))
Esempio n. 6
0
def restore(event_id):
    """Restores a deleted event."""
    event = Event.get(event_id)
    if event is None:
        click.secho('This event does not exist', fg='red')
        sys.exit(1)
    elif not event.is_deleted:
        click.secho('This event is not deleted', fg='yellow')
        sys.exit(1)
    event.is_deleted = False
    db.session.commit()
    click.secho('Event undeleted: "{}"'.format(event.title), fg='green')
Esempio n. 7
0
 def session(self, idlist):
     event = Event.get(self._eventId, is_deleted=False)
     if not event:
         return []
     idlist = set(map(int, idlist))
     sessions = (Session.query.with_parent(event).filter(
         Session.id.in_(idlist), ~Session.is_deleted).all())
     # Fallback for friendly_id
     sessions += (Session.query.with_parent(event).filter(
         Session.friendly_id.in_(idlist - {s.id
                                           for s in sessions}),
         ~Session.is_deleted).all())
     self._detail_level = 'contributions'
     return self._build_sessions_api_data(sessions)
Esempio n. 8
0
def is_feature_enabled(event, name):
    """Checks if a feature is enabled for an event.

    :param event: The event (or event ID) to check.
    :param name: The name of the feature.
    """
    feature = get_feature_definition(name)
    enabled_features = features_event_settings.get(event, 'enabled')
    if enabled_features is not None:
        return feature.name in enabled_features
    else:
        if isinstance(event, (basestring, int, long)):
            event = Event.get(event)
        return event and feature.is_default_for_event(event)
Esempio n. 9
0
def export(event_id, target_file):
    """Exports all data associated with an event.

    This exports the whole event as an archive which can be imported
    on another other fossir instance.  Importing an event is only
    guaranteed to work if it was exported on the same fossir version.
    """
    event = Event.get(event_id)
    if event is None:
        click.secho('This event does not exist', fg='red')
        sys.exit(1)
    elif event.is_deleted:
        click.secho('This event has been deleted', fg='yellow')
        click.confirm('Export it anyway?', abort=True)
    export_event(event, target_file)
Esempio n. 10
0
def test_deleted_relationships(db, dummy_event):
    event = dummy_event
    assert not event.contributions
    assert not event.sessions
    s = Session(event=event, title='s')
    sd = Session(event=event, title='sd', is_deleted=True)
    c = Contribution(event=event,
                     title='c',
                     session=sd,
                     duration=timedelta(minutes=30))
    cd = Contribution(event=event,
                      title='cd',
                      session=sd,
                      duration=timedelta(minutes=30),
                      is_deleted=True)
    sc = SubContribution(contribution=c,
                         title='sc',
                         duration=timedelta(minutes=10))
    scd = SubContribution(contribution=c,
                          title='scd',
                          duration=timedelta(minutes=10),
                          is_deleted=True)
    db.session.flush()
    db.session.expire_all()
    # reload all the objects from the db
    event = Event.get(event.id)
    s = Session.get(s.id)
    sd = Session.get(sd.id)
    c = Contribution.get(c.id)
    cd = Contribution.get(cd.id)
    sc = SubContribution.get(sc.id)
    scd = SubContribution.get(scd.id)
    # deleted items should not be in the lists
    assert event.sessions == [s]
    assert event.contributions == [c]
    assert sd.contributions == [c]
    assert c.subcontributions == [sc]
    # the other direction should work fine even in case of deletion
    assert s.event == event
    assert sd.event == event
    assert c.event == event
    assert cd.event == event
    assert sc.contribution == c
    assert scd.contribution == c
Esempio n. 11
0
 def _getParams(self):
     super(AttachmentsExportHook, self)._getParams()
     event = self._obj = Event.get(self._pathParams['event_id'],
                                   is_deleted=False)
     if event is None:
         raise HTTPAPIError('No such event', 404)
     session_id = self._pathParams.get('session_id')
     if session_id:
         self._obj = Session.query.with_parent(event).filter_by(
             id=session_id).first()
         if self._obj is None:
             raise HTTPAPIError("No such session", 404)
     contribution_id = self._pathParams.get('contribution_id')
     if contribution_id:
         contribution = self._obj = Contribution.query.with_parent(
             event).filter_by(id=contribution_id).first()
         if contribution is None:
             raise HTTPAPIError("No such contribution", 404)
         subcontribution_id = self._pathParams.get('subcontribution_id')
         if subcontribution_id:
             self._obj = SubContribution.query.with_parent(
                 contribution).filter_by(id=subcontribution_id).first()
             if self._obj is None:
                 raise HTTPAPIError("No such subcontribution", 404)
Esempio n. 12
0
 def _process_args(self):
     self.event = Event.get(int(request.view_args['confId']))
     if self.event is None:
         raise NotFound(_('An event with this ID does not exist.'))
     elif self.event.is_deleted:
         raise NotFound(_('This event has been deleted.'))