Commit 5c8681e2 authored by hypsug0's avatar hypsug0
Browse files

feat: hide confidential studies for non creator/manager

parent 49d4e399
......@@ -2050,7 +2050,7 @@ const strNormalize = (str) => {
.replace(/[\u0300-\u036f]/g, '')
}
const studyListApp = () => {
const studyListApp = (userId) => {
return {
el: '#studyList',
delimiters: ['[[', ']]'],
......@@ -2075,19 +2075,26 @@ const studyListApp = () => {
.catch((error) => console.error(error))
},
filterStudies() {
const keys = Object.keys(this.search)
console.log(this.search)
let filteredStudies = [...this.fullStudyList]
if (this.search.name) {
filteredStudies = filteredStudies.filter((e) =>
e.name && strNormalize(e.name).includes(
strNormalize(this.search.name)
)
filteredStudies = filteredStudies.filter(
(e) =>
e.name &&
strNormalize(e.name).includes(
strNormalize(this.search.name)
)
)
}
if (this.search.year) {
filteredStudies = filteredStudies.filter((e) =>
e.year && e.year.includes(this.search.year)
filteredStudies = filteredStudies.filter(
(e) => e.year && e.year.includes(this.search.year)
)
}
if (this.search.myStudies) {
filteredStudies = filteredStudies.filter(
(e) =>
e.project_manager &&
e.project_manager?.id == userId
)
}
if (this.search.manager) {
......@@ -2128,7 +2135,7 @@ const studyListApp = () => {
)
}
if (this.search.public_raw_data) {
filteredStudies = filteredStudies.filter(
filteredStudies = filteredStudies.filter(
(e) => e.public_raw_data
)
}
......@@ -2138,7 +2145,6 @@ const studyListApp = () => {
)
}
this.studyList = filteredStudies
},
},
watch: {
......
# import the logging library
import logging
from django.db.models import Prefetch
from django.db.models import Prefetch, Q
from rest_framework.generics import ListAPIView
from sights.models import Place, Session
from sights.observation.api import GeoJSONSighting
from ..models import Study
from .permissions import StudyDetailPermission
......@@ -14,15 +13,6 @@ from .serializers import StudyDataSerializer, StudySerializer
logger = logging.getLogger(__name__)
class StudySightingsApi(GeoJSONSighting):
pagination_class = None
def get_queryset(self, *args, **kwargs):
qs = super().get_queryset()
qs = qs.filter(session__study__pk=self.kwargs.get("pk"))
return qs.distinct().order_by("-timestamp_update")
class StudyDatasApi(ListAPIView):
serializer_class = StudyDataSerializer
queryset = (
......@@ -77,3 +67,21 @@ class StudyListApi(ListAPIView):
.order_by("timestamp_update")
# .prefetch_related(Prefetch("sessions__other_observer"))
)
def get_queryset(self, *args, **kwargs):
qs = super().get_queryset()
user = self.request.user
if user.access_all_data or user.edit_all_data or user.is_superuser:
# If advanced user, can see all studies
qs = qs
if not (user.access_all_data or user.edit_all_data or user.is_superuser):
# If not advanced user, can see own and public studies
logger.debug("step1")
logger.debug(f"QS1 {qs}")
qs = qs.filter(
(Q(confidential=True) & Q(project_manager=user))
| (Q(confidential=True) & Q(created_by=user))
| Q(confidential=False)
)
logger.debug(f"QS2 {qs}")
return qs
......@@ -4,17 +4,14 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Prefetch
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.generic import DetailView, TemplateView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django_tables2 import SingleTableView
from ..forms import StudyForm
from ..mixins import ManagementAuthMixin
from ..models import Study
from ..tables import StudyTable
from .mixins import StudyAuthMixin
......@@ -74,10 +71,7 @@ class StudyDelete(ManagementAuthMixin, DeleteView):
class StudyList(LoginRequiredMixin, TemplateView):
# table_class = StudyTable
# model = Study
template_name = "study_list.html"
# table_pagination = {"per_page": 25}
def get_context_data(self, **kwargs):
context = super(StudyList, self).get_context_data(**kwargs)
......@@ -91,18 +85,6 @@ class StudyList(LoginRequiredMixin, TemplateView):
class StudyDetail(LoginRequiredMixin, StudyAuthMixin, DetailView):
# queryset = (
# Study.objects.select_related("project_manager")
# .select_related("created_by")
# .select_related("updated_by")
# .prefetch_related("sessions")
# .prefetch_related(Prefetch("sessions__observations"))
# .prefetch_related(Prefetch("sessions__place"))
# .prefetch_related(Prefetch("sessions__contact"))
# .prefetch_related(Prefetch("sessions__observations__codesp"))
# .prefetch_related(Prefetch("sessions__main_observer"))
# .prefetch_related(Prefetch("sessions__other_observer"))
# )
model = Study
template_name = "study_detail.html"
......
......@@ -55,6 +55,11 @@
<input type="checkbox" v-model="search.confidential"> Confidentiel
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" v-model="search.myStudies"> Mes études
</label>
</div>
</form>
</div>
</div>
......@@ -118,8 +123,9 @@
</div>
</div>
<script>
const myId = parseInt("{{user.id}}")
$(document).ready(() => {
const vm = new Vue(studyListApp())
const vm = new Vue(studyListApp(myId))
})
</script>
......
from django.urls import path
from .study.api import StudyDatasApi, StudyListApi, StudySightingsApi
from .study.api import StudyDatasApi, StudyListApi
from .study.views import StudyCreate, StudyDelete, StudyDetail, StudyList, StudyUpdate
from .transmitter.api import TransmitterSearchApi
from .transmitter.views import (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment