Conversation
4829058
to
c279d3c
Compare
c279d3c
to
202390e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The models look good but I found what look like a few required fixes that we need to make to the API.
e55a295
to
bf022d3
Compare
202390e
to
f4b2479
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the permission updates and they look good. There were two lines in the test instructions that failed for me
- Preventing the creation of multiple configs for a single contributor
- Returning the embed config from the profile endpoint
Consider changes similar to these:
diff --git a/src/django/api/serializers.py b/src/django/api/serializers.py
index fd9bab1..a9ee624 100644
--- a/src/django/api/serializers.py
+++ b/src/django/api/serializers.py
@@ -171,11 +171,13 @@ class UserProfileSerializer(ModelSerializer):
other_contributor_type = SerializerMethodField()
facility_lists = SerializerMethodField()
is_verified = SerializerMethodField()
+ embed_config = SerializerMethodField()
class Meta:
model = User
fields = ('id', 'name', 'description', 'website', 'contributor_type',
- 'other_contributor_type', 'facility_lists', 'is_verified')
+ 'other_contributor_type', 'facility_lists', 'is_verified',
+ 'embed_config')
def get_name(self, user):
try:
@@ -233,6 +235,12 @@ class UserProfileSerializer(ModelSerializer):
except Contributor.DoesNotExist:
return False
+ def get_embed_config(self, user):
+ try:
+ return EmbedConfigSerializer(user.contributor.embed_config).data
+ except Contributor.DoesNotExist:
+ return None
+
class FacilityListSummarySerializer(ModelSerializer):
contributor_id = SerializerMethodField()
diff --git a/src/django/api/views.py b/src/django/api/views.py
index 5c60122..e5aac11 100644
--- a/src/django/api/views.py
+++ b/src/django/api/views.py
@@ -3534,6 +3534,8 @@ class EmbedConfigViewSet(mixins.ListModelMixin,
return Response(status=status.HTTP_401_UNAUTHORIZED)
contributor = self.get_contributor(request)
+ if contributor.embed_config is not None:
+ raise ValidationError('Contributor has an existing embed configuration.')
fields_data = request.data.pop('embed_fields', [])
@@ -3531,7 +3534,7 @@ def create(self, request): | |||
raise ValidationError( | |||
'Contributor has an existing embedded map configuration.') | |||
|
|||
fields_data = request.data.pop('embed_fields') | |||
fields_data = request.data.pop('embed_fields', []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice. I don't regularly use pop
and may have missed the fact that you can provide a default argument 👍
Thanks for the feedback! I've updated the profile fetching and the contributor check in d4b0b0c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for working through the changes with me.
The embed config is complex and will grow over time as we add features. Rather than serialize to the query string, store the config in the database and link it to the contributor.
Allow users to create, fetch and update embedded map configuration settings.
d4b0b0c
to
6422957
Compare
Thank you for reviewing! |
Overview
The embed config is complex and will grow over time as we add features. Rather than serialize to the query string, store the config in the database and link it to the contributor.
EmbedConfig
Connects #1299
Demo
Testing Instructions
./scripts/manage migrate
./scripts/server
and login as a user with an associated contributorPOST
a new embed config objectChecklist
fixup!
commits have been squashed