Dar permiso a los gestores para ver cualquier proyecto

parent 79d55100
Pipeline #519 failed with stage
in 0 seconds
# Generated by Django 3.0.2 on 2020-01-31 11:45
# https://docs.djangoproject.com/en/3.0/howto/writing-migrations/
from django.db import migrations
from django.apps import apps as django_apps
from django.db import migrations, models
def add_managers_group(apps, schema_editor):
......@@ -15,8 +16,30 @@ def add_managers_group(apps, schema_editor):
group.permissions.add(listar_proyectos)
def geo_post_migrate_signal(apps, schema_editor):
"""Emit the post-migrate signal during the migration.
Permissions are not actually created during or after an individual migration,
but are triggered by a post-migrate signal which is sent after the
`python manage.py migrate` command completes successfully.
This is necessary because this permission is used in the next migration.
"""
indo_config = django_apps.get_app_config("indo")
models.signals.post_migrate.send(
sender=indo_config,
app_config=indo_config,
verbosity=2,
interactive=False,
using=schema_editor.connection.alias,
)
class Migration(migrations.Migration):
dependencies = [("indo", "0002_auto_20200131_1244")]
operations = [migrations.RunPython(add_managers_group)]
operations = [
migrations.RunPython(add_managers_group),
migrations.RunPython(geo_post_migrate_signal),
]
# Generated by Django 3.0.2 on 2020-01-31 13:09
from django.apps import apps as django_apps
from django.db import migrations, models
def add_permission_to_group(apps, schema_editor):
group = apps.get_model("auth", "Group")
permission = apps.get_model("auth", "Permission")
gestores = group.objects.get(name="Gestores")
ver_proyecto = permission.objects.get(codename="ver_proyecto")
gestores.permissions.add(ver_proyecto)
def geo_post_migrate_signal(apps, schema_editor):
"""Emit the post-migrate signal during the migration.
Permissions are not actually created during or after an individual migration,
but are triggered by a post-migrate signal which is sent after the
`python manage.py migrate` command completes successfully.
This is necessary because this permission is used later in this migration.
"""
indo_config = django_apps.get_app_config("indo")
models.signals.post_migrate.send(
sender=indo_config,
app_config=indo_config,
verbosity=2,
interactive=False,
using=schema_editor.connection.alias,
)
class Migration(migrations.Migration):
dependencies = [("indo", "0003_auto_20200131_1245")]
operations = [
migrations.AlterModelOptions(
name="proyecto",
options={
"permissions": [
(
"listar_proyectos",
"Puede ver el listado de todos los proyectos presentados.",
),
("ver_proyecto", "Puede ver cualquier proyecto."),
]
},
),
migrations.RunPython(geo_post_migrate_signal),
migrations.RunPython(add_permission_to_group),
]
......@@ -474,7 +474,8 @@ class Proyecto(models.Model):
class Meta:
permissions = [
("listar_proyectos", _("Puede ver el listado de todos los proyectos."))
("listar_proyectos", _("Puede ver el listado de todos los proyectos.")),
("ver_proyecto", _("Puede ver cualquier proyecto.")),
]
def __str__(self):
......
......@@ -118,8 +118,11 @@ class ChecksMixin(UserPassesTestMixin):
"""
Devuelve si el usuario actual está vinculado al proyecto indicado
o es decano o director del centro del proyecto."""
esta_autorizado = self.esta_vinculado(proyecto_id) or self.es_decano_o_director(
proyecto_id
usuario_actual = self.request.user
esta_autorizado = (
self.esta_vinculado(proyecto_id)
or self.es_decano_o_director(proyecto_id)
or usuario_actual.has_perm("indo.ver_proyecto") # Gestores y evaluadores
)
self.permission_denied_message = _(
"Usted no está vinculado a este proyecto, "
......@@ -382,7 +385,6 @@ class ProyectoDetailView(LoginRequiredMixin, ChecksMixin, DetailView):
return context
def test_func(self):
# TODO: Los evaluadores y gestores también tendrán que tener acceso.
proyecto_id = self.kwargs["pk"]
return self.esta_vinculado_o_es_decano(proyecto_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment