Skip to content

Commit

Permalink
Merge branch 'hotfix/5.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed May 6, 2024
2 parents 33b3a4a + 8dee2aa commit 1518820
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ keywords:
- elasticsearch
- natural language processing
license: MIT
version: 5.6.1
date-released: '2024-05-03'
version: 5.6.2
date-released: '2024-05-06'
42 changes: 12 additions & 30 deletions backend/api/tests/test_api_views.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,29 @@
from datetime import datetime
from addcorpus.models import Corpus
from rest_framework.status import is_success

def mock_query_data(user, corpus_name):
return {
'aborted': False,
'corpus': corpus_name,
'user': user.id,
'started': datetime.now().isoformat(),
'completed': datetime.now().isoformat(),
'query_json': {
"queryText": "example",
"filters": [],
"sortAscending": False
},
'total_results': 10,
'transferred': 0,
}
from api.models import Query
from visualization.query import MATCH_ALL

def test_search_history_view(admin_user, admin_client):
corpus = Corpus.objects.create(name = 'mock-corpus')

# get search history
response = admin_client.get('/api/search_history/')
assert is_success(response.status_code)
assert len(response.data) == 0

# add a query to search history
data = mock_query_data(admin_user, 'mock-corpus')
response = admin_client.post('/api/search_history/', data, content_type='application/json')
assert is_success(response.status_code)

# get search history again
response = admin_client.get('/api/search_history/')
assert is_success(response.status_code)
assert len(response.data) == 1


def test_delete_search_history(auth_client, auth_user, db):
mock_corpus = 'mock-corpus'
corpus = Corpus.objects.create(name = mock_corpus)
query = mock_query_data(auth_user, mock_corpus)
auth_client.post('/api/search_history/', query, content_type='application/json')
Query.objects.create(
user=auth_user,
corpus=corpus,
query_json = {'es_query': MATCH_ALL},
started=datetime.now(),
completed=datetime.now(),
total_results=10,
transferred=10,
aborted=False,
)

assert len(auth_user.queries.all()) == 1

Expand Down
4 changes: 2 additions & 2 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logger = logging.getLogger()


class QueryViewset(viewsets.ModelViewSet):
class QueryViewset(viewsets.ReadOnlyModelViewSet):
'''
Access search history
'''
Expand Down Expand Up @@ -45,7 +45,7 @@ def post(self, request, *args, **kwargs):
results = [celery_app.AsyncResult(id=task_id) for task_id in task_ids]
if not all(results):
raise APIException(detail='Could not get task data')

if any(result.state == 'FAILURE' for result in results):
raise APIException(detail='Task failed')

Expand Down
3 changes: 1 addition & 2 deletions backend/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ class Meta:


class CustomUserDetailsSerializer(UserDetailsSerializer):
is_admin = serializers.BooleanField(source='is_staff')
is_admin = serializers.BooleanField(source='is_staff', read_only=True)
profile = UserProfileSerializer()

class Meta(UserDetailsSerializer.Meta):
fields = ('id', 'username', 'email', 'saml',
'download_limit', 'is_admin', 'profile')


def update(self, instance, validated_data):
profile_data = validated_data.pop('profile', None)

Expand Down
13 changes: 13 additions & 0 deletions backend/users/tests/test_user_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ def test_user_updates(auth_client):
assert response.status_code == 200

assert not search_history_enabled()

def test_readonly_fields(auth_client):
'''
Test that is_admin is readonly
'''

route = '/users/user/'
details = lambda: auth_client.get(route)
is_admin = lambda: details().data.get('is_admin')

assert not is_admin()
response = auth_client.patch(route, {'is_admin': True}, content_type='application/json')
assert not is_admin()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "i-analyzer",
"version": "5.6.1",
"version": "5.6.2",
"license": "MIT",
"scripts": {
"postinstall": "yarn install-back && yarn install-front",
Expand Down

0 comments on commit 1518820

Please sign in to comment.