Exemplo n.º 1
0
    def test_board_membership_permissions_for_admin(self):
        organization_membership = OrganizationMembershipFactory(role=OrganizationMemberRole.ADMIN)
        board_membership = BoardMembershipFactory(organization_membership=organization_membership)
        target_board_membership = BoardMembershipFactory(
            organization_membership=OrganizationMembershipFactory(organization=organization_membership.organization),
            board_id=board_membership.board_id,
        )
        target_owner_board_membership = BoardMembershipFactory(
            organization_membership=OrganizationMembershipFactory(
                organization=organization_membership.organization,
                role=OrganizationMemberRole.OWNER,
            ),
            board_id=board_membership.board_id,
        )

        permissions = PermissionsService.get_board_membership_permissions(
            board_membership_id=target_board_membership.id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_all_permissions(permissions)

        permissions = PermissionsService.get_board_membership_permissions(
            board_membership_id=target_owner_board_membership.id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_read_permissions(permissions)

        permissions = PermissionsService.get_board_membership_permissions(
            board_membership_id=board_membership.id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_all_permissions(permissions)
Exemplo n.º 2
0
    def test_delete_member_user_is_organization_owner(self):
        membership = BoardMembershipFactory(
            organization_membership=OrganizationMembershipFactory(
                role=OrganizationMemberRole.OWNER), )

        with self.assertRaises(CanNotLeaveBoardException):
            BoardMembershipService.delete_board_membership(membership.id)
Exemplo n.º 3
0
    def test_ticket_permissions_for_board_member(self):
        board_membership = BoardMembershipFactory()
        ticket = TicketFactory(category=CategoryFactory(board_id=board_membership.board_id))

        permissions = PermissionsService.get_ticket_permissions(
            ticket_id=ticket.id,
            user_id=board_membership.organization_membership.user_id,
        )
        self._assert_has_all_permissions(permissions)
Exemplo n.º 4
0
    def test_category_permissions_for_board_member(self):
        board_membership = BoardMembershipFactory()
        category = CategoryFactory(board_id=board_membership.board_id)

        permissions = PermissionsService.get_category_permissions(
            category_id=category.id,
            user_id=board_membership.organization_membership.user_id,
        )
        self._assert_has_all_permissions(permissions)
Exemplo n.º 5
0
    def test_board_permissions_for_member(self):
        organization_membership = OrganizationMembershipFactory(role=OrganizationMemberRole.MEMBER)
        board_membership = BoardMembershipFactory(organization_membership=organization_membership)

        permissions = PermissionsService.get_board_permissions(
            board_id=board_membership.board_id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_read_permissions(permissions)
Exemplo n.º 6
0
    def test_board_permissions_for_admin(self):
        organization_membership = OrganizationMembershipFactory(role=OrganizationMemberRole.ADMIN)
        board_membership = BoardMembershipFactory(organization_membership=organization_membership)

        permissions = PermissionsService.get_board_permissions(
            board_id=board_membership.board_id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_mutate_permissions(permissions)
Exemplo n.º 7
0
    def test_add_member_membership_already_exists(self):
        board_membership = BoardMembershipFactory()

        with self.assertRaises(BoardMembershipAlreadyExistsException):
            _ = BoardMembershipService.create_board_membership(
                board_id=board_membership.board_id,
                organization_membership_id=board_membership.
                organization_membership_id,
            )
Exemplo n.º 8
0
    def test_create_comment_ticket_not_found(self):
        board_membership = BoardMembershipFactory()

        with self.assertRaises(TicketNotFoundException):
            _ = CommentService.create_comment(
                ticket_id=-1,
                user_id=board_membership.organization_membership.user_id,
                message='test_message',
            )
Exemplo n.º 9
0
    def test_board_membership_permissions_for_not_a_board_member(self):
        organization_membership = OrganizationMembershipFactory(role=OrganizationMemberRole.MEMBER)
        target_board_membership = BoardMembershipFactory(
            organization_membership=OrganizationMembershipFactory(organization=organization_membership.organization),
        )

        permissions = PermissionsService.get_board_membership_permissions(
            board_membership_id=target_board_membership.id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_no_permissions(permissions)
    def test_assign_member(self):
        board_membership = BoardMembershipFactory()
        ticket = TicketFactory(category__board_id=board_membership.board_id)

        ticket_assignment = TicketAssignmentService.create_ticket_assignment(
            ticket_id=ticket.id,
            board_membership_id=board_membership.id,
        )

        self.assertIsNotNone(ticket_assignment)
        self.assertEqual(ticket_assignment.ticket_id, ticket.id)
        self.assertEqual(ticket_assignment.assignee_id, board_membership.id)
Exemplo n.º 11
0
    def test_create_comment(self):
        ticket = TicketFactory()
        board_membership = BoardMembershipFactory(
            board_id=ticket.category.board_id)

        comment = CommentService.create_comment(
            ticket_id=ticket.id,
            user_id=board_membership.organization_membership.user_id,
            message='test_message',
        )

        self.assertIsNotNone(comment)
        self.assertEqual(comment.message, 'test_message')
        self.assertEqual(comment.ticket_id, ticket.id)
        self.assertEqual(comment.author_id, board_membership.id)
Exemplo n.º 12
0
    def test_create_board_membership(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)
        board_membership = BoardMembershipFactory()

        payload = {
            'board_id': board_membership.board_id,
            'organization_id': 56,
            'organization_membership_id': 42,
        }

        with \
                patch.object(
                    PermissionsService,
                    'get_board_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    BoardMembershipService,
                    'create_board_membership',
                    return_value=board_membership,
                ) as mocked_add_member:
            response = api_client.post('/api/v1/board-memberships', data=payload, format='json')

        self.assertEqual(response.status_code, 201)
        mocked_get_permissions.assert_called_with(
            board_id=payload['board_id'],
            user_id=user.id,
        )
        mocked_add_member.assert_called_with(
            board_id=payload['board_id'],
            organization_membership_id=payload['organization_membership_id'],
        )
        self.assertDictEqual(
            response.data,
            {
                'id': str(board_membership.id),
                'board_id': str(board_membership.board_id),
                'organization_membership_id': str(board_membership.organization_membership_id),
            },
        )
Exemplo n.º 13
0
 def test_board_membership_permissions_for_a_random_user(self):
     permissions = PermissionsService.get_board_membership_permissions(
         board_membership_id=BoardMembershipFactory().id,
         user_id=UserFactory().id,
     )
     self._assert_has_no_permissions(permissions)
    def test_assign_member_ticket_not_found(self):
        board_membership = BoardMembershipFactory()

        with self.assertRaises(TicketNotFoundException):
            _ = TicketAssignmentService.create_ticket_assignment(
                ticket_id=-1, board_membership_id=board_membership.id)
Exemplo n.º 15
0
    def test_delete_member(self):
        board_membership = BoardMembershipFactory()
        BoardMembershipService.delete_board_membership(board_membership.id)

        self.assertIsNone(
            BoardMembership.objects.filter(id=board_membership.id).first())