garrensmith closed pull request #1027: Use PUT endpoint to clone doc
URL: https://github.com/apache/couchdb-fauxton/pull/1027
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/app/addons/documents/doc-editor/actions.js
b/app/addons/documents/doc-editor/actions.js
index e66d5cd8a..fe49cfa28 100644
--- a/app/addons/documents/doc-editor/actions.js
+++ b/app/addons/documents/doc-editor/actions.js
@@ -12,7 +12,6 @@
/* global FormData */
-import app from "../../../app";
import FauxtonAPI from "../../../core/api";
import ActionTypes from "./actiontypes";
@@ -116,14 +115,11 @@ function hideCloneDocModal () {
}
function cloneDoc (database, doc, newId) {
- const docId = app.utils.getSafeIdForDoc(newId);
hideCloneDocModal();
- doc.copy(docId).then(() => {
- doc.set({ _id: docId });
-
- FauxtonAPI.navigate('/database/' + database.safeID() + '/' + docId, {
trigger: true });
+ doc.copy(newId).then(() => {
+ FauxtonAPI.navigate('/database/' + database.safeID() + '/' +
encodeURIComponent(newId), { trigger: true });
FauxtonAPI.addNotification({
msg: 'Document has been duplicated.'
diff --git a/app/addons/documents/doc-editor/components.js
b/app/addons/documents/doc-editor/components.js
index 252d0d6c9..5185676f2 100644
--- a/app/addons/documents/doc-editor/components.js
+++ b/app/addons/documents/doc-editor/components.js
@@ -1,6 +1,3 @@
-import FauxtonAPI from "../../../core/api";
-import app from "../../../app";
-
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
of
// the License at
@@ -13,9 +10,9 @@ import app from "../../../app";
// License for the specific language governing permissions and limitations
under
// the License.
-
+import FauxtonAPI from "../../../core/api";
+import app from "../../../app";
import PropTypes from 'prop-types';
-
import React from "react";
import { Dropdown, MenuItem } from "react-bootstrap";
import ReactDOM from "react-dom";
diff --git a/app/addons/documents/shared-resources.js
b/app/addons/documents/shared-resources.js
index 0f2516020..440911547 100644
--- a/app/addons/documents/shared-resources.js
+++ b/app/addons/documents/shared-resources.js
@@ -183,11 +183,12 @@ Documents.Doc = FauxtonAPI.Model.extend({
},
copy: function (copyId) {
- return $.ajax({
- type: 'COPY',
- url: '/' + this.database.safeID() + '/' + this.safeID(),
- headers: {Destination: copyId}
+ const attrs = Object.assign({}, this.attributes, {_id: copyId});
+ delete attrs._rev;
+ const clonedDoc = new this.constructor(attrs, {
+ database: this.database
});
+ return clonedDoc.save();
},
isNewDoc: function () {
diff --git a/app/addons/documents/tests/nightwatch/cloneDoc.js
b/app/addons/documents/tests/nightwatch/cloneDoc.js
index bcad6eaea..7f636ae95 100644
--- a/app/addons/documents/tests/nightwatch/cloneDoc.js
+++ b/app/addons/documents/tests/nightwatch/cloneDoc.js
@@ -16,6 +16,7 @@ module.exports = {
const waitTime = client.globals.maxWaitTime;
const newDatabaseName = client.globals.testDatabaseName;
const newDocumentName = 'clone_doc_doc';
+ const clonedDocName = 'cloned/document';
const baseUrl = client.globals.test_settings.launch_url;
client
@@ -32,13 +33,13 @@ module.exports = {
.clickWhenVisible('.clone-doc-modal input')
.clearValue('.clone-doc-modal input')
- .setValue('.clone-doc-modal input', ['ente'])
+ .setValue('.clone-doc-modal input', [clonedDocName])
.clickWhenVisible('.clone-doc-modal button.btn.btn-primary')
.closeNotification()
.waitForAttribute('.faux-header__breadcrumbs
.faux-header__breadcrumbs-element:last-child', 'textContent', function
(docContents) {
- return 'ente' === docContents.trim();
+ return clonedDocName === docContents.trim();
})
.url(`${baseUrl}'/'${newDatabaseName}/${newDocumentName}`)
@@ -46,7 +47,7 @@ module.exports = {
.waitForElementNotPresent('.loading-lines', waitTime, false)
.getText('#editor-container', function (result) {
const data = result.value;
- const isCreatedDocumentPresent = data.indexOf('ente') !== -1;
+ const isCreatedDocumentPresent = data.indexOf(clonedDocName) !== -1;
this.verify.ok(
isCreatedDocumentPresent,
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services