Skip to content

Commit

Permalink
fix: project context mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
sbanoeon committed Jul 20, 2022
1 parent 98c8f43 commit e1d22c0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/Entirety/projects/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
from django.contrib.auth.mixins import UserPassesTestMixin
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404

from projects.models import Project


class ProjectContextMixin:
project = None

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["project"] = self.project

return context

def dispatch(self, request, *args, **kwargs):
self.project = get_object_or_404(Project, pk=kwargs.get("project_id", None))

if not (
self.project.is_owner(user=request.user)
or self.project.is_user(user=request.user)
):
raise PermissionDenied()

return super().dispatch(request, *args, **kwargs)


class ProjectSelfMixin(UserPassesTestMixin):
Expand Down

0 comments on commit e1d22c0

Please sign in to comment.