Example #1
0
def update_discussion_web(project_string_id, discussion_id):
    """
        Update a discussion description, status or attached elements.
    :param project_string_id:
    :param discussion_id:
    :return:
    """

    # For now, no filters needed. But might add in the future.
    issue_new_spec_list = [
        {"description": {
            'kind': str,
            'required': False
        }},
        {"status": {
            'kind': str,
            'required': False
        }},
        {"attached_elements": {
            'kind': list,
            'allow_empty': True
        }},
    ]

    log, input, untrusted_input = regular_input.master(
        request = request,
        spec_list = issue_new_spec_list)

    if len(log["error"].keys()) >= 1:
        return jsonify(log = log), 400

    with sessionMaker.session_scope() as session:

        project = Project.get_by_string_id(session, project_string_id)
        user = User.get(session)
        discussion = Discussion.get_by_id(session, id = discussion_id)
        if discussion is None:
            log['error']['discussion'] = 'Discussion ID not found'
            return jsonify(log = log), 400

        if user:
            member = user.member
        else:
            client_id = request.authorization.get('username', None)
            auth = Auth_api.get(session, client_id)
            member = auth.member

        discussion_data, log = update_discussion_core(
            session = session,
            log = log,
            discussion = discussion,
            member = member,
            description = input['description'],
            status = input['status'],
            attached_elements = input['attached_elements']
        )
        if len(log["error"].keys()) >= 1:
            return jsonify(log = log), 400

        return jsonify(discussion = discussion_data), 200
Example #2
0
 def test_get_by_id(self):
     issue = Discussion.new(
         session = self.session,
         title = 'test',
         description = 'description',
         project_id = self.project.id,
         status = 'open'
     )
     issue2 = Discussion.get_by_id(self.session, issue.id)
     self.assertEqual(issue, issue2)
def update_discussion_comment_web(project_string_id, discussion_id):
    """
        Update comment's content of the given comment_id in the POST payload.
    :param project_string_id:
    :param discussion_id:
    :return:
    """
    # For now, no filters needed. But might add in the future.
    issue_new_spec_list = [
        {
            "comment_id": {
                'kind': int
            }
        },
        {
            "content": {
                'kind': str
            }
        },
    ]

    log, input, untrusted_input = regular_input.master(
        request=request, spec_list=issue_new_spec_list)

    if len(log["error"].keys()) >= 1:
        return jsonify(log=log), 400

    with sessionMaker.session_scope() as session:

        project = Project.get_by_string_id(session, project_string_id)
        user = User.get(session)
        discussion = Discussion.get_by_id(session, id=discussion_id)
        if discussion is None:
            log['error']['discussion'] = 'Discussion ID not found'
            return jsonify(log=log), 400

        if user:
            member = user.member
        else:
            client_id = request.authorization.get('username', None)
            auth = Auth_api.get(session, client_id)
            member = auth.member

        comment_data, log = update_discussion_comments_core(
            session=session,
            log=log,
            comment_id=input['comment_id'],
            member=member,
            content=input['content'])
        if len(log["error"].keys()) >= 1:
            return jsonify(log=log), 400

        return jsonify(comment=comment_data), 200
def new_discussion_comment_web(project_string_id, discussion_id):
    """
        Create a new comment on the given discussion_id.
        The comment content will be an HTML string.
    :param project_string_id:
    :param discussion_id:
    :return:
    """
    issue_new_spec_list = [
        {
            "content": {
                'kind': str
            }
        },
    ]

    log, input, untrusted_input = regular_input.master(
        request=request, spec_list=issue_new_spec_list)

    if len(log["error"].keys()) >= 1:
        return jsonify(log=log), 400

    with sessionMaker.session_scope() as session:

        project = Project.get_by_string_id(session, project_string_id)
        user = User.get(session)
        discussion = Discussion.get_by_id(session, id=discussion_id)
        if discussion is None:
            log['error']['discussion'] = 'Discussion ID not found'
            return jsonify(log=log), 400

        if user:
            member = user.member
        else:
            client_id = request.authorization.get('username', None)
            auth = Auth_api.get(session, client_id)
            member = auth.member

        comment_data, log = new_discussion_comment_core(
            session=session,
            log=log,
            member=member,
            user=user,
            project=project,
            discussion=discussion,
            content=input['content'])
        if len(log["error"].keys()) >= 1:
            return jsonify(log=log), 400

        return jsonify(comment=comment_data), 200
def list_discussion_comment_web(project_string_id, discussion_id):
    """
        List all the comments of the given discussion_id

    :param project_string_id:
    :param discussion_id:
    :return:
    """
    # For now, no filters needed. But might add in the future.
    issue_new_spec_list = []

    log, input, untrusted_input = regular_input.master(
        request=request, spec_list=issue_new_spec_list)

    if len(log["error"].keys()) >= 1:
        return jsonify(log=log), 400

    with sessionMaker.session_scope() as session:

        project = Project.get_by_string_id(session, project_string_id)
        user = User.get(session)
        discussion = Discussion.get_by_id(session, id=discussion_id)
        if discussion is None:
            log['error']['discussion'] = 'Discussion ID not found'
            return jsonify(log=log), 400

        if user:
            member = user.member
        else:
            client_id = request.authorization.get('username', None)
            auth = Auth_api.get(session, client_id)
            member = auth.member

        comments_data, log = list_discussion_comments_core(
            session=session,
            log=log,
            project=project,
            discussion=discussion,
        )
        if len(log["error"].keys()) >= 1:
            return jsonify(log=log), 400

        return jsonify(comments=comments_data), 200
Example #6
0
def discussion_detail_core(session,
                           log = regular_log.default(),
                           project = None,
                           discussion_id = None):
    """
        Return serialized dictionary with data of the given discussion.
    :param session:
    :param log:
    :param project:
    :param discussion_id:
    :return: dictionary of the given discussion data.
    """

    discussion = Discussion.get_by_id(session, id = discussion_id)

    if discussion.project_id != project.id:
        log['error']['project_id'] = 'Wrong project ID provided.'

    if discussion is None:
        log['error']['discussion_id'] = 'discussion ID not found'
        return None, log

    issue_data = discussion.serialize(session = session)
    return issue_data, log
Example #7
0
 def test_update_attached_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.update_attached_instances(
         session = self.session,
         attached_elements = [{'type': 'instance', 'instance_id': instance.id}]
     )
     self.session.commit()
     disc = Discussion.get_by_id(session = self.session, id=discussion.id)
     self.assertEqual(len(disc.serialize_attached_elements(self.session)), 2)