Exemplo n.º 1
0
    def post(self, project_pk, column):
        """
        Order Tickets in Columns
        :param project_pk: Project ID
        :param column: Column ID
        :return: Order
        """
        data = request.get_json(silent=True)

        if not data:
            raise api_errors.InvalidAPIUsage(api_errors.INVALID_JSON_BODY_MSG)

        project = get_project_request(project_pk)

        col = Column.get_by_id(column)
        if not col:
            raise api_errors.MissingResource(api_errors.INVALID_COLUMN_MSG)

        if project.project_type == 'S':
            sprint = get_sprint_request(data.get('sprint'))
            TicketCT.order_items(data.get('order'), sprint=sprint)
        else:
            TicketCT.order_items(data.get('order'))

        # save activity
        save_notification(project_pk=project_pk,
                          verb='ticket_column_order',
                          data=data)
        return data, 200
Exemplo n.º 2
0
    def put(self, project_pk, tkt_id, comment_id):
        """
        Update a comment
        :param project_pk: Project ID
        :param tkt_id: Ticket ID
        :param comment_id: Comment ID
        :return: Updated Comment
        """
        get_project_request(project_pk)
        get_ticket_request(tkt_id)

        comment = Comment.get_by_id(comment_id)
        if not comment:
            raise api_errors.MissingResource(api_errors.INVALID_COMMENT_MSG)

        data = request.get_json(silent=True)
        if not data:
            raise api_errors.InvalidAPIUsage(api_errors.INVALID_JSON_BODY_MSG)

        if comment.who.id != current_user.id:
            raise api_errors.ForbiddenRequest()

        comment.comment = data.get('comment')
        comment.save()

        save_notification(project_pk=project_pk,
                          verb='update_comment',
                          data={
                              "comment": comment.to_dict(),
                              "ticket": comment.ticket.to_dict()
                          })

        return comment, 200
Exemplo n.º 3
0
    def delete(self, project_pk, tkt_id, comment_id):
        """
        Delete a Comment
        :param project_pk: Project ID
        :param tkt_id: Ticket ID
        :param comment_id: Comment ID
        :return: Nothing
        """
        get_project_request(project_pk)
        get_ticket_request(tkt_id)

        comment = Comment.get_by_id(comment_id)
        if not comment:
            raise api_errors.MissingResource(api_errors.INVALID_COMMENT_MSG)

        if comment.who.id != current_user.id:
            raise api_errors.ForbiddenRequest()

        # save activity
        save_notification(project_pk=project_pk,
                          verb='delete_comment',
                          data={
                              "comment": comment.to_dict(),
                              "ticket": comment.ticket.to_dict()
                          })

        comment.delete()
        return {}, 204
Exemplo n.º 4
0
    def put(self, project_pk, tkt_id, pm_id):
        """
        Assign a member to a ticket, this will update the ticket
        :param project_pk: Project ID
        :param tkt_id: Ticket ID
        :param member_id: Member ID
        :return: Ticket Object
        """
        get_project_request(project_pk)
        tkt = get_ticket_request(tkt_id)
        pm = ProjectMember.get_by_id(pm_id)
        if not pm:
            raise api_errors.MissingResource(
                api_errors.INVALID_PROJECT_MEMBER_MSG)

        if pm in tkt.assigned_to:
            raise api_errors.InvalidAPIUsage(
                api_errors.INVALID_ALREADY_ADDED_MSG)

        tkt.assigned_to.append(pm)
        tkt.save()

        # save activity
        save_notification(project_pk=project_pk,
                          verb='new_assigment',
                          data=tkt.to_dict())
        return tkt, 200
Exemplo n.º 5
0
    def post(self):
        """
        Activate a user based on a token
        :return: token auth
        """
        data = request.get_json(silent=True)
        if not data:
            raise api_errors.InvalidAPIUsage(
                api_errors.INVALID_JSON_BODY_MSG
            )

        user = User.get_by_activation_token(data.get('token'))
        if not user:
            raise api_errors.MissingResource(
                api_errors.ACTIVATION_INVALID_TOKEN_MSG
            )

        user.active = True
        user.save()

        tokens_dict = current_app.token_handler.generate_tokens_dict(
            user.pk
        )

        return tokens_dict, 200
Exemplo n.º 6
0
def get_ticket_request(ticket_id):
    """
    Get Ticket from the url
    :param ticket_id: Ticket ID
    :return: Ticket Object
    """
    tkt = Ticket.get_by_id(ticket_id)
    if tkt is None:
        raise api_errors.MissingResource(api_errors.INVALID_TICKET_MSG)
    return tkt
Exemplo n.º 7
0
def get_project_request(project_id):
    """
    Get Projects from the url
    :param project_id: Project ID
    :return: Project Object
    """
    prj = Project.get_by_id(project_id)
    if prj is None:
        raise api_errors.MissingResource(
            api_errors.INVALID_PROJECT_MSG
        )
    return prj
Exemplo n.º 8
0
 def get(self, project_pk, tkt_id, att_id):
     """
     Get an Attachment
     :param project_pk: Project ID
     :param tkt_id: Ticket ID
     :param att_id: Attachment ID
     :return: Attachment
     """
     get_project_request(project_pk)
     get_ticket_request(tkt_id)
     att = Attachment.get_by_id(att_id)
     if not att:
         raise api_errors.MissingResource(api_errors.INVALID_ATTACHMENT_MSG)
     return att, 200
Exemplo n.º 9
0
    def delete(self, project_pk, tkt_id, rtkt_id):
        """
        Delete Related Ticket
        :param project_pk: Project ID
        :param tkt_id: Ticket ID
        :param rtkt_id: Related Ticket ID
        :return:
        """
        get_project_request(project_pk)
        get_ticket_request(tkt_id)

        rtkt = TicketDependency.get_by_id(rtkt_id)
        if not rtkt:
            raise api_errors.MissingResource(api_errors.INVALID_TICKET_MSG)

        Ticket.remove_related_ticket(tkt_id, rtkt)
        return {}, 204
Exemplo n.º 10
0
    def get(self, project_pk, member_pk):
        """
        Get a Single instance of a ProjectMember

        :param project_pk: project ID
        :param member_pk: ProjectMember ID
        :return: ProjectMember object
        """
        get_project_request(project_pk)

        pm = ProjectMember.get_by_id(member_pk)
        if not pm:
            raise api_errors.MissingResource(
                api_errors.INVALID_PROJECT_MEMBER_MSG
            )

        return pm, 200
Exemplo n.º 11
0
def get_user_for_request(user_id):
    """
    Get a user by ID
    :param user_id: Id of the User
    :return: User Instance
    """
    if user_id == 'me':
        # TODO: Find a better way to do this
        # Workaround: mongoengine can not always deal with proxies'
        return current_user._get_current_object()

    user = User.get_by_id(user_id)
    if not user:
        raise api_errors.MissingResource(
            api_errors.INVALID_USER_ID_MSG
        )
    return user
Exemplo n.º 12
0
    def get(self, project_pk, tkt_id, comment_id):
        """
        Get a Comment Resource

        :param project_pk: Project ID
        :param tkt_id: Ticket ID
        :param comment_id: Comment ID
        :return:
        """
        get_project_request(project_pk)

        get_ticket_request(tkt_id)

        comment = Comment.get_by_id(comment_id)
        if not comment:
            api_errors.MissingResource(api_errors.INVALID_COMMENT_MSG)

        return comment, 200
Exemplo n.º 13
0
    def delete(self, project_pk, member_pk):
        """
        Delete ProjectMember Resource

        :param project_pk: ProjectID
        :param member_pk: Project MemberID
        :return: Nothing
        """
        get_project_request(project_pk)

        pm = ProjectMember.get_by_id(member_pk)
        if not pm:
            raise api_errors.MissingResource(
                api_errors.INVALID_PROJECT_MEMBER_MSG
            )

        pm.delete()
        return {}, 204
Exemplo n.º 14
0
    def delete(self, project_pk, column_pk):
        """
        Delete a column resource

        :param project_pk: Project that belongs
        :param column_pk:Id of the column
        :return: Nothing
        """
        prj = get_project_request(project_pk)
        col = Column.get_by_id(column_pk)
        if not col:
            raise api_errors.MissingResource(
                api_errors.INVALID_COLUMN_MSG
            )
        # save activity
        save_notification(project_pk=prj.id,
                          verb='delete_column',
                          data=col.to_dict())

        col.delete()
        return {}, 204
Exemplo n.º 15
0
    def put(self, project_pk, column_pk):
        """
        Update a column instance

        :param project_pk: Project that belongs
        :param column_pk: Id of the column
        :return: The updated resource
        """

        col = Column.get_by_id(column_pk)
        if not col:
            raise api_errors.MissingResource(
                api_errors.INVALID_COLUMN_MSG
            )

        data = request.get_json(silent=True)

        if not data:
            raise api_errors.InvalidAPIUsage(
                api_errors.INVALID_JSON_BODY_MSG
            )

        col.title = data.get('title')
        col.color_max_cards = data.get('color_max_cards', '#FF0000')
        col.done_column = data.get('done_column', False)
        col.max_cards = data.get('max_cards', 9999)

        # check set other columns of the project to done_column in False
        if col.done_column:
            Column.clear_done_columns(project_pk)
        col.save()

        # save activity
        save_notification(project_pk=project_pk,
                          verb='update_column',
                          data=col.to_dict())

        return col, 200
Exemplo n.º 16
0
    def delete(self, project_pk, tkt_id, pm_id):
        """
        Remove member from ticket
        :param project_pk: Project ID
        :param tkt_id: Ticket ID
        :param member_id: ProjectMember ID
        :return: Nothing
        """
        get_project_request(project_pk)
        tkt = get_ticket_request(tkt_id)

        pm = ProjectMember.get_by_id(pm_id)
        if not pm:
            raise api_errors.MissingResource(
                api_errors.INVALID_PROJECT_MEMBER_MSG)

        Ticket.remove_member(tkt, pm)

        # save activity
        save_notification(project_pk=project_pk,
                          verb='delete_assignment',
                          data=tkt.to_dict())
        return {}, 204
Exemplo n.º 17
0
    def put(self, project_pk, member_pk):
        """
        Update ProjectMember Resource

        :param project_pk: ProjectID
        :param member_pk: Project MemberID
        :return: ProjectMember Instance
        """
        prj = get_project_request(project_pk)
        pm = ProjectMember.get_by_id(member_pk)

        if not pm:
            raise api_errors.MissingResource(
                api_errors.INVALID_PROJECT_MEMBER_MSG
            )

        ProjectMember.clear_ownership(prj)

        pm.is_owner = True
        pm.save()
        prj.owner = pm.member
        prj.save()

        return pm, 200
Exemplo n.º 18
0
def get_sprint_request(sprint_id):
    sprint = Sprint.get_by_id(sprint_id)
    if not sprint:
        raise api_errors.MissingResource(api_errors.INVALID_SPRINT_MSG)
    return sprint
Exemplo n.º 19
0
    def post(self, project_pk):
        """
        Move Ticket to Column or Backlog
        :param project_pk: Project ID
        :return: Ticket Transition
        """
        project = get_project_request(project_pk)

        data = request.get_json(silent=True)
        if not data:
            raise api_errors.InvalidAPIUsage(api_errors.INVALID_JSON_BODY_MSG)

        tkt = get_ticket_request(data.get('ticket'))

        result = {}
        if data.get('backlog'):
            latest_tran = TicketCT.get_latest_transition(tkt)
            if latest_tran:
                latest_tran.latest_state = False
                latest_tran.save()

            SprintTicketOrder.order_items(data.get('order'),
                                          data.get('backlog'))
            # save activity
            save_notification(project_pk=project_pk,
                              verb='ticket_transition',
                              data=data)

            result = latest_tran.to_json(), 200

        else:
            # Search already state
            col = Column.get_by_id(data.get('column'))

            if not col:
                raise api_errors.MissingResource(api_errors.INVALID_COLUMN_MSG)

            user = User.get_by_id(current_user.id)
            if not user:
                raise api_errors.MissingResource(
                    api_errors.INVALID_USER_ID_MSG)

            transition = TicketCT()
            transition.ticket = tkt
            transition.column = col
            transition.order = TicketCT.get_next_order_index(col)

            if project.project_type == 'S':
                sprint = get_sprint_request(data.get('sprint'))
                latest_tran = TicketCT.get_latest_transition(tkt, sprint)

                transition.sprint = sprint
            else:
                latest_tran = TicketCT.get_latest_transition(tkt)

            if latest_tran:
                latest_tran.latest_state = False
                latest_tran.save()

            transition.latest_state = True
            transition.who = user
            transition.save()

            if project.project_type == 'S':
                sprint = get_sprint_request(data.get('sprint'))
                TicketCT.order_items(data.get('order'),
                                     sprint=sprint,
                                     column=col)
            else:
                TicketCT.order_items(data.get('order'), column=col)

            # save activity
            save_notification(project_pk=project_pk,
                              verb='ticket_transition',
                              data=transition.to_dict())

            result = transition.to_json(), 201
        return result