Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
v-model="contentDefaults"
/>

<VBtn class="mt-5" color="primary" type="submit">
<VBtn class="mt-5" color="primary" type="submit" :disabled="isDisable">
{{ isNew ? $tr('createButton') : $tr('saveChangesButton' ) }}
</VBtn>
</VForm>
Expand Down Expand Up @@ -153,6 +153,7 @@
showUnsavedDialog: false,
diffTracker: {},
dialog: true,
isDisable: false,
};
},
computed: {
Expand Down Expand Up @@ -287,21 +288,25 @@
...mapActions('channel', ['updateChannel', 'loadChannel', 'commitChannel']),
...mapMutations('channel', ['REMOVE_CHANNEL']),
saveChannel() {
this.isDisable = true;
if (this.$refs.detailsform.validate()) {
this.changed = false;
if (this.isNew) {
return this.commitChannel({ id: this.channelId, ...this.diffTracker }).then(() => {
// TODO: Make sure channel gets created before navigating to channel
window.location = window.Urls.channel(this.channelId);
this.isDisable = false;
});
} else {
return this.updateChannel({ id: this.channelId, ...this.diffTracker }).then(() => {
this.$store.dispatch('showSnackbarSimple', this.$tr('changesSaved'));
this.header = this.channel.name;
this.isDisable = false;
});
}
} else if (this.$refs.detailsform.$el.scrollIntoView) {
this.$refs.detailsform.$el.scrollIntoView({ behavior: 'smooth' });
this.isDisable = false;
}
},
updateTitleForPage() {
Expand Down
8 changes: 7 additions & 1 deletion contentcuration/contentcuration/viewsets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from celery import states
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from django.db.utils import IntegrityError
from django.http import Http404
from django.http.request import HttpRequest
from django_bulk_update.helper import bulk_update
Expand Down Expand Up @@ -659,7 +660,12 @@ def create_from_changes(self, changes):
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)

try:
self.perform_create(serializer)

except IntegrityError as e:
return Response({"error": str(e)}, status=409)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's worth doing, but if the endpoint returns this 409 status code, then perhaps the frontend can redirect to the channel page like it does with the normal 201 response?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our main objective while implementing this was to try and throw a more meaningful error when creating a channel that the Id already exists.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay! I was simply thinking about whether the change was as meaningful to the end-user as it is to us, since it would silence error reports on our end.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! But again, do we need a redirect when double creation happens? Or we could try and find a way of letting the user know if double creation happened.

Copy link
Copy Markdown
Member

@bjester bjester Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's very unlikely a user encounters this scenario submitting the form. But if they somehow did encounter it, or perhaps even a gateway timeout 502 error, I don't think the frontend would give the user notice one of those errors occurred, meaning the submit button would be forever disabled without any indication to the user.

instance = serializer.instance
return Response(self.serialize_object(pk=instance.pk), status=HTTP_201_CREATED)

Expand Down