Fix: no-changes on board name should be allowed

This commit is contained in:
winkidney
2020-02-11 17:49:18 +08:00
parent dd76375399
commit e2de094ba0
4 changed files with 25 additions and 6 deletions

View File

@@ -221,10 +221,11 @@ class BoardSerializer(serializers.HyperlinkedModelSerializer):
def update(self, instance: Board, validated_data): def update(self, instance: Board, validated_data):
pins_to_add = validated_data.pop("pins_to_add", []) pins_to_add = validated_data.pop("pins_to_add", [])
pins_to_remove = validated_data.pop("pins_to_remove", []) pins_to_remove = validated_data.pop("pins_to_remove", [])
if Board.objects.filter( board = Board.objects.filter(
submitter=instance.submitter, submitter=instance.submitter,
name=validated_data.get('name', None) name=validated_data.get('name', None)
).exists(): ).first()
if board.id != instance.id:
raise ValidationError( raise ValidationError(
detail={'name': "Board with this name already exists"} detail={'name': "Board with this name already exists"}
) )

View File

@@ -17,6 +17,13 @@
maxlength="128" maxlength="128"
> >
</b-input> </b-input>
</b-field>
<b-field label="Privacy Option"
:type="createModel.form.private.type"
:message="createModel.form.private.error">
<b-checkbox v-model="createModel.form.private.value">
{{ pinModel.form.private.value?"only visible to yourself":"visible to everyone" }}
</b-checkbox>
</b-field> </b-field>
</div> </div>
<div v-if="isEdit"> <div v-if="isEdit">
@@ -30,6 +37,13 @@
maxlength="128" maxlength="128"
> >
</b-input> </b-input>
</b-field>
<b-field label="Privacy Option"
:type="editModel.form.private.type"
:message="editModel.form.private.error">
<b-checkbox v-model="editModel.form.private.value">
{{ editModel.form.private.value?"only visible to yourself":"visible to everyone" }}
</b-checkbox>
</b-field> </b-field>
</div> </div>
</section> </section>
@@ -56,7 +70,7 @@ import API from './api';
import ModelForm from './utils/ModelForm'; import ModelForm from './utils/ModelForm';
import bus from './utils/bus'; import bus from './utils/bus';
const fields = ['name']; const fields = ['name', 'private'];
export default { export default {
name: 'BoardEditModal', name: 'BoardEditModal',
@@ -108,7 +122,10 @@ export default {
}, },
createBoard() { createBoard() {
const self = this; 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( promise.then(
(resp) => { (resp) => {
bus.bus.$emit(bus.events.refreshBoards); bus.bus.$emit(bus.events.refreshBoards);

View File

@@ -76,6 +76,7 @@ function createBoardItem(board) {
} }
boardItem.id = board.id; boardItem.id = board.id;
boardItem.name = board.name; boardItem.name = board.name;
boardItem.private = board.private;
boardItem.total_pins = pins4Board.length; boardItem.total_pins = pins4Board.length;
if (previewImage.image.thumbnail.image !== null) { if (previewImage.image.thumbnail.image !== null) {
boardItem.preview_image_url = pinHandler.escapeUrl( boardItem.preview_image_url = pinHandler.escapeUrl(

View File

@@ -4,9 +4,9 @@ import storage from './utils/storage';
const API_PREFIX = '/api/v2/'; const API_PREFIX = '/api/v2/';
const Board = { const Board = {
create(name) { create(name, private_ = false) {
const url = `${API_PREFIX}boards/`; const url = `${API_PREFIX}boards/`;
const data = { name }; const data = { name, private: private_ };
return new Promise( return new Promise(
(resolve, reject) => { (resolve, reject) => {
axios.post(url, data).then( axios.post(url, data).then(