Пример #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)
Пример #2
0
    def test_organization_permissions_for_organization_member(self):
        organization_membership_1 = OrganizationMembershipFactory(role=OrganizationMemberRole.ADMIN)
        organization_membership_2 = OrganizationMembershipFactory(role=OrganizationMemberRole.MEMBER)

        for member in (organization_membership_1, organization_membership_2):
            permissions = PermissionsService.get_organization_permissions(
                organization_id=member.organization_id,
                user_id=member.user_id,
            )
            self._assert_has_read_permissions(permissions)
Пример #3
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)
Пример #4
0
    def test_send_invite_already_a_member(self):
        owner = OrganizationMembershipFactory(
            role=OrganizationMemberRole.OWNER)
        existing_member = OrganizationMembershipFactory(
            organization=owner.organization)

        with self.assertRaises(OrganizationMembershipAlreadyExistsException):
            _ = OrganizationInviteService.create_organization_invite(
                organization_id=owner.organization_id,
                email=existing_member.user.email,
                message='message',
            )
Пример #5
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)
    def test_delete_member(self):
        membership = OrganizationMembershipFactory()
        OrganizationMembershipService.delete_organization_membership(
            membership.id)

        self.assertIsNone(
            OrganizationMembership.objects.filter(id=membership.id).first())
Пример #7
0
    def test_organization_membership_permissions_for_owner(self):
        organization_membership = OrganizationMembershipFactory(role=OrganizationMemberRole.OWNER)
        target_organization_membership = OrganizationMembershipFactory(
            organization_id=organization_membership.organization_id,
        )

        permissions = PermissionsService.get_organization_membership_permissions(
            organization_membership_id=target_organization_membership.id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_all_permissions(permissions)

        permissions = PermissionsService.get_organization_membership_permissions(
            organization_membership_id=organization_membership.id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_all_permissions(permissions)
    def test_add_member_already_a_member(self):
        membership = OrganizationMembershipFactory()

        with self.assertRaises(OrganizationMembershipAlreadyExistsException):
            _ = OrganizationMembershipService.create_organization_membership(
                organization_id=membership.organization_id,
                user_id=membership.user_id,
            )
Пример #9
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)
Пример #10
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)
Пример #11
0
    def test_create_board_name_not_unique(self):
        organization_membership = OrganizationMembershipFactory(
            role=OrganizationMemberRole.OWNER)
        board = BoardFactory(
            organization_id=organization_membership.organization_id, )

        with self.assertRaises(BoardAlreadyExistsException):
            _ = BoardService.create_board(
                name=board.name,
                organization_id=organization_membership.organization_id)
Пример #12
0
    def test_ticket_assignment_permissions_for_not_a_board_member(self):
        ticket_assignment = TicketAssignmentFactory()
        organization_membership = OrganizationMembershipFactory(
            organization_id=ticket_assignment.ticket.category.board.organization_id,
        )

        permissions = PermissionsService.get_ticket_assignment_permissions(
            ticket_assignment_id=ticket_assignment.id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_no_permissions(permissions)
Пример #13
0
    def test_category_permissions_for_not_a_board_member(self):
        category = CategoryFactory()
        organization_membership = OrganizationMembershipFactory(
            organization_id=category.board.organization_id,
        )

        permissions = PermissionsService.get_category_permissions(
            category_id=category.id,
            user_id=organization_membership.user_id,
        )
        self._assert_has_no_permissions(permissions)
Пример #14
0
    def test_send_invite_already_invited(self):
        member = OrganizationMembershipFactory(
            role=OrganizationMemberRole.OWNER)
        invite = OrganizationInviteFactory(
            organization_id=member.organization_id)

        with self.assertRaises(OrganizationInviteAlreadyExistsException):
            _ = OrganizationInviteService.create_organization_invite(
                organization_id=member.organization_id,
                email=invite.user.email,
                message='message',
            )
Пример #15
0
    def test_add_member(self):
        organization_membership = OrganizationMembershipFactory()
        board = BoardFactory(
            organization_id=organization_membership.organization_id, )

        board_membership = BoardMembershipService.create_board_membership(
            board_id=board.id,
            organization_membership_id=organization_membership.id,
        )

        self.assertIsNotNone(board_membership)
        self.assertEqual(board_membership.board.id, board.id)
        self.assertEqual(board_membership.organization_membership.id,
                         organization_membership.id)
Пример #16
0
    def test_create_board(self):
        organization_membership = OrganizationMembershipFactory(
            role=OrganizationMemberRole.OWNER)

        with patch.object(BoardMembershipService,
                          'create_board_membership') as mocked_add_member:
            board = BoardService.create_board(
                name='board',
                organization_id=organization_membership.organization_id)

        self.assertIsNotNone(board)
        self.assertEqual(board.name, 'board')
        self.assertEqual(board.organization.id,
                         organization_membership.organization_id)
        mocked_add_member.assert_called_with(
            board_id=board.id,
            organization_membership_id=organization_membership.id,
        )
Пример #17
0
 def test_organization_membership_permissions_for_not_organization_member(self):
     permissions = PermissionsService.get_organization_membership_permissions(
         organization_membership_id=OrganizationMembershipFactory().id,
         user_id=UserFactory().id,
     )
     self._assert_has_no_permissions(permissions)