Ejemplo n.º 1
0
def update_discussion_core(session,
                           discussion,
                           member,
                           status = None,
                           description = None,
                           attached_elements = None,
                           log = regular_log.default()):
    """
       Updates a discussion. At this point we assume data has been validated so no extra checks are
        done to the input data.
    :param session:
    :param log:
    :param member:
    :param project:
    :param discussion:
    :param content:
    :return:
    """

    if member.id != discussion.member_created_id:
        log['error']['member'] = 'Member cannot update the discussion authored by another member. (Permission denied).'
        return None, log

    discussion = Discussion.update(
        session = session,
        description = description,
        status = status,
        attached_elements = attached_elements,
        discussion_id = discussion.id
    )

    discussion_data = discussion.serialize(session)
    return discussion_data, log
Ejemplo n.º 2
0
    def test_detach_all_instances(self):
        # Create mock discussion
        discussion = data_mocking.create_discussion({
            'title': 'test',
            'description': 'test',
            'member_created_id': self.member.id,
            'project_id': self.project.id
        }, self.session)
        member = self.member

        instance = data_mocking.create_instance({
            'project_id': self.project.id,
            'type': 'box',
            'x_min': 0,
            'x_max': 0,
            'y_min': 0,
            'y_max': 0,
        }, self.session)
        discussion.attach_element(session = self.session, element = {
            'type': 'instance',
            'id': instance.id
        })
        self.session.commit()
        discussion_updated = Discussion.update(
            session = self.session,
            discussion_id = discussion.id,
            attached_elements = []
        )
        attached = discussion_updated.serialize_attached_elements(self.session)
        self.assertEqual(len(attached), 1)