From 47ca2dad7cb8a76fd96332b1fce61e88563af357 Mon Sep 17 00:00:00 2001 From: Matthias Koenig Date: Tue, 7 May 2019 10:11:51 +0200 Subject: [PATCH 001/127] Fix #354, updated npm dependencies --- frontend/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/package.json b/frontend/package.json index b2a79c7a..a7b67774 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,7 +14,7 @@ "@fortawesome/free-brands-svg-icons": "^5.3.1", "@fortawesome/free-solid-svg-icons": "^5.3.1", "@fortawesome/vue-fontawesome": "^0.1.1", - "@statnett/vue-plotly": "^0.2.0", + "@statnett/vue-plotly": "^0.3.2", "axios": "^0.18.0", "vue": "^2.5.17", "vue-auth-image": "0.0.2", From cf53cf747ded5b0f054268ea6ef7eacf2396baca Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 7 May 2019 10:16:04 +0200 Subject: [PATCH 002/127] study user based query now finished --- backend/pkdb_app/studies/views.py | 39 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/backend/pkdb_app/studies/views.py b/backend/pkdb_app/studies/views.py index 68798982..982572e1 100644 --- a/backend/pkdb_app/studies/views.py +++ b/backend/pkdb_app/studies/views.py @@ -7,7 +7,6 @@ from pkdb_app.users.models import PUBLIC from pkdb_app.users.permissions import IsAdminOrCreatorOrCurator, StudyPermission, user_group from rest_framework.exceptions import ValidationError -from rest_framework.permissions import IsAdminUser from django.views.decorators.csrf import csrf_exempt from django.http import JsonResponse from elasticsearch import helpers @@ -30,6 +29,8 @@ from django.core.exceptions import ObjectDoesNotExist +from elasticsearch_dsl.query import Q + ################### # References @@ -233,34 +234,42 @@ def get_object(self): raise Http404("No result matches the given query.") def get_queryset(self): - - qs = super().get_queryset() + search = self.search#.query() + #qs = super().get_queryset() #return qs group = user_group(self.request) - print("*"*100) - print(group) - print("*"*100) if group in ["admin","reviewer"]: - return qs + return search.query() elif group == "basic": + qs = search.query( + Q('match', access__raw=PUBLIC) | + Q('match', creator__username__raw=self.request.user.username) | + Q('match', curators__username__raw=self.request.user.username) | + Q('match', collaborators__username__raw=self.request.user.username) - #todo:hier weiter machen - return qs.filter(access=True).filter(creator=self.request.user).filter(curators__in=[self.request.user]).filter(collaborators__in=[self.request.user]) - - elif group =="anonymous": - qs = qs.filter( - 'term', - **{"access": PUBLIC} ) + #) + #qs = qs.filter( + # 'term', + # **{"access": PUBLIC, "creator":self.request.user} + #) return qs + #return qs.filter(access=True).filter(creator=self.request.user).filter(curators__in=[self.request.user]).filter(collaborators__in=[self.request.user]) + + elif group == "anonymous": + qs = search.query( + 'match', + **{"access__raw": PUBLIC} + ) + + return qs - From bbcc24e4bea4612cf2d54f98c764a993ada09c96 Mon Sep 17 00:00:00 2001 From: Matthias Koenig Date: Tue, 7 May 2019 10:21:29 +0200 Subject: [PATCH 003/127] Fix #347, nginx endpoint for django admin added --- nginx/config/conf.d/local.conf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nginx/config/conf.d/local.conf b/nginx/config/conf.d/local.conf index eb49db5d..29821614 100644 --- a/nginx/config/conf.d/local.conf +++ b/nginx/config/conf.d/local.conf @@ -38,6 +38,14 @@ server { proxy_redirect off; } + # django admin + location /admin { + proxy_pass http://backend_server; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + # vue.js frontend location / { From d699e9443577e0813145fefc64a57b7b8d1f16fb Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 7 May 2019 10:41:14 +0200 Subject: [PATCH 004/127] empty characteristica --- backend/pkdb_app/serializers.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/pkdb_app/serializers.py b/backend/pkdb_app/serializers.py index b65dd6db..b7fad0a0 100644 --- a/backend/pkdb_app/serializers.py +++ b/backend/pkdb_app/serializers.py @@ -146,8 +146,14 @@ def number_of_entries(self, entry): # validation (either 1 or max length) n_set = set(n_values) - if len(n_set) not in [1, 2]: - serializers.ValidationError( + + if len(n_set) == 0: + raise serializers.ValidationError( + f"Empty characteristica are not allowed", entry + ) + + elif len(n_set) not in [1, 2]: + raise serializers.ValidationError( f"Fields have different length, check || separators", entry ) From fff57617b255a4cea4a4dbb7484eeb78ba4ab557 Mon Sep 17 00:00:00 2001 From: Matthias Koenig Date: Tue, 7 May 2019 12:24:51 +0200 Subject: [PATCH 005/127] displaying sid in study view --- docker-update.sh | 8 +++++--- frontend/src/components/detail/StudyDetail.vue | 2 +- frontend/src/components/detail/StudyInfo.vue | 10 ---------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/docker-update.sh b/docker-update.sh index 125c90d5..6a7cbf69 100755 --- a/docker-update.sh +++ b/docker-update.sh @@ -13,27 +13,29 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) sudo echo "Update docker containers" # shut down all containers +echo "*** Shutdown containers ***" docker-compose -f $PKDB_DOCKER_COMPOSE_YAML down -# make sure containers are removed (if not running) +echo "*** Remove containers ***" docker container rm -f pkdb_frontend_1 docker container rm -f pkdb_backend_1 docker container rm -f pkdb_postgres_1 docker container rm -f pkdb_elasticsearch_1 docker container rm -f pkdb_nginx_1 -# make sure images are removed +echo "*** Remove images ***" docker image rm -f pkdb_frontend:latest docker image rm -f pkdb_backend:latest docker image rm -f pkdb_postgres:latest docker image rm -f pkdb_elasticsearch:latest docker image rm -f pkdb_nginx:latest -# remove frontend volumes +echo "*** Remove frontend volumes ***" docker volume rm -f pkdb_node_modules docker volume rm -f pkdb_vue_dist # cleanup all dangling images, containers, volumes and networks +echo "*** Cleanup volumes ***" docker system prune --force # build and start containers diff --git a/frontend/src/components/detail/StudyDetail.vue b/frontend/src/components/detail/StudyDetail.vue index 0c5e2ce8..45668540 100644 --- a/frontend/src/components/detail/StudyDetail.vue +++ b/frontend/src/components/detail/StudyDetail.vue @@ -2,7 +2,7 @@
- + {{icon("about")}} diff --git a/frontend/src/components/detail/StudyInfo.vue b/frontend/src/components/detail/StudyInfo.vue index 98fd237e..f92ad9e3 100644 --- a/frontend/src/components/detail/StudyInfo.vue +++ b/frontend/src/components/detail/StudyInfo.vue @@ -4,16 +4,6 @@ -
Substances
From ac76522bfc0cce9bced2c6e52181b6ebb48ba706 Mon Sep 17 00:00:00 2001 From: Matthias Koenig Date: Tue, 7 May 2019 15:51:42 +0200 Subject: [PATCH 006/127] Fix #316, comments displayed correctly --- frontend/src/components/lib/Annotations.vue | 4 +++- frontend/src/components/lib/Comments.vue | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/lib/Annotations.vue b/frontend/src/components/lib/Annotations.vue index b5455bd3..0f76e514 100644 --- a/frontend/src/components/lib/Annotations.vue +++ b/frontend/src/components/lib/Annotations.vue @@ -1,11 +1,13 @@ diff --git a/frontend/src/components/lib/Comments.vue b/frontend/src/components/lib/Comments.vue index bd5e701e..47f92cf7 100644 --- a/frontend/src/components/lib/Comments.vue +++ b/frontend/src/components/lib/Comments.vue @@ -1,7 +1,7 @@ From 1baa01b9736c9773113c22429991bb8c0f2367e1 Mon Sep 17 00:00:00 2001 From: Matthias Koenig Date: Tue, 7 May 2019 16:56:25 +0200 Subject: [PATCH 007/127] frontend fixes and npm updates --- frontend/package.json | 13 ++-- frontend/src/components/AboutInformation.vue | 6 +- frontend/src/components/detail/StudyInfo.vue | 2 +- frontend/src/components/lib/Annotations.vue | 5 -- frontend/src/components/lib/Comments.vue | 9 ++- frontend/src/components/lib/Descriptions.vue | 15 ++-- frontend/src/components/lib/UserAvatar.vue | 68 +------------------ frontend/src/components/lib/UserRating.vue | 26 +++++++ .../src/components/tables/StudiesTable.vue | 2 +- frontend/src/main.js | 4 ++ 10 files changed, 62 insertions(+), 88 deletions(-) create mode 100644 frontend/src/components/lib/UserRating.vue diff --git a/frontend/package.json b/frontend/package.json index a7b67774..fefa38f2 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,13 +16,14 @@ "@fortawesome/vue-fontawesome": "^0.1.1", "@statnett/vue-plotly": "^0.3.2", "axios": "^0.18.0", - "vue": "^2.5.17", + "vue": "^2.6.10", "vue-auth-image": "0.0.2", + "vue-plotly": "^1.0.0", "vue-resource": "^1.5.1", - "vue-router": "^3.0.1", - "vue-text-highlight": "^1.1.2", - "vuetify": "^1.2.0", - "vuex": "^3.0.1", + "vue-router": "^3.0.6", + "vue-text-highlight": "^1.1.3", + "vuetify": "^1.5.14", + "vuex": "^3.1.0", "vuex-persist": "^2.0.0" }, "devDependencies": { @@ -39,6 +40,6 @@ "stylus": "^0.54.5", "stylus-loader": "^3.0.2", "vue-cli-plugin-vuetify": "^0.2.1", - "vue-template-compiler": "^2.5.17" + "vue-template-compiler": "^2.6.10" } } diff --git a/frontend/src/components/AboutInformation.vue b/frontend/src/components/AboutInformation.vue index ae11986a..374095dd 100644 --- a/frontend/src/components/AboutInformation.vue +++ b/frontend/src/components/AboutInformation.vue @@ -8,7 +8,7 @@ Version: {{ version }}

- + {{ item.icon }} {{ item.title }}

@@ -41,8 +41,8 @@

This project is supported by the Federal Ministry of Education and Research (BMBF, Germany) within the research network Systems Medicine of the Liver (LiSyM, grant number 031L0054).

-   - +   +

diff --git a/frontend/src/components/detail/StudyInfo.vue b/frontend/src/components/detail/StudyInfo.vue index f92ad9e3..cd242441 100644 --- a/frontend/src/components/detail/StudyInfo.vue +++ b/frontend/src/components/detail/StudyInfo.vue @@ -19,7 +19,7 @@
Curators
- +
diff --git a/frontend/src/components/lib/Annotations.vue b/frontend/src/components/lib/Annotations.vue index 0f76e514..51d7cfe9 100644 --- a/frontend/src/components/lib/Annotations.vue +++ b/frontend/src/components/lib/Annotations.vue @@ -1,11 +1,6 @@ diff --git a/frontend/src/components/lib/UserAvatar.vue b/frontend/src/components/lib/UserAvatar.vue index 6e140677..d7232a37 100644 --- a/frontend/src/components/lib/UserAvatar.vue +++ b/frontend/src/components/lib/UserAvatar.vue @@ -1,23 +1,8 @@ @@ -34,17 +19,6 @@ comment: String, }, - watch: { - search: { - handler() { - this.calculate_size() - }, - } - }, - data() {return { - pulse : "" - - }}, computed: { username() { return this.user.first_name + ' ' + this.user.last_name; @@ -65,49 +39,9 @@ } return img_dir + 'anonymous_128.png'; }, - - }, - methods:{ - calculate_size(){ - if (this.search.length > 0 && this.username.toLowerCase().includes(this.search.toLowerCase())) { - this.pulse = "pulse" - } - else { - this.pulse = "" - } - } } } \ No newline at end of file diff --git a/frontend/src/components/lib/UserRating.vue b/frontend/src/components/lib/UserRating.vue new file mode 100644 index 00000000..f0595c93 --- /dev/null +++ b/frontend/src/components/lib/UserRating.vue @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/components/tables/StudiesTable.vue b/frontend/src/components/tables/StudiesTable.vue index 7ea4116c..c8e1714b 100644 --- a/frontend/src/components/tables/StudiesTable.vue +++ b/frontend/src/components/tables/StudiesTable.vue @@ -36,7 +36,7 @@ - + diff --git a/frontend/src/main.js b/frontend/src/main.js index 3931b4b6..1072de21 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -48,6 +48,8 @@ import Descriptions from './components/lib/Descriptions'; import Annotations from './components/lib/Annotations'; import UserAvatar from './components/lib/UserAvatar'; +import UserRating from './components/lib/UserRating'; + import Heading from './components/lib/Heading'; import HeadingToolbar from './components/lib/HeadingToolbar'; @@ -74,6 +76,8 @@ Vue.component('Annotations', Annotations); Vue.component('UserAvatar', UserAvatar); +Vue.component('UserRating', UserRating); + Vue.component('Heading', Heading); Vue.component('HeadingToolbar', HeadingToolbar); From 9dbd353891aa059be228b3e89a13fb3581a68b72 Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 7 May 2019 16:58:27 +0200 Subject: [PATCH 008/127] reference repair --- backend/pkdb_app/outputs/serializers.py | 2 +- backend/pkdb_app/studies/documents.py | 7 +-- backend/pkdb_app/studies/models.py | 9 ++-- backend/pkdb_app/studies/serializers.py | 10 +++-- backend/pkdb_app/studies/views.py | 44 +++++++++++++++++-- .../src/components/tables/ReferencesTable.vue | 6 +-- 6 files changed, 61 insertions(+), 17 deletions(-) diff --git a/backend/pkdb_app/outputs/serializers.py b/backend/pkdb_app/outputs/serializers.py index b0ba6e2a..749a467a 100644 --- a/backend/pkdb_app/outputs/serializers.py +++ b/backend/pkdb_app/outputs/serializers.py @@ -197,7 +197,7 @@ def validate_figure(self, value): class TimecourseSerializer(BaseOutputExSerializer): - pktype = serializers.SlugRelatedField(slug_field="key", queryset=PharmacokineticType.objects.all()) + pktype = serializers.SlugRelatedField(slug_field="key", queryset=PharmacokineticType.objects.all(),required=True) group = serializers.PrimaryKeyRelatedField( queryset=Group.objects.all(), read_only=False, required=False, allow_null=True diff --git a/backend/pkdb_app/studies/documents.py b/backend/pkdb_app/studies/documents.py index c6a980a5..1b007e70 100644 --- a/backend/pkdb_app/studies/documents.py +++ b/backend/pkdb_app/studies/documents.py @@ -16,10 +16,11 @@ @reference_index.doc_type class ReferenceDocument(DocType): pk = fields.IntegerField(attr='pk') - sid = fields.IntegerField(attr='sid') + sid = string_field(attr='sid') pmid = string_field(attr='pmid') study = ObjectField(properties={ "pk": fields.IntegerField(), + "sid": string_field('sid'), "name": string_field('name'), }) name = string_field("name") @@ -127,9 +128,9 @@ class StudyDocument(DocType): reference = ObjectField(properties={ - 'sid': fields.IntegerField(attr='sid'), + 'sid': string_field(attr='sid'), 'pk': fields.IntegerField(attr='pk'), - 'name': string_field("name") + 'name': string_field(attr="name") }) curators = fields.ObjectField( diff --git a/backend/pkdb_app/studies/models.py b/backend/pkdb_app/studies/models.py index 0c445528..50fc8cbb 100644 --- a/backend/pkdb_app/studies/models.py +++ b/backend/pkdb_app/studies/models.py @@ -56,8 +56,8 @@ class Reference(models.Model): This is the main class describing the publication or reference which describes the study. In most cases this is a published paper, but could be a thesis or unpublished. """ + sid = models.CharField(max_length=CHAR_MAX_LENGTH, unique=True) pmid = models.CharField(max_length=CHAR_MAX_LENGTH, null=True) # optional - sid = models.CharField(max_length=CHAR_MAX_LENGTH, primary_key=True) name = models.CharField(max_length=CHAR_MAX_LENGTH) doi = models.CharField(max_length=150, null=True) # optional title = models.TextField() @@ -70,9 +70,10 @@ class Reference(models.Model): def __str__(self): return self.title - @property - def id(self): - return self.pk + #@property + #def id(self): + # return self.pk + @property def study_pk(self): if self.study.first(): diff --git a/backend/pkdb_app/studies/serializers.py b/backend/pkdb_app/studies/serializers.py index aee6efe9..fcedda7b 100644 --- a/backend/pkdb_app/studies/serializers.py +++ b/backend/pkdb_app/studies/serializers.py @@ -40,7 +40,7 @@ def to_internal_value(self, data): return super().to_internal_value(data) -class ReferenceSerializer(SidSerializer): +class ReferenceSerializer(WrongKeyValidationSerializer): authors = AuthorSerializer(many=True, read_only=False) class Meta: @@ -59,7 +59,11 @@ class Meta: ) def create(self, validated_data): + #return super().create(validated_data) + authors_data = validated_data.pop("authors", []) + + reference = Reference.objects.create(**validated_data) update_or_create_multiple(reference, authors_data, "authors") reference.save() @@ -113,7 +117,7 @@ class StudySerializer(SidSerializer): """ - reference = serializers.PrimaryKeyRelatedField( + reference = serializers.SlugRelatedField(slug_field="sid", queryset=Reference.objects.all(), required=False, allow_null=True ) groupset = GroupSetSerializer(read_only=False, required=False, allow_null=True) @@ -375,7 +379,7 @@ class StudySmallElasticSerializer(serializers.HyperlinkedModelSerializer): #url = serializers.HyperlinkedIdentityField(read_only=True, lookup_field="id",view_name="references_elastic-detail") class Meta: model = Study - fields = ["pk","name"]#, 'url'] + fields = ["pk","sid","name"]#, 'url'] class CuratorRatingElasticSerializer(serializers.Serializer): rating = serializers.FloatField() diff --git a/backend/pkdb_app/studies/views.py b/backend/pkdb_app/studies/views.py index 982572e1..ce23b854 100644 --- a/backend/pkdb_app/studies/views.py +++ b/backend/pkdb_app/studies/views.py @@ -155,8 +155,8 @@ def update_index_study(request): class ElasticStudyViewSet(DocumentViewSet): - document_uid_field = "pk" - lookup_field = "pk" + document_uid_field = "sid__raw" + lookup_field = "sid" document = StudyDocument pagination_class = CustomPagination serializer_class = StudyElasticSerializer @@ -275,8 +275,9 @@ def get_queryset(self): class ElasticReferenceViewSet(DocumentViewSet): """Read/query/search references. """ + document_uid_field = "sid__raw" + lookup_field = "sid" document = ReferenceDocument - lookup_field = "id" pagination_class = CustomPagination permission_classes = (IsAdminOrCreatorOrCurator,) serializer_class = ReferenceElasticSerializer @@ -303,3 +304,40 @@ class ElasticReferenceViewSet(DocumentViewSet): "pdf":"pdf", "authors":"authors.last_name", } + + def get_object(self): + """Get object.""" + queryset = self.get_queryset() + lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field + if lookup_url_kwarg not in self.kwargs: + raise AttributeError( + "Expected view %s to be called with a URL keyword argument " + "named '%s'. Fix your URL conf, or set the `.lookup_field` " + "attribute on the view correctly." % ( + self.__class__.__name__, + lookup_url_kwarg + ) + ) + + if lookup_url_kwarg == 'id': + obj = self.document.get(id=self.kwargs[lookup_url_kwarg]) + return DictionaryProxy(obj.to_dict()) + else: + queryset = queryset.filter( + 'match', + **{self.document_uid_field: self.kwargs[lookup_url_kwarg]} + ) + + count = queryset.count() + if count == 1: + obj = queryset.execute().hits.hits[0]['_source'] + + return DictionaryProxy(obj) + + elif count > 1: + raise Http404( + "Multiple results matches the given query. " + "Expected a single result." + ) + + raise Http404("No result matches the given query.") diff --git a/frontend/src/components/tables/ReferencesTable.vue b/frontend/src/components/tables/ReferencesTable.vue index b23b5fd9..a3afb0e7 100644 --- a/frontend/src/components/tables/ReferencesTable.vue +++ b/frontend/src/components/tables/ReferencesTable.vue @@ -11,10 +11,10 @@ > @@ -239,4 +242,4 @@ top: 0px; visibility: hidden; } -https://vuetifyjs.com/en/components/api-explorer \ No newline at end of file + \ No newline at end of file diff --git a/frontend/src/components/detail/StudyInfo.vue b/frontend/src/components/detail/StudyInfo.vue index 7efb7344..e7424a72 100644 --- a/frontend/src/components/detail/StudyInfo.vue +++ b/frontend/src/components/detail/StudyInfo.vue @@ -1,23 +1,33 @@