Example #1
0
    def test_orgs_list_shared_with_user(self):
        authenticated_user = self.user
        user_in_shared_organization, _ = User.objects.get_or_create(
            username='******')

        unshared_organization, _ = User.objects.get_or_create(
            username='******')
        unshared_organization_profile, _ = OrganizationProfile\
            .objects.get_or_create(
                user=unshared_organization,
                creator=authenticated_user)

        add_user_to_organization(unshared_organization_profile,
                                 authenticated_user)

        shared_organization, _ = User.objects.get_or_create(username='******')
        shared_organization_profile, _ = OrganizationProfile\
            .objects.get_or_create(
                user=shared_organization,
                creator=user_in_shared_organization)

        add_user_to_organization(shared_organization_profile,
                                 authenticated_user)

        request = self.factory.get('/', **self.extra)
        response = self.view(request)
        self.assertTrue(len(response.data), 2)
        request = self.factory.get('/',
                                   data={'shared_with': 'the_stalked'},
                                   **self.extra)
        response = self.view(request)
        self.assertEqual(len(response.data), 1)
    def test_orgs_list_shared_with_user(self):
        authenticated_user = self.user
        user_in_shared_organization, _ = User.objects.get_or_create(
            username='******')

        unshared_organization, _ = User.objects.get_or_create(
            username='******')
        unshared_organization_profile, _ = OrganizationProfile\
            .objects.get_or_create(
                user=unshared_organization,
                creator=authenticated_user)

        add_user_to_organization(unshared_organization_profile,
                                 authenticated_user)

        shared_organization, _ = User.objects.get_or_create(username='******')
        shared_organization_profile, _ = OrganizationProfile\
            .objects.get_or_create(
                user=shared_organization,
                creator=user_in_shared_organization)

        add_user_to_organization(shared_organization_profile,
                                 authenticated_user)

        request = self.factory.get('/', **self.extra)
        response = self.view(request)
        self.assertTrue(len(response.data), 2)
        request = self.factory.get('/',
                                   data={'shared_with': 'the_stalked'},
                                   **self.extra)
        response = self.view(request)
        self.assertEqual(len(response.data), 1)
    def create(self, validated_data):
        organization = validated_data.get("organization")
        username = validated_data.get("username")
        role = validated_data.get('role')
        email_msg = validated_data.get('email_msg')
        email_subject = validated_data.get('email_subject')
        remove = validated_data.get('remove')

        if username:
            user = User.objects.get(username=username)

            add_user_to_organization(organization, user)

            if role:
                _set_organization_role_to_user(organization, user, role)

            if email_msg:
                _compose_send_email(organization, user, email_msg,
                                    email_subject)

            if remove:
                remove_user_from_organization(organization, user)

        return organization
    def create(self, validated_data):
        organization = validated_data.get("organization")
        username = validated_data.get("username")
        role = validated_data.get('role')
        email_msg = validated_data.get('email_msg')
        email_subject = validated_data.get('email_subject')
        remove = validated_data.get('remove')

        if username:
            user = User.objects.get(username=username)

            add_user_to_organization(organization, user)

            if role:
                _set_organization_role_to_user(organization, user, role)

            if email_msg:
                _compose_send_email(organization, user, email_msg,
                                    email_subject)

            if remove:
                remove_user_from_organization(organization, user)

        return organization