Exemplo n.º 1
0
def user_pre_delete(sender, document, *args, **kwargs):
    """
    Delete related documents when a User is deleted
    :param sender: Class
    :param document: User Object
    :return: Nothing
    """

    # delete projects
    Project.objects(owner=document).delete()
    # delete from project members
    ProjectMember.objects(member=document).delete()
    # delete comment
    Comment.objects(who=document).delete()
Exemplo n.º 2
0
def project_pre_delete(sender, document, *args, **kwargs):
    """
    Delete related documents when a User is deleted
    :param sender: Class
    :param document: Project Object
    :return: Nothing
    """
    # delete sprints
    Sprint.objects(project=document).delete()
    # delete members
    ProjectMember.objects(project=document).delete()
    # delete tickets
    Ticket.objects(project=document).delete()
    # delete columns
    Column.objects(project=document).delete()
Exemplo n.º 3
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.º 4
0
    def get(self, project_pk):
        """
        Return list of project members by project

        :param project_pk: Project ID
        :return: List of project members
        """
        prj = get_project_request(project_pk)
        return ProjectMember.objects(project=prj), 200
Exemplo n.º 5
0
 def get(self, query):
     """
     Search Tickets that contains the query
     :param query: text to search
     :return: List of matched tickets
     """
     projects = []
     projects_query = ProjectMember.get_by_member(current_user.id)
     for p in projects_query:
         projects.append(str(p.project.pk))
     return Ticket.search(query, projects), 200
Exemplo n.º 6
0
    def post(self, project_pk):
        """
        Create a new Project Member

        :param project_pk: Project ID
        :return: the created ProjectMember
        """

        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)

        members_added = []
        errors_list = []
        for member in data:
            if member.get('value'):
                user = User.get_by_id(member.get('value'))
                if not user:
                    errors_list.append(
                        dict(member=api_errors.INVALID_MEMBER_MSG))
            else:
                user = User(email=member.get('text'))
                user.active = False
                user.save()
            if user and project.owner.id != user.id:
                m = ProjectMember.get_by_project_member(project, user)
                if not m:
                    m = ProjectMember(project=project)
                    m.member = user
                    m.save()
                    # Send email notification
                    create_new_member_email(m.member, project)
                    members_added.append(m.to_dict())
                else:
                    errors_list.append(dict(
                        member=api_errors.INVALID_ALREADY_ADDED_MSG
                    ))
        if errors_list:
            raise api_errors.InvalidAPIUsage(
                api_errors.VALIDATION_ERROR_MSG,
                payload=errors_list
            )

        if members_added:
            # save activity
            save_notification(project_pk=project.id,
                              verb='new_members',
                              data={'members': members_added})
        return {}, 200
Exemplo n.º 7
0
 def get(self):
     """
     Get the list of projects that the user belongs
     :return: List of project resources
     """
     prj_mem = ProjectMember.get_by_member(current_user.id)
     projects = []
     for pm in prj_mem:
         if not isinstance(pm.project, DBRef):
             if pm.project.active:
                 projects.append(pm.project)
             elif pm.project.owner.id == current_user.id:
                 projects.append(pm.project)
     return projects, 200
Exemplo n.º 8
0
def project_serializer(prj):
    """
    Serialize a Project Object
    :param prj: Project Instance
    :return: Project Composite
    """
    prj_dict = prj.to_dict()
    prj_dict['owner'] = prj.owner.to_dict()

    if isinstance(prj.project_type, bool) and prj.project_type:
        prj_dict["project_type"] = 'S'
    elif isinstance(prj.project_type, bool) and not prj.project_type:
        prj_dict["project_type"] = 'K'
    prj_dict['members'] = ProjectMember.get_members_for_project(prj)
    return prj_dict
Exemplo n.º 9
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.º 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 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.º 12
0
def activity_post_save(sender, document, *args, **kwargs):
    # project notify
    r = RedisClient(channel=str(document.project.pk))
    r.store(document.verb, str(document.author.pk))

    if document.to is not None:
        un = UserNotification(activity=document)
        un.user = document.to
        un.save()
        r = RedisClient(channel=str(un.user.pk))
        r.store(document.verb, str(document.author.pk))
    else:
        pms = ProjectMember.objects(project=document.project)
        for pm in pms:
            un = UserNotification(activity=document)
            un.user = pm.member
            un.save()
            r = RedisClient(channel=str(un.user.pk))
            r.store(document.verb, str(document.author.pk))
Exemplo n.º 13
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.º 14
0
    def post(self):
        """
        Create Project
        """
        data = request.get_json(silent=True)
        if not data:
            raise api_errors.InvalidAPIUsage(
                api_errors.INVALID_JSON_BODY_MSG
            )

        prj = Project(name=data.get('name'),
                      owner=g.user.to_dbref())
        prj.active = data.get('active')
        prj.private = data.get('private')
        prj.prefix = data.get('prefix', data.get('name')[:3].upper())
        prj.description = data.get('description')
        prj.project_type = data.get('project_type', 'S')

        # Add initial config
        prj.sprint_duration = 15
        prj.save()

        # add owner as member
        pm = ProjectMember(project=prj)
        pm.member = prj.owner
        pm.is_owner = True
        pm.save()

        # Add 3 columns states
        col_names = ['ToDo', 'In Progress', 'Done']
        for index, c in enumerate(col_names):
            col = Column()
            col.title = c
            col.project = prj
            if index == len(col_names) - 1:
                col.done_column = True
            col.save()

        # save activity
        save_notification(project_pk=prj.pk,
                          verb='new_project',
                          data=prj.to_dict())

        return prj, 201