Exemplo n.º 1
0
 def put(self, request, *args, **kwargs):
     if not request.user.is_staff and not self.user_in_org:
         return HttpResponse(status=status.HTTP_403_FORBIDDEN)
     if not self.userprofile:
         return HttpResponse(status=status.HTTP_404_NOT_FOUND)
     add_user_to_org(self.userprofile, self.organization)
     return HttpResponse(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 2
0
    def test_add_user_to_org(self):
        user = User.objects.create(username='******',
                                   email='*****@*****.**',
                                   last_name='One',
                                   first_name='User')
        userprofile = UserProfile.objects.create(user=user,
                                                 mnemonic='user1',
                                                 created_by='user1',
                                                 updated_by='user1')
        org = Organization.objects.create(name='org1',
                                          mnemonic='org1',
                                          created_by='user1',
                                          updated_by='user1')

        self.assertEquals(0, userprofile.orgs)
        self.assertEquals(0, org.num_members)

        add_user_to_org(userprofile, org)

        self.assertEquals(1, userprofile.orgs)
        self.assertEquals(1, org.num_members)

        self.assertEquals(org.id, userprofile.organizations[0])
        self.assertEquals(userprofile.id, org.members[0])

        remove_user_from_org(userprofile, org)

        self.assertEquals(0, userprofile.orgs)
        self.assertEquals(0, org.num_members)
Exemplo n.º 3
0
 def put(self, request, *args, **kwargs):
     if not request.user.is_staff and not self.user_in_org:
         return HttpResponse(status=status.HTTP_403_FORBIDDEN)
     if not self.userprofile:
         return HttpResponse(status=status.HTTP_404_NOT_FOUND)
     add_user_to_org(self.userprofile, self.organization)
     return HttpResponse(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 4
0
    def test_add_user_to_org(self):
        user = User.objects.create(
            username='******',
            email='*****@*****.**',
            last_name='One',
            first_name='User'
        )
        userprofile = UserProfile.objects.create(user=user, mnemonic='user1', created_by='user1', updated_by='user1')
        org = Organization.objects.create(name='org1', mnemonic='org1', created_by='user1', updated_by='user1')

        self.assertEquals(0, userprofile.orgs)
        self.assertEquals(0, org.num_members)

        add_user_to_org(userprofile, org)

        self.assertEquals(1, userprofile.orgs)
        self.assertEquals(1, org.num_members)

        self.assertEquals(org.id, userprofile.organizations[0])
        self.assertEquals(userprofile.id, org.members[0])

        remove_user_from_org(userprofile, org)

        self.assertEquals(0, userprofile.orgs)
        self.assertEquals(0, org.num_members)
Exemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     if self.related_object_type or self.related_object_kwarg:
         return HttpResponse(status=status.HTTP_405_METHOD_NOT_ALLOWED)
     self.serializer_class = OrganizationCreateSerializer
     response = self.create(request, *args, **kwargs)
     if response.status_code == 201:
         add_user_to_org(request.user.get_profile(), self.object)
     return response
Exemplo n.º 6
0
 def post(self, request, *args, **kwargs):
     if self.related_object_type or self.related_object_kwarg:
         return HttpResponse(status=status.HTTP_405_METHOD_NOT_ALLOWED)
     self.serializer_class = OrganizationCreateSerializer
     response = self.create(request, *args, **kwargs)
     if response.status_code == 201:
         add_user_to_org(request.user.get_profile(), self.object)
     return response
Exemplo n.º 7
0
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.DATA,
                                         files=request.FILES)

        if serializer.is_valid():
            self.pre_save(serializer.object)
            self.object = serializer.save(force_insert=True)
            self.post_save(self.object, created=True)
            add_user_to_org(request.user.get_profile(), self.object)
            headers = self.get_success_headers(serializer.data)
            serializer = OrganizationDetailSerializer(
                self.object, context={'request': request})
            return Response(serializer.data,
                            status=status.HTTP_201_CREATED,
                            headers=headers)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 8
0
    def setUp(self):
        super(MappingBaseTest, self).setUp()
        self.user1 = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            last_name='One',
            first_name='User'
        )
        self.user2 = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            last_name='Two',
            first_name='User'
        )

        self.userprofile1 = UserProfile.objects.create(user=self.user1, mnemonic='user1')
        self.userprofile2 = UserProfile.objects.create(user=self.user2, mnemonic='user2')

        self.org1 = Organization.objects.create(name='org1', mnemonic='org1')
        self.org2 = Organization.objects.create(name='org2', mnemonic='org2')
        add_user_to_org(self.userprofile2, self.org2)

        self.source1 = Source(
            name='source1',
            mnemonic='source1',
            full_name='Source One',
            source_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.source1.com',
            description='This is the first test source',
        )
        kwargs = {
            'parent_resource': self.userprofile1
        }
        Source.persist_new(self.source1, self.user1, **kwargs)
        self.source1 = Source.objects.get(id=self.source1.id)

        self.source2 = Source(
            name='source2',
            mnemonic='source2',
            full_name='Source Two',
            source_type='Reference',
            public_access=ACCESS_TYPE_VIEW,
            default_locale='fr',
            supported_locales=['fr'],
            website='www.source2.com',
            description='This is the second test source',
        )
        kwargs = {
            'parent_resource': self.org2,
        }
        Source.persist_new(self.source2, self.user1, **kwargs)
        self.source2 = Source.objects.get(id=self.source2.id)

        self.name = LocalizedText.objects.create(name='Fred', locale='en', type='FULLY_SPECIFIED')

        (self.concept1, errors) = create_concept(mnemonic='concept1', user=self.user1, source=self.source1, names=[self.name], descriptions=[self.name])
        (self.concept2, errors) = create_concept(mnemonic='concept2', user=self.user1, source=self.source1, names=[self.name], descriptions=[self.name])
        (self.concept3, errors) = create_concept(mnemonic='concept3', user=self.user1, source=self.source2, names=[self.name], descriptions=[self.name])
        (self.concept4, errors) = create_concept(mnemonic='concept4', user=self.user1, source=self.source2, names=[self.name], descriptions=[self.name])
Exemplo n.º 9
0
    def setUp(self):
        super(MappingBaseTest, self).setUp()
        self.user1 = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            last_name='One',
            first_name='User'
        )
        self.user2 = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******',
            last_name='Two',
            first_name='User'
        )

        self.userprofile1 = UserProfile.objects.create(user=self.user1, mnemonic='user1')
        self.userprofile2 = UserProfile.objects.create(user=self.user2, mnemonic='user2')

        self.org1 = Organization.objects.create(name='org1', mnemonic='org1')
        self.org2 = Organization.objects.create(name='org2', mnemonic='org2')
        add_user_to_org(self.userprofile2, self.org2)

        self.source1 = Source(
            name='source1',
            mnemonic='source1',
            full_name='Source One',
            source_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.source1.com',
            description='This is the first test source',
        )
        kwargs = {
            'parent_resource': self.userprofile1
        }
        Source.persist_new(self.source1, self.user1, **kwargs)
        self.source1 = Source.objects.get(id=self.source1.id)

        self.source2 = Source(
            name='source2',
            mnemonic='source2',
            full_name='Source Two',
            source_type='Reference',
            public_access=ACCESS_TYPE_VIEW,
            default_locale='fr',
            supported_locales=['fr'],
            website='www.source2.com',
            description='This is the second test source',
        )
        kwargs = {
            'parent_resource': self.org2,
        }
        Source.persist_new(self.source2, self.user1, **kwargs)
        self.source2 = Source.objects.get(id=self.source2.id)

        self.name = LocalizedText.objects.create(name='Fred', locale='en', type='FULLY_SPECIFIED')

        (self.concept1, errors) = create_concept(mnemonic='concept1', user=self.user1, source=self.source1, names=[self.name], descriptions=[self.name])
        (self.concept2, errors) = create_concept(mnemonic='concept2', user=self.user1, source=self.source1, names=[self.name], descriptions=[self.name])
        (self.concept3, errors) = create_concept(mnemonic='concept3', user=self.user1, source=self.source2, names=[self.name], descriptions=[self.name])
        (self.concept4, errors) = create_concept(mnemonic='concept4', user=self.user1, source=self.source2, names=[self.name], descriptions=[self.name])
        (self.concept5, errors) = create_concept(mnemonic='concept5', user=self.user1, source=self.source1,
                                                 names=[self.name], descriptions=[self.name])
        (self.concept6, errors) = create_concept(mnemonic='concept6', user=self.user1, source=self.source1,
                                                 names=[self.name], descriptions=[self.name])
Exemplo n.º 10
0
    def setUp(self):
        self.user1 = User.objects.create_user(username='******',
                                              email='*****@*****.**',
                                              password='******',
                                              last_name='One',
                                              first_name='User')
        self.user2 = User.objects.create_user(username='******',
                                              email='*****@*****.**',
                                              password='******',
                                              last_name='Two',
                                              first_name='User')

        self.userprofile1 = UserProfile.objects.create(user=self.user1,
                                                       mnemonic='user1')
        self.userprofile2 = UserProfile.objects.create(user=self.user2,
                                                       mnemonic='user2')

        self.org1 = Organization.objects.create(name='org1', mnemonic='org1')
        self.org2 = Organization.objects.create(name='org2', mnemonic='org2')
        add_user_to_org(self.userprofile2, self.org2)

        self.source1 = Source(
            name='source1',
            mnemonic='source1',
            full_name='Source One',
            source_type='Dictionary',
            public_access=ACCESS_TYPE_EDIT,
            default_locale='en',
            supported_locales=['en'],
            website='www.source1.com',
            description='This is the first test source',
        )
        kwargs = {'parent_resource': self.userprofile1}
        Source.persist_new(self.source1, self.user1, **kwargs)
        self.source1 = Source.objects.get(id=self.source1.id)

        self.source2 = Source(
            name='source2',
            mnemonic='source2',
            full_name='Source Two',
            source_type='Reference',
            public_access=ACCESS_TYPE_VIEW,
            default_locale='fr',
            supported_locales=['fr'],
            website='www.source2.com',
            description='This is the second test source',
        )
        kwargs = {
            'parent_resource': self.org2,
        }
        Source.persist_new(self.source2, self.user1, **kwargs)
        self.source2 = Source.objects.get(id=self.source2.id)

        self.name = LocalizedText.objects.create(name='Fred', locale='en')

        self.concept1 = Concept(
            mnemonic='concept1',
            updated_by=self.user1,
            parent=self.source1,
            concept_class='First',
            names=[self.name],
        )
        kwargs = {
            'parent_resource': self.source1,
        }
        Concept.persist_new(self.concept1, self.user1, **kwargs)

        self.concept2 = Concept(
            mnemonic='concept2',
            updated_by=self.user1,
            parent=self.source1,
            concept_class='Second',
            names=[self.name],
        )
        kwargs = {
            'parent_resource': self.source1,
        }
        Concept.persist_new(self.concept2, self.user1, **kwargs)

        self.concept3 = Concept(
            mnemonic='concept3',
            updated_by=self.user1,
            parent=self.source2,
            concept_class='Third',
            names=[self.name],
        )
        kwargs = {
            'parent_resource': self.source2,
        }
        Concept.persist_new(self.concept3, self.user1, **kwargs)

        self.concept4 = Concept(
            mnemonic='concept4',
            updated_by=self.user2,
            parent=self.source2,
            concept_class='Fourth',
            names=[self.name],
        )
        kwargs = {
            'parent_resource': self.source2,
        }
        Concept.persist_new(self.concept4, self.user1, **kwargs)