mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-09 03:16:25 +00:00
Correction d'une erreure si aucun ticket et creation des acls
This commit is contained in:
parent
18a97caa56
commit
0596df673f
2 changed files with 45 additions and 5 deletions
|
@ -5,11 +5,13 @@ from django.template import Context, loader
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from re2o.mixins import AclMixin
|
||||||
|
|
||||||
from preferences.models import GeneralOption
|
from preferences.models import GeneralOption
|
||||||
|
|
||||||
import users.models
|
import users.models
|
||||||
|
|
||||||
class Ticket(models.Model):
|
class Ticket(AclMixin, models.Model):
|
||||||
"""Class définissant un ticket"""
|
"""Class définissant un ticket"""
|
||||||
|
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
|
@ -60,6 +62,26 @@ class Ticket(models.Model):
|
||||||
[to_addr],
|
[to_addr],
|
||||||
fail_silently = False)
|
fail_silently = False)
|
||||||
|
|
||||||
|
def can_view(self, user_request, *_args, **_kwargs):
|
||||||
|
"""Verifie que la personne à le droit pour voir le ticket
|
||||||
|
ou qu'elle est l'auteur du ticket"""
|
||||||
|
if (not user_request.has_perm('tickets.view_ticket') and self.user != user_request):
|
||||||
|
return False, _("You don't have the right to view other Tickets than yours.")
|
||||||
|
else:
|
||||||
|
return True, None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def can_view_all(user_request, *_args, **_kwargs):
|
||||||
|
"""Vérifie si l'user a acccés à la liste de tous les tickets"""
|
||||||
|
return(
|
||||||
|
user_request.has_perm('tickets.view_tickets'),
|
||||||
|
_("You don't have the right to view the list of tickets.")
|
||||||
|
)
|
||||||
|
|
||||||
|
def can_create(user_request,*_args, **_kwargs):
|
||||||
|
"""Autorise tout les utilisateurs à créer des tickets"""
|
||||||
|
return True,None
|
||||||
|
|
||||||
class Preferences(models.Model):
|
class Preferences(models.Model):
|
||||||
""" Class cannonique définissants les préférences des tickets """
|
""" Class cannonique définissants les préférences des tickets """
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.views.decorators.cache import cache_page
|
from django.views.decorators.cache import cache_page
|
||||||
|
@ -10,6 +11,13 @@ from re2o.base import (
|
||||||
re2o_paginator,
|
re2o_paginator,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from re2o.acl import(
|
||||||
|
can_view,
|
||||||
|
can_view_all,
|
||||||
|
can_edit,
|
||||||
|
can_create,
|
||||||
|
)
|
||||||
|
|
||||||
from preferences.models import GeneralOption
|
from preferences.models import GeneralOption
|
||||||
from .models import(
|
from .models import(
|
||||||
Ticket,
|
Ticket,
|
||||||
|
@ -51,6 +59,8 @@ def new_ticket(request):
|
||||||
ticketform = NewTicketForm
|
ticketform = NewTicketForm
|
||||||
return form({'ticketform':ticketform,},'tickets/form_ticket.html',request)
|
return form({'ticketform':ticketform,},'tickets/form_ticket.html',request)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_view(Ticket)
|
||||||
def aff_ticket(request,ticketid):
|
def aff_ticket(request,ticketid):
|
||||||
"""Vue d'affichage d'un ticket"""
|
"""Vue d'affichage d'un ticket"""
|
||||||
ticket = Ticket.objects.filter(id=ticketid).get()
|
ticket = Ticket.objects.filter(id=ticketid).get()
|
||||||
|
@ -60,12 +70,17 @@ def aff_ticket(request,ticketid):
|
||||||
ticket.save()
|
ticket.save()
|
||||||
return render(request,'tickets/aff_ticket.html',{'ticket':ticket,'changestatusform':changestatusform})
|
return render(request,'tickets/aff_ticket.html',{'ticket':ticket,'changestatusform':changestatusform})
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_view_all(Ticket)
|
||||||
def aff_tickets(request):
|
def aff_tickets(request):
|
||||||
""" Vue d'affichage de tout les tickets """
|
""" Vue d'affichage de tout les tickets """
|
||||||
tickets_list = Ticket.objects.all().order_by('-date')
|
tickets_list = Ticket.objects.all().order_by('-date')
|
||||||
last_ticket_date = tickets_list.first().date
|
|
||||||
nbr_tickets = tickets_list.count()
|
nbr_tickets = tickets_list.count()
|
||||||
nbr_tickets_unsolved = tickets_list.filter(solved=False).count()
|
nbr_tickets_unsolved = tickets_list.filter(solved=False).count()
|
||||||
|
if nbr_tickets:
|
||||||
|
last_ticket_date = tickets_list.first().date
|
||||||
|
else:
|
||||||
|
last_ticket_date = "Jamais"
|
||||||
|
|
||||||
pagination_number = (GeneralOption
|
pagination_number = (GeneralOption
|
||||||
.get_cached_value('pagination_number'))
|
.get_cached_value('pagination_number'))
|
||||||
|
@ -105,9 +120,12 @@ def edit_preferences(request):
|
||||||
def profil(request,user):
|
def profil(request,user):
|
||||||
""" Vue cannonique d'affichage des tickets dans l'accordeon du profil"""
|
""" Vue cannonique d'affichage des tickets dans l'accordeon du profil"""
|
||||||
tickets_list = Ticket.objects.filter(user=user).all().order_by('-date')
|
tickets_list = Ticket.objects.filter(user=user).all().order_by('-date')
|
||||||
last_ticket_date = tickets_list.first().date
|
|
||||||
nbr_tickets = tickets_list.count()
|
nbr_tickets = tickets_list.count()
|
||||||
nbr_tickets_unsolved = tickets_list.filter(solved=False).count()
|
nbr_tickets_unsolved = tickets_list.filter(solved=False).count()
|
||||||
|
if nbr_tickets:
|
||||||
|
last_ticket_date = tickets_list.first().date
|
||||||
|
else:
|
||||||
|
last_ticket_date = "Jamais"
|
||||||
|
|
||||||
pagination_number = (GeneralOption
|
pagination_number = (GeneralOption
|
||||||
.get_cached_value('pagination_large_number'))
|
.get_cached_value('pagination_large_number'))
|
||||||
|
|
Loading…
Reference in a new issue