Example #1
0
def test_get_for_linked_object_preload(note, dummy_user, count_queries,
                                       preload):
    note.create_revision(RenderMode.html, 'test', dummy_user)
    assert EventNote.get_for_linked_object(note.object, preload_event=preload)
    with count_queries() as cnt:
        EventNote.get_for_linked_object(note.object)
    assert (cnt() == 0) == preload
Example #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)
Example #3
0
 def _getParams(self):
     super(NoteExportHook, self)._getParams()
     event = self._obj = ConferenceHolder().getById(
         self._pathParams['event_id'], True)
     if event is None:
         raise HTTPAPIError('No such event', 404)
     session_id = self._pathParams.get('session_id')
     if session_id:
         session = self._obj = event.getSessionById(session_id)
         if session is None:
             raise HTTPAPIError("No such session", 404)
     contribution_id = self._pathParams.get('contribution_id')
     if contribution_id:
         contribution = self._obj = event.getContributionById(
             contribution_id)
         if contribution is None:
             raise HTTPAPIError("No such contribution", 404)
     subcontribution_id = self._pathParams.get('subcontribution_id')
     if subcontribution_id:
         subcontribution = self._obj = contribution.getSubContributionById(
             subcontribution_id)
         if subcontribution is None:
             raise HTTPAPIError("No such subcontribution", 404)
     self._note = EventNote.get_for_linked_object(self._obj)
     if self._note is None or self._note.is_deleted:
         raise HTTPAPIError("No such note", 404)
Example #4
0
 def _getParams(self):
     super()._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)
Example #5
0
 def _process(self):
     note = EventNote.get_for_linked_object(self.object, preload_event=False)
     if note is not None:
         note.delete(session.user)
         signals.event.notes.note_deleted.send(note)
         logger.info('Note %s deleted by %s', note, session.user)
         self.event.log(EventLogRealm.participants, EventLogKind.negative, 'Minutes', 'Removed minutes',
                        session.user, data=note.link_event_log_data)
     return redirect(self.event.url)
Example #6
0
 def _process(self):
     note = EventNote.get_for_linked_object(self.object, preload_event=False)
     if note is not None:
         note.delete(session.user)
         signals.event.notes.note_deleted.send(note)
         logger.info('Note {} deleted by {}'.format(note, session.user))
         self.event.log(EventLogRealm.participants, EventLogKind.negative, 'Minutes',
                        'Removed minutes from {} {}'.format(self.object_type, self.object.getTitle()), session.user)
     return redirect(url_for('event.conferenceDisplay', self.event))
Example #7
0
 def _process(self):
     note = EventNote.get_for_linked_object(self.object, preload_event=False)
     if note is not None:
         note.delete(session.user)
         signals.event.notes.note_deleted.send(note)
         logger.info("Note {} deleted by {}".format(note, session.user))
         self.event.log(
             EventLogRealm.participants,
             EventLogKind.negative,
             "Minutes",
             "Removed minutes",
             session.user,
             data=note.link_event_log_data,
         )
     return redirect(url_for("event.conferenceDisplay", self.event))
Example #8
0
 def _getParams(self):
     super(NoteExportHook, self)._getParams()
     event = self._obj = ConferenceHolder().getById(self._pathParams['event_id'], True)
     if event is None:
         raise HTTPAPIError('No such event', 404)
     session_id = self._pathParams.get('session_id')
     if session_id:
         session = self._obj = event.getSessionById(session_id)
         if session is None:
             raise HTTPAPIError("No such session", 404)
     contribution_id = self._pathParams.get('contribution_id')
     if contribution_id:
         contribution = self._obj = session.getContributionById(contribution_id)
         if contribution is None:
             raise HTTPAPIError("No such contribution", 404)
     subcontribution_id = self._pathParams.get('subcontribution_id')
     if subcontribution_id:
         subcontribution = self._obj = contribution.getSubContributionById(subcontribution_id)
         if subcontribution is None:
             raise HTTPAPIError("No such subcontribution", 404)
     self._note = EventNote.get_for_linked_object(self._obj)
     if self._note is None or self._note.is_deleted:
         raise HTTPAPIError("No such note", 404)
Example #9
0
 def _make_form(self, source=None):
     note = None
     if not source:
         note = EventNote.get_for_linked_object(self.object, preload_event=False)
     return NoteForm(obj=self._get_defaults(note=note, source=source))
Example #10
0
 def _process(self):
     note = EventNote.get_for_linked_object(self.object, preload_event=False)
     if not note:
         raise NotFound
     return sanitize_html(note.html)
Example #11
0
def test_get_for_linked_object_deleted(note, dummy_user):
    note.create_revision(RenderMode.html, 'test', dummy_user)
    note.is_deleted = True
    assert EventNote.get_for_linked_object(note.linked_object) is None
Example #12
0
def test_get_for_linked_object_preload(note, dummy_user, mocker, preload):
    note.create_revision(RenderMode.html, 'test', dummy_user)
    assert EventNote.get_for_linked_object(note.linked_object, preload_event=preload)
    query = mocker.patch.object(EventNote, 'query', new=PropertyMock())
    EventNote.get_for_linked_object(note.linked_object)
    assert query.called == (not preload)
Example #13
0
def test_get_for_linked_object(note, dummy_user, create_event):
    note.create_revision(RenderMode.html, 'test', dummy_user)
    assert EventNote.get_for_linked_object(note.linked_object) == note
    assert EventNote.get_for_linked_object(create_event('123')) is None
Example #14
0
def test_get_for_linked_object_deleted(note, dummy_user):
    note.create_revision(RenderMode.html, 'test', dummy_user)
    note.is_deleted = True
    assert EventNote.get_for_linked_object(note.object) is None
Example #15
0
def test_get_for_linked_object(note, dummy_user, create_event):
    note.create_revision(RenderMode.html, 'test', dummy_user)
    assert EventNote.get_for_linked_object(note.object) == note
    assert EventNote.get_for_linked_object(create_event(123)) is None
Example #16
0
def test_get_for_linked_object_preload(note, dummy_user, count_queries, preload):
    note.create_revision(RenderMode.html, 'test', dummy_user)
    assert EventNote.get_for_linked_object(note.object, preload_event=preload)
    with count_queries() as cnt:
        EventNote.get_for_linked_object(note.object)
    assert (cnt() == 0) == preload
Example #17
0
 def has_note(self):
     return EventNote.get_for_linked_object(self, preload_event=self.PRELOAD_EVENT_NOTES) is not None
Example #18
0
 def has_note(self):
     return EventNote.get_for_linked_object(
         self, preload_event=self.PRELOAD_EVENT_NOTES) is not None