Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide unvalidated taxon to non expert/superuser #4347

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions bims/api_views/taxon.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,18 @@ def get_taxa_by_parameters(request):
try:
validated = ast.literal_eval(validated.replace('/', ''))
if not validated:
validated_filters = {
'taxongrouptaxonomy__is_validated': False,
}
# Check if the user is a superuser or has expert permissions for the taxon group
is_user_expert = is_expert(
request.user,
TaxonGroup.objects.get(id=taxon_group_id)
)
if request.user.is_superuser or is_user_expert:
validated_filters = {
'taxongrouptaxonomy__is_validated': False,
}
else:
taxon_list = taxon_list.none()
return taxon_list
else:
validated_filters = {
'taxongrouptaxonomy__is_validated': True,
Expand Down
2 changes: 1 addition & 1 deletion bims/models/location_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def add_context_group(self, group_key):
table_name=layer.query_table_name,
field_names=[context_key],
coordinates=[(self.longitude, self.latitude)],
tolerance=10
tolerance=0
)
# Find by name first
context_groups = LocationContextGroup.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion bims/tests/test_location_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_add_location_context_from_native_layer(self, mock_query_features):
table_name=layer.query_table_name,
field_names=[context_key],
coordinates=[(location_site.longitude, location_site.latitude)],
tolerance=10
tolerance=0
)

location_context_group = LocationContextGroup.objects.filter(
Expand Down
8 changes: 4 additions & 4 deletions bims/tests/test_review_taxon_proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def test_expert_approve_taxon(self):
taxa_list_url = reverse('taxa-list')
unvalidated_taxa_list_url = f'{taxa_list_url}?taxonGroup={taxon_group_level_3.id}&validated=False'
response = self.client.get(unvalidated_taxa_list_url)
self.assertFalse(
response.data['results'][0]['can_be_validated']
self.assertEqual(
len(response.data['results']), 0
)

# The expert of taxon group level 2 validates the taxa.
Expand Down Expand Up @@ -217,8 +217,8 @@ def test_expert_approve_taxon(self):
self.client.login(username='experts_2', password='password')
unvalidated_taxa_list_url = f'{taxa_list_url}?taxonGroup={self.taxon_group.id}&validated=False'
response = self.client.get(unvalidated_taxa_list_url)
self.assertFalse(
response.data['results'][0]['can_be_validated']
self.assertEqual(
len(response.data['results']), 0
)

# The expert of taxon group level 1 validates the taxa.
Expand Down
14 changes: 11 additions & 3 deletions mobile/api_views/taxon_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from bims.api_views.taxon_update import is_expert
from bims.models.taxon_group import TaxonGroup
from bims.serializers.taxon_serializer import TaxonGroupSerializer
from bims.enums.taxonomic_group_category import TaxonomicGroupCategory
Expand Down Expand Up @@ -40,9 +41,16 @@ def collect_taxonomy_ids(self, taxon_group):
validated = taxon_group.taxonomies.filter(
taxongrouptaxonomy__is_validated=True
).count()
unvalidated = taxon_group.taxonomies.filter(
taxongrouptaxonomy__is_validated=False
).count()
is_user_expert = is_expert(
self.request.user,
TaxonGroup.objects.get(id=taxon_group.id)
)
if self.request.user.is_superuser or is_user_expert:
unvalidated = taxon_group.taxonomies.filter(
taxongrouptaxonomy__is_validated=False
).count()
else:
unvalidated = 0

self.validated_count += validated
self.unvalidated_count += unvalidated
Expand Down
Loading