WIP: gestion des permissions pour l'édition des émissions #130
							
								
								
									
										15
									
								
								aircox/templates/accounts/profile.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								aircox/templates/accounts/profile.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
{% extends "aircox/base.html" %}
 | 
			
		||||
{% load i18n aircox %}
 | 
			
		||||
 | 
			
		||||
{% block head_title %}
 | 
			
		||||
    {% block title %}{{ user.username }}{% endblock %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block main %}
 | 
			
		||||
  <h2 class="subtitle is-3">Mes émissions</h2>
 | 
			
		||||
  <ul>
 | 
			
		||||
  {% for p in programs %}
 | 
			
		||||
    <li>• <a href="{% url 'program-detail' slug=p.slug %}">{{ p.title }}</a></li>
 | 
			
		||||
  {% endfor %}
 | 
			
		||||
  </ul>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@ -85,7 +85,7 @@ Usefull context:
 | 
			
		||||
 | 
			
		||||
                            {% if user.is_authenticated %}
 | 
			
		||||
                                <div class="navbar-item">
 | 
			
		||||
                                <a>{{ user.username }}</a>   <a href="{% url 'logout' %}"> <i class="fa fa-power-off"></i></a>
 | 
			
		||||
                                    <a href="{% url 'profile' %}">{{ user.username }}</a>   <a href="{% url 'logout' %}"> <i class="fa fa-power-off"></i></a>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            {% endif %}
 | 
			
		||||
                        </div>
 | 
			
		||||
 | 
			
		||||
@ -10,3 +10,13 @@ def test_authenticate(user, client, program):
 | 
			
		||||
    r = client.post(reverse("login"), kwargs={"username": "foo", "password": "bar"})
 | 
			
		||||
    assert b"errorlist" in r.content
 | 
			
		||||
    assert client.login(username="user1", password="bar")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.mark.django_db()
 | 
			
		||||
def test_profile_programs(user, client, program):
 | 
			
		||||
    client.force_login(user)
 | 
			
		||||
    r = client.get(reverse("profile"))
 | 
			
		||||
    assert program.title not in r.content.decode("utf-8")
 | 
			
		||||
    user.groups.add(program.editors)
 | 
			
		||||
    r = client.get(reverse("profile"))
 | 
			
		||||
    assert program.title in r.content.decode("utf-8")
 | 
			
		||||
 | 
			
		||||
@ -117,4 +117,6 @@ urls = [
 | 
			
		||||
        views.errors.NoStationErrorView.as_view(),
 | 
			
		||||
        name="errors-no-station",
 | 
			
		||||
    ),
 | 
			
		||||
    path("gestion/", views.profile, name="profile"),
 | 
			
		||||
    path("accounts/profile/", views.profile, name="profile"),
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@ from .page import (
 | 
			
		||||
    PageDetailView,
 | 
			
		||||
    PageListView,
 | 
			
		||||
)
 | 
			
		||||
from .profile import profile
 | 
			
		||||
from .program import (
 | 
			
		||||
    ProgramDetailView,
 | 
			
		||||
    ProgramListView,
 | 
			
		||||
@ -36,6 +37,7 @@ __all__ = (
 | 
			
		||||
    "BasePageListView",
 | 
			
		||||
    "PageDetailView",
 | 
			
		||||
    "PageListView",
 | 
			
		||||
    "profile",
 | 
			
		||||
    "ProgramDetailView",
 | 
			
		||||
    "ProgramListView",
 | 
			
		||||
    "ProgramPageDetailView",
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								aircox/views/profile.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								aircox/views/profile.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
from django.contrib.auth.decorators import login_required
 | 
			
		||||
from django.template.response import TemplateResponse
 | 
			
		||||
 | 
			
		||||
from aircox.models import Program
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def profile(request):
 | 
			
		||||
    programs = []
 | 
			
		||||
    ugroups = request.user.groups.all()
 | 
			
		||||
    for p in Program.objects.all():
 | 
			
		||||
        if p.editors in ugroups:
 | 
			
		||||
            programs.append(p)
 | 
			
		||||
    context = {"user": request.user, "programs": programs}
 | 
			
		||||
    return TemplateResponse(request, "accounts/profile.html", context)
 | 
			
		||||
		Reference in New Issue
	
	Block a user