mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 09:21:54 +02:00
69 lines
2 KiB
Python
69 lines
2 KiB
Python
"""View classes that enforce authorization."""
|
|
|
|
import abc # abstract base class
|
|
|
|
from django.views.generic import DetailView, DeleteView
|
|
|
|
from registrar.models import Domain, DomainApplication, DomainInvitation
|
|
|
|
from .mixins import (
|
|
DomainPermission,
|
|
DomainApplicationPermission,
|
|
DomainInvitationPermission,
|
|
)
|
|
|
|
|
|
class DomainPermissionView(DomainPermission, DetailView, abc.ABC):
|
|
|
|
"""Abstract base view for domains that enforces permissions.
|
|
|
|
This abstract view cannot be instantiated. Actual views must specify
|
|
`template_name`.
|
|
"""
|
|
|
|
# DetailView property for what model this is viewing
|
|
model = Domain
|
|
# variable name in template context for the model object
|
|
context_object_name = "domain"
|
|
|
|
# Abstract property enforces NotImplementedError on an attribute.
|
|
@property
|
|
@abc.abstractmethod
|
|
def template_name(self):
|
|
raise NotImplementedError
|
|
|
|
|
|
class DomainApplicationPermissionView(DomainApplicationPermission, DetailView, abc.ABC):
|
|
|
|
"""Abstract base view for domain applications that enforces permissions
|
|
|
|
This abstract view cannot be instantiated. Actual views must specify
|
|
`template_name`.
|
|
"""
|
|
|
|
# DetailView property for what model this is viewing
|
|
model = DomainApplication
|
|
# variable name in template context for the model object
|
|
context_object_name = "domainapplication"
|
|
|
|
# Abstract property enforces NotImplementedError on an attribute.
|
|
@property
|
|
@abc.abstractmethod
|
|
def template_name(self):
|
|
raise NotImplementedError
|
|
|
|
|
|
class DomainInvitationPermissionDeleteView(
|
|
DomainInvitationPermission, DeleteView, abc.ABC
|
|
):
|
|
|
|
"""Abstract view for deleting a domain invitation.
|
|
|
|
This one is fairly specialized, but this is the only thing that we do
|
|
right now with domain invitations. We still have the full
|
|
`DomainInvitationPermission` class, but here we just pair it with a
|
|
DeleteView.
|
|
"""
|
|
|
|
model = DomainInvitation
|
|
object: DomainInvitation # workaround for type mismatch in DeleteView
|