From 63d9022d124a1552e690b27763d787cb602572d3 Mon Sep 17 00:00:00 2001 From: Stoyan Ekupov Date: Thu, 18 May 2017 04:58:02 +0300 Subject: [PATCH] 334 delete inventory requests (#1071) * Add delete request to inventory/index * Add delete inventory request tests --- app/inventory/index/controller.js | 10 ++++++- app/inventory/index/template.hbs | 15 ++++++----- tests/acceptance/inventory-test.js | 43 ++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/app/inventory/index/controller.js b/app/inventory/index/controller.js index 95f34b0f67..b80b5c21b4 100644 --- a/app/inventory/index/controller.js +++ b/app/inventory/index/controller.js @@ -1,5 +1,9 @@ +import Ember from 'ember'; import AbstractPagedController from 'hospitalrun/controllers/abstract-paged-controller'; import UserSession from 'hospitalrun/mixins/user-session'; + +const { computed } = Ember; + export default AbstractPagedController.extend(UserSession, { startKey: [], canAdd: function() { @@ -8,5 +12,9 @@ export default AbstractPagedController.extend(UserSession, { canFulfill: function() { return this.currentUserCan('fulfill_inventory'); - }.property() + }.property(), + + currentUserName: computed('', function() { + return this.getUserName(); + }) }); diff --git a/app/inventory/index/template.hbs b/app/inventory/index/template.hbs index 5dfeda9831..47d38319d8 100755 --- a/app/inventory/index/template.hbs +++ b/app/inventory/index/template.hbs @@ -6,9 +6,7 @@ {{t 'labels.quantity'}} {{t 'labels.requestedOn'}} {{t 'labels.requestedBy'}} - {{#if canFulfill}} - {{t 'labels.actions'}} - {{/if}} + {{t 'labels.actions'}} {{#each model as |request|}} @@ -16,11 +14,14 @@ {{request.quantity}} {{date-format request.dateRequested}} {{request.requestedBy}} - {{#if canFulfill}} - + + {{#if canFulfill}} - - {{/if}} + {{/if}} + {{#if (or canFulfill (and canAdd (eq request.requestedBy currentUserName)))}} + + {{/if}} + {{/each}} diff --git a/tests/acceptance/inventory-test.js b/tests/acceptance/inventory-test.js index db3fea97fd..3e3b030536 100644 --- a/tests/acceptance/inventory-test.js +++ b/tests/acceptance/inventory-test.js @@ -210,6 +210,49 @@ test('Fulfilling an inventory request', function(assert) { }); }); +test('Deleting an inventory request', function(assert) { + runWithPouchDump('inventory', function() { + authenticateUser(); + visit('/inventory'); + + andThen(() => { + assert.equal(currentURL(), '/inventory', 'Navigated to /inventory'); + assert.equal(find('button:contains(Delete)').length, 1, 'There is one request'); + }); + + click('button:contains(Delete)'); + waitToAppear('.modal-dialog'); + + andThen(() => { + assert.equal(find('.modal-title').text(), 'Delete Item', 'Deleting confirmation'); + }); + + click('.modal-content button:contains(Delete)'); + waitToAppear('.panel-body .alert-info'); + + andThen(function() { + assert.equal(currentURL(), '/inventory', 'Navigated to /inventory'); + assert.equal(find('button:contains(Delete)').length, 0, 'Request was deleted'); + }); + }); +}); + +test('User with add_inventory_request and without fulfill_inventory rights should not be able to delete others\' requests', function(assert) { + runWithPouchDump('inventory', function() { + authenticateUser({ + name: 'nurse.mgr', + roles: ['Nurse Manager', 'user'], + role: 'Nurse Manager' + }); + visit('/inventory'); + + andThen(() => { + assert.equal(currentURL(), '/inventory', 'Navigated to /inventory'); + assert.equal(find('button:contains(Delete)').length, 0, 'User doesn\'t see Delete button'); + }); + }); +}); + test('Receiving inventory', function(assert) { runWithPouchDump('inventory', function() { authenticateUser();