Пример #1
0
def creausuario(sender,user,request,**kwargs):
	if user.is_superuser == False:
		#Activar idioma
		activate('en')
		#Lista de permisos
		permisos=['Can add article','Can view article','Can change article','Can delete article','Can add cms plugin','Can view cms plugin','Can change cms plugin','Can delete cms plugin','Can add placeholder','Can view placeholder','Can change placeholder','Can delete placeholder','Can use Structure mode','Can add placeholder reference','Can change placeholder reference','Can add content type','Can change content type','Can delete content type','Can view content type']			#Al usuario que se está registrando se le añaden los permisos, y se guarda
		usuario=User.objects.get(username=user.username)
		for p in permisos:
			per=Permission.objects.get(name=str(p))
			usuario.user_permissions.add(per)
		usuario.save()
			#Crearmos la Userpage, el blog para el usuario y la página del usuario, luego
		#asignaremos permisos y finalmente publicaremos la página.
		try:
			Page.objects.get(created_by=usuario)
		except Page.DoesNotExist:
			#Crear UserPage
			api.create_page_user(created_by=usuario,user=usuario,can_add_page=True)
			#Crear Blog
			blog=NewsBlogConfig()
			blog.app_title=usuario.username
			blog.namespace=usuario.username
			blog.save()
			#Crear pagina del usuario
			pagina=api.create_page(title=usuario.username,language='en',template=TEMPLATE_INHERITANCE_MAGIC,parent=None,created_by=usuario,apphook='NewsBlogApp',apphook_namespace=usuario.username) 
			#Permisos de usuario
			api.assign_user_to_page(pagina,usuario,can_add=True,can_change=True,can_delete=True)
			pagina.publish('en')
			pagina.save()
Пример #2
0
def creasitios(sender, user, request, **kwargs):
    #Comprobamos que el usuario que se conecta no es el administrador, para evitar que se dispare el script en tal caso
    if user.username != "Administracion":
        #Indicamos que queremos utilizar el idioma español en la creacion
        activate('es')
        #Probamos a comprobar si ese usuario tiene una pagina o no
        try:
            Page.objects.get(created_by=user.username)
        #Si no la tiene pasamos a asignarle los permisos al usuario y crearle la página, ya que damos por supuesto que dicho usuario no existia
        except Page.DoesNotExist:
            #Indicamos la lista de permisos
            permisos = [
                'Can add boostrap3 panel body plugin',
                'Can change boostrap3 panel body plugin',
                'Can add boostrap3 panel plugin',
                'Can change boostrap3 panel plugin', 'Can add article',
                'Can change article', 'Can delete article',
                'Can add cms plugin', 'Can change cms plugin',
                'Can delete cms plugin', 'Can add placeholder',
                'Can change placeholder', 'Can delete placeholder',
                'Can use Structure mode', 'Can add placeholder reference',
                'Can change placeholder reference', 'Can add content type',
                'Can change content type', 'Can delete content type'
            ]
            usuario = User.objects.get(username=user.username)
            #Le añadimos los permisos al usuario que estamos creando
            for ele in permisos:
                per = Permission.objects.get(name=str(ele))
                usuario.user_permissions.add(per)
            #Guardamos el usuario
            usuario.save()
            #Creamos el usuario de página
            api.create_page_user(created_by=usuario,
                                 user=usuario,
                                 can_add_page=True)
            #Creamos el blog y lo configuramos
            blog = NewsBlogConfig()
            blog.app_title = usuario.username
            blog.namespace = usuario.username
            #Guardamos el blog en nuestra base de datos
            blog.save()
            #Le creamos una página al usuario
            pagina = api.create_page(title=usuario.username,
                                     language='es',
                                     template=TEMPLATE_INHERITANCE_MAGIC,
                                     parent=None,
                                     created_by=usuario,
                                     apphook='NewsBlogApp',
                                     apphook_namespace=usuario.username)
            #Se la asignamos
            api.assign_user_to_page(pagina,
                                    usuario,
                                    can_add=True,
                                    can_change=True,
                                    can_delete=True)
            #Publicamos la página para que sea visile por el resto de usuarios.
            pagina.publish('es')
Пример #3
0
def nuevousuario(sender,user,request,**kwargs):
	if user.username != "administrador":
		activate('en')
		if Page.objects.filter(created_by=user).count() <= 0:
            usuario=User.objects.get(username=user.username)
		    usuario.save()				
			api.create_page_user(created_by=usuario,user=usuario,can_add_page=True)
			blog=NewsBlogConfig()
			blog.app_title=usuario.username
			blog.namespace=usuario.username
			blog.save()
			pagina=api.create_page(title=usuario.username,language='en',template=TEMPLATE_INHERITANCE_MAGIC,parent=None,in_navigation=True,created_by=usuario,apphook='NewsBlogApp',apphook_namespace=usuario.username) 
			api.assign_user_to_page(pagina,usuario,can_add=True,can_change=True,can_delete=True)
			pagina.publish('en')
			print("Usuario y blog creado")
Пример #4
0
 def test_mail_page_user_change(self):
     user = User.objects.create_superuser("username",
                                          "*****@*****.**",
                                          "username")
     user = create_page_user(user, user, grant_all=True)
     mail_page_user_change(user)
     self.assertEqual(len(mail.outbox), 1)
Пример #5
0
    def test_user_globalpermission(self):
        # Global user
        with self.login_user_context(self.user_super):
            user_global = User(username="******", is_active=True)
            user_global.set_password("global")
            user_global.save()
            user_global = create_page_user(user_global, user_global)
            user_global.is_staff = False
            user_global.save() # Prevent is_staff permission
            global_page = create_page("global", "nav_playground.html", "en",
                                      published=True)
            global_page = publish_page(global_page, user_global, approve=True)
            # it's allowed for the normal user to view the page
            assign_user_to_page(global_page, user_global,
                global_permission=True, can_view=True)
        
        url = global_page.get_absolute_url('en')

        with self.login_user_context(user_global):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 200)

        with self.login_user_context(self.user_non_global):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 404)
Пример #6
0
 def test_page_user_form_initial(self):
     myuser = User.objects.create_superuser("myuser", "*****@*****.**", "myuser")
     user = create_page_user(myuser, myuser, grant_all=True)
     puf = PageUserForm(instance=user)
     names = ['can_add_page', 'can_change_page', 'can_delete_page',
              'can_add_pageuser', 'can_change_pageuser',
              'can_delete_pageuser', 'can_add_pagepermission',
              'can_change_pagepermission', 'can_delete_pagepermission']
     for name in names:
         self.assertTrue(puf.initial.get(name, False))
Пример #7
0
 def test_page_user_form_initial(self):
     myuser = User.objects.create_superuser("myuser", "*****@*****.**", "myuser")
     user = create_page_user(myuser, myuser, grant_all=True)
     puf = PageUserForm(instance=user)
     names = ['can_add_page', 'can_change_page', 'can_delete_page',
              'can_add_pageuser', 'can_change_pageuser',
              'can_delete_pageuser', 'can_add_pagepermission',
              'can_change_pagepermission', 'can_delete_pagepermission']
     for name in names:
         self.assertTrue(puf.initial.get(name, False))
    def test_user_globalpermission(self):
        # Global user
        user_global = User(username="******", is_active=True)
        user_global.set_password("global")
        user_global.save()
        with self.login_user_context(self.user_super):
            user_global = create_page_user(user_global, user_global)
            user_global.is_staff = False
            user_global.save()  # Prevent is_staff permission
            global_page = create_page("global",
                                      "nav_playground.html",
                                      "en",
                                      published=True)
            # Removed call since global page user doesn't have publish permission
            #global_page = publish_page(global_page, user_global)
            # it's allowed for the normal user to view the page
            assign_user_to_page(global_page,
                                user_global,
                                global_permission=True,
                                can_view=True)

        url = global_page.get_absolute_url('en')
        all_view_perms = PagePermission.objects.filter(can_view=True)
        has_perm = False
        for perm in all_view_perms:
            if perm.page == self.page_b and perm.user == user_global:
                has_perm = True
        self.assertEqual(has_perm, False)

        global_page_perm_q = Q(user=user_global) & Q(can_view=True)
        global_view_perms = GlobalPagePermission.objects.filter(
            global_page_perm_q).exists()
        self.assertEqual(global_view_perms, True)

        # user_global
        with self.login_user_context(user_global):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 200)
            # self.non_user_global
        has_perm = False
        for perm in all_view_perms:
            if perm.page == self.page_b and perm.user == self.user_non_global:
                has_perm = True
        self.assertEqual(has_perm, False)

        global_page_perm_q = Q(user=self.user_non_global) & Q(can_view=True)
        global_view_perms = GlobalPagePermission.objects.filter(
            global_page_perm_q).exists()
        self.assertEqual(global_view_perms, False)

        with self.login_user_context(self.user_non_global):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 404)
Пример #9
0
	def handle(self, *args, **options):
		activate('en')
		user=options['user']
		usuario=LDAPBackend().populate_user(user)
		if usuario is None:
			self.stdout.write(self.style.SUCCESS('Usuario no existe'))
		else:				
			if Page.objects.filter(created_by=user).count() <= 0:
				api.create_page_user(created_by=usuario,user=usuario,can_add_page=True)

				blog=NewsBlogConfig()
				blog.app_title=usuario.username
				blog.namespace=usuario.username
				blog.save()

				pagina=api.create_page(title=usuario.username,language='en',template=TEMPLATE_INHERITANCE_MAGIC,parent=None,in_navigation=True,created_by=usuario,apphook='NewsBlogApp',apphook_namespace=usuario.username) 
				api.assign_user_to_page(pagina,usuario,can_add=True,can_change=True,can_delete=True)
				pagina.publish('en')
				self.stdout.write(self.style.SUCCESS('Usuario y blog creado'))
			else:
				self.stdout.write(self.style.SUCCESS('El usuario ya tiene su página y su blog'))
Пример #10
0
    def test_user_globalpermission(self):
        # Global user
        User = auth.get_user_model()
        user_global = User(username="******", is_active=True)
        user_global.set_password("global")
        user_global.save()
        with self.login_user_context(self.user_super):
            user_global = create_page_user(user_global, user_global)
            user_global.is_staff = False
            user_global.save() # Prevent is_staff permission
            global_page = create_page("global", "nav_playground.html", "en",
                                      published=True)
            # Removed call since global page user doesn't have publish permission
            #global_page = publish_page(global_page, user_global)
            # it's allowed for the normal user to view the page
            assign_user_to_page(global_page, user_global, 
                                global_permission=True, can_view=True)
        
        url = global_page.get_absolute_url('en')
        all_view_perms = PagePermission.objects.filter(can_view=True)
        has_perm = False
        for perm in all_view_perms:
            if perm.page == self.page_b and perm.user == user_global:
                has_perm = True
        self.assertEqual(has_perm, False)
        
        global_page_perm_q = Q(user=user_global) & Q(can_view=True)
        global_view_perms = GlobalPagePermission.objects.filter(global_page_perm_q).exists()
        self.assertEqual(global_view_perms, True)
        
        # user_global
        with self.login_user_context(user_global):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 200)
        # self.non_user_global
        has_perm = False
        for perm in all_view_perms:
            if perm.page == self.page_b and perm.user == self.user_non_global:
                has_perm = True
        self.assertEqual(has_perm, False)

        global_page_perm_q = Q(user=self.user_non_global) & Q(can_view=True)
        global_view_perms = GlobalPagePermission.objects.filter(global_page_perm_q).exists()
        self.assertEqual(global_view_perms, False)
        
        with self.login_user_context(self.user_non_global):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 404)
Пример #11
0
    def test_page_user_form_initial(self):
        if get_user_model().USERNAME_FIELD == "email":
            myuser = get_user_model().objects.create_superuser(
                "myuser", "*****@*****.**", "*****@*****.**"
            )
        else:
            myuser = get_user_model().objects.create_superuser("myuser", "*****@*****.**", "myuser")

        user = create_page_user(myuser, myuser, grant_all=True)
        puf = PageUserForm(instance=user)
        names = [
            "can_add_page",
            "can_change_page",
            "can_delete_page",
            "can_add_pageuser",
            "can_change_pageuser",
            "can_delete_pageuser",
            "can_add_pagepermission",
            "can_change_pagepermission",
            "can_delete_pagepermission",
        ]
        for name in names:
            self.assertTrue(puf.initial.get(name, False))
Пример #12
0
 def setUp(self):
     # create super user
     self.user_super = User(username="******", is_staff=True, is_active=True, 
         is_superuser=True)
     self.user_super.set_password("super")
     self.user_super.save()
     with self.login_user_context(self.user_super):
     
         self._home_page = create_page("home", "nav_playground.html", "en",
                                      created_by=self.user_super)
         
         # master page & master user
         
         self._master_page = create_page("master", "nav_playground.html", "en")
 
         # create master user
         master = User.objects.create(username="******", email="*****@*****.**", password="******")
         self.user_master = create_page_user(self.user_super, master, grant_all=True)
         
         # assign master user under home page
         assign_user_to_page(self.home_page, self.user_master,
                             grant_on=ACCESS_DESCENDANTS, grant_all=True)
         
         # and to master page
         assign_user_to_page(self.master_page, self.user_master, grant_all=True)
         
         # slave page & slave user
         
         self._slave_page = create_page("slave-home", "nav_playground.html", "en",
                           parent=self.master_page, created_by=self.user_super)
         slave = User(username='******', email='*****@*****.**', is_staff=True, is_active=True)
         slave.set_password('slave')
         slave.save()
         self.user_slave = create_page_user(self.user_super, slave,  can_add_page=True,
                                     can_change_page=True, can_delete_page=True)
         
         assign_user_to_page(self.slave_page, self.user_slave, grant_all=True)
         
         # create page_a - sample page from master
         
         page_a = create_page("pageA", "nav_playground.html", "en",
                              created_by=self.user_super)
         assign_user_to_page(page_a, self.user_master, 
             can_add=True, can_change=True, can_delete=True, can_publish=True, 
             can_move_page=True, can_moderate=True)
         
         # publish after creating all drafts
         publish_page(self.home_page, self.user_super)
         publish_page(self.master_page, self.user_super)
         # logg in as master, and request moderation for slave page and descendants
         self.request_moderation(self.slave_page, 7)
     
     with self.login_user_context(self.user_slave):
     
         # all of them are under moderation... 
         self._pa = create_page("pa", "nav_playground.html", "en", parent=self.slave_page)
         self._pb = create_page("pb", "nav_playground.html", "en", parent=self.pa, position="right")
         self._pc = create_page("pc", "nav_playground.html", "en", parent=self.pb, position="right")
         
         self._pd = create_page("pd", "nav_playground.html", "en", parent=self.pb)
         self._pe = create_page("pe", "nav_playground.html", "en", parent=self.pd, position="right")
         
         self._pf = create_page("pf", "nav_playground.html", "en", parent=self.pe)
         self._pg = create_page("pg", "nav_playground.html", "en", parent=self.pf, position="right")
         self._ph = create_page("ph", "nav_playground.html", "en", parent=self.pf, position="right")
         
         self.assertFalse(self.pg.publisher_public)
         
         # login as master for approval
         publish_page(self.slave_page, self.user_master, approve=True)
         
         # publish and approve them all
         publish_page(self.pa, self.user_master, approve=True)
         publish_page(self.pb, self.user_master, approve=True)
         publish_page(self.pc, self.user_master, approve=True)
         publish_page(self.pd, self.user_master, approve=True)
         publish_page(self.pe, self.user_master, approve=True)
         publish_page(self.pf, self.user_master, approve=True)
         publish_page(self.pg, self.user_master, approve=True)
         publish_page(self.ph, self.user_master, approve=True)
Пример #13
0
    def setUp(self):
        # create super user
        self.user_super = User(username="******", is_staff=True, is_active=True, 
            is_superuser=True)
        self.user_super.set_password("super")
        self.user_super.save()
        # create staff user
        self.user_staff = User(username="******", is_staff=True, is_active=True)
        self.user_staff.set_password("staff")
        self.user_staff.save()
        
        with self.login_user_context(self.user_super):
            
            self._home_page = create_page("home", "nav_playground.html", "en",
                                         created_by=self.user_super)
        
            # master page & master user
            
            self._master_page = create_page("master", "nav_playground.html", "en")
            
            # create master user
            master = User(username="******", email="*****@*****.**", is_staff=True, is_active=True)
            master.set_password('master')
            master.save()
            master.user_permissions.add(Permission.objects.get(codename='add_text'))
            master.user_permissions.add(Permission.objects.get(codename='delete_text'))
            master.user_permissions.add(Permission.objects.get(codename='change_text'))
            
            self.user_master = create_page_user(self.user_super, master, grant_all=True)
            # create non global, non staff user
            self.user_non_global = User(username="******", is_active=True)
            self.user_non_global.set_password("nonglobal")
            self.user_non_global.save()
            
            # assign master user under home page
            assign_user_to_page(self.home_page, self.user_master,
                                grant_on=ACCESS_DESCENDANTS, grant_all=True)
            
            # and to master page
            assign_user_to_page(self.master_page, self.user_master,
                                grant_on=ACCESS_PAGE_AND_DESCENDANTS, grant_all=True)
            
            # slave page & slave user
            
            self._slave_page = create_page("slave-home", "nav_playground.html", "en",
                              parent=self.master_page, created_by=self.user_super)
        
            slave = User(username='******', email='*****@*****.**', is_staff=True)
            slave.set_password('slave')
            slave.save()
            slave.user_permissions.add(Permission.objects.get(codename='add_text'))
            slave.user_permissions.add(Permission.objects.get(codename='delete_text'))
            slave.user_permissions.add(Permission.objects.get(codename='change_text'))
            
            self.user_slave = create_page_user(self.user_super, slave,  can_add_page=True,
                                        can_change_page=True, can_delete_page=True)
            
            assign_user_to_page(self.slave_page, self.user_slave, grant_all=True)
    
            # create page_b
            page_b = create_page("pageB", "nav_playground.html", "en", created_by=self.user_super)
            # Normal user
            normal = User(username='******', email='*****@*****.**', is_active=True)
            normal.set_password('normal')
            normal.save()
            self.user_normal = create_page_user(self.user_master, normal)
            # it's allowed for the normal user to view the page
            assign_user_to_page(page_b, self.user_normal, can_view=True)
            self.user_normal = self.reload(self.user_normal)
            # create page_a - sample page from master
            
            page_a = create_page("pageA", "nav_playground.html", "en",
                                 created_by=self.user_super)
            assign_user_to_page(page_a, self.user_master, 
                can_add=True, can_change=True, can_delete=True, can_publish=True, 
                can_move_page=True, can_moderate=True)

            # publish after creating all drafts
            publish_page(self.home_page, self.user_super)
            
            publish_page(self.master_page, self.user_super)
            
            self.page_b = publish_page(page_b, self.user_super)
            # logg in as master, and request moderation for slave page and descendants
            self.request_moderation(self.slave_page, 7)
Пример #14
0
    def handle(self, *args, **options):
        #Activamos el idioma que queremos que utilice en nuestro sitio
        activate('es')
        #Guardamos el parametro de usuario que hemos pasado anteriormente en una variable
        usr = options['user']
        #Introducimos una lista con todos los permisos genericos que tendrá dicho usuario
        permisos = [
            'Can add boostrap3 panel body plugin',
            'Can change boostrap3 panel body plugin',
            'Can add boostrap3 panel plugin',
            'Can change boostrap3 panel plugin', 'Can add article',
            'Can change article', 'Can delete article', 'Can add cms plugin',
            'Can change cms plugin', 'Can delete cms plugin',
            'Can add placeholder', 'Can change placeholder',
            'Can delete placeholder', 'Can use Structure mode',
            'Can add placeholder reference',
            'Can change placeholder reference', 'Can add content type',
            'Can change content type', 'Can delete content type'
        ]

        usuario = LDAPBackend().populate_user(usr)
        #Comprobamos si el usuario existe o no en LDAP
        if usuario is None:
            self.stdout.write(
                self.style.SUCCESS('No existe el usuario en LDAP.'))
        else:
            #Asignamos los permisos al usuario
            for ele in permisos:
                per = Permission.objects.get(name=str(ele))
                usuario.user_permissions.add(per)
            usuario.save()
            #Comprobamos si existe la página del usuario
            try:
                Page.objects.get(created_by=usuario)

            except Page.DoesNotExist:
                #Creamos un Page User
                api.create_page_user(created_by=usuario,
                                     user=usuario,
                                     can_add_page=True)
                #Creamos el blog del usuario
                blog = NewsBlogConfig()
                blog.app_title = usuario.username
                blog.namespace = usuario.username
                blog.save()
                #Creamos la pagina del usuario.
                pagina = api.create_page(title=usuario.username,
                                         language='es',
                                         template=TEMPLATE_INHERITANCE_MAGIC,
                                         parent=None,
                                         created_by=usuario,
                                         apphook='NewsBlogApp',
                                         apphook_namespace=usuario.username)
                #Asignamos los permisos que tendra el usuario sobre su pagina.
                api.assign_user_to_page(pagina,
                                        usuario,
                                        can_add=True,
                                        can_change=True,
                                        can_delete=True)
                #Publicamos la pagina
                pagina.publish('es')
                self.stdout.write(
                    self.style.SUCCESS(
                        'Creacion de usuario finalizada con sus respectivos añadidos.'
                    ))

            else:
                self.stdout.write(
                    self.style.SUCCESS(
                        'El usuario ya tiene páginas en su propiedad.'))
Пример #15
0
    def setUp(self):
        # create super user
        self.user_super = self._create_user("super", True, True)

        with self.login_user_context(self.user_super):
            self.home_page = create_page("home",
                                         "nav_playground.html",
                                         "en",
                                         created_by=self.user_super)

            # master page & master user

            self.master_page = create_page("master", "nav_playground.html",
                                           "en")

            # create master user
            self.user_master = self._create_user("master", True)
            self.add_permission(self.user_master, 'change_page')
            self.add_permission(self.user_master, 'publish_page')
            #self.user_master = create_page_user(self.user_super, master, grant_all=True)

            # assign master user under home page
            assign_user_to_page(self.home_page,
                                self.user_master,
                                grant_on=ACCESS_DESCENDANTS,
                                grant_all=True)

            # and to master page
            assign_user_to_page(self.master_page,
                                self.user_master,
                                grant_all=True)

            # slave page & slave user

            self.slave_page = create_page("slave-home",
                                          "nav_playground.html",
                                          "en",
                                          parent=self.master_page,
                                          created_by=self.user_super)
            slave = self._create_user("slave", True)
            self.user_slave = create_page_user(self.user_super,
                                               slave,
                                               can_add_page=True,
                                               can_change_page=True,
                                               can_delete_page=True)

            assign_user_to_page(self.slave_page,
                                self.user_slave,
                                grant_all=True)

            # create page_a - sample page from master

            page_a = create_page("pageA",
                                 "nav_playground.html",
                                 "en",
                                 created_by=self.user_super)
            assign_user_to_page(page_a,
                                self.user_master,
                                can_add=True,
                                can_change=True,
                                can_delete=True,
                                can_publish=True,
                                can_move_page=True)

            # publish after creating all drafts
            publish_page(self.home_page, self.user_super, 'en')
            publish_page(self.master_page, self.user_super, 'en')

        with self.login_user_context(self.user_slave):
            # 000200010001
            self.pa = create_page("pa",
                                  "nav_playground.html",
                                  "en",
                                  parent=self.slave_page)
            # 000200010002
            self.pb = create_page("pb",
                                  "nav_playground.html",
                                  "en",
                                  parent=self.pa,
                                  position="right")
            # 000200010003
            self.pc = create_page("pc",
                                  "nav_playground.html",
                                  "en",
                                  parent=self.pb,
                                  position="right")

            self.pd = create_page("pd",
                                  "nav_playground.html",
                                  "en",
                                  parent=self.pb)
            self.pe = create_page("pe",
                                  "nav_playground.html",
                                  "en",
                                  parent=self.pd,
                                  position="right")

            self.pf = create_page("pf",
                                  "nav_playground.html",
                                  "en",
                                  parent=self.pe)
            self.pg = create_page("pg",
                                  "nav_playground.html",
                                  "en",
                                  parent=self.pf,
                                  position="right")
            self.ph = create_page("ph",
                                  "nav_playground.html",
                                  "en",
                                  parent=self.pf,
                                  position="right")

            self.assertFalse(self.pg.publisher_public)

            # login as master for approval
            self.slave_page = self.slave_page.reload()

            publish_page(self.slave_page, self.user_master, 'en')

            # publish and approve them all
            publish_page(self.pa, self.user_master, 'en')
            publish_page(self.pb, self.user_master, 'en')
            publish_page(self.pc, self.user_master, 'en')
            publish_page(self.pd, self.user_master, 'en')
            publish_page(self.pe, self.user_master, 'en')
            publish_page(self.pf, self.user_master, 'en')
            publish_page(self.pg, self.user_master, 'en')
            publish_page(self.ph, self.user_master, 'en')
            self.reload_pages()
Пример #16
0
    def handle(self, *args, **options):
        #Activar idioma
        activate('en')
        #Recuperar el parámetro guardándolo en la variables user
        user = options['user']
        #Lista de permisos
        permisos = [
            'Can add article', 'Can view article', 'Can change article',
            'Can delete article', 'Can add cms plugin', 'Can view cms plugin',
            'Can change cms plugin', 'Can delete cms plugin',
            'Can add placeholder', 'Can view placeholder',
            'Can change placeholder', 'Can delete placeholder',
            'Can use Structure mode', 'Can add placeholder reference',
            'Can change placeholder reference', 'Can add content type',
            'Can change content type', 'Can delete content type',
            'Can view content type'
        ]
        usuario = LDAPBackend().populate_user(user)
        #Si el usuairo no existe en LDAP asignaremos permisos y si no existe la página del usuario crearmos la Userpage, el blog para el usuario y la página del usuario, luego
        #asignaremos permisos y finalmente publicaremos la página.
        #si ya existe la página del usuario entonces mostramos un mensaje informativo.
        if usuario is None:
            self.stdout.write(
                self.style.SUCCESS('No existe ese usuario en LDAP.'))

        else:
            for p in permisos:
                per = Permission.objects.get(name=str(p))
                usuario.user_permissions.add(per)
            usuario.save()

            try:
                Page.objects.get(created_by=usuario)

            except Page.DoesNotExist:
                #Crear UserPage
                api.create_page_user(created_by=usuario,
                                     user=usuario,
                                     can_add_page=True)
                #Crear Blog
                blog = NewsBlogConfig()
                blog.app_title = usuario.username
                blog.namespace = usuario.username
                blog.save()
                #Crear pagina del usuario
                pagina = api.create_page(title=usuario.username,
                                         language='en',
                                         template=TEMPLATE_INHERITANCE_MAGIC,
                                         parent=None,
                                         created_by=usuario,
                                         apphook='NewsBlogApp',
                                         apphook_namespace=usuario.username)
                #Permisos de usuario
                api.assign_user_to_page(pagina,
                                        usuario,
                                        can_add=True,
                                        can_change=True,
                                        can_delete=True)

                pagina.publish('en')
                self.stdout.write(
                    self.style.SUCCESS(
                        'Creación de usuario y blog finalizada'))

            else:
                self.stdout.write(
                    self.style.SUCCESS(
                        'El usuario ya tiene página y blog creados'))
Пример #17
0
 def test_mail_page_user_change(self):
     User = auth.get_user_model()
     user = User.objects.create_superuser("username", "*****@*****.**", "username")
     user = create_page_user(user, user, grant_all=True)
     mail_page_user_change(user)
     self.assertEqual(len(mail.outbox), 1)
Пример #18
0
    def setUp(self):
        # create super user
        self.user_super = User(username="******",
                               is_staff=True,
                               is_active=True,
                               is_superuser=True)
        self.user_super.set_password("super")
        self.user_super.save()
        # create staff user
        self.user_staff = User(username="******", is_staff=True, is_active=True)
        self.user_staff.set_password("staff")
        self.user_staff.save()

        with self.login_user_context(self.user_super):

            self._home_page = create_page("home",
                                          "nav_playground.html",
                                          "en",
                                          created_by=self.user_super)

            # master page & master user

            self._master_page = create_page("master", "nav_playground.html",
                                            "en")

            # create master user
            master = User(username="******",
                          email="*****@*****.**",
                          is_staff=True,
                          is_active=True)
            master.set_password('master')
            master.save()
            master.user_permissions.add(
                Permission.objects.get(codename='add_text'))
            master.user_permissions.add(
                Permission.objects.get(codename='delete_text'))
            master.user_permissions.add(
                Permission.objects.get(codename='change_text'))

            self.user_master = create_page_user(self.user_super,
                                                master,
                                                grant_all=True)
            # create non global, non staff user
            self.user_non_global = User(username="******", is_active=True)
            self.user_non_global.set_password("nonglobal")
            self.user_non_global.save()

            # assign master user under home page
            assign_user_to_page(self.home_page,
                                self.user_master,
                                grant_on=ACCESS_DESCENDANTS,
                                grant_all=True)

            # and to master page
            assign_user_to_page(self.master_page,
                                self.user_master,
                                grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                                grant_all=True)

            # slave page & slave user

            self._slave_page = create_page("slave-home",
                                           "nav_playground.html",
                                           "en",
                                           parent=self.master_page,
                                           created_by=self.user_super)

            slave = User(username='******',
                         email='*****@*****.**',
                         is_staff=True)
            slave.set_password('slave')
            slave.save()
            slave.user_permissions.add(
                Permission.objects.get(codename='add_text'))
            slave.user_permissions.add(
                Permission.objects.get(codename='delete_text'))
            slave.user_permissions.add(
                Permission.objects.get(codename='change_text'))

            self.user_slave = create_page_user(self.user_super,
                                               slave,
                                               can_add_page=True,
                                               can_change_page=True,
                                               can_delete_page=True)

            assign_user_to_page(self.slave_page,
                                self.user_slave,
                                grant_all=True)

            # create page_b
            page_b = create_page("pageB",
                                 "nav_playground.html",
                                 "en",
                                 created_by=self.user_super)
            # Normal user
            normal = User(username='******',
                          email='*****@*****.**',
                          is_active=True)
            normal.set_password('normal')
            normal.save()
            self.user_normal = create_page_user(self.user_master, normal)
            # it's allowed for the normal user to view the page
            assign_user_to_page(page_b, self.user_normal, can_view=True)
            self.user_normal = self.reload(self.user_normal)
            # create page_a - sample page from master

            page_a = create_page("pageA",
                                 "nav_playground.html",
                                 "en",
                                 created_by=self.user_super)
            assign_user_to_page(page_a,
                                self.user_master,
                                can_add=True,
                                can_change=True,
                                can_delete=True,
                                can_publish=True,
                                can_move_page=True,
                                can_moderate=True)

            # publish after creating all drafts
            publish_page(self.home_page, self.user_super)

            publish_page(self.master_page, self.user_super)

            self.page_b = publish_page(page_b, self.user_super)
            # logg in as master, and request moderation for slave page and descendants
            self.request_moderation(self.slave_page, 7)
Пример #19
0
    def setUp(self):
        # create super user
        self.user_super = User(username="******", is_staff=True, is_active=True, 
            is_superuser=True)
        self.user_super.set_password("super")
        self.user_super.save()
        with self.login_user_context(self.user_super):
        
            self.home_page = create_page("home", "nav_playground.html", "en",
                                         created_by=self.user_super)
            
            # master page & master user
            
            self.master_page = create_page("master", "nav_playground.html", "en")
    
            # create master user
            self.user_master = User.objects.create(username="******", email="*****@*****.**", password="******", is_staff=True)
            self.user_master.user_permissions.add(Permission.objects.get(codename='publish_page'))
            #self.user_master = create_page_user(self.user_super, master, grant_all=True)
            
            # assign master user under home page
            assign_user_to_page(self.home_page, self.user_master,
                                grant_on=ACCESS_DESCENDANTS, grant_all=True)
            
            # and to master page
            assign_user_to_page(self.master_page, self.user_master, grant_all=True)
            
            # slave page & slave user
            
            self.slave_page = create_page("slave-home", "nav_playground.html", "en",
                              parent=self.master_page, created_by=self.user_super)
            slave = User(username='******', email='*****@*****.**', is_staff=True, is_active=True)
            slave.set_password('slave')
            slave.save()
            self.user_slave = create_page_user(self.user_super, slave,  can_add_page=True,
                                        can_change_page=True, can_delete_page=True)
            
            assign_user_to_page(self.slave_page, self.user_slave, grant_all=True)
            
            # create page_a - sample page from master
            
            page_a = create_page("pageA", "nav_playground.html", "en",
                                 created_by=self.user_super)
            assign_user_to_page(page_a, self.user_master,
                can_add=True, can_change=True, can_delete=True, can_publish=True, 
                can_move_page=True)
            
            # publish after creating all drafts
            publish_page(self.home_page, self.user_super)
            publish_page(self.master_page, self.user_super)

        with self.login_user_context(self.user_slave):
        
            # all of them are under moderation... 
            self.pa = create_page("pa", "nav_playground.html", "en", parent=self.slave_page)
            self.pb = create_page("pb", "nav_playground.html", "en", parent=self.pa, position="right")
            self.pc = create_page("pc", "nav_playground.html", "en", parent=self.pb, position="right")
            
            self.pd = create_page("pd", "nav_playground.html", "en", parent=self.pb)
            self.pe = create_page("pe", "nav_playground.html", "en", parent=self.pd, position="right")
            
            self.pf = create_page("pf", "nav_playground.html", "en", parent=self.pe)
            self.pg = create_page("pg", "nav_playground.html", "en", parent=self.pf, position="right")
            self.ph = create_page("ph", "nav_playground.html", "en", parent=self.pf, position="right")
            
            self.assertFalse(self.pg.publisher_public)
            
            # login as master for approval
            publish_page(self.slave_page, self.user_master)
            
            # publish and approve them all
            publish_page(self.pa, self.user_master)
            publish_page(self.pb, self.user_master)
            publish_page(self.pc, self.user_master)
            publish_page(self.pd, self.user_master)
            publish_page(self.pe, self.user_master)
            publish_page(self.pf, self.user_master)
            publish_page(self.pg, self.user_master)
            publish_page(self.ph, self.user_master)
Пример #20
0
    def setUp(self):
        # create super user
        self.user_super = self._create_user("super", True, True)

        with self.login_user_context(self.user_super):
            self.home_page = create_page("home", "nav_playground.html", "en",
                                         created_by=self.user_super)

            # master page & master user

            self.master_page = create_page("master", "nav_playground.html", "en")

            # create master user
            self.user_master = self._create_user("master", True)
            self.user_master.user_permissions.add(Permission.objects.get(codename='publish_page'))
            #self.user_master = create_page_user(self.user_super, master, grant_all=True)

            # assign master user under home page
            assign_user_to_page(self.home_page, self.user_master,
                                grant_on=ACCESS_DESCENDANTS, grant_all=True)

            # and to master page
            assign_user_to_page(self.master_page, self.user_master, grant_all=True)

            # slave page & slave user

            self.slave_page = create_page("slave-home", "nav_playground.html", "en",
                                          parent=self.master_page, created_by=self.user_super)
            slave = self._create_user("slave", True)
            self.user_slave = create_page_user(self.user_super, slave, can_add_page=True,
                                               can_change_page=True, can_delete_page=True)

            assign_user_to_page(self.slave_page, self.user_slave, grant_all=True)

            # create page_a - sample page from master

            page_a = create_page("pageA", "nav_playground.html", "en",
                                 created_by=self.user_super)
            assign_user_to_page(page_a, self.user_master,
                                can_add=True, can_change=True, can_delete=True, can_publish=True,
                                can_move_page=True)

            # publish after creating all drafts
            publish_page(self.home_page, self.user_super, 'en')
            publish_page(self.master_page, self.user_super, 'en')

        with self.login_user_context(self.user_slave):
            # all of them are under moderation...
            self.pa = create_page("pa", "nav_playground.html", "en", parent=self.slave_page)
            self.pb = create_page("pb", "nav_playground.html", "en", parent=self.pa, position="right")
            self.pc = create_page("pc", "nav_playground.html", "en", parent=self.pb, position="right")

            self.pd = create_page("pd", "nav_playground.html", "en", parent=self.pb)
            self.pe = create_page("pe", "nav_playground.html", "en", parent=self.pd, position="right")

            self.pf = create_page("pf", "nav_playground.html", "en", parent=self.pe)
            self.pg = create_page("pg", "nav_playground.html", "en", parent=self.pf, position="right")
            self.ph = create_page("ph", "nav_playground.html", "en", parent=self.pf, position="right")

            self.assertFalse(self.pg.publisher_public)

            # login as master for approval
            self.slave_page = self.slave_page.reload()

            publish_page(self.slave_page, self.user_master, 'en')

            # publish and approve them all
            publish_page(self.pa, self.user_master, 'en')
            publish_page(self.pb, self.user_master, 'en')
            publish_page(self.pc, self.user_master, 'en')
            publish_page(self.pd, self.user_master, 'en')
            publish_page(self.pe, self.user_master, 'en')
            publish_page(self.pf, self.user_master, 'en')
            publish_page(self.pg, self.user_master, 'en')
            publish_page(self.ph, self.user_master, 'en')
            self.reload_pages()
Пример #21
0
 def test_mail_page_user_change(self):
     user = get_user_model().objects.create_superuser(
         "username", "*****@*****.**", "username")
     user = create_page_user(user, user, grant_all=True)
     mail_page_user_change(user)
     self.assertEqual(len(mail.outbox), 1)