Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Delete Product Tooltip To Archive Product #2030

Merged
merged 7 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place your settings in this file to overwrite default and user settings.
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
type="button"
class="rui delete-product2 btn btn-danger flat"
data-toggle="tooltip"
title="{{i18n 'productDetailEdit.deleteProduct' 'Delete Product'}}"
data-original-title="{{i18n 'productDetailEdit.deleteProduct' 'Delete Product'}}"
data-event-action="deleteProduct"
title="{{i18n 'productDetailEdit.archiveProduct' 'Archive Product'}}"
data-original-title="{{i18n 'productDetailEdit.archiveProduct' 'Archive Product'}}"
data-event-action="archiveProduct"
>
<span class="fa fa-trash-o fa-lg"></span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ Template.productSettings.events({
"click [data-event-action=cloneProduct]": function () {
ReactionProduct.cloneProduct(this.products);
},
"click [data-event-action=deleteProduct]": function () {
ReactionProduct.maybeDeleteProduct(this.products);
"click [data-event-action=archiveProduct]": function () {
ReactionProduct.archiveProduct(this.products);
},
"click [data-event-action=changeProductWeight]": function (event) {
event.preventDefault();
Expand Down
4 changes: 2 additions & 2 deletions lib/api/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ ReactionProduct.cloneProduct = function (productOrArray) {
* @param {Object} productOrArray - product Object
* @returns {undefined} - returns nothing, and alerts, happen here
*/
ReactionProduct.maybeDeleteProduct = function (productOrArray) {
ReactionProduct.archiveProduct = function (productOrArray) {
const products = !_.isArray(productOrArray) ? [productOrArray] : productOrArray;
const productIds = _.map(products, product => typeof product === "string" ? product : product._id);
let confirmTitle;
Expand All @@ -451,7 +451,7 @@ ReactionProduct.maybeDeleteProduct = function (productOrArray) {
confirmButtonText: "Archive"
}, (isConfirm) => {
if (isConfirm) {
Meteor.call("products/deleteProduct", productIds, function (error, result) {
Meteor.call("products/archiveProduct", productIds, function (error, result) {
let title;
if (error) {
title = products.length === 1 ?
Expand Down
2 changes: 1 addition & 1 deletion private/data/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
"duplicateProduct": "Duplicate Product",
"pinProduct": "Pin Product",
"toggleSize": "Toggle Size",
"deleteProduct": "Delete Product",
"archiveProduct": "Archive Product",
"restoreProduct": "Restore Product from Trash",
"deleteSelectedProducts": "Delete selected products?",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need this "Delete selected products?"?

Copy link
Author

Choose a reason for hiding this comment

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

No, we do not.

"archiveThisProduct": "Archive this product?",
Expand Down
10 changes: 5 additions & 5 deletions server/methods/catalog.app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,30 +427,30 @@ describe("core product methods", function () {
it("should throw 403 error by non admin", function () {
sandbox.stub(Reaction, "hasPermission", () => false);
const removeProductSpy = sandbox.spy(Products, "remove");
expect(() => Meteor.call("products/deleteProduct", "fakeId")).to.throw(Meteor.Error, /Access Denied/);
expect(() => Meteor.call("products/archiveProduct", "fakeId")).to.throw(Meteor.Error, /Access Denied/);
expect(removeProductSpy).to.not.have.been.called;
});

it("should not mark product as deleted by admin", function () {
sandbox.stub(Reaction, "hasPermission", () => true);
let product = addProduct();
Meteor.call("products/deleteProduct", product._id);
Meteor.call("products/archiveProduct", product._id);
product = Products.findOne(product._id);
expect(product.isDeleted).to.equal(false);
});

it("should mark product revision as deleted by admin", function () {
sandbox.stub(Reaction, "hasPermission", () => true);
const product = addProduct();
Meteor.call("products/deleteProduct", product._id);
Meteor.call("products/archiveProduct", product._id);
const productRevision = Revisions.findOne({ documentId: product._id });
expect(productRevision.documentData.isDeleted).to.equal(true);
});

it("should publish product revision marked as deleted by admin", function () {
sandbox.stub(Reaction, "hasPermission", () => true);
let product = addProduct();
Meteor.call("products/deleteProduct", product._id);
Meteor.call("products/archiveProduct", product._id);
Meteor.call("revisions/publish", product._id);
product = Products.findOne(product._id);
expect(product.isDeleted).to.equal(true);
Expand All @@ -460,7 +460,7 @@ describe("core product methods", function () {
sandbox.stub(Reaction, "hasPermission", () => true);
const product = addProduct();
sandbox.stub(Products, "remove");
expect(() => Meteor.call("products/deleteProduct", product._id)).to.throw(Meteor.Error,
expect(() => Meteor.call("products/archiveProduct", product._id)).to.throw(Meteor.Error,
/Something went wrong, nothing was deleted/);
expect(Products.find(product._id).count()).to.equal(1);
});
Expand Down
4 changes: 2 additions & 2 deletions server/methods/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,12 @@ Meteor.methods({
},

/**
* products/deleteProduct
* products/archiveProduct
* @summary delete a product and unlink it from all media
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably should change this in the comment as well

* @param {String} productId - productId to delete
* @returns {Number} returns number of removed products
*/
"products/deleteProduct": function (productId) {
"products/archiveProduct": function (productId) {
check(productId, Match.OneOf(Array, String));
// must have admin permission to delete
if (!Reaction.hasPermission("createProduct") && !Reaction.hasAdminAccess()) {
Expand Down