コード例 #1
0
ファイル: groups.py プロジェクト: GunioRobot/hubplus
def import_group(f_name, group_type, fn_place) :
    groups = pickle.load(open(f_name))
    admin = get_admin_user()
    site = get_site(admin)
    for g in groups:
        #print g.keys()
 
        print g['groupname'], g['body'], g['description'],g['joinpolicy'],g['imagefilename']

        if g['joinpolicy']== 'open' :
            permission_prototype='public'
        else :
            permission_prototype='private'

        description = ""
        if g['description'] :
            description = description + g['description']
        if g['body'] :
            description = description + g['body']
        if description == "" :
            description = 'About this group'

        display_name = g['groupname']
        group_name = psn_group_name(display_name)
        psn_id = g['uid']

        keywords = g['keywords']

        image_file = g['imagefilename'].split('/')[-1]

        print group_name, display_name, psn_id, permission_prototype,image_file
        print description
        print keywords

        groups = TgGroup.objects.filter(psn_id=psn_id)
        if groups : 
            group = groups[0]
        else :
            group = site.create_TgGroup(
                group_name = group_name,
                display_name = display_name,
                group_type = group_type ,
                level = 'member',
                user = admin,
                description = description,
                permission_prototype = permission_prototype,
                )
            group = group.get_inner()

        group.psn_id = psn_id
        group.group_name = group_name

        group.place = fn_place(g)        
        group.save()

        print "XX ", group.display_name, group.group_type
        if group.group_type != 'Hub' :
            add_avatar(group,"group_images",image_file)
        else :
            add_avatar(group,"hub_images",image_file)
コード例 #2
0
ファイル: tests.py プロジェクト: GunioRobot/hubplus
 def test_pp(self):
     god = get_admin_user()
     site = get_site(god)
     u = User(username='******', email_address='*****@*****.**')
     u.save()
     p = u.get_profile()
     self.assertTrue(p.get_ref())
     self.assertEquals(p.get_security_context(),site.get_inner().get_security_context())
コード例 #3
0
ファイル: tests.py プロジェクト: GunioRobot/hubplus
 def test_pp(self):
     god = get_admin_user()
     site = get_site(god)
     u = User(username='******', email_address='*****@*****.**')
     u.save()
     p = u.get_profile()
     self.assertTrue(p.get_ref())
     self.assertEquals(p.get_security_context(),
                       site.get_inner().get_security_context())
コード例 #4
0
ファイル: groups.py プロジェクト: mrchrisadams/hubplus
def import_group(f_name, group_type, fn_place) :
    groups = pickle.load(open(f_name))
    admin = get_admin_user()
    site = get_site(admin)
    for g in groups:
        print g.keys()
    #print g['groupname'], g['body'], g['description'],g['joinpolicy']
        if g['joinpolicy']== 'open' :
            permission_prototype='public'
        else :
            permission_prototype='private'

        description = ""
        if g['description'] :
            description = description + g['description']
        if g['body'] :
            description = description + g['body']
        if description == "" :
            description = 'About this group'

        group_name = make_name(g['groupname'])
        if len(group_name)>30 :
            group_name = group_name[30]
        display_name = g['groupname']
        psn_id = g['uid']

        keywords = g['keywords']

        print group_name, display_name, psn_id, permission_prototype
        print description
        print keywords

        groups = TgGroup.objects.filter(group_name=group_name)
        if groups : 
            group = groups[0]
        else :
            group = site.create_TgGroup(
                group_name = group_name,
                display_name = display_name,
                group_type = group_type ,
                level = 'member',
                user = admin,
                description = description,
                permission_prototype = permission_prototype,
                )
            group = group.get_inner()
        group.psn_id = psn_id
        
        group.place = fn_place(g)
        
        group.save()
コード例 #5
0
ファイル: decorators.py プロジェクト: mrchrisadams/hubplus
 def g(request, *args, **kwargs):
     user = request.user
     return f(request, get_site(user), *args, **kwargs)
コード例 #6
0
ファイル: tests.py プロジェクト: GunioRobot/hubplus
    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)
コード例 #7
0
ファイル: tests.py プロジェクト: GunioRobot/hubplus
    def test_invite(self):
        site = get_site(get_admin_user())
        all_members = get_all_members_group()

        u = create_user('fred', '*****@*****.**')
コード例 #8
0
ファイル: decorators.py プロジェクト: GunioRobot/hubplus
 def g(request, *args, **kwargs):
     user = request.user
     return f(request, get_site(user), *args, **kwargs)
コード例 #9
0
ファイル: tests.py プロジェクト: GunioRobot/hubplus
    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)
コード例 #10
0
ファイル: tests.py プロジェクト: GunioRobot/hubplus
    def test_invite(self):
        site = get_site(get_admin_user())
        all_members = get_all_members_group()

        u = create_user('fred','*****@*****.**')