mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-02 19:07:06 +00:00
[FEAT] Limit Map and Network views to admins
This commit is contained in:
@@ -104,15 +104,15 @@
|
|||||||
<a href="{% url 'activities:activity.list' %}" class="nav-link">Activities</a>
|
<a href="{% url 'activities:activity.list' %}" class="nav-link">Activities</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="nav-item">
|
|
||||||
<a href="{% url 'people:map' %}" class="nav-link">Map</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="nav-item">
|
|
||||||
<a href="{% url 'people:network' %}" class="nav-link">Network</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
{% if request.user.is_superuser %}
|
{% if request.user.is_superuser %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="{% url 'people:map' %}" class="nav-link">Map</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="{% url 'people:network' %}" class="nav-link">Network</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a href="{% url 'export:index' %}" class="nav-link">Export</a>
|
<a href="{% url 'export:index' %}" class="nav-link">Export</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from django.views.generic.edit import UpdateView
|
from django.views.generic.edit import UpdateView
|
||||||
|
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||||
|
import typing
|
||||||
|
|
||||||
from . import forms
|
from . import forms
|
||||||
|
|
||||||
@@ -19,6 +21,10 @@ class IndexView(TemplateView):
|
|||||||
# Template set in Django settings file - may be customised by a customisation app
|
# Template set in Django settings file - may be customised by a customisation app
|
||||||
template_name = settings.TEMPLATE_NAME_INDEX
|
template_name = settings.TEMPLATE_NAME_INDEX
|
||||||
|
|
||||||
|
class UserIsStaffMixin(UserPassesTestMixin):
|
||||||
|
def test_func(self) -> typing.Optional[bool]:
|
||||||
|
return self.request.user.is_staff
|
||||||
|
|
||||||
|
|
||||||
class ConsentTextView(LoginRequiredMixin, UpdateView):
|
class ConsentTextView(LoginRequiredMixin, UpdateView):
|
||||||
"""View with consent text and form for users to indicate consent."""
|
"""View with consent text and form for users to indicate consent."""
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
import csv
|
import csv
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from django.views.generic.list import BaseListView
|
from django.views.generic.list import BaseListView
|
||||||
|
from breccia_mapper.views import UserIsStaffMixin
|
||||||
|
|
||||||
|
|
||||||
class QuotedCsv(csv.excel):
|
class QuotedCsv(csv.excel):
|
||||||
quoting = csv.QUOTE_NONNUMERIC
|
quoting = csv.QUOTE_NONNUMERIC
|
||||||
|
|
||||||
|
|
||||||
class UserIsStaffMixin(UserPassesTestMixin):
|
|
||||||
def test_func(self) -> typing.Optional[bool]:
|
|
||||||
return self.request.user.is_staff
|
|
||||||
|
|
||||||
|
|
||||||
class CsvExportView(UserIsStaffMixin, BaseListView):
|
class CsvExportView(UserIsStaffMixin, BaseListView):
|
||||||
model = None
|
model = None
|
||||||
serializer_class = None
|
serializer_class = None
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from django.utils import timezone
|
|||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
from people import forms, models, permissions
|
from people import forms, models, permissions
|
||||||
|
from breccia_mapper.views import UserIsStaffMixin
|
||||||
|
|
||||||
|
|
||||||
def get_map_data(obj: typing.Union[models.Person, models.Organisation]) -> typing.Dict[str, typing.Any]:
|
def get_map_data(obj: typing.Union[models.Person, models.Organisation]) -> typing.Dict[str, typing.Any]:
|
||||||
@@ -33,7 +34,7 @@ def get_map_data(obj: typing.Union[models.Person, models.Organisation]) -> typin
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class MapView(LoginRequiredMixin, TemplateView):
|
class MapView(UserIsStaffMixin, LoginRequiredMixin, TemplateView):
|
||||||
"""View displaying a map of :class:`Person` and :class:`Organisation` locations."""
|
"""View displaying a map of :class:`Person` and :class:`Organisation` locations."""
|
||||||
template_name = 'people/map.html'
|
template_name = 'people/map.html'
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from django.utils import timezone
|
|||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
from people import forms, models, serializers
|
from people import forms, models, serializers
|
||||||
|
from breccia_mapper.views import UserIsStaffMixin
|
||||||
|
|
||||||
logger = logging.getLogger(__name__) # pylint: disable=invalid-name
|
logger = logging.getLogger(__name__) # pylint: disable=invalid-name
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ filter_people = filter_by_form_answers(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NetworkView(LoginRequiredMixin, TemplateView):
|
class NetworkView(UserIsStaffMixin, LoginRequiredMixin, TemplateView):
|
||||||
"""View to display relationship network."""
|
"""View to display relationship network."""
|
||||||
template_name = 'people/network.html'
|
template_name = 'people/network.html'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user