From e2de094ba0c5a60e4b08f5aa5fcb0c6c51a28218 Mon Sep 17 00:00:00 2001 From: winkidney Date: Tue, 11 Feb 2020 17:49:18 +0800 Subject: [PATCH] Fix: no-changes on board name should be allowed --- core/serializers.py | 5 +++-- pinry-spa/src/components/BoardEdit.vue | 21 +++++++++++++++++++-- pinry-spa/src/components/Boards.vue | 1 + pinry-spa/src/components/api.js | 4 ++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/core/serializers.py b/core/serializers.py index b4a1552..76f58e6 100644 --- a/core/serializers.py +++ b/core/serializers.py @@ -221,10 +221,11 @@ class BoardSerializer(serializers.HyperlinkedModelSerializer): def update(self, instance: Board, validated_data): pins_to_add = validated_data.pop("pins_to_add", []) pins_to_remove = validated_data.pop("pins_to_remove", []) - if Board.objects.filter( + board = Board.objects.filter( submitter=instance.submitter, name=validated_data.get('name', None) - ).exists(): + ).first() + if board.id != instance.id: raise ValidationError( detail={'name': "Board with this name already exists"} ) diff --git a/pinry-spa/src/components/BoardEdit.vue b/pinry-spa/src/components/BoardEdit.vue index 373368a..5d4e7aa 100644 --- a/pinry-spa/src/components/BoardEdit.vue +++ b/pinry-spa/src/components/BoardEdit.vue @@ -17,6 +17,13 @@ maxlength="128" > + + + + {{ pinModel.form.private.value?"only visible to yourself":"visible to everyone" }} +
@@ -30,6 +37,13 @@ maxlength="128" > + + + + {{ editModel.form.private.value?"only visible to yourself":"visible to everyone" }} +
@@ -56,7 +70,7 @@ import API from './api'; import ModelForm from './utils/ModelForm'; import bus from './utils/bus'; -const fields = ['name']; +const fields = ['name', 'private']; export default { name: 'BoardEditModal', @@ -108,7 +122,10 @@ export default { }, createBoard() { const self = this; - const promise = API.Board.create(this.createModel.form.name.value); + const promise = API.Board.create( + this.createModel.form.name.value, + this.createModel.form.private.value, + ); promise.then( (resp) => { bus.bus.$emit(bus.events.refreshBoards); diff --git a/pinry-spa/src/components/Boards.vue b/pinry-spa/src/components/Boards.vue index c7fda3b..e0341cd 100644 --- a/pinry-spa/src/components/Boards.vue +++ b/pinry-spa/src/components/Boards.vue @@ -76,6 +76,7 @@ function createBoardItem(board) { } boardItem.id = board.id; boardItem.name = board.name; + boardItem.private = board.private; boardItem.total_pins = pins4Board.length; if (previewImage.image.thumbnail.image !== null) { boardItem.preview_image_url = pinHandler.escapeUrl( diff --git a/pinry-spa/src/components/api.js b/pinry-spa/src/components/api.js index 3e07936..d64e46b 100644 --- a/pinry-spa/src/components/api.js +++ b/pinry-spa/src/components/api.js @@ -4,9 +4,9 @@ import storage from './utils/storage'; const API_PREFIX = '/api/v2/'; const Board = { - create(name) { + create(name, private_ = false) { const url = `${API_PREFIX}boards/`; - const data = { name }; + const data = { name, private: private_ }; return new Promise( (resolve, reject) => { axios.post(url, data).then(