Ejemplo n.º 1
0
    def setUp(self):

        # an admin of the parent group, non-member of the child group
        self.u = User.objects.create_user('user', '*****@*****.**', 'password')

        # a member (non-admin) of the parent group, non-member of the child group
        self.u2 = User.objects.create_user('user2', '*****@*****.**', 'password')

        # admin of the child group
        self.u3 = User.objects.create_user('user3', '*****@*****.**', 'password')

        # member (non-admin) of the child group
        self.u4 = User.objects.create_user('user4', '*****@*****.**', 'password')

        # random nobody
        self.u5 = User.objects.create_user('user5', '*****@*****.**', 'password')

        # set up the groups & memberships...s
        self.parent = BaseGroup.objects.create(slug='bg',
                                               name='a base group',
                                               creator=self.u,
                                               visibility='E')
        m = GroupMember(group=self.parent, user=self.u2, is_admin=False)
        m.save()

        self.child = Community.objects.create(slug='community',
                                              name='a community',
                                              creator=self.u3,
                                              parent=self.parent,
                                              visibility='M')
        m2 = GroupMember(group=self.child, user=self.u4, is_admin=False)
        m2.save()
Ejemplo n.º 2
0
    def setUp(self):
        self.creator = User.objects.create_user('creator', '*****@*****.**',
                                                'password')
        self.creator.save()

        self.member = User.objects.create_user('member', '*****@*****.**',
                                               'password')
        self.member.save()

        self.nonmember = User.objects.create_user('nonmember', '*****@*****.**',
                                                  'password')
        self.nonmember.save()

        self.admin = User.objects.create_user('admin', '*****@*****.**',
                                              'password')
        self.admin.is_superuser = True
        self.admin.save()

        self.grpadmin = User.objects.create_user('grpadmin', '*****@*****.**',
                                                 'password')
        self.grpadmin.save()

        self.publicgrp = Network.objects.create(slug='publicgrp',
                                                name='a public group',
                                                creator=self.member,
                                                visibility='E')
        self.privategrp = BaseGroup.objects.create(slug='privategrp',
                                                   name='a private group',
                                                   creator=self.member,
                                                   model='Community',
                                                   visibility='M',
                                                   parent=self.publicgrp)

        self.publicpost = GroupTopic.objects.create(title="publicpost",
                                                    body="some test text.",
                                                    group=self.publicgrp,
                                                    creator=self.creator)

        self.privatepost = GroupTopic.objects.create(
            title="privatepost",
            body="some more test text.",
            group=self.privategrp,
            creator=self.creator)

        self.tag = Tag.objects.create(name='testtag')
        self.item1 = TaggedItem.objects.create(tag=self.tag,
                                               object=self.publicpost)
        self.item2 = TaggedItem.objects.create(tag=self.tag,
                                               object=self.privatepost)

        m = GroupMember(user=self.grpadmin,
                        group=self.publicgrp,
                        is_admin=True)
        m.save()

        self.gtopic = ContentType.objects.get(app_label="group_topics",
                                              model="grouptopic")
Ejemplo n.º 3
0
    def setUp(self):
        self.creator = User.objects.create_user('creator', '*****@*****.**', 'password')
        self.creator.save()
        
        self.member = User.objects.create_user('member', '*****@*****.**', 'password')
        self.member.save()
        
        self.nonmember = User.objects.create_user('nonmember', '*****@*****.**', 'password')
        self.nonmember.save()
        
        self.admin = User.objects.create_user('admin', '*****@*****.**', 'password')
        self.admin.is_superuser = True
        self.admin.save()
        
        self.grpadmin = User.objects.create_user('grpadmin', '*****@*****.**', 'password')
        self.grpadmin.save()
        
        self.publicgrp = Network.objects.create(slug='publicgrp',
                                                name='a public group',
                                                creator=self.member,
                                                visibility='E')
        self.privategrp = BaseGroup.objects.create(slug='privategrp',
                                                   name='a private group',
                                                   creator=self.member,
                                                   model='Community',
                                                   visibility='M',
                                                   parent=self.publicgrp)
        
        self.publicpost = GroupTopic.objects.create(title="publicpost",
                                                    body="some test text.",
                                                    group=self.publicgrp,
                                                    creator=self.creator)
        
        self.privatepost = GroupTopic.objects.create(title="privatepost",
                                                     body="some more test text.",
                                                     group=self.privategrp,
                                                     creator=self.creator)

        self.tag = Tag.objects.create(name='testtag')
        self.item1 = TaggedItem.objects.create(tag=self.tag, object=self.publicpost)
        self.item2 = TaggedItem.objects.create(tag=self.tag, object=self.privatepost)
        
        m = GroupMember(user=self.grpadmin,
                        group=self.publicgrp,
                        is_admin=True)
        m.save()

        self.gtopic = ContentType.objects.get(app_label="group_topics", model="grouptopic")
Ejemplo n.º 4
0
    def test_private_with_execovision2(self):
        # ensure someone with execovision access only has that power in their 
        # own group, not in all groups =)
        publicgrp2 = Network.objects.create(slug='publicgrp2',
                                             name='a public group2',
                                             creator=self.member,
                                             visibility='E')
        privategrp2 = BaseGroup.objects.create(slug='privategrp2',
                                              name='a private group2',
                                              creator=self.member,
                                              model='Community',
                                              visibility='M',
                                              parent=publicgrp2)
        
        privatepost2 = GroupTopic.objects.create(title="privatepost2",
                                                body="some more test text2.",
                                                group=privategrp2,
                                                creator=self.creator)

        self.grpadmin.get_profile().adminovision = True
        visible_to_admin = GroupTopic.objects.visible(self.grpadmin)
        self.assertFalse(privatepost2 in visible_to_admin)
        
        # but. because i'm paranoid.  a publicgrp2 admin *can* see privatepost2
        # and can't see privatepost.
        grpadmin2 = User.objects.create_user('grpadmin2', '*****@*****.**', 'password')
        grpadmin2.save()
        
        m2 = GroupMember(user=grpadmin2,
                        group=publicgrp2,
                        is_admin=True)
        m2.save()
        
        grpadmin2.get_profile().adminovision = True
        visible_to_admin = GroupTopic.objects.visible(grpadmin2)
        self.assertTrue(privatepost2 in visible_to_admin)
        self.assertFalse(self.privatepost in visible_to_admin)
        
        # and i'm way too paranoid.  if you're an admin of two networks...
        m3 = GroupMember(user=grpadmin2,
                        group=self.publicgrp,
                        is_admin=True)
        m3.save()
        
        visible_to_admin = GroupTopic.objects.visible(grpadmin2)
        self.assertTrue(privatepost2 in visible_to_admin)
        self.assertTrue(self.privatepost in visible_to_admin)
Ejemplo n.º 5
0
def create_work_record(request, username, object=None):
    form = WorkRecordForm(request.POST)
    other_user = User.objects.get(username=username)
    if form.is_valid():
        work_record = form.save(commit=False)
        work_record.user = other_user
        
        employer = form.cleaned_data['employer']
        # find network ID (based on name they entered)
        # TODO: remove from network when someone ends their employment
        networks = Network.objects.filter(name=employer)
        # networks = networks.filter(network_type='C')
        
        if networks.count() == 0:
            # FIXME: this is duplicated in networks.views.networks_index
            # (refactor to centralize)
            # also kinda dupicated below, create_work_record
            network = Network(network_type='C', slug=employer,
                              name=employer,
                              creator=other_user)
            network.save()
        else:
            network = networks[0]

        # FIXME this should be implemented as a signal - profiles should not know about GroupMember
        existing_members=network.members.filter(user=other_user)
        if existing_members.count() == 0:
            network_member = GroupMember(group=network, user=other_user, is_admin=False)
            network.members.add(network_member)
            network_member.save()

        work_record.network = network
        
        work_record.save()
        return HttpResponseRedirect(reverse('profile_detail', kwargs={'username': other_user.username }))

    else:
        return render_to_response(
                'profiles/new_work_record.html',
                {
                'form': form,
                'other_user': other_user,
                },
                context_instance=RequestContext(request)
                )
Ejemplo n.º 6
0
    def test_private_with_execovision2(self):
        # ensure someone with execovision access only has that power in their
        # own group, not in all groups =)
        publicgrp2 = Network.objects.create(slug='publicgrp2',
                                            name='a public group2',
                                            creator=self.member,
                                            visibility='E')
        privategrp2 = BaseGroup.objects.create(slug='privategrp2',
                                               name='a private group2',
                                               creator=self.member,
                                               model='Community',
                                               visibility='M',
                                               parent=publicgrp2)

        privatepost2 = GroupTopic.objects.create(title="privatepost2",
                                                 body="some more test text2.",
                                                 group=privategrp2,
                                                 creator=self.creator)

        self.grpadmin.get_profile().adminovision = True
        visible_to_admin = GroupTopic.objects.visible(self.grpadmin)
        self.assertFalse(privatepost2 in visible_to_admin)

        # but. because i'm paranoid.  a publicgrp2 admin *can* see privatepost2
        # and can't see privatepost.
        grpadmin2 = User.objects.create_user('grpadmin2', '*****@*****.**',
                                             'password')
        grpadmin2.save()

        m2 = GroupMember(user=grpadmin2, group=publicgrp2, is_admin=True)
        m2.save()

        grpadmin2.get_profile().adminovision = True
        visible_to_admin = GroupTopic.objects.visible(grpadmin2)
        self.assertTrue(privatepost2 in visible_to_admin)
        self.assertFalse(self.privatepost in visible_to_admin)

        # and i'm way too paranoid.  if you're an admin of two networks...
        m3 = GroupMember(user=grpadmin2, group=self.publicgrp, is_admin=True)
        m3.save()

        visible_to_admin = GroupTopic.objects.visible(grpadmin2)
        self.assertTrue(privatepost2 in visible_to_admin)
        self.assertTrue(self.privatepost in visible_to_admin)
Ejemplo n.º 7
0
def create_student_record(request, username, object=None):
    form = StudentRecordForm(request.POST)
    other_user = User.objects.get(username=username)
    if form.is_valid():
        student_record = form.save(commit=False)
        student_record.user = other_user
        
        # find network ID (based on name they entered)
        # TODO: remove from network when someone ends their employment
        institution = form.cleaned_data['institution']
        networks = Network.objects.filter(name=institution)
        # networks = networks.filter(network_type='U')
        
        if networks.count() == 0:
            network = Network(network_type='U', slug=institution,
                              name=institution,
                              creator=other_user)
            network.save()
        else:
            network = networks[0]

        # FIXME this should be implemented as a signal - profiles should not know about GroupMember
        existing_members=network.members.filter(user=other_user)
        if existing_members.count() == 0:
            network_member = GroupMember(group=network, user=other_user, is_admin=False)
            network.members.add(network_member)
            network_member.save()

        student_record.network = network
        
        student_record.save()
        return HttpResponseRedirect(reverse('profile_detail', kwargs={'username': other_user.username }))
        
    else:
        return render_to_response(
                'profiles/new_student_record.html',
                {
                'form': form,
                'other_user': other_user,
                },
                context_instance=RequestContext(request)
                )
Ejemplo n.º 8
0
    def setUp(self):

        # an admin of the parent group, non-member of the child group
        self.u = User.objects.create_user('user', '*****@*****.**', 'password')
        
        # a member (non-admin) of the parent group, non-member of the child group
        self.u2 = User.objects.create_user('user2', '*****@*****.**', 'password')
        
        # admin of the child group
        self.u3 = User.objects.create_user('user3', '*****@*****.**', 'password')
        
        # member (non-admin) of the child group
        self.u4 = User.objects.create_user('user4', '*****@*****.**', 'password')
        
        # random nobody
        self.u5 = User.objects.create_user('user5', '*****@*****.**', 'password')
        
        # set up the groups & memberships...s
        self.parent = BaseGroup.objects.create(slug='bg',
                                               name='a base group',
                                               creator=self.u,
                                               visibility='E')
        m = GroupMember(group=self.parent,
                        user=self.u2,
                        is_admin=False)
        m.save()
        
        self.child = Community.objects.create(slug='community',
                                              name='a community',
                                              creator=self.u3,
                                              parent=self.parent,
                                              visibility='M')
        m2 = GroupMember(group=self.child,
                         user=self.u4,
                         is_admin=False)
        m2.save()