Beispiel #1
0
 def load_interfaces_for(self, agent, interface_names=None, diagnose=None) :
     """Load interfaces for the wrapped inner content that are available to the agent"""
     resource = self.get_inner()
     cls = resource.__class__
     interface_map = type_interfaces_map[cls.__name__]
     if not interface_names:
         interface_names = interface_map.keys()
     for iname in interface_names:
         interface = interface_map[iname]
         iface_name = self.get_inner().__class__.__name__ + '.' + iname
         #XXX we certainly shouldn't do an individual has access check for each interface but rather process them all at the same time
         if has_access(agent=agent, resource=resource, interface=iface_name, diagnose=diagnose):
             self._interfaces.add(iface_name)
             self.add_permissions(interface)
Beispiel #2
0
    def test_application(self):

        god = get_admin_user(
        )  # now a standard user, and member of the site_members_group's admin
        site = get_site(god)

        contact = site.create_Contact(god,
                                      first_name='kate',
                                      last_name='smith',
                                      email_address='*****@*****.**')
        contact.save()

        self.assertTrue(contact.get_inner().get_creator())

        group = site.create_TgGroup(god,
                                    group_name='sexy_salad',
                                    display_name='Sexy Salad',
                                    level='member')

        self.assertTrue(
            group.get_inner().get_creator())  # group should have a creator
        self.assertEquals(group.get_inner().get_creator().id, god.id)

        application = site.create_Application(god,
                                              applicant=contact,
                                              request='I want to join in')

        # the following should be true because application was created by god
        # so god is its "creator" and default for Application.Editor is "creator"

        self.assertTrue(has_access(god, application, 'Application.Editor'))
        application.group = group.get_inner()
        application.save()

        self.assertTrue(has_access(group, application, 'Application.Viewer'))

        self.assertEquals(application.date.date(),
                          datetime.datetime.today().date())

        self.assertTrue(application.applicant.s_eq(contact))
        self.assertEquals(application.request, 'I want to join in')
        self.assertTrue(application.group.s_eq(group))
        self.assertEquals(application.status, PENDING)
        self.assertEquals(application.admin_comment, '')
        self.assertEquals(application.accepted_by, None)

        # adding a couple more

        ap2 = site.create_Application(god,
                                      applicant=contact,
                                      request='ap2',
                                      group=get_anonymous_group())
        ap3 = site.create_Application(god,
                                      applicant=contact,
                                      request='ap3',
                                      group=get_all_members_group())

        self.assertEquals(self.count(Application.objects.filter()), 3)
        self.assertEquals(
            self.count(Application.objects.filter(request='ap2')), 1)

        mable = User(username='******', email_address='*****@*****.**')
        mable.save()
        self.assertEquals(Application.objects.plus_count(mable), 0)

        # now there's a security tag which links "group" as context to the interface "ApplicationViewer"
        site.get_inner().get_security_context().add_arbitrary_agent(
            group, 'Application.Viewer', god)

        self.assertTrue(has_access(group, ap2, 'Application.Viewer'))

        self.assertFalse(has_access(mable, ap2, 'Application.Viewer'))

        self.assertEquals(Application.objects.plus_count(group), 3)

        s_application = Application.objects.plus_get(mable, id=application.id)

        def f(application, sponsor):
            application.accept(sponsor)

        self.assertRaises(PlusPermissionsNoAccessException, f, s_application,
                          mable)

        self.assertEquals(s_application.get_inner().status, PENDING)

        application = Application.objects.get(id=application.id)

        application.accept(mable, 'site_root', admin_comment='great choice')

        self.assertEquals(application.status, WAITING_USER_SIGNUP)
        self.assertEquals(application.admin_comment, 'great choice')
        self.assertEquals(application.accepted_by, mable)
Beispiel #3
0
    def test_application(self) :

        god = get_admin_user() # now a standard user, and member of the site_members_group's admin
        site = get_site(god)

        contact = site.create_Contact(god, first_name='kate', last_name='smith', email_address='*****@*****.**')
        contact.save()

        self.assertTrue(contact.get_inner().get_creator())

        group = site.create_TgGroup(god, group_name='sexy_salad', display_name='Sexy Salad', level='member')
        

        self.assertTrue(group.get_inner().get_creator()) # group should have a creator
        self.assertEquals(group.get_inner().get_creator().id,god.id)
        
        application = site.create_Application(god, applicant=contact, request='I want to join in')
        
        # the following should be true because application was created by god
        # so god is its "creator" and default for Application.Editor is "creator"

        self.assertTrue(has_access(god, application, 'Application.Editor'))
        application.group = group.get_inner()
        application.save()

        self.assertTrue(has_access(group,application,'Application.Viewer'))

        self.assertEquals(application.date.date(),datetime.datetime.today().date())


        self.assertTrue(application.applicant.s_eq(contact))
        self.assertEquals(application.request, 'I want to join in')
        self.assertTrue(application.group.s_eq(group))
        self.assertEquals(application.status, PENDING)
        self.assertEquals(application.admin_comment,'')
        self.assertEquals(application.accepted_by,None)


        # adding a couple more 

        ap2 = site.create_Application(god, applicant=contact,request='ap2',group=get_anonymous_group())
        ap3 = site.create_Application(god, applicant=contact,request='ap3',group=get_all_members_group())
        
        self.assertEquals(self.count(Application.objects.filter()),3)
        self.assertEquals(self.count(Application.objects.filter(request='ap2')),1)

        mable = User(username='******',email_address='*****@*****.**')
        mable.save()
        self.assertEquals(Application.objects.plus_count(mable),0)

        # now there's a security tag which links "group" as context to the interface "ApplicationViewer"
        site.get_inner().get_security_context().add_arbitrary_agent(group, 'Application.Viewer', god)
        
        self.assertTrue(has_access(group, ap2, 'Application.Viewer'))

        self.assertFalse(has_access(mable, ap2, 'Application.Viewer'))

        self.assertEquals(Application.objects.plus_count(group),3)
            
        s_application = Application.objects.plus_get(mable, id=application.id)
        
        def f(application,sponsor) :
            application.accept(sponsor)
        
        self.assertRaises(PlusPermissionsNoAccessException,f,s_application,mable)
            
        self.assertEquals(s_application.get_inner().status,PENDING)

        application = Application.objects.get(id=application.id)

        application.accept(mable, 'site_root', admin_comment='great choice')

        self.assertEquals(application.status,WAITING_USER_SIGNUP)
        self.assertEquals(application.admin_comment,'great choice')
        self.assertEquals(application.accepted_by, mable)