From 7cef82e3ec6a12a6c1dde277ad2bb26e28df03c1 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Fri, 13 Jul 2018 16:50:50 -0400
Subject: [PATCH 01/36] creating new deliveries WIP
Adds
deliveries/new/select-project route
deliveries/new/select-recipient route
deliveries/new/enter-user-message route
Passses IDs as queryParams between routes
TODO:
replace underscore query params with camel case
filter projects to those we can actually deliver
filter recipient to not include current user
cleanup select recipient screen - still confusing
---
app/components/delivery-breadcrumbs.js | 8 +++-
app/components/duke-ds-project-list.js | 20 ++++++++++
app/components/duke-ds-user-list.js | 23 +++++++++++
app/controllers/deliveries.js | 18 +++++++++
.../deliveries/new/enter-user-message.js | 40 +++++++++++++++++++
.../deliveries/new/select-project.js | 22 ++++++++++
.../deliveries/new/select-recipient.js | 39 ++++++++++++++++++
.../deliveries/show/can-resend-controller.js | 21 ++--------
app/models/delivery-answer-set.js | 9 +++++
app/models/delivery.js | 2 +-
app/router.js | 5 +++
app/routes/deliveries/new.js | 7 ++++
.../deliveries/new/enter-user-message.js | 4 ++
app/routes/deliveries/new/index.js | 7 ++++
app/routes/deliveries/new/select-project.js | 7 ++++
app/routes/deliveries/new/select-recipient.js | 9 +++++
app/styles/app.css | 4 ++
.../components/delivery-breadcrumbs.hbs | 4 ++
app/templates/components/delivery-table.hbs | 2 +-
.../components/duke-ds-project-list.hbs | 12 ++++++
.../components/duke-ds-user-list.hbs | 13 ++++++
app/templates/deliveries/index.hbs | 1 +
app/templates/deliveries/new.hbs | 1 +
.../deliveries/new/enter-user-message.hbs | 30 ++++++++++++++
app/templates/deliveries/new/index.hbs | 1 +
.../deliveries/new/select-project.hbs | 11 +++++
.../deliveries/new/select-recipient.hbs | 13 ++++++
.../components/duke-ds-project-list-test.js | 25 ++++++++++++
.../components/duke-ds-user-list-test.js | 25 ++++++++++++
tests/unit/controllers/deliveries-test.js | 12 ++++++
.../deliveries/new/enter-user-message-test.js | 12 ++++++
.../deliveries/new/select-project-test.js | 12 ++++++
.../deliveries/new/select-recipient-test.js | 12 ++++++
tests/unit/models/delivery-answer-set-test.js | 12 ++++++
tests/unit/routes/deliveries/new-test.js | 11 +++++
.../deliveries/new/enter-user-message-test.js | 11 +++++
.../unit/routes/deliveries/new/index-test.js | 11 +++++
.../deliveries/new/select-project-test.js | 11 +++++
.../deliveries/new/select-recipient-test.js | 11 +++++
39 files changed, 477 insertions(+), 21 deletions(-)
create mode 100644 app/components/duke-ds-project-list.js
create mode 100644 app/components/duke-ds-user-list.js
create mode 100644 app/controllers/deliveries.js
create mode 100644 app/controllers/deliveries/new/enter-user-message.js
create mode 100644 app/controllers/deliveries/new/select-project.js
create mode 100644 app/controllers/deliveries/new/select-recipient.js
create mode 100644 app/models/delivery-answer-set.js
create mode 100644 app/routes/deliveries/new.js
create mode 100644 app/routes/deliveries/new/enter-user-message.js
create mode 100644 app/routes/deliveries/new/index.js
create mode 100644 app/routes/deliveries/new/select-project.js
create mode 100644 app/routes/deliveries/new/select-recipient.js
create mode 100644 app/templates/components/duke-ds-project-list.hbs
create mode 100644 app/templates/components/duke-ds-user-list.hbs
create mode 100644 app/templates/deliveries/new.hbs
create mode 100644 app/templates/deliveries/new/enter-user-message.hbs
create mode 100644 app/templates/deliveries/new/index.hbs
create mode 100644 app/templates/deliveries/new/select-project.hbs
create mode 100644 app/templates/deliveries/new/select-recipient.hbs
create mode 100644 tests/integration/components/duke-ds-project-list-test.js
create mode 100644 tests/integration/components/duke-ds-user-list-test.js
create mode 100644 tests/unit/controllers/deliveries-test.js
create mode 100644 tests/unit/controllers/deliveries/new/enter-user-message-test.js
create mode 100644 tests/unit/controllers/deliveries/new/select-project-test.js
create mode 100644 tests/unit/controllers/deliveries/new/select-recipient-test.js
create mode 100644 tests/unit/models/delivery-answer-set-test.js
create mode 100644 tests/unit/routes/deliveries/new-test.js
create mode 100644 tests/unit/routes/deliveries/new/enter-user-message-test.js
create mode 100644 tests/unit/routes/deliveries/new/index-test.js
create mode 100644 tests/unit/routes/deliveries/new/select-project-test.js
create mode 100644 tests/unit/routes/deliveries/new/select-recipient-test.js
diff --git a/app/components/delivery-breadcrumbs.js b/app/components/delivery-breadcrumbs.js
index 4e63ccc..0e20553 100644
--- a/app/components/delivery-breadcrumbs.js
+++ b/app/components/delivery-breadcrumbs.js
@@ -6,9 +6,13 @@ export default Ember.Component.extend({
transfer: null, /* specific transfer to be passed to child breadcrumbs */
selectedRouteName: null, /* route we should select ('deliveries.index', 'deliveries.show', etc) */
isDeliverySelected: Ember.computed('selectedRouteName', function () {
- return this.get('selectedRouteName') !== 'deliveries.index';
+ // selected route starts with deliveries.show
+ return this.get('selectedRouteName').indexOf('deliveries.show') == 0;
}),
isResendSelected: Ember.computed('selectedRouteName', function () {
return this.get('selectedRouteName') === 'deliveries.show.resend';
- })
+ }),
+ isNewDeliverySelected: Ember.computed('selectedRouteName', function () {
+ return this.get('selectedRouteName') === 'deliveries.new';
+ }),
});
diff --git a/app/components/duke-ds-project-list.js b/app/components/duke-ds-project-list.js
new file mode 100644
index 0000000..e169c49
--- /dev/null
+++ b/app/components/duke-ds-project-list.js
@@ -0,0 +1,20 @@
+import Ember from 'ember';
+
+const DukeDSProjectList = Ember.Component.extend({
+ projects: null,
+ selectionChanged: null, /** action */
+ columns: [
+ { propertyName: "name", title: "Project Name"}
+ ],
+ actions: {
+ displayDataChanged: function (e) {
+ this.get('selectionChanged')(e);
+ }
+ }
+});
+
+DukeDSProjectList.reopenClass({
+ positionalParams: ['projects']
+});
+
+export default DukeDSProjectList;
diff --git a/app/components/duke-ds-user-list.js b/app/components/duke-ds-user-list.js
new file mode 100644
index 0000000..33bee87
--- /dev/null
+++ b/app/components/duke-ds-user-list.js
@@ -0,0 +1,23 @@
+import Ember from 'ember';
+
+const DukeDSUserList = Ember.Component.extend({
+ users: null,
+ multipleSelect: false,
+ pageSize: 12,
+ selectionChanged: null, /** action */
+ columns: [
+ { propertyName: "fullName", title: "Name"},
+ { propertyName: "email", title: "Email"}
+ ],
+ actions: {
+ displayDataChanged: function (e) {
+ this.get('selectionChanged')(e);
+ }
+ }
+});
+
+DukeDSUserList.reopenClass({
+ positionalParams: ['users']
+});
+
+export default DukeDSUserList;
diff --git a/app/controllers/deliveries.js b/app/controllers/deliveries.js
new file mode 100644
index 0000000..d1ff13c
--- /dev/null
+++ b/app/controllers/deliveries.js
@@ -0,0 +1,18 @@
+import Ember from 'ember';
+
+export default Ember.Controller.extend({
+ session: Ember.inject.service('session'),
+ dukeDsUser: Ember.inject.service('duke-ds-user'),
+ currentDukeDsUser: null,
+ authenticatedDidChange: Ember.on('init',
+ Ember.observer('session.isAuthenticated', function() {
+ if (this.get('session.isAuthenticated')) {
+ this.get('dukeDsUser').currentDukeDsUser().then(currentDukeDsUser => {
+ this.set('currentDukeDsUser', currentDukeDsUser);
+ });
+ } else {
+ this.set('currentDukeDsUser', null);
+ }
+ })
+ )
+});
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
new file mode 100644
index 0000000..b4cc2af
--- /dev/null
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -0,0 +1,40 @@
+import Ember from 'ember';
+
+export default Ember.Controller.extend({
+ queryParams: ['project_id', 'to_user_id', 'share_user_ids'],
+ project_id: null,
+ to_user_id: null,
+ share_user_ids: null,
+ deliveriesController: Ember.inject.controller('deliveries'),
+ project: Ember.computed('project_id', function () {
+ return this.get('store').findRecord('duke-ds-project', this.get('project_id'));
+ }),
+ fromUser: Ember.computed.alias('deliveriesController.currentDukeDsUser'),
+ toUser: Ember.computed('to_user_id', function () {
+ return this.get('store').findRecord('duke-ds-user', this.get('to_user_id'));
+ }),
+ shareUsers: Ember.computed('share_user_ids', function () {
+ const store = this.get('store');
+ return this.get('share_user_ids')
+ .split(',')
+ .map(user_id => store.findRecord('duke-ds-user', user_id));
+ }),
+ actions: {
+ back() {
+ const projectId = this.get('project_id');
+ this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { project_id: projectId }});
+ },
+ saveAndSend() {
+ const delivery = this.get('store').createRecord({
+ project: this.get('project.id'),
+ toUser: this.get('toUser.id'),
+ shareUsers: this.get('shareUsers').mapBy('id')
+ });
+ delivery.save().then(function (delivery) {
+ delivery.send().then(function () {
+ self.transitionToRoute('deliveries.show', delivery.get('transfer'));
+ });
+ });
+ }
+ },
+});
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
new file mode 100644
index 0000000..98c429d
--- /dev/null
+++ b/app/controllers/deliveries/new/select-project.js
@@ -0,0 +1,22 @@
+import Ember from 'ember';
+
+export default Ember.Controller.extend({
+ disableNext: Ember.computed.not('project'),
+ project: null,
+ actions: {
+ back() {
+ this.transitionToRoute('deliveries');
+ },
+ next() {
+ const projectId = this.get('project.id');
+ this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { project_id: projectId }});
+ },
+ projectSelectionChanged(actionData) {
+ var selectedItem = null;
+ if (actionData.selectedItems) {
+ selectedItem = actionData.selectedItems[0];
+ }
+ this.set('project', selectedItem);
+ }
+ },
+});
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
new file mode 100644
index 0000000..96b90e4
--- /dev/null
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -0,0 +1,39 @@
+import Ember from 'ember';
+
+export default Ember.Controller.extend({
+ queryParams: ['project_id'],
+ project_id: null,
+ project: Ember.computed('project_id', function () {
+ return this.get('store').findRecord('duke-ds-project', this.get('project_id'));
+ }),
+ toUser: null,
+ shareUsers: null,
+ disableNext: Ember.computed.not('toUser'),
+ actions: {
+ toUserSelectionChanged(actionData) {
+ var selectedItem = null;
+ if (actionData.selectedItems) {
+ selectedItem = actionData.selectedItems[0];
+ }
+ this.set('toUser', selectedItem);
+ },
+ shareUsersSelectionChanged(actionData) {
+ this.set('shareUsers', actionData.selectedItems);
+ },
+ back() {
+ this.transitionToRoute('deliveries.new.select-project');
+ },
+ next() {
+ const projectId = this.get('project.id');
+ const toUserId = this.get('toUser.id');
+ const shareUserIds = this.get('shareUsers').mapBy('id').join(',');
+ this.transitionToRoute('deliveries.new.enter-user-message', {
+ queryParams: {
+ project_id: projectId,
+ to_user_id: toUserId,
+ share_user_ids: shareUserIds
+ }
+ });
+ }
+ }
+});
diff --git a/app/controllers/deliveries/show/can-resend-controller.js b/app/controllers/deliveries/show/can-resend-controller.js
index ee56c42..664c03f 100644
--- a/app/controllers/deliveries/show/can-resend-controller.js
+++ b/app/controllers/deliveries/show/can-resend-controller.js
@@ -4,27 +4,14 @@
import Ember from 'ember';
export default Ember.Controller.extend({
- session: Ember.inject.service('session'),
- dukeDsUser: Ember.inject.service('duke-ds-user'),
- currentDukeDsUser: null,
- canResend: Ember.computed('model.canResend', 'model.fromUser.id', 'currentDukeDsUser.id', function () {
+ deliveriesController: Ember.inject.controller('deliveries'),
+ canResend: Ember.computed('deliveriesController.currentDukeDsUser.id', function () {
const modelCanResend = this.get('model.canResend');
const fromUserId = this.get('model.fromUser.id');
- const currentDukeDsUserId = this.get('currentDukeDsUser.id');
+ const currentDukeDsUserId = this.get('deliveriesController.currentDukeDsUser.id');
if (!currentDukeDsUserId) {
return false;
}
return modelCanResend && fromUserId == currentDukeDsUserId;
- }),
- authenticatedDidChange: Ember.on('init',
- Ember.observer('session.isAuthenticated', function() {
- if (this.get('session.isAuthenticated')) {
- this.get('dukeDsUser').currentDukeDsUser().then(currentDukeDsUser => {
- this.set('currentDukeDsUser', currentDukeDsUser);
- });
- } else {
- this.set('currentDukeDsUser', null);
- }
- })
- )
+ })
});
diff --git a/app/models/delivery-answer-set.js b/app/models/delivery-answer-set.js
new file mode 100644
index 0000000..085c1a8
--- /dev/null
+++ b/app/models/delivery-answer-set.js
@@ -0,0 +1,9 @@
+import DS from 'ember-data';
+
+export default DS.Model.extend({
+ project: DS.belongsTo('DukeDsProject'),
+ fromUser: DS.belongsTo('DukeDsUser'),
+ toUser: DS.belongsTo('DukeDsUser'),
+ shareUsers: DS.hasMany('DukeDsUser'),
+ userMessage: DS.attr('string'),
+});
diff --git a/app/models/delivery.js b/app/models/delivery.js
index 3b73436..9cf8ad5 100644
--- a/app/models/delivery.js
+++ b/app/models/delivery.js
@@ -9,7 +9,7 @@ export default DS.Model.extend({
project: DS.belongsTo('DukeDsProject'),
fromUser: DS.belongsTo('DukeDsUser'),
toUser: DS.belongsTo('DukeDsUser'),
- state: DS.attr('string'),
+ state: DS.attr('string', { defaultValue() { return STATE_NEW }}),
transfer: DS.belongsTo('DukeDsProjectTransfer'),
userMessage: DS.attr('string'),
shareUsers: DS.hasMany('DukeDsUser'),
diff --git a/app/router.js b/app/router.js
index cd7519f..bea88ce 100644
--- a/app/router.js
+++ b/app/router.js
@@ -12,6 +12,11 @@ Router.map(function() {
this.route('show', { path: '/:transfer_id'}, function () {
this.route('resend', {});
});
+ this.route('new', function() {
+ this.route('select-project');
+ this.route('select-recipient');
+ this.route('enter-user-message');
+ });
});
this.route('get-token');
});
diff --git a/app/routes/deliveries/new.js b/app/routes/deliveries/new.js
new file mode 100644
index 0000000..cf30cdb
--- /dev/null
+++ b/app/routes/deliveries/new.js
@@ -0,0 +1,7 @@
+import Ember from 'ember';
+
+export default Ember.Route.extend({
+ model() {
+ return this.get('store').createRecord('delivery');
+ }
+});
diff --git a/app/routes/deliveries/new/enter-user-message.js b/app/routes/deliveries/new/enter-user-message.js
new file mode 100644
index 0000000..26d9f31
--- /dev/null
+++ b/app/routes/deliveries/new/enter-user-message.js
@@ -0,0 +1,4 @@
+import Ember from 'ember';
+
+export default Ember.Route.extend({
+});
diff --git a/app/routes/deliveries/new/index.js b/app/routes/deliveries/new/index.js
new file mode 100644
index 0000000..5581e9c
--- /dev/null
+++ b/app/routes/deliveries/new/index.js
@@ -0,0 +1,7 @@
+import Ember from 'ember';
+
+export default Ember.Route.extend({
+ beforeModel() {
+ this.transitionTo('deliveries.new.select-project');
+ }
+});
diff --git a/app/routes/deliveries/new/select-project.js b/app/routes/deliveries/new/select-project.js
new file mode 100644
index 0000000..4ec2d88
--- /dev/null
+++ b/app/routes/deliveries/new/select-project.js
@@ -0,0 +1,7 @@
+import Ember from 'ember';
+
+export default Ember.Route.extend({
+ model() {
+ return this.get('store').findAll('duke-ds-project');
+ }
+});
diff --git a/app/routes/deliveries/new/select-recipient.js b/app/routes/deliveries/new/select-recipient.js
new file mode 100644
index 0000000..5306082
--- /dev/null
+++ b/app/routes/deliveries/new/select-recipient.js
@@ -0,0 +1,9 @@
+import Ember from 'ember';
+
+export default Ember.Route.extend({
+ model() {
+
+
+ return this.get('store').findAll('duke-ds-user');
+ }
+});
diff --git a/app/styles/app.css b/app/styles/app.css
index f234508..1c89467 100644
--- a/app/styles/app.css
+++ b/app/styles/app.css
@@ -1,3 +1,7 @@
.small-left-margin {
margin-left: 1em;
}
+
+tr.selected-row>td:not(.grouping-cell), tr.selected-expand>td:not(.grouping-cell) {
+ background: #C6E746;
+}
diff --git a/app/templates/components/delivery-breadcrumbs.hbs b/app/templates/components/delivery-breadcrumbs.hbs
index f9dd2b7..e8fbab2 100644
--- a/app/templates/components/delivery-breadcrumbs.hbs
+++ b/app/templates/components/delivery-breadcrumbs.hbs
@@ -12,5 +12,9 @@
context=transfer
selectedRouteName=selectedRouteName}}
{{/if}}
+{{else if isNewDeliverySelected}}
+ {{breadcrumb-item label="New"
+ routeName="deliveries.new"
+ selectedRouteName=selectedRouteName}}
{{/if}}
{{yield}}
diff --git a/app/templates/components/delivery-table.hbs b/app/templates/components/delivery-table.hbs
index 0d0b003..02511ad 100644
--- a/app/templates/components/delivery-table.hbs
+++ b/app/templates/components/delivery-table.hbs
@@ -5,5 +5,5 @@
showColumnsDropdown=false
showGlobalFilter=false
showPageSize=false
- pageSize=20
+ pageSize=12
}}
diff --git a/app/templates/components/duke-ds-project-list.hbs b/app/templates/components/duke-ds-project-list.hbs
new file mode 100644
index 0000000..8029f8f
--- /dev/null
+++ b/app/templates/components/duke-ds-project-list.hbs
@@ -0,0 +1,12 @@
+{{models-table
+ data=projects
+ columns=columns
+ multipleColumnsSorting=false
+ showColumnsDropdown=false
+ showGlobalFilter=false
+ showPageSize=false
+ pageSize=12
+ displayDataChangedAction=(action "displayDataChanged")
+}}
+
+{{yield}}
diff --git a/app/templates/components/duke-ds-user-list.hbs b/app/templates/components/duke-ds-user-list.hbs
new file mode 100644
index 0000000..848993f
--- /dev/null
+++ b/app/templates/components/duke-ds-user-list.hbs
@@ -0,0 +1,13 @@
+{{models-table
+ data=users
+ columns=columns
+ multipleColumnsSorting=false
+ showColumnsDropdown=false
+ showGlobalFilter=false
+ showPageSize=false
+ pageSize=pageSize
+ displayDataChangedAction=(action "displayDataChanged")
+ multipleSelect=multipleSelect
+}}
+
+{{yield}}
diff --git a/app/templates/deliveries/index.hbs b/app/templates/deliveries/index.hbs
index f49268d..f5296a5 100644
--- a/app/templates/deliveries/index.hbs
+++ b/app/templates/deliveries/index.hbs
@@ -2,3 +2,4 @@
Deliveries
{{delivery-table model}}
+{{#link-to 'deliveries.new' class="btn btn-primary"}}New Delivery{{/link-to}}
\ No newline at end of file
diff --git a/app/templates/deliveries/new.hbs b/app/templates/deliveries/new.hbs
new file mode 100644
index 0000000..c24cd68
--- /dev/null
+++ b/app/templates/deliveries/new.hbs
@@ -0,0 +1 @@
+{{outlet}}
diff --git a/app/templates/deliveries/new/enter-user-message.hbs b/app/templates/deliveries/new/enter-user-message.hbs
new file mode 100644
index 0000000..f84f05d
--- /dev/null
+++ b/app/templates/deliveries/new/enter-user-message.hbs
@@ -0,0 +1,30 @@
+{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
+New Delivery
+
+
+
+
Project: {{project.name}}
+
+
+ {{row-label-value label="From" value=fromUser.fullName}}
+ {{row-label-value label="To" value=toUser.fullName}}
+ {{#each shareUsers as |shareUser index|}}
+ {{#if index}}
+ {{row-label-value label="" value=shareUser.fullName}}
+ {{else}}
+ {{row-label-value label="Shared With" value=shareUser.fullName}}
+ {{/if}}
+ {{/each}}
+ {{user-message-textarea value=delivery.userMessage readonly=false}}
+
+
+
+{{error-message-alert errorMessages}}
+
+{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
+
+{{#bs-button type="primary" disabled=disableNext onClick=(action 'saveAndSend') class="pull-right next-button"}}
+ Create Delivery
+{{/bs-button}}
+
+{{outlet}}
diff --git a/app/templates/deliveries/new/index.hbs b/app/templates/deliveries/new/index.hbs
new file mode 100644
index 0000000..c24cd68
--- /dev/null
+++ b/app/templates/deliveries/new/index.hbs
@@ -0,0 +1 @@
+{{outlet}}
diff --git a/app/templates/deliveries/new/select-project.hbs b/app/templates/deliveries/new/select-project.hbs
new file mode 100644
index 0000000..6f32225
--- /dev/null
+++ b/app/templates/deliveries/new/select-project.hbs
@@ -0,0 +1,11 @@
+{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
+New Delivery
+Select project to deliver.
+
+{{duke-ds-project-list model selectionChanged=(action 'projectSelectionChanged')}}
+
+{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
+
+{{#bs-button type="primary" disabled=disableNext onClick=(action 'next') class="pull-right next-button"}}Next{{/bs-button}}
+
+{{outlet}}
diff --git a/app/templates/deliveries/new/select-recipient.hbs b/app/templates/deliveries/new/select-recipient.hbs
new file mode 100644
index 0000000..3a930fe
--- /dev/null
+++ b/app/templates/deliveries/new/select-recipient.hbs
@@ -0,0 +1,13 @@
+{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
+New Delivery
+
+Select recipient of {{project.name}}.
+{{duke-ds-user-list model pageSize=6 selectionChanged=(action 'toUserSelectionChanged')}}
+
+Select additional users to share project.
+{{duke-ds-user-list model pageSize=6 multipleSelect=true selectionChanged=(action 'shareUsersSelectionChanged')}}
+
+{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
+{{#bs-button type="primary" disabled=disableNext onClick=(action 'next') class="pull-right next-button"}}Next{{/bs-button}}
+
+{{outlet}}
diff --git a/tests/integration/components/duke-ds-project-list-test.js b/tests/integration/components/duke-ds-project-list-test.js
new file mode 100644
index 0000000..9c3150e
--- /dev/null
+++ b/tests/integration/components/duke-ds-project-list-test.js
@@ -0,0 +1,25 @@
+import { moduleForComponent, test } from 'ember-qunit';
+import hbs from 'htmlbars-inline-precompile';
+
+moduleForComponent('duke-ds-project-list', 'Integration | Component | duke ds project list', {
+ integration: true
+});
+
+test('it renders', function(assert) {
+
+ // Set any properties with this.set('myProperty', 'value');
+ // Handle any actions with this.on('myAction', function(val) { ... });
+
+ this.render(hbs`{{duke-ds-project-list}}`);
+
+ assert.equal(this.$().text().trim(), '');
+
+ // Template block usage:
+ this.render(hbs`
+ {{#duke-ds-project-list}}
+ template block text
+ {{/duke-ds-project-list}}
+ `);
+
+ assert.equal(this.$().text().trim(), 'template block text');
+});
diff --git a/tests/integration/components/duke-ds-user-list-test.js b/tests/integration/components/duke-ds-user-list-test.js
new file mode 100644
index 0000000..cbdd27a
--- /dev/null
+++ b/tests/integration/components/duke-ds-user-list-test.js
@@ -0,0 +1,25 @@
+import { moduleForComponent, test } from 'ember-qunit';
+import hbs from 'htmlbars-inline-precompile';
+
+moduleForComponent('duke-ds-user-list', 'Integration | Component | duke ds user list', {
+ integration: true
+});
+
+test('it renders', function(assert) {
+
+ // Set any properties with this.set('myProperty', 'value');
+ // Handle any actions with this.on('myAction', function(val) { ... });
+
+ this.render(hbs`{{duke-ds-user-list}}`);
+
+ assert.equal(this.$().text().trim(), '');
+
+ // Template block usage:
+ this.render(hbs`
+ {{#duke-ds-user-list}}
+ template block text
+ {{/duke-ds-user-list}}
+ `);
+
+ assert.equal(this.$().text().trim(), 'template block text');
+});
diff --git a/tests/unit/controllers/deliveries-test.js b/tests/unit/controllers/deliveries-test.js
new file mode 100644
index 0000000..4de27a5
--- /dev/null
+++ b/tests/unit/controllers/deliveries-test.js
@@ -0,0 +1,12 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('controller:deliveries', 'Unit | Controller | deliveries', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function(assert) {
+ let controller = this.subject();
+ assert.ok(controller);
+});
diff --git a/tests/unit/controllers/deliveries/new/enter-user-message-test.js b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
new file mode 100644
index 0000000..a3d1b8c
--- /dev/null
+++ b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
@@ -0,0 +1,12 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('controller:deliveries/new/enter-user-message', 'Unit | Controller | deliveries/new/enter user message', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function(assert) {
+ let controller = this.subject();
+ assert.ok(controller);
+});
diff --git a/tests/unit/controllers/deliveries/new/select-project-test.js b/tests/unit/controllers/deliveries/new/select-project-test.js
new file mode 100644
index 0000000..b5f9849
--- /dev/null
+++ b/tests/unit/controllers/deliveries/new/select-project-test.js
@@ -0,0 +1,12 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('controller:deliveries/new/select-project', 'Unit | Controller | deliveries/new/select project', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function(assert) {
+ let controller = this.subject();
+ assert.ok(controller);
+});
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
new file mode 100644
index 0000000..d4b7864
--- /dev/null
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -0,0 +1,12 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('controller:deliveries/new/select-recipient', 'Unit | Controller | deliveries/new/select recipient', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function(assert) {
+ let controller = this.subject();
+ assert.ok(controller);
+});
diff --git a/tests/unit/models/delivery-answer-set-test.js b/tests/unit/models/delivery-answer-set-test.js
new file mode 100644
index 0000000..20d5b2b
--- /dev/null
+++ b/tests/unit/models/delivery-answer-set-test.js
@@ -0,0 +1,12 @@
+import { moduleForModel, test } from 'ember-qunit';
+
+moduleForModel('delivery-answer-set', 'Unit | Model | delivery answer set', {
+ // Specify the other units that are required for this test.
+ needs: []
+});
+
+test('it exists', function(assert) {
+ let model = this.subject();
+ // let store = this.store();
+ assert.ok(!!model);
+});
diff --git a/tests/unit/routes/deliveries/new-test.js b/tests/unit/routes/deliveries/new-test.js
new file mode 100644
index 0000000..9daa85d
--- /dev/null
+++ b/tests/unit/routes/deliveries/new-test.js
@@ -0,0 +1,11 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('route:deliveries/new', 'Unit | Route | deliveries/new', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+test('it exists', function(assert) {
+ let route = this.subject();
+ assert.ok(route);
+});
diff --git a/tests/unit/routes/deliveries/new/enter-user-message-test.js b/tests/unit/routes/deliveries/new/enter-user-message-test.js
new file mode 100644
index 0000000..64806e7
--- /dev/null
+++ b/tests/unit/routes/deliveries/new/enter-user-message-test.js
@@ -0,0 +1,11 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('route:deliveries/new/enter-user-message', 'Unit | Route | deliveries/new/enter user message', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+test('it exists', function(assert) {
+ let route = this.subject();
+ assert.ok(route);
+});
diff --git a/tests/unit/routes/deliveries/new/index-test.js b/tests/unit/routes/deliveries/new/index-test.js
new file mode 100644
index 0000000..4de8241
--- /dev/null
+++ b/tests/unit/routes/deliveries/new/index-test.js
@@ -0,0 +1,11 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('route:deliveries/new/index', 'Unit | Route | deliveries/new/index', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+test('it exists', function(assert) {
+ let route = this.subject();
+ assert.ok(route);
+});
diff --git a/tests/unit/routes/deliveries/new/select-project-test.js b/tests/unit/routes/deliveries/new/select-project-test.js
new file mode 100644
index 0000000..fe5ad00
--- /dev/null
+++ b/tests/unit/routes/deliveries/new/select-project-test.js
@@ -0,0 +1,11 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('route:deliveries/new/select-project', 'Unit | Route | deliveries/new/select project', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+test('it exists', function(assert) {
+ let route = this.subject();
+ assert.ok(route);
+});
diff --git a/tests/unit/routes/deliveries/new/select-recipient-test.js b/tests/unit/routes/deliveries/new/select-recipient-test.js
new file mode 100644
index 0000000..513497c
--- /dev/null
+++ b/tests/unit/routes/deliveries/new/select-recipient-test.js
@@ -0,0 +1,11 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('route:deliveries/new/select-recipient', 'Unit | Route | deliveries/new/select recipient', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+test('it exists', function(assert) {
+ let route = this.subject();
+ assert.ok(route);
+});
From 708831cde72589009f2cb7e947f309f3aa56b288 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Wed, 25 Jul 2018 16:13:28 -0400
Subject: [PATCH 02/36] checkbox for selecting and other cleanup
Adds checkboxes for selecting projects and users.
Filters users to exclude current user.
---
app/components/duke-ds-project-list.js | 6 +++
app/components/duke-ds-user-list.js | 6 +++
app/components/select-row-checkbox.js | 12 ++++++
.../deliveries/new/enter-user-message.js | 31 +++++++++------
.../deliveries/new/select-project.js | 1 +
.../deliveries/new/select-recipient.js | 18 ++++++++-
.../deliveries/show/can-resend-controller.js | 2 +-
app/routes/deliveries/new/select-recipient.js | 2 -
app/styles/app.css | 4 +-
app/templates/components/delivery-table.hbs | 4 +-
.../components/select-row-checkbox.hbs | 1 +
app/templates/deliveries/index.hbs | 4 +-
.../deliveries/new/enter-user-message.hbs | 38 ++++++++++++-------
.../deliveries/new/select-recipient.hbs | 4 +-
.../components/select-row-checkbox-test.js | 25 ++++++++++++
15 files changed, 121 insertions(+), 37 deletions(-)
create mode 100644 app/components/select-row-checkbox.js
create mode 100644 app/templates/components/select-row-checkbox.hbs
create mode 100644 tests/integration/components/select-row-checkbox-test.js
diff --git a/app/components/duke-ds-project-list.js b/app/components/duke-ds-project-list.js
index e169c49..ff40cae 100644
--- a/app/components/duke-ds-project-list.js
+++ b/app/components/duke-ds-project-list.js
@@ -4,6 +4,12 @@ const DukeDSProjectList = Ember.Component.extend({
projects: null,
selectionChanged: null, /** action */
columns: [
+ {
+ component: "select-row-checkbox",
+ useFilter: false,
+ mayBeHidden: false,
+ className: "select-row-checkbox-column",
+ },
{ propertyName: "name", title: "Project Name"}
],
actions: {
diff --git a/app/components/duke-ds-user-list.js b/app/components/duke-ds-user-list.js
index 33bee87..0966c3f 100644
--- a/app/components/duke-ds-user-list.js
+++ b/app/components/duke-ds-user-list.js
@@ -6,6 +6,12 @@ const DukeDSUserList = Ember.Component.extend({
pageSize: 12,
selectionChanged: null, /** action */
columns: [
+ {
+ component: "select-row-checkbox",
+ useFilter: false,
+ mayBeHidden: false,
+ className: "select-row-checkbox-column",
+ },
{ propertyName: "fullName", title: "Name"},
{ propertyName: "email", title: "Email"}
],
diff --git a/app/components/select-row-checkbox.js b/app/components/select-row-checkbox.js
new file mode 100644
index 0000000..8af6ae4
--- /dev/null
+++ b/app/components/select-row-checkbox.js
@@ -0,0 +1,12 @@
+import Component from '@ember/component';
+import {get} from '@ember/object';
+import layout from '../templates/components/select-row-checkbox';
+export default Component.extend({
+ layout,
+ actions: {
+ clickOnRow(index, record, event) {
+ get(this, 'clickOnRow')(index, record);
+ event.stopPropagation();
+ }
+ }
+});
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index b4cc2af..01cb056 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -5,6 +5,7 @@ export default Ember.Controller.extend({
project_id: null,
to_user_id: null,
share_user_ids: null,
+ userMessage: null,
deliveriesController: Ember.inject.controller('deliveries'),
project: Ember.computed('project_id', function () {
return this.get('store').findRecord('duke-ds-project', this.get('project_id'));
@@ -15,9 +16,13 @@ export default Ember.Controller.extend({
}),
shareUsers: Ember.computed('share_user_ids', function () {
const store = this.get('store');
- return this.get('share_user_ids')
- .split(',')
- .map(user_id => store.findRecord('duke-ds-user', user_id));
+ const shareUserIds = this.get('share_user_ids');
+ if (!shareUserIds) {
+ return [];
+ }
+ return shareUserIds
+ .split(',')
+ .map(user_id => store.findRecord('duke-ds-user', user_id));
}),
actions: {
back() {
@@ -25,15 +30,19 @@ export default Ember.Controller.extend({
this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { project_id: projectId }});
},
saveAndSend() {
- const delivery = this.get('store').createRecord({
- project: this.get('project.id'),
- toUser: this.get('toUser.id'),
- shareUsers: this.get('shareUsers').mapBy('id')
- });
- delivery.save().then(function (delivery) {
- delivery.send().then(function () {
- self.transitionToRoute('deliveries.show', delivery.get('transfer'));
+ this.get('shareUsers').then(function (shareUsers) {
+ const delivery = this.get('store').createRecord('delivery', {
+ project: this.get('project'),
+ fromUser: this.get('fromUser'),
+ shareUsers: shareUsers,
+ toUser: this.get('toUser'),
+ userMessage: this.get('userMessage')
});
+ return delivery.save();
+ }).then(savedDelivery => {
+ return savedDelivery.send();
+ }).then(sentDelivery => {
+ this.transitionToRoute('deliveries.show', sentDelivery.get('transfer'));
});
}
},
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index 98c429d..eaadbfb 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -10,6 +10,7 @@ export default Ember.Controller.extend({
next() {
const projectId = this.get('project.id');
this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { project_id: projectId }});
+ this.set('project', null);
},
projectSelectionChanged(actionData) {
var selectedItem = null;
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index 96b90e4..79ed845 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -6,6 +6,16 @@ export default Ember.Controller.extend({
project: Ember.computed('project_id', function () {
return this.get('store').findRecord('duke-ds-project', this.get('project_id'));
}),
+ application: Ember.inject.controller(),
+ currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
+ otherUsersList: Ember.computed('model.[]', 'currentDukeDsUser', function () {
+ const currentDukeDSUser = this.get('currentDukeDsUser');
+ if (currentDukeDSUser) {
+ return this.get('model').rejectBy('id', currentDukeDSUser.get('id'));
+ } else {
+ return this.get('model');
+ }
+ }),
toUser: null,
shareUsers: null,
disableNext: Ember.computed.not('toUser'),
@@ -26,7 +36,11 @@ export default Ember.Controller.extend({
next() {
const projectId = this.get('project.id');
const toUserId = this.get('toUser.id');
- const shareUserIds = this.get('shareUsers').mapBy('id').join(',');
+ const shareUsers = this.get('shareUsers');
+ var shareUserIds = null;
+ if (shareUsers) {
+ shareUserIds = shareUsers.mapBy('id').join(',');
+ }
this.transitionToRoute('deliveries.new.enter-user-message', {
queryParams: {
project_id: projectId,
@@ -34,6 +48,8 @@ export default Ember.Controller.extend({
share_user_ids: shareUserIds
}
});
+ this.set('toUser', null);
+ this.set('shareUsers', null);
}
}
});
diff --git a/app/controllers/deliveries/show/can-resend-controller.js b/app/controllers/deliveries/show/can-resend-controller.js
index 56e3925..f69edf9 100644
--- a/app/controllers/deliveries/show/can-resend-controller.js
+++ b/app/controllers/deliveries/show/can-resend-controller.js
@@ -9,7 +9,7 @@ export default Ember.Controller.extend({
canResend: Ember.computed('model.canResend', 'model.fromUser.id', 'currentDukeDsUser.id', function () {
const modelCanResend = this.get('model.canResend');
const fromUserId = this.get('model.fromUser.id');
- const currentDukeDsUserId = this.get('deliveriesController.currentDukeDsUser.id');
+ const currentDukeDsUserId = this.get('currentDukeDsUser.id');
if (!currentDukeDsUserId) {
return false;
}
diff --git a/app/routes/deliveries/new/select-recipient.js b/app/routes/deliveries/new/select-recipient.js
index 5306082..01b8712 100644
--- a/app/routes/deliveries/new/select-recipient.js
+++ b/app/routes/deliveries/new/select-recipient.js
@@ -2,8 +2,6 @@ import Ember from 'ember';
export default Ember.Route.extend({
model() {
-
-
return this.get('store').findAll('duke-ds-user');
}
});
diff --git a/app/styles/app.css b/app/styles/app.css
index 1c89467..15cc033 100644
--- a/app/styles/app.css
+++ b/app/styles/app.css
@@ -2,6 +2,6 @@
margin-left: 1em;
}
-tr.selected-row>td:not(.grouping-cell), tr.selected-expand>td:not(.grouping-cell) {
- background: #C6E746;
+.select-row-checkbox-column {
+ width: 2em;
}
diff --git a/app/templates/components/delivery-table.hbs b/app/templates/components/delivery-table.hbs
index 2157901..960d59a 100644
--- a/app/templates/components/delivery-table.hbs
+++ b/app/templates/components/delivery-table.hbs
@@ -1,4 +1,6 @@
-Outgoing
+Outgoing {{#link-to 'deliveries.new' class="btn btn-primary pull-right"}}New Delivery{{/link-to}}
+
+
{{models-table
data=outgoingTransfers
columns=outgoingColumns
diff --git a/app/templates/components/select-row-checkbox.hbs b/app/templates/components/select-row-checkbox.hbs
new file mode 100644
index 0000000..0193eb3
--- /dev/null
+++ b/app/templates/components/select-row-checkbox.hbs
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/app/templates/deliveries/index.hbs b/app/templates/deliveries/index.hbs
index ecfd61a..b747f98 100644
--- a/app/templates/deliveries/index.hbs
+++ b/app/templates/deliveries/index.hbs
@@ -1,6 +1,4 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.index"}}
All Deliveries
-{{delivery-table model currentDukeDsUser}}
-
-{{#link-to 'deliveries.new' class="btn btn-primary"}}New Delivery{{/link-to}}
\ No newline at end of file
+{{delivery-table model currentDukeDsUser}}
\ No newline at end of file
diff --git a/app/templates/deliveries/new/enter-user-message.hbs b/app/templates/deliveries/new/enter-user-message.hbs
index f84f05d..3fc7abf 100644
--- a/app/templates/deliveries/new/enter-user-message.hbs
+++ b/app/templates/deliveries/new/enter-user-message.hbs
@@ -1,21 +1,32 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
-New Delivery
-
+New Delivery
+
+ Click the Send Delivery button to send the delivery to the recipient.
+
+
+ The sent email will be generated from a template and include a link for the recipient to accept or decline the delivery.
+ If you wish to add or edit a custom message (e.g. details about this specific delivery), please enter those notes in the
+ User Message area.
+
Project: {{project.name}}
- {{row-label-value label="From" value=fromUser.fullName}}
- {{row-label-value label="To" value=toUser.fullName}}
- {{#each shareUsers as |shareUser index|}}
- {{#if index}}
- {{row-label-value label="" value=shareUser.fullName}}
- {{else}}
- {{row-label-value label="Shared With" value=shareUser.fullName}}
- {{/if}}
- {{/each}}
- {{user-message-textarea value=delivery.userMessage readonly=false}}
+
+
+ {{#detail-label-value label="From"}}{{fromUser.fullName}}{{/detail-label-value}}
+ {{#detail-label-value label="To"}}{{toUser.fullName}}{{/detail-label-value}}
+ {{#each shareUsers as |shareUser index|}}
+ {{#if index}}
+ {{#detail-label-value label=""}}{{shareUser.fullName}}{{/detail-label-value}}
+ {{else}}
+ {{#detail-label-value label="Shared With"}}{{shareUser.fullName}}{{/detail-label-value}}
+ {{/if}}
+ {{/each}}
+ {{#detail-label-value label="User Message"}}{{user-message-textarea value=userMessage readonly=false}}{{/detail-label-value}}
+
+
@@ -24,7 +35,6 @@
{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
{{#bs-button type="primary" disabled=disableNext onClick=(action 'saveAndSend') class="pull-right next-button"}}
- Create Delivery
+ Send Delivery
{{/bs-button}}
-
{{outlet}}
diff --git a/app/templates/deliveries/new/select-recipient.hbs b/app/templates/deliveries/new/select-recipient.hbs
index 3a930fe..b54312a 100644
--- a/app/templates/deliveries/new/select-recipient.hbs
+++ b/app/templates/deliveries/new/select-recipient.hbs
@@ -2,10 +2,10 @@
New Delivery
Select recipient of {{project.name}}.
-{{duke-ds-user-list model pageSize=6 selectionChanged=(action 'toUserSelectionChanged')}}
+{{duke-ds-user-list otherUsersList pageSize=6 selectionChanged=(action 'toUserSelectionChanged')}}
Select additional users to share project.
-{{duke-ds-user-list model pageSize=6 multipleSelect=true selectionChanged=(action 'shareUsersSelectionChanged')}}
+{{duke-ds-user-list otherUsersList pageSize=6 multipleSelect=true selectionChanged=(action 'shareUsersSelectionChanged')}}
{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
{{#bs-button type="primary" disabled=disableNext onClick=(action 'next') class="pull-right next-button"}}Next{{/bs-button}}
diff --git a/tests/integration/components/select-row-checkbox-test.js b/tests/integration/components/select-row-checkbox-test.js
new file mode 100644
index 0000000..3c46053
--- /dev/null
+++ b/tests/integration/components/select-row-checkbox-test.js
@@ -0,0 +1,25 @@
+import { moduleForComponent, test } from 'ember-qunit';
+import hbs from 'htmlbars-inline-precompile';
+
+moduleForComponent('select-row-checkbox', 'Integration | Component | select row checkbox', {
+ integration: true
+});
+
+test('it renders', function(assert) {
+
+ // Set any properties with this.set('myProperty', 'value');
+ // Handle any actions with this.on('myAction', function(val) { ... });
+
+ this.render(hbs`{{select-row-checkbox}}`);
+
+ assert.equal(this.$().text().trim(), '');
+
+ // Template block usage:
+ this.render(hbs`
+ {{#select-row-checkbox}}
+ template block text
+ {{/select-row-checkbox}}
+ `);
+
+ assert.equal(this.$().text().trim(), 'template block text');
+});
From 695fa8554c79faa47d4f798141f5294efa10a6f2 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 26 Jul 2018 10:15:22 -0400
Subject: [PATCH 03/36] tests for new components
also fixes failing new tests for controllers
---
app/components/duke-ds-project-list.js | 5 ++-
app/components/duke-ds-user-list.js | 4 +-
app/components/select-row-checkbox.js | 2 +
.../components/duke-ds-project-list-test.js | 35 ++++++++++-------
.../components/duke-ds-user-list-test.js | 39 ++++++++++++-------
.../components/select-row-checkbox-test.js | 36 ++++++++++-------
tests/unit/controllers/deliveries-test.js | 1 +
.../deliveries/new/enter-user-message-test.js | 1 +
.../deliveries/new/select-recipient-test.js | 1 +
9 files changed, 76 insertions(+), 48 deletions(-)
diff --git a/app/components/duke-ds-project-list.js b/app/components/duke-ds-project-list.js
index ff40cae..c405c80 100644
--- a/app/components/duke-ds-project-list.js
+++ b/app/components/duke-ds-project-list.js
@@ -10,7 +10,10 @@ const DukeDSProjectList = Ember.Component.extend({
mayBeHidden: false,
className: "select-row-checkbox-column",
},
- { propertyName: "name", title: "Project Name"}
+ {
+ propertyName: "name", title: "Project Name",
+ className: "duke-ds-project-name"
+ }
],
actions: {
displayDataChanged: function (e) {
diff --git a/app/components/duke-ds-user-list.js b/app/components/duke-ds-user-list.js
index 0966c3f..5c59f90 100644
--- a/app/components/duke-ds-user-list.js
+++ b/app/components/duke-ds-user-list.js
@@ -12,8 +12,8 @@ const DukeDSUserList = Ember.Component.extend({
mayBeHidden: false,
className: "select-row-checkbox-column",
},
- { propertyName: "fullName", title: "Name"},
- { propertyName: "email", title: "Email"}
+ { propertyName: "fullName", title: "Name", className: "duke-ds-user-fullName"},
+ { propertyName: "email", title: "Email", className: "duke-ds-user-email"}
],
actions: {
displayDataChanged: function (e) {
diff --git a/app/components/select-row-checkbox.js b/app/components/select-row-checkbox.js
index 8af6ae4..f8ca250 100644
--- a/app/components/select-row-checkbox.js
+++ b/app/components/select-row-checkbox.js
@@ -1,6 +1,8 @@
+// from http://onechiporenko.github.io/ember-models-table/v.2/#/examples/select-rows-with-checkboxes
import Component from '@ember/component';
import {get} from '@ember/object';
import layout from '../templates/components/select-row-checkbox';
+
export default Component.extend({
layout,
actions: {
diff --git a/tests/integration/components/duke-ds-project-list-test.js b/tests/integration/components/duke-ds-project-list-test.js
index 9c3150e..c9505b1 100644
--- a/tests/integration/components/duke-ds-project-list-test.js
+++ b/tests/integration/components/duke-ds-project-list-test.js
@@ -5,21 +5,26 @@ moduleForComponent('duke-ds-project-list', 'Integration | Component | duke ds pr
integration: true
});
-test('it renders', function(assert) {
+test('it renders a list of projects', function(assert) {
+ this.set('projects', [
+ {name: 'Project1'},
+ {name: 'Project2'}
+ ]);
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.on('myAction', function(val) { ... });
-
- this.render(hbs`{{duke-ds-project-list}}`);
-
- assert.equal(this.$().text().trim(), '');
-
- // Template block usage:
- this.render(hbs`
- {{#duke-ds-project-list}}
- template block text
- {{/duke-ds-project-list}}
- `);
+ this.render(hbs`{{duke-ds-project-list projects}}`);
+ assert.equal(this.$('.duke-ds-project-name').eq(0).text().trim(), 'Project Name'); //header
+ // index 1 is the search box
+ assert.equal(this.$('.duke-ds-project-name').eq(2).text().trim(), 'Project1');
+ assert.equal(this.$('.duke-ds-project-name').eq(3).text().trim(), 'Project2');
+});
- assert.equal(this.$().text().trim(), 'template block text');
+test('it sends selected project to selectionChanged action', function(assert) {
+ assert.expect(1);
+ this.set('projects', [
+ {name: 'Project1'},
+ {name: 'Project2'}
+ ]);
+ this.set('externalAction', (actionData) => assert.equal(actionData.selectedItems[0].name, 'Project2'));
+ this.render(hbs`{{duke-ds-project-list projects selectionChanged=(action externalAction)}}`);
+ this.$('.duke-ds-project-name').eq(3).click(); //click Project 2 row
});
diff --git a/tests/integration/components/duke-ds-user-list-test.js b/tests/integration/components/duke-ds-user-list-test.js
index cbdd27a..330d281 100644
--- a/tests/integration/components/duke-ds-user-list-test.js
+++ b/tests/integration/components/duke-ds-user-list-test.js
@@ -5,21 +5,30 @@ moduleForComponent('duke-ds-user-list', 'Integration | Component | duke ds user
integration: true
});
-test('it renders', function(assert) {
+test('it renders a list of users', function(assert) {
+ this.set('users', [
+ {fullName: 'Joe', email: 'joe@joe.org'},
+ {fullName: 'Jim', email: 'jim@jim.org'},
+ ]);
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.on('myAction', function(val) { ... });
-
- this.render(hbs`{{duke-ds-user-list}}`);
-
- assert.equal(this.$().text().trim(), '');
-
- // Template block usage:
- this.render(hbs`
- {{#duke-ds-user-list}}
- template block text
- {{/duke-ds-user-list}}
- `);
+ this.render(hbs`{{duke-ds-user-list users}}`);
+ //assert.equal(this.$().html().trim(), 'Project Name');
+ assert.equal(this.$('.duke-ds-user-fullName').eq(0).text().trim(), 'Name'); //header
+ assert.equal(this.$('.duke-ds-user-email').eq(0).text().trim(), 'Email'); //header
+ // index 1 is the search box
+ assert.equal(this.$('.duke-ds-user-fullName').eq(2).text().trim(), 'Joe');
+ assert.equal(this.$('.duke-ds-user-email').eq(2).text().trim(), 'joe@joe.org');
+ assert.equal(this.$('.duke-ds-user-fullName').eq(3).text().trim(), 'Jim');
+ assert.equal(this.$('.duke-ds-user-email').eq(3).text().trim(), 'jim@jim.org');
+});
- assert.equal(this.$().text().trim(), 'template block text');
+test('it sends selected project to selectionChanged action', function(assert) {
+ assert.expect(1);
+ this.set('users', [
+ {fullName: 'Joe', email: 'joe@joe.org'},
+ {fullName: 'Jim', email: 'jim@jim.org'},
+ ]);
+ this.set('externalAction', (actionData) => assert.equal(actionData.selectedItems[0].fullName, 'Jim'));
+ this.render(hbs`{{duke-ds-user-list users selectionChanged=(action externalAction)}}`);
+ this.$('.duke-ds-user-fullName').eq(3).click(); //click Jim row
});
diff --git a/tests/integration/components/select-row-checkbox-test.js b/tests/integration/components/select-row-checkbox-test.js
index 3c46053..5dbbd0b 100644
--- a/tests/integration/components/select-row-checkbox-test.js
+++ b/tests/integration/components/select-row-checkbox-test.js
@@ -5,21 +5,27 @@ moduleForComponent('select-row-checkbox', 'Integration | Component | select row
integration: true
});
-test('it renders', function(assert) {
-
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.on('myAction', function(val) { ... });
-
- this.render(hbs`{{select-row-checkbox}}`);
-
- assert.equal(this.$().text().trim(), '');
+test('it renders with select-row class when selected', function(assert) {
+ this.set('themeInstance', {
+ 'select-row': 'selectedClass',
+ 'deselect-row': 'unselectedClass',
+ });
+ this.render(hbs`{{select-row-checkbox isSelected=true themeInstance=themeInstance}}`);
+ assert.equal(this.$('span').attr('class').trim(), 'selectedClass');
+});
- // Template block usage:
- this.render(hbs`
- {{#select-row-checkbox}}
- template block text
- {{/select-row-checkbox}}
- `);
+test('it renders with deselect-row class when unselected', function(assert) {
+ this.set('themeInstance', {
+ 'select-row': 'selectedClass',
+ 'deselect-row': 'unselectedClass',
+ });
+ this.render(hbs`{{select-row-checkbox isSelected=false themeInstance=themeInstance}}`);
+ assert.equal(this.$('span').attr('class').trim(), 'unselectedClass');
+});
- assert.equal(this.$().text().trim(), 'template block text');
+test('when span clicked passes index', function(assert) {
+ assert.expect(1);
+ this.set('externalAction', (index) => assert.equal(index, 123));
+ this.render(hbs`{{select-row-checkbox index=123 clickOnRow=(action externalAction)}}`);
+ this.$('span').click();
});
diff --git a/tests/unit/controllers/deliveries-test.js b/tests/unit/controllers/deliveries-test.js
index 4de27a5..a03c866 100644
--- a/tests/unit/controllers/deliveries-test.js
+++ b/tests/unit/controllers/deliveries-test.js
@@ -3,6 +3,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('controller:deliveries', 'Unit | Controller | deliveries', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
+ needs: ['controller:application', 'service:session', 'service:duke-ds-user']
});
// Replace this with your real tests.
diff --git a/tests/unit/controllers/deliveries/new/enter-user-message-test.js b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
index a3d1b8c..40153ac 100644
--- a/tests/unit/controllers/deliveries/new/enter-user-message-test.js
+++ b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
@@ -3,6 +3,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('controller:deliveries/new/enter-user-message', 'Unit | Controller | deliveries/new/enter user message', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
+ needs: ['controller:application', 'controller:deliveries']
});
// Replace this with your real tests.
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
index d4b7864..1225830 100644
--- a/tests/unit/controllers/deliveries/new/select-recipient-test.js
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -3,6 +3,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('controller:deliveries/new/select-recipient', 'Unit | Controller | deliveries/new/select recipient', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
+ needs: ['controller:application']
});
// Replace this with your real tests.
From 466b672dbb095159ab1274d3a73f44dd6067f6f0 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 26 Jul 2018 10:56:50 -0400
Subject: [PATCH 04/36] remove unused model
---
app/models/delivery-answer-set.js | 9 ---------
tests/unit/models/delivery-answer-set-test.js | 12 ------------
2 files changed, 21 deletions(-)
delete mode 100644 app/models/delivery-answer-set.js
delete mode 100644 tests/unit/models/delivery-answer-set-test.js
diff --git a/app/models/delivery-answer-set.js b/app/models/delivery-answer-set.js
deleted file mode 100644
index 085c1a8..0000000
--- a/app/models/delivery-answer-set.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import DS from 'ember-data';
-
-export default DS.Model.extend({
- project: DS.belongsTo('DukeDsProject'),
- fromUser: DS.belongsTo('DukeDsUser'),
- toUser: DS.belongsTo('DukeDsUser'),
- shareUsers: DS.hasMany('DukeDsUser'),
- userMessage: DS.attr('string'),
-});
diff --git a/tests/unit/models/delivery-answer-set-test.js b/tests/unit/models/delivery-answer-set-test.js
deleted file mode 100644
index 20d5b2b..0000000
--- a/tests/unit/models/delivery-answer-set-test.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import { moduleForModel, test } from 'ember-qunit';
-
-moduleForModel('delivery-answer-set', 'Unit | Model | delivery answer set', {
- // Specify the other units that are required for this test.
- needs: []
-});
-
-test('it exists', function(assert) {
- let model = this.subject();
- // let store = this.store();
- assert.ok(!!model);
-});
From cb44c0042cf68bde68fb5b63b37f52159284c5bf Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 26 Jul 2018 11:23:49 -0400
Subject: [PATCH 05/36] remove deliveries controller
application now contains logic for currentDukeDsUser
so this is no longer needed.
---
app/controllers/deliveries.js | 18 ------------------
.../deliveries/new/enter-user-message.js | 5 +++--
.../components/delivery-breadcrumbs-test.js | 8 ++++++++
tests/unit/controllers/deliveries-test.js | 13 -------------
.../deliveries/new/enter-user-message-test.js | 2 +-
5 files changed, 12 insertions(+), 34 deletions(-)
delete mode 100644 app/controllers/deliveries.js
delete mode 100644 tests/unit/controllers/deliveries-test.js
diff --git a/app/controllers/deliveries.js b/app/controllers/deliveries.js
deleted file mode 100644
index d1ff13c..0000000
--- a/app/controllers/deliveries.js
+++ /dev/null
@@ -1,18 +0,0 @@
-import Ember from 'ember';
-
-export default Ember.Controller.extend({
- session: Ember.inject.service('session'),
- dukeDsUser: Ember.inject.service('duke-ds-user'),
- currentDukeDsUser: null,
- authenticatedDidChange: Ember.on('init',
- Ember.observer('session.isAuthenticated', function() {
- if (this.get('session.isAuthenticated')) {
- this.get('dukeDsUser').currentDukeDsUser().then(currentDukeDsUser => {
- this.set('currentDukeDsUser', currentDukeDsUser);
- });
- } else {
- this.set('currentDukeDsUser', null);
- }
- })
- )
-});
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index 01cb056..a923a39 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -6,11 +6,12 @@ export default Ember.Controller.extend({
to_user_id: null,
share_user_ids: null,
userMessage: null,
- deliveriesController: Ember.inject.controller('deliveries'),
+ application: Ember.inject.controller(),
+ currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
project: Ember.computed('project_id', function () {
return this.get('store').findRecord('duke-ds-project', this.get('project_id'));
}),
- fromUser: Ember.computed.alias('deliveriesController.currentDukeDsUser'),
+ fromUser: Ember.computed.alias('currentDukeDsUser'),
toUser: Ember.computed('to_user_id', function () {
return this.get('store').findRecord('duke-ds-user', this.get('to_user_id'));
}),
diff --git a/tests/integration/components/delivery-breadcrumbs-test.js b/tests/integration/components/delivery-breadcrumbs-test.js
index 2da252b..9da9d5f 100644
--- a/tests/integration/components/delivery-breadcrumbs-test.js
+++ b/tests/integration/components/delivery-breadcrumbs-test.js
@@ -39,3 +39,11 @@ test('it renders with delivery.resend selected', function(assert) {
assert.equal(this.$('a').length, 2, 'There are two links to parent routes.');
assert.equal(this.$('li').eq(2).text().trim(), 'resend', 'show resend as text');
});
+
+test('it renders with delivery.new selected', function(assert) {
+ this.render(hbs`{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}`);
+ assert.equal(this.$('li').eq(0).text().trim(), 'Data Delivery');
+ assert.equal(this.$('li').eq(1).text().trim(), 'New');
+ assert.equal(this.$('a').length, 1, 'there is one anchor');
+ assert.equal(this.$('a').text().trim(), 'Data Delivery', 'Data Delivery is a link');
+});
diff --git a/tests/unit/controllers/deliveries-test.js b/tests/unit/controllers/deliveries-test.js
deleted file mode 100644
index a03c866..0000000
--- a/tests/unit/controllers/deliveries-test.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import { moduleFor, test } from 'ember-qunit';
-
-moduleFor('controller:deliveries', 'Unit | Controller | deliveries', {
- // Specify the other units that are required for this test.
- // needs: ['controller:foo']
- needs: ['controller:application', 'service:session', 'service:duke-ds-user']
-});
-
-// Replace this with your real tests.
-test('it exists', function(assert) {
- let controller = this.subject();
- assert.ok(controller);
-});
diff --git a/tests/unit/controllers/deliveries/new/enter-user-message-test.js b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
index 40153ac..2385143 100644
--- a/tests/unit/controllers/deliveries/new/enter-user-message-test.js
+++ b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
@@ -3,7 +3,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('controller:deliveries/new/enter-user-message', 'Unit | Controller | deliveries/new/enter user message', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
- needs: ['controller:application', 'controller:deliveries']
+ needs: ['controller:application']
});
// Replace this with your real tests.
From 44781cd936bd1991f63f35832ba9bd8ecb8e07d9 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 26 Jul 2018 11:54:16 -0400
Subject: [PATCH 06/36] test delivery state field defaults to NEW
---
tests/unit/models/delivery-test.js | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tests/unit/models/delivery-test.js b/tests/unit/models/delivery-test.js
index 993d2b3..cf828d0 100644
--- a/tests/unit/models/delivery-test.js
+++ b/tests/unit/models/delivery-test.js
@@ -16,6 +16,12 @@ test('it exists', function(assert) {
assert.ok(!!model);
});
+test('it defaults state to new', function(assert) {
+ let model = this.subject();
+ const STATE_NEW = 0;
+ assert.equal(model.get('state'), STATE_NEW);
+});
+
const relationships = [
{key: 'project', kind: 'belongsTo', type: 'duke-ds-project'},
{key: 'fromUser', kind: 'belongsTo', type: 'duke-ds-user'},
From 50ca344e33509e1235fedcb95182382313e13aa7 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 26 Jul 2018 12:20:45 -0400
Subject: [PATCH 07/36] queries project list with isDeliverable
adds tests for new routes
---
app/routes/deliveries/new.js | 3 ---
app/routes/deliveries/new/select-project.js | 4 +++-
tests/unit/routes/deliveries/new/index-test.js | 9 +++++++++
.../deliveries/new/select-project-test.js | 17 +++++++++++++++++
.../deliveries/new/select-recipient-test.js | 15 +++++++++++++++
5 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/app/routes/deliveries/new.js b/app/routes/deliveries/new.js
index cf30cdb..26d9f31 100644
--- a/app/routes/deliveries/new.js
+++ b/app/routes/deliveries/new.js
@@ -1,7 +1,4 @@
import Ember from 'ember';
export default Ember.Route.extend({
- model() {
- return this.get('store').createRecord('delivery');
- }
});
diff --git a/app/routes/deliveries/new/select-project.js b/app/routes/deliveries/new/select-project.js
index 4ec2d88..551f9ec 100644
--- a/app/routes/deliveries/new/select-project.js
+++ b/app/routes/deliveries/new/select-project.js
@@ -2,6 +2,8 @@ import Ember from 'ember';
export default Ember.Route.extend({
model() {
- return this.get('store').findAll('duke-ds-project');
+ return this.get('store').query('duke-ds-project', {
+ isDeliverable: true
+ });
}
});
diff --git a/tests/unit/routes/deliveries/new/index-test.js b/tests/unit/routes/deliveries/new/index-test.js
index 4de8241..72b700c 100644
--- a/tests/unit/routes/deliveries/new/index-test.js
+++ b/tests/unit/routes/deliveries/new/index-test.js
@@ -9,3 +9,12 @@ test('it exists', function(assert) {
let route = this.subject();
assert.ok(route);
});
+
+test('it transitions to project selection', function(assert) {
+ let route = this.subject({
+ transitionTo(routeName) {
+ assert.equal('deliveries.new.select-project', routeName);
+ }
+ });
+ route.beforeModel();
+});
diff --git a/tests/unit/routes/deliveries/new/select-project-test.js b/tests/unit/routes/deliveries/new/select-project-test.js
index fe5ad00..9dd34ff 100644
--- a/tests/unit/routes/deliveries/new/select-project-test.js
+++ b/tests/unit/routes/deliveries/new/select-project-test.js
@@ -1,4 +1,5 @@
import { moduleFor, test } from 'ember-qunit';
+import Ember from 'ember';
moduleFor('route:deliveries/new/select-project', 'Unit | Route | deliveries/new/select project', {
// Specify the other units that are required for this test.
@@ -9,3 +10,19 @@ test('it exists', function(assert) {
let route = this.subject();
assert.ok(route);
});
+
+test('it sets model to deliverable projects', function(assert) {
+ assert.expect(4);
+ let route = this.subject({
+ store: {
+ query(recordModel, params) {
+ assert.equal(recordModel, 'duke-ds-project');
+ assert.equal(params.isDeliverable, true);
+ return [Ember.Object.create({id: 123})];
+ }
+ }
+ });
+ let model = route.model();
+ assert.equal(model.length, 1);
+ assert.equal(model[0].get('id'), 123);
+});
diff --git a/tests/unit/routes/deliveries/new/select-recipient-test.js b/tests/unit/routes/deliveries/new/select-recipient-test.js
index 513497c..b96d1b8 100644
--- a/tests/unit/routes/deliveries/new/select-recipient-test.js
+++ b/tests/unit/routes/deliveries/new/select-recipient-test.js
@@ -1,4 +1,5 @@
import { moduleFor, test } from 'ember-qunit';
+import Ember from 'ember';
moduleFor('route:deliveries/new/select-recipient', 'Unit | Route | deliveries/new/select recipient', {
// Specify the other units that are required for this test.
@@ -9,3 +10,17 @@ test('it exists', function(assert) {
let route = this.subject();
assert.ok(route);
});
+
+test('it sets model to all duke-ds-users', function(assert) {
+ let route = this.subject({
+ store: {
+ findAll(recordModel) {
+ assert.equal(recordModel, 'duke-ds-user');
+ return [Ember.Object.create({id: 456})];
+ }
+ }
+ });
+ let model = route.model();
+ assert.equal(model.length, 1);
+ assert.equal(model[0].get('id'), 456);
+});
From d5f092f00aa894c19318a0059079eaa517d22518 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 26 Jul 2018 13:25:04 -0400
Subject: [PATCH 08/36] tests for select-project and select-recipient
controllers
---
.../deliveries/new/select-project.js | 1 -
.../deliveries/new/select-recipient.js | 2 -
.../deliveries/new/select-project-test.js | 36 ++++++++
.../deliveries/new/select-recipient-test.js | 86 ++++++++++++++++++-
4 files changed, 121 insertions(+), 4 deletions(-)
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index eaadbfb..98c429d 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -10,7 +10,6 @@ export default Ember.Controller.extend({
next() {
const projectId = this.get('project.id');
this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { project_id: projectId }});
- this.set('project', null);
},
projectSelectionChanged(actionData) {
var selectedItem = null;
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index 79ed845..824f477 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -48,8 +48,6 @@ export default Ember.Controller.extend({
share_user_ids: shareUserIds
}
});
- this.set('toUser', null);
- this.set('shareUsers', null);
}
}
});
diff --git a/tests/unit/controllers/deliveries/new/select-project-test.js b/tests/unit/controllers/deliveries/new/select-project-test.js
index b5f9849..1f98384 100644
--- a/tests/unit/controllers/deliveries/new/select-project-test.js
+++ b/tests/unit/controllers/deliveries/new/select-project-test.js
@@ -1,4 +1,5 @@
import { moduleFor, test } from 'ember-qunit';
+import Ember from 'ember';
moduleFor('controller:deliveries/new/select-project', 'Unit | Controller | deliveries/new/select project', {
// Specify the other units that are required for this test.
@@ -10,3 +11,38 @@ test('it exists', function(assert) {
let controller = this.subject();
assert.ok(controller);
});
+
+test('it handles back action', function(assert) {
+ assert.expect(1);
+ let controller = this.subject({
+ transitionToRoute(routeName) {
+ assert.equal(routeName, 'deliveries', 'back action should transition to deliveries');
+ }
+ });
+ controller.send('back');
+});
+
+test('it handles next action and resets project', function(assert) {
+ let project = Ember.Object.create({ id: '123' });
+ let controller = this.subject({
+ project: project,
+ transitionToRoute(routeName, data) {
+ assert.equal(routeName, 'deliveries.new.select-recipient', 'next action should transition to recipient selection');
+ assert.equal(data.queryParams.project_id, '123', 'next action should pass project_id');
+ }
+ });
+ controller.send('next');
+});
+
+test('it handles projectSelectionChanged', function(assert) {
+ let project = Ember.Object.create({ id: '123' });
+ let controller = this.subject({
+ project: null,
+ });
+ controller.send('projectSelectionChanged', {
+ selectedItems: [
+ project
+ ]
+ });
+ assert.equal(controller.get('project'), project);
+});
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
index 1225830..8e6e6d1 100644
--- a/tests/unit/controllers/deliveries/new/select-recipient-test.js
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -1,9 +1,10 @@
import { moduleFor, test } from 'ember-qunit';
+import Ember from "ember";
moduleFor('controller:deliveries/new/select-recipient', 'Unit | Controller | deliveries/new/select recipient', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
- needs: ['controller:application']
+ needs: ['controller:application', 'service:session', 'service:duke-ds-user']
});
// Replace this with your real tests.
@@ -11,3 +12,86 @@ test('it exists', function(assert) {
let controller = this.subject();
assert.ok(controller);
});
+
+test('it handles back action', function(assert) {
+ assert.expect(1);
+ let controller = this.subject({
+ transitionToRoute(routeName) {
+ assert.equal(routeName, 'deliveries.new.select-project', 'back action should transition to select-project');
+ }
+ });
+ controller.send('back');
+});
+
+test('it handles next action and resets project', function(assert) {
+ let project = Ember.Object.create({ id: '123' });
+ let toUser = Ember.Object.create({ id: '456' });
+ let shareUsers = [Ember.Object.create({ id: '789'}), Ember.Object.create({ id: '001'})];
+ let controller = this.subject({
+ project: project,
+ toUser: toUser,
+ shareUsers: shareUsers,
+ transitionToRoute(routeName, data) {
+ assert.equal(routeName, 'deliveries.new.enter-user-message', 'next action should transition to enter-user-message');
+ assert.equal(data.queryParams.project_id, '123', 'next action should pass project_id');
+ assert.equal(data.queryParams.to_user_id, '456', 'next action should pass to_user_id');
+ assert.equal(data.queryParams.share_user_ids, '789,001', 'next action should pass share_user_ids');
+ }
+ });
+ controller.send('next');
+});
+
+test('it looks up project based on query param', function(assert) {
+ let controller = this.subject({
+ project_id: '123',
+ store: {
+ findRecord(modelName, modelKey) {
+ assert.equal(modelName, 'duke-ds-project');
+ assert.equal(modelKey, '123');
+ return 'someproject';
+ }
+ }
+ });
+ assert.equal(controller.get('project'), 'someproject');
+});
+
+test('it computes a list of users outside of the currentDukeDSUser', function(assert) {
+ let currentDukeDsUser = Ember.Object.create({ id: '123' });
+ let userList = [
+ currentDukeDsUser,
+ Ember.Object.create({ id: '456' })
+ ];
+ let controller = this.subject({
+ application: {
+ currentDukeDsUser: currentDukeDsUser
+ },
+ model: userList,
+ });
+ assert.equal(controller.get('model').length, 2);
+ assert.equal(controller.get('otherUsersList').length, 1);
+ assert.equal(controller.get('otherUsersList')[0].get('id'), '456');
+});
+
+test('it handles toUserSelectionChanged', function(assert) {
+ let toUser = Ember.Object.create({ id: '123' });
+ let controller = this.subject({
+ toUser: null,
+ });
+ controller.send('toUserSelectionChanged', {
+ selectedItems: [
+ toUser
+ ]
+ });
+ assert.equal(controller.get('toUser'), toUser);
+});
+
+test('it handles shareUsersSelectionChanged', function(assert) {
+ let shareUsers = [Ember.Object.create({ id: '123' })];
+ let controller = this.subject({
+ project: null,
+ });
+ controller.send('shareUsersSelectionChanged', {
+ selectedItems: shareUsers
+ });
+ assert.equal(controller.get('shareUsers'), shareUsers);
+});
From dbbe482932e1d43ad074b8ffb397e7a21a6ec178 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 26 Jul 2018 16:05:10 -0400
Subject: [PATCH 09/36] Add back in RSVP.all for saveAndSend
Th computed field shareUsers returns a javascript array of promises
so we can't just call `then` on the returned array.
---
.../deliveries/new/enter-user-message.js | 2 +-
.../deliveries/new/enter-user-message-test.js | 124 +++++++++++++++++-
.../deliveries/new/select-recipient-test.js | 2 +-
3 files changed, 125 insertions(+), 3 deletions(-)
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index a923a39..4ace57c 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -31,7 +31,7 @@ export default Ember.Controller.extend({
this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { project_id: projectId }});
},
saveAndSend() {
- this.get('shareUsers').then(function (shareUsers) {
+ return Ember.RSVP.all(this.get('shareUsers')).then((shareUsers) => {
const delivery = this.get('store').createRecord('delivery', {
project: this.get('project'),
fromUser: this.get('fromUser'),
diff --git a/tests/unit/controllers/deliveries/new/enter-user-message-test.js b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
index 2385143..ac72b96 100644
--- a/tests/unit/controllers/deliveries/new/enter-user-message-test.js
+++ b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
@@ -1,9 +1,10 @@
import { moduleFor, test } from 'ember-qunit';
+import Ember from "ember";
moduleFor('controller:deliveries/new/enter-user-message', 'Unit | Controller | deliveries/new/enter user message', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
- needs: ['controller:application']
+ needs: ['controller:application', 'service:duke-ds-user', 'service:session']
});
// Replace this with your real tests.
@@ -11,3 +12,124 @@ test('it exists', function(assert) {
let controller = this.subject();
assert.ok(controller);
});
+
+test('it handles back action', function(assert) {
+ assert.expect(2);
+ let controller = this.subject({
+ project_id: '123',
+ transitionToRoute(routeName, data) {
+ assert.equal(routeName, 'deliveries.new.select-recipient', 'back action should transition to select-project');
+ assert.equal(data.queryParams.project_id, '123', 'include project_id in select-project query params');
+ }
+ });
+ controller.send('back');
+});
+
+test('it looks up project based on query param', function(assert) {
+ let controller = this.subject({
+ project_id: '123',
+ store: {
+ findRecord(modelName, modelKey) {
+ if (modelName === 'duke-ds-project') {
+ assert.equal(modelKey, '123');
+ return 'someproject';
+ }
+ return null;
+ }
+ }
+ });
+ assert.equal(controller.get('project'), 'someproject');
+});
+
+test('it looks up toUser based on query param', function(assert) {
+ let controller = this.subject({
+ to_user_id: '456',
+ store: {
+ findRecord(modelName, modelKey) {
+ if (modelName === 'duke-ds-user') {
+ assert.equal(modelKey, '456');
+ return 'someuser';
+ }
+ return null;
+ }
+ }
+ });
+ assert.equal(controller.get('toUser'), 'someuser');
+});
+
+test('it looks up shareUsers based on query param', function(assert) {
+ let controller = this.subject({
+ to_user_id: '456',
+ share_user_ids: '789',
+ store: {
+ findRecord(modelName, modelKey) {
+ if (modelName === 'duke-ds-user' && modelKey === '789') {
+ return 'someuser';
+ }
+ return null;
+ }
+ }
+ });
+ assert.equal(controller.get('shareUsers').length, 1);
+ assert.equal(controller.get('shareUsers')[0], 'someuser');
+});
+
+test('it handles saveAndSend action', function(assert) {
+ assert.expect(10);
+ const project = Ember.Object.create({ id: '123' });
+ const fromUser = Ember.Object.create({ id: '222' });
+ const toUser = Ember.Object.create({ id: '456' });
+ const shareUser1 = Ember.Object.create({ id: '789'})
+ const shareUser2 = Ember.Object.create({ id: '001'});
+ const controller = this.subject({
+ project: project,
+ currentDukeDsUser: fromUser,
+ toUser: toUser,
+ share_user_ids: '789,001',
+ userMessage: 'hey bob',
+ store: {
+ findRecord(modelName, modelKey) {
+ if (modelName === 'duke-ds-user') {
+ if (modelKey === shareUser1.get('id')) {
+ return Ember.RSVP.resolve(shareUser1);
+ } else if (modelKey === shareUser2.get('id')) {
+ return Ember.RSVP.resolve(shareUser2);
+ }
+ }
+ return null;
+ },
+ createRecord(modelName, payload) {
+ assert.equal(modelName, 'delivery');
+ assert.equal(payload.project, project);
+ assert.equal(payload.fromUser, fromUser);
+ assert.equal(payload.toUser, toUser);
+ assert.equal(payload.shareUsers.length, 2);
+ assert.equal(payload.shareUsers[0], shareUser1);
+ assert.equal(payload.shareUsers[1], shareUser2);
+ assert.equal(payload.userMessage, 'hey bob');
+ const mockDelivery = {
+ get(name) {
+ if (name === 'transfer') {
+ return 'sometransferid';
+ }
+ return null;
+ }
+ };
+ mockDelivery.save = function () {
+ return Ember.RSVP.resolve(mockDelivery);
+ };
+ mockDelivery.send = function () {
+ return Ember.RSVP.resolve(mockDelivery);
+ };
+ return mockDelivery;
+ }
+ },
+ transitionToRoute(routeName, data) {
+ assert.equal(routeName, 'deliveries.show', 'next action should transition to show new delivery');
+ assert.equal(data, 'sometransferid', 'next action should pass project_id');
+ }
+ });
+ Ember.run(() => {
+ controller.send('saveAndSend');
+ });
+});
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
index 8e6e6d1..f1a9901 100644
--- a/tests/unit/controllers/deliveries/new/select-recipient-test.js
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -23,7 +23,7 @@ test('it handles back action', function(assert) {
controller.send('back');
});
-test('it handles next action and resets project', function(assert) {
+test('it handles next action', function(assert) {
let project = Ember.Object.create({ id: '123' });
let toUser = Ember.Object.create({ id: '456' });
let shareUsers = [Ember.Object.create({ id: '789'}), Ember.Object.create({ id: '001'})];
From d543d4e2ddb1b7a67a79733fbf5779593a9981de Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Mon, 30 Jul 2018 09:35:57 -0400
Subject: [PATCH 10/36] duke-ds-project isDeliverable -> is_deliverable
Switch to match existing pattern.
---
app/routes/deliveries/new/select-project.js | 2 +-
tests/unit/routes/deliveries/new/select-project-test.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/routes/deliveries/new/select-project.js b/app/routes/deliveries/new/select-project.js
index 551f9ec..51aba07 100644
--- a/app/routes/deliveries/new/select-project.js
+++ b/app/routes/deliveries/new/select-project.js
@@ -3,7 +3,7 @@ import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').query('duke-ds-project', {
- isDeliverable: true
+ is_deliverable: true
});
}
});
diff --git a/tests/unit/routes/deliveries/new/select-project-test.js b/tests/unit/routes/deliveries/new/select-project-test.js
index 9dd34ff..70dd65d 100644
--- a/tests/unit/routes/deliveries/new/select-project-test.js
+++ b/tests/unit/routes/deliveries/new/select-project-test.js
@@ -17,7 +17,7 @@ test('it sets model to deliverable projects', function(assert) {
store: {
query(recordModel, params) {
assert.equal(recordModel, 'duke-ds-project');
- assert.equal(params.isDeliverable, true);
+ assert.equal(params.is_deliverable, true);
return [Ember.Object.create({id: 123})];
}
}
From 6d77719f78c244e7255372cadd6b5cfa0b50c222 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Mon, 30 Jul 2018 10:35:27 -0400
Subject: [PATCH 11/36] Add user instructions to the delivery new subroutes
---
app/templates/deliveries/new/enter-user-message.hbs | 7 +++++--
app/templates/deliveries/new/select-project.hbs | 9 +++++++--
app/templates/deliveries/new/select-recipient.hbs | 12 ++++++++++--
3 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/app/templates/deliveries/new/enter-user-message.hbs b/app/templates/deliveries/new/enter-user-message.hbs
index 3fc7abf..56687e9 100644
--- a/app/templates/deliveries/new/enter-user-message.hbs
+++ b/app/templates/deliveries/new/enter-user-message.hbs
@@ -1,10 +1,13 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
New Delivery
- Click the Send Delivery button to send the delivery to the recipient.
+ Click the Send Delivery button to begin delivery of
+ {{project.name}} to {{toUser.fullName}}.
- The sent email will be generated from a template and include a link for the recipient to accept or decline the delivery.
+ This will send an email to the recipient that includes a link for the recipient to accept or delcine the delivery.
+ If the user accepts the delivery they will take ownership of the project.
+ Once the delivery is accepted you will retain read-only permissions.
If you wish to add or edit a custom message (e.g. details about this specific delivery), please enter those notes in the
User Message area.
diff --git a/app/templates/deliveries/new/select-project.hbs b/app/templates/deliveries/new/select-project.hbs
index 6f32225..9f9c098 100644
--- a/app/templates/deliveries/new/select-project.hbs
+++ b/app/templates/deliveries/new/select-project.hbs
@@ -1,7 +1,12 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
New Delivery
-Select project to deliver.
-
+
+ Select a project to deliver to another user.
+
+
+ This will transfer ownership of the project to another user.
+ Once the recipient accepts the delivery you will retain read-only permissions.
+
{{duke-ds-project-list model selectionChanged=(action 'projectSelectionChanged')}}
{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
diff --git a/app/templates/deliveries/new/select-recipient.hbs b/app/templates/deliveries/new/select-recipient.hbs
index b54312a..3946a3c 100644
--- a/app/templates/deliveries/new/select-recipient.hbs
+++ b/app/templates/deliveries/new/select-recipient.hbs
@@ -1,10 +1,18 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
New Delivery
-Select recipient of {{project.name}}.
+
+ Select the recipient you wish to transfer ownership of {{project.name}} to.
+
+
+ This selected user will take ownership of the project once the delivery is accepted.
+ Once the delivery is accepted you will retain read-only permissions.
+
{{duke-ds-user-list otherUsersList pageSize=6 selectionChanged=(action 'toUserSelectionChanged')}}
-Select additional users to share project.
+
+ Select additional users to share project.
+
{{duke-ds-user-list otherUsersList pageSize=6 multipleSelect=true selectionChanged=(action 'shareUsersSelectionChanged')}}
{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
From 15da3a8ad80b3d1ff7925588e3fcf8f77841f170 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Wed, 8 Aug 2018 16:03:44 -0400
Subject: [PATCH 12/36] check perms after user picks a project for delivery
Instead of filtering by deliverable filters by is_deleted to
work around ember DS caching issues.
---
.../deliveries/new/enter-user-message.js | 28 ++++-----
.../deliveries/new/select-project.js | 57 ++++++++++++++++---
.../deliveries/new/select-recipient.js | 16 +++---
app/models/duke-ds-project-permission.js | 7 +++
app/routes/deliveries/new/select-project.js | 6 +-
.../deliveries/new/select-project.hbs | 7 +++
.../deliveries/new/enter-user-message-test.js | 14 ++---
.../deliveries/new/select-project-test.js | 7 ++-
.../deliveries/new/select-recipient-test.js | 11 ++--
.../models/duke-ds-project-permission-test.js | 12 ++++
.../deliveries/new/select-project-test.js | 4 +-
11 files changed, 121 insertions(+), 48 deletions(-)
create mode 100644 app/models/duke-ds-project-permission.js
create mode 100644 tests/unit/models/duke-ds-project-permission-test.js
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index 4ace57c..0f26b12 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -1,36 +1,38 @@
import Ember from 'ember';
export default Ember.Controller.extend({
- queryParams: ['project_id', 'to_user_id', 'share_user_ids'],
- project_id: null,
- to_user_id: null,
- share_user_ids: null,
+ queryParams: ['projectId', 'toUserId', 'shareUserIds'],
+ projectId: null,
+ toUserId: null,
+ shareUserIds: null,
userMessage: null,
application: Ember.inject.controller(),
currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
- project: Ember.computed('project_id', function () {
- return this.get('store').findRecord('duke-ds-project', this.get('project_id'));
+ project: Ember.computed('projectId', function () {
+ return this.get('store').findRecord('duke-ds-project', this.get('projectId'));
}),
fromUser: Ember.computed.alias('currentDukeDsUser'),
- toUser: Ember.computed('to_user_id', function () {
- return this.get('store').findRecord('duke-ds-user', this.get('to_user_id'));
+ toUser: Ember.computed('toUserId', function () {
+ return this.get('store').findRecord('duke-ds-user', this.get('toUserId'));
}),
- shareUsers: Ember.computed('share_user_ids', function () {
+ shareUsers: Ember.computed('shareUserIds', function () {
const store = this.get('store');
- const shareUserIds = this.get('share_user_ids');
+ const shareUserIds = this.get('shareUserIds');
if (!shareUserIds) {
return [];
}
return shareUserIds
.split(',')
- .map(user_id => store.findRecord('duke-ds-user', user_id));
+ .map(userId => store.findRecord('duke-ds-user', userId));
}),
actions: {
back() {
- const projectId = this.get('project_id');
- this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { project_id: projectId }});
+ const projectId = this.get('projectId');
+ this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { projectId: projectId }});
},
saveAndSend() {
+ // shareUsers returns a javascript array of promises, these promises need to be resolved
+ // into models before we can use them in saving the delivery
return Ember.RSVP.all(this.get('shareUsers')).then((shareUsers) => {
const delivery = this.get('store').createRecord('delivery', {
project: this.get('project'),
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index 98c429d..fb0fead 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -1,22 +1,63 @@
import Ember from 'ember';
export default Ember.Controller.extend({
- disableNext: Ember.computed.not('project'),
project: null,
+ application: Ember.inject.controller(),
+ currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
+ currentUserProjectPermissions: Ember.computed('project', 'currentDukeDsUser.id', function () {
+ const projectId = this.get('project.id');
+ const currentUserId = this.get('currentDukeDsUser.id');
+ if (!projectId || !currentUserId) {
+ return [];
+ }
+ return this.get('store').query('duke-ds-project-permission', {
+ 'project': projectId,
+ 'user': currentUserId,
+ });
+ }),
+ currentUserProjectAuthRole: Ember.computed('currentUserProjectPermissions.[]', function () {
+ const authRoles = this.get('currentUserProjectPermissions').mapBy('auth_role');
+ if (authRoles) {
+ return authRoles[0];
+ } else {
+ return null;
+ }
+ }),
+ currentUserCanDeliver: Ember.computed('currentUserProjectAuthRole', function () {
+ return this.get('currentUserProjectAuthRole') == 'project_admin';
+ }),
+ disableNext: Ember.computed.not('currentUserCanDeliver'),
+ showUserMissingPrivilegesError: Ember.computed('project.id', 'currentUserProjectAuthRole', function () {
+ if (this.get('project.id') == null) {
+ return false; // do not show error when no project is selected
+ }
+ const authRole = this.get('currentUserProjectAuthRole');
+ if (!authRole) {
+ return false; //do not show error while we are fetching users auth role for this project
+ }
+ return authRole != 'project_admin';
+ }),
actions: {
- back() {
- this.transitionToRoute('deliveries');
- },
- next() {
- const projectId = this.get('project.id');
- this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { project_id: projectId }});
- },
projectSelectionChanged(actionData) {
var selectedItem = null;
if (actionData.selectedItems) {
selectedItem = actionData.selectedItems[0];
}
this.set('project', selectedItem);
+ this.set('showMissingPrivilegesError', false);
+ },
+ back() {
+ this.transitionToRoute('deliveries');
+ },
+ next() {
+ const projectId = this.get('project.id');
+ if (projectId) {
+ if (this.get('currentUserCanDeliver')) {
+ this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { projectId: projectId }})
+ } else {
+ this.set('showMissingPrivilegesError', true);
+ }
+ }
}
},
});
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index 824f477..1eea8b6 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -1,10 +1,10 @@
import Ember from 'ember';
export default Ember.Controller.extend({
- queryParams: ['project_id'],
- project_id: null,
- project: Ember.computed('project_id', function () {
- return this.get('store').findRecord('duke-ds-project', this.get('project_id'));
+ queryParams: ['projectId'],
+ projectId: null,
+ project: Ember.computed('projectId', function () {
+ return this.get('store').findRecord('duke-ds-project', this.get('projectId'));
}),
application: Ember.inject.controller(),
currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
@@ -34,7 +34,7 @@ export default Ember.Controller.extend({
this.transitionToRoute('deliveries.new.select-project');
},
next() {
- const projectId = this.get('project.id');
+ const projectId = this.get('projectId');
const toUserId = this.get('toUser.id');
const shareUsers = this.get('shareUsers');
var shareUserIds = null;
@@ -43,9 +43,9 @@ export default Ember.Controller.extend({
}
this.transitionToRoute('deliveries.new.enter-user-message', {
queryParams: {
- project_id: projectId,
- to_user_id: toUserId,
- share_user_ids: shareUserIds
+ projectId: projectId,
+ toUserId: toUserId,
+ shareUserIds: shareUserIds
}
});
}
diff --git a/app/models/duke-ds-project-permission.js b/app/models/duke-ds-project-permission.js
new file mode 100644
index 0000000..bbb71bf
--- /dev/null
+++ b/app/models/duke-ds-project-permission.js
@@ -0,0 +1,7 @@
+import DS from 'ember-data';
+
+export default DS.Model.extend({
+ project: DS.belongsTo('DukeDsProject'),
+ user: DS.belongsTo('DukeDsUser'),
+ auth_role: DS.attr('string')
+});
diff --git a/app/routes/deliveries/new/select-project.js b/app/routes/deliveries/new/select-project.js
index 51aba07..dc67c54 100644
--- a/app/routes/deliveries/new/select-project.js
+++ b/app/routes/deliveries/new/select-project.js
@@ -2,8 +2,12 @@ import Ember from 'ember';
export default Ember.Route.extend({
model() {
+ // The duke-ds-project response returns only non-deleted when querying for all records
+ // however it will return projects that are deleted if queried individually.
+ // This can cause deleted projects to be included in the project list due to caching in
+ // ember-data for projects referenced in duke-ds-project-transfers.
return this.get('store').query('duke-ds-project', {
- is_deliverable: true
+ is_deleted: false
});
}
});
diff --git a/app/templates/deliveries/new/select-project.hbs b/app/templates/deliveries/new/select-project.hbs
index 9f9c098..3d56d73 100644
--- a/app/templates/deliveries/new/select-project.hbs
+++ b/app/templates/deliveries/new/select-project.hbs
@@ -7,6 +7,13 @@
This will transfer ownership of the project to another user.
Once the recipient accepts the delivery you will retain read-only permissions.
+{{#bs-alert
+ visible=showUserMissingPrivilegesError
+ type="danger"
+ dismissible=false
+}}
+ You do not have admin privileges for project {{project.name}}. Please select another project.
+{{/bs-alert}}
{{duke-ds-project-list model selectionChanged=(action 'projectSelectionChanged')}}
{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
diff --git a/tests/unit/controllers/deliveries/new/enter-user-message-test.js b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
index ac72b96..7608aa3 100644
--- a/tests/unit/controllers/deliveries/new/enter-user-message-test.js
+++ b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
@@ -16,10 +16,10 @@ test('it exists', function(assert) {
test('it handles back action', function(assert) {
assert.expect(2);
let controller = this.subject({
- project_id: '123',
+ projectId: '123',
transitionToRoute(routeName, data) {
assert.equal(routeName, 'deliveries.new.select-recipient', 'back action should transition to select-project');
- assert.equal(data.queryParams.project_id, '123', 'include project_id in select-project query params');
+ assert.equal(data.queryParams.projectId, '123', 'include project in select-project query params');
}
});
controller.send('back');
@@ -27,7 +27,7 @@ test('it handles back action', function(assert) {
test('it looks up project based on query param', function(assert) {
let controller = this.subject({
- project_id: '123',
+ projectId: '123',
store: {
findRecord(modelName, modelKey) {
if (modelName === 'duke-ds-project') {
@@ -43,7 +43,7 @@ test('it looks up project based on query param', function(assert) {
test('it looks up toUser based on query param', function(assert) {
let controller = this.subject({
- to_user_id: '456',
+ toUserId: '456',
store: {
findRecord(modelName, modelKey) {
if (modelName === 'duke-ds-user') {
@@ -59,8 +59,8 @@ test('it looks up toUser based on query param', function(assert) {
test('it looks up shareUsers based on query param', function(assert) {
let controller = this.subject({
- to_user_id: '456',
- share_user_ids: '789',
+ toUserId: '456',
+ shareUserIds: '789',
store: {
findRecord(modelName, modelKey) {
if (modelName === 'duke-ds-user' && modelKey === '789') {
@@ -85,7 +85,7 @@ test('it handles saveAndSend action', function(assert) {
project: project,
currentDukeDsUser: fromUser,
toUser: toUser,
- share_user_ids: '789,001',
+ shareUserIds: '789,001',
userMessage: 'hey bob',
store: {
findRecord(modelName, modelKey) {
diff --git a/tests/unit/controllers/deliveries/new/select-project-test.js b/tests/unit/controllers/deliveries/new/select-project-test.js
index 1f98384..44e5b69 100644
--- a/tests/unit/controllers/deliveries/new/select-project-test.js
+++ b/tests/unit/controllers/deliveries/new/select-project-test.js
@@ -3,7 +3,7 @@ import Ember from 'ember';
moduleFor('controller:deliveries/new/select-project', 'Unit | Controller | deliveries/new/select project', {
// Specify the other units that are required for this test.
- // needs: ['controller:foo']
+ needs: ['controller:application', 'service:session', 'service:duke-ds-user', 'model:duke-ds-project-permission']
});
// Replace this with your real tests.
@@ -22,13 +22,14 @@ test('it handles back action', function(assert) {
controller.send('back');
});
-test('it handles next action and resets project', function(assert) {
+test('it handles next action', function(assert) {
let project = Ember.Object.create({ id: '123' });
let controller = this.subject({
project: project,
+ currentUserCanDeliver: true,
transitionToRoute(routeName, data) {
assert.equal(routeName, 'deliveries.new.select-recipient', 'next action should transition to recipient selection');
- assert.equal(data.queryParams.project_id, '123', 'next action should pass project_id');
+ assert.equal(data.queryParams.projectId, '123', 'next action should pass projectId');
}
});
controller.send('next');
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
index f1a9901..79566b5 100644
--- a/tests/unit/controllers/deliveries/new/select-recipient-test.js
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -24,18 +24,17 @@ test('it handles back action', function(assert) {
});
test('it handles next action', function(assert) {
- let project = Ember.Object.create({ id: '123' });
let toUser = Ember.Object.create({ id: '456' });
let shareUsers = [Ember.Object.create({ id: '789'}), Ember.Object.create({ id: '001'})];
let controller = this.subject({
- project: project,
+ projectId: '123',
toUser: toUser,
shareUsers: shareUsers,
transitionToRoute(routeName, data) {
assert.equal(routeName, 'deliveries.new.enter-user-message', 'next action should transition to enter-user-message');
- assert.equal(data.queryParams.project_id, '123', 'next action should pass project_id');
- assert.equal(data.queryParams.to_user_id, '456', 'next action should pass to_user_id');
- assert.equal(data.queryParams.share_user_ids, '789,001', 'next action should pass share_user_ids');
+ assert.equal(data.queryParams.projectId, '123', 'next action should pass projectId');
+ assert.equal(data.queryParams.toUserId, '456', 'next action should pass toUserId');
+ assert.equal(data.queryParams.shareUserIds, '789,001', 'next action should pass shareUserIds');
}
});
controller.send('next');
@@ -43,7 +42,7 @@ test('it handles next action', function(assert) {
test('it looks up project based on query param', function(assert) {
let controller = this.subject({
- project_id: '123',
+ projectId: '123',
store: {
findRecord(modelName, modelKey) {
assert.equal(modelName, 'duke-ds-project');
diff --git a/tests/unit/models/duke-ds-project-permission-test.js b/tests/unit/models/duke-ds-project-permission-test.js
new file mode 100644
index 0000000..3cfe423
--- /dev/null
+++ b/tests/unit/models/duke-ds-project-permission-test.js
@@ -0,0 +1,12 @@
+import { moduleForModel, test } from 'ember-qunit';
+
+moduleForModel('duke-ds-project-permission', 'Unit | Model | duke ds project permission', {
+ // Specify the other units that are required for this test.
+ needs: []
+});
+
+test('it exists', function(assert) {
+ let model = this.subject();
+ // let store = this.store();
+ assert.ok(!!model);
+});
diff --git a/tests/unit/routes/deliveries/new/select-project-test.js b/tests/unit/routes/deliveries/new/select-project-test.js
index 70dd65d..2f027c5 100644
--- a/tests/unit/routes/deliveries/new/select-project-test.js
+++ b/tests/unit/routes/deliveries/new/select-project-test.js
@@ -11,13 +11,13 @@ test('it exists', function(assert) {
assert.ok(route);
});
-test('it sets model to deliverable projects', function(assert) {
+test('it sets model to non-deleted projects', function(assert) {
assert.expect(4);
let route = this.subject({
store: {
query(recordModel, params) {
assert.equal(recordModel, 'duke-ds-project');
- assert.equal(params.is_deliverable, true);
+ assert.equal(params.is_deleted, false);
return [Ember.Object.create({id: 123})];
}
}
From 2871f016af92920b8fc3f34c10216ba67cf8b000 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Wed, 8 Aug 2018 16:54:06 -0400
Subject: [PATCH 13/36] force reload of recipient list
---
app/routes/deliveries/new/select-recipient.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/app/routes/deliveries/new/select-recipient.js b/app/routes/deliveries/new/select-recipient.js
index 01b8712..2892967 100644
--- a/app/routes/deliveries/new/select-recipient.js
+++ b/app/routes/deliveries/new/select-recipient.js
@@ -2,6 +2,7 @@ import Ember from 'ember';
export default Ember.Route.extend({
model() {
- return this.get('store').findAll('duke-ds-user');
+ // force loading all list of users so they don't start filling in after a few seconds
+ return this.get('store').findAll('duke-ds-user', {reload: true});
}
});
From 068ddab64da677cccf89e7f17ba6ceec7969a523 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 11:04:17 -0400
Subject: [PATCH 14/36] simplify breadcrumb computed properties
---
app/components/delivery-breadcrumbs.js | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/app/components/delivery-breadcrumbs.js b/app/components/delivery-breadcrumbs.js
index 0e20553..6dbfdbe 100644
--- a/app/components/delivery-breadcrumbs.js
+++ b/app/components/delivery-breadcrumbs.js
@@ -9,10 +9,6 @@ export default Ember.Component.extend({
// selected route starts with deliveries.show
return this.get('selectedRouteName').indexOf('deliveries.show') == 0;
}),
- isResendSelected: Ember.computed('selectedRouteName', function () {
- return this.get('selectedRouteName') === 'deliveries.show.resend';
- }),
- isNewDeliverySelected: Ember.computed('selectedRouteName', function () {
- return this.get('selectedRouteName') === 'deliveries.new';
- }),
+ isResendSelected: Ember.computed.equal('selectedRouteName', 'deliveries.show.resend'),
+ isNewDeliverySelected: Ember.computed.equal('selectedRouteName', 'deliveries.new')
});
From 3bf70ad75d94250a80c896a7e88d30236424dbd7 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 11:52:36 -0400
Subject: [PATCH 15/36] remove share user selection from select-recipient
Adds some code to show errors.
---
.../deliveries/new/enter-user-message.js | 40 ++++++++-----------
.../deliveries/new/select-recipient.js | 10 -----
app/routes/deliveries/new/select-recipient.js | 3 +-
.../deliveries/new/enter-user-message.hbs | 12 +++---
.../deliveries/new/select-project.hbs | 5 +--
.../deliveries/new/select-recipient.hbs | 15 +++----
6 files changed, 29 insertions(+), 56 deletions(-)
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index 0f26b12..cd7b86d 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -4,7 +4,6 @@ export default Ember.Controller.extend({
queryParams: ['projectId', 'toUserId', 'shareUserIds'],
projectId: null,
toUserId: null,
- shareUserIds: null,
userMessage: null,
application: Ember.inject.controller(),
currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
@@ -15,36 +14,29 @@ export default Ember.Controller.extend({
toUser: Ember.computed('toUserId', function () {
return this.get('store').findRecord('duke-ds-user', this.get('toUserId'));
}),
- shareUsers: Ember.computed('shareUserIds', function () {
- const store = this.get('store');
- const shareUserIds = this.get('shareUserIds');
- if (!shareUserIds) {
- return [];
- }
- return shareUserIds
- .split(',')
- .map(userId => store.findRecord('duke-ds-user', userId));
- }),
+ errors: null,
+ errorMessages: Ember.computed.mapBy('errors', 'detail'),
actions: {
back() {
const projectId = this.get('projectId');
this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { projectId: projectId }});
},
saveAndSend() {
- // shareUsers returns a javascript array of promises, these promises need to be resolved
- // into models before we can use them in saving the delivery
- return Ember.RSVP.all(this.get('shareUsers')).then((shareUsers) => {
- const delivery = this.get('store').createRecord('delivery', {
- project: this.get('project'),
- fromUser: this.get('fromUser'),
- shareUsers: shareUsers,
- toUser: this.get('toUser'),
- userMessage: this.get('userMessage')
- });
- return delivery.save();
- }).then(savedDelivery => {
+ const delivery = this.get('store').createRecord('delivery', {
+ project: this.get('project'),
+ fromUser: this.get('fromUser'),
+ toUser: this.get('toUser'),
+ userMessage: this.get('userMessage')
+ });
+ this.set('errorMessage', null);
+ return delivery.save().then(
+ savedDelivery => {
return savedDelivery.send();
- }).then(sentDelivery => {
+ },
+ errorResponse => {
+ console.log(errorResponse.errors);
+ this.set('errors', errorResponse.errors);
+ }).then(sentDelivery => {
this.transitionToRoute('deliveries.show', sentDelivery.get('transfer'));
});
}
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index 1eea8b6..b04b69f 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -17,7 +17,6 @@ export default Ember.Controller.extend({
}
}),
toUser: null,
- shareUsers: null,
disableNext: Ember.computed.not('toUser'),
actions: {
toUserSelectionChanged(actionData) {
@@ -27,25 +26,16 @@ export default Ember.Controller.extend({
}
this.set('toUser', selectedItem);
},
- shareUsersSelectionChanged(actionData) {
- this.set('shareUsers', actionData.selectedItems);
- },
back() {
this.transitionToRoute('deliveries.new.select-project');
},
next() {
const projectId = this.get('projectId');
const toUserId = this.get('toUser.id');
- const shareUsers = this.get('shareUsers');
- var shareUserIds = null;
- if (shareUsers) {
- shareUserIds = shareUsers.mapBy('id').join(',');
- }
this.transitionToRoute('deliveries.new.enter-user-message', {
queryParams: {
projectId: projectId,
toUserId: toUserId,
- shareUserIds: shareUserIds
}
});
}
diff --git a/app/routes/deliveries/new/select-recipient.js b/app/routes/deliveries/new/select-recipient.js
index 2892967..01b8712 100644
--- a/app/routes/deliveries/new/select-recipient.js
+++ b/app/routes/deliveries/new/select-recipient.js
@@ -2,7 +2,6 @@ import Ember from 'ember';
export default Ember.Route.extend({
model() {
- // force loading all list of users so they don't start filling in after a few seconds
- return this.get('store').findAll('duke-ds-user', {reload: true});
+ return this.get('store').findAll('duke-ds-user');
}
});
diff --git a/app/templates/deliveries/new/enter-user-message.hbs b/app/templates/deliveries/new/enter-user-message.hbs
index 56687e9..9ba35ed 100644
--- a/app/templates/deliveries/new/enter-user-message.hbs
+++ b/app/templates/deliveries/new/enter-user-message.hbs
@@ -1,15 +1,15 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
New Delivery
-
- Click the Send Delivery button to begin delivery of
- {{project.name}} to {{toUser.fullName}}.
-
+
+ Click the Send Delivery button to begin transfering ownership of
+ {{project.name}} to {{toUser.fullName}}.
+
This will send an email to the recipient that includes a link for the recipient to accept or delcine the delivery.
If the user accepts the delivery they will take ownership of the project.
Once the delivery is accepted you will retain read-only permissions.
If you wish to add or edit a custom message (e.g. details about this specific delivery), please enter those notes in the
- User Message area.
+ User Message area below.
@@ -17,7 +17,6 @@
-
{{#detail-label-value label="From"}}{{fromUser.fullName}}{{/detail-label-value}}
{{#detail-label-value label="To"}}{{toUser.fullName}}{{/detail-label-value}}
{{#each shareUsers as |shareUser index|}}
@@ -28,7 +27,6 @@
{{/if}}
{{/each}}
{{#detail-label-value label="User Message"}}{{user-message-textarea value=userMessage readonly=false}}{{/detail-label-value}}
-
diff --git a/app/templates/deliveries/new/select-project.hbs b/app/templates/deliveries/new/select-project.hbs
index 3d56d73..f5f615b 100644
--- a/app/templates/deliveries/new/select-project.hbs
+++ b/app/templates/deliveries/new/select-project.hbs
@@ -1,12 +1,11 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
New Delivery
-
- Select a project to deliver to another user.
-
+Select a project to deliver to another user.
This will transfer ownership of the project to another user.
Once the recipient accepts the delivery you will retain read-only permissions.
+
{{#bs-alert
visible=showUserMissingPrivilegesError
type="danger"
diff --git a/app/templates/deliveries/new/select-recipient.hbs b/app/templates/deliveries/new/select-recipient.hbs
index 3946a3c..fe2e12a 100644
--- a/app/templates/deliveries/new/select-recipient.hbs
+++ b/app/templates/deliveries/new/select-recipient.hbs
@@ -1,19 +1,14 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
New Delivery
+
+ Select the user you wish to transfer ownership of {{project.name}} to.
+
- Select the recipient you wish to transfer ownership of {{project.name}} to.
-
-
- This selected user will take ownership of the project once the delivery is accepted.
+ The selected user will take ownership of the project once the delivery is accepted.
Once the delivery is accepted you will retain read-only permissions.
-{{duke-ds-user-list otherUsersList pageSize=6 selectionChanged=(action 'toUserSelectionChanged')}}
-
-
- Select additional users to share project.
-
-{{duke-ds-user-list otherUsersList pageSize=6 multipleSelect=true selectionChanged=(action 'shareUsersSelectionChanged')}}
+{{duke-ds-user-list otherUsersList pageSize=12 selectionChanged=(action 'toUserSelectionChanged')}}
{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
{{#bs-button type="primary" disabled=disableNext onClick=(action 'next') class="pull-right next-button"}}Next{{/bs-button}}
From 2b9d464b61f7078731a7fe0c3d57a692f1b5d2b8 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 12:07:07 -0400
Subject: [PATCH 16/36] fix tests for removed shareUsers
---
app/adapters/duke-ds-project-permission.js | 9 +++++
.../deliveries/new/enter-user-message.js | 1 -
.../duke-ds-project-permission-test.js | 12 +++++++
.../deliveries/new/enter-user-message-test.js | 34 +------------------
.../deliveries/new/select-recipient-test.js | 14 --------
5 files changed, 22 insertions(+), 48 deletions(-)
create mode 100644 app/adapters/duke-ds-project-permission.js
create mode 100644 tests/unit/adapters/duke-ds-project-permission-test.js
diff --git a/app/adapters/duke-ds-project-permission.js b/app/adapters/duke-ds-project-permission.js
new file mode 100644
index 0000000..4d941ca
--- /dev/null
+++ b/app/adapters/duke-ds-project-permission.js
@@ -0,0 +1,9 @@
+import ApplicationAdapter from './application';
+
+export default ApplicationAdapter.extend({
+ urlForQuery(query) {
+ const projectId = query.project;
+ delete query.project; // remove project from query so it will not be appended to the url
+ return this.buildURL('duke-ds-project') + projectId + '/permissions/';
+ }
+});
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index cd7b86d..5c2a42b 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -34,7 +34,6 @@ export default Ember.Controller.extend({
return savedDelivery.send();
},
errorResponse => {
- console.log(errorResponse.errors);
this.set('errors', errorResponse.errors);
}).then(sentDelivery => {
this.transitionToRoute('deliveries.show', sentDelivery.get('transfer'));
diff --git a/tests/unit/adapters/duke-ds-project-permission-test.js b/tests/unit/adapters/duke-ds-project-permission-test.js
new file mode 100644
index 0000000..7d39fc0
--- /dev/null
+++ b/tests/unit/adapters/duke-ds-project-permission-test.js
@@ -0,0 +1,12 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('adapter:duke-ds-project-permission', 'Unit | Adapter | duke ds project permission', {
+ // Specify the other units that are required for this test.
+ needs: ['service:session']
+});
+
+test('it returns duke-ds-project permisions sub route for urlForQuery', function(assert) {
+ let adapter = this.subject();
+ let url = adapter.urlForQuery({project: 'project1'}, 'duke-ds-project-permission');
+ assert.equal(url, 'http://testhost/duke-ds-projects/project1/permissions/')
+});
diff --git a/tests/unit/controllers/deliveries/new/enter-user-message-test.js b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
index 7608aa3..fbf112a 100644
--- a/tests/unit/controllers/deliveries/new/enter-user-message-test.js
+++ b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
@@ -57,55 +57,23 @@ test('it looks up toUser based on query param', function(assert) {
assert.equal(controller.get('toUser'), 'someuser');
});
-test('it looks up shareUsers based on query param', function(assert) {
- let controller = this.subject({
- toUserId: '456',
- shareUserIds: '789',
- store: {
- findRecord(modelName, modelKey) {
- if (modelName === 'duke-ds-user' && modelKey === '789') {
- return 'someuser';
- }
- return null;
- }
- }
- });
- assert.equal(controller.get('shareUsers').length, 1);
- assert.equal(controller.get('shareUsers')[0], 'someuser');
-});
test('it handles saveAndSend action', function(assert) {
- assert.expect(10);
+ assert.expect(7);
const project = Ember.Object.create({ id: '123' });
const fromUser = Ember.Object.create({ id: '222' });
const toUser = Ember.Object.create({ id: '456' });
- const shareUser1 = Ember.Object.create({ id: '789'})
- const shareUser2 = Ember.Object.create({ id: '001'});
const controller = this.subject({
project: project,
currentDukeDsUser: fromUser,
toUser: toUser,
- shareUserIds: '789,001',
userMessage: 'hey bob',
store: {
- findRecord(modelName, modelKey) {
- if (modelName === 'duke-ds-user') {
- if (modelKey === shareUser1.get('id')) {
- return Ember.RSVP.resolve(shareUser1);
- } else if (modelKey === shareUser2.get('id')) {
- return Ember.RSVP.resolve(shareUser2);
- }
- }
- return null;
- },
createRecord(modelName, payload) {
assert.equal(modelName, 'delivery');
assert.equal(payload.project, project);
assert.equal(payload.fromUser, fromUser);
assert.equal(payload.toUser, toUser);
- assert.equal(payload.shareUsers.length, 2);
- assert.equal(payload.shareUsers[0], shareUser1);
- assert.equal(payload.shareUsers[1], shareUser2);
assert.equal(payload.userMessage, 'hey bob');
const mockDelivery = {
get(name) {
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
index 79566b5..b104d1c 100644
--- a/tests/unit/controllers/deliveries/new/select-recipient-test.js
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -25,16 +25,13 @@ test('it handles back action', function(assert) {
test('it handles next action', function(assert) {
let toUser = Ember.Object.create({ id: '456' });
- let shareUsers = [Ember.Object.create({ id: '789'}), Ember.Object.create({ id: '001'})];
let controller = this.subject({
projectId: '123',
toUser: toUser,
- shareUsers: shareUsers,
transitionToRoute(routeName, data) {
assert.equal(routeName, 'deliveries.new.enter-user-message', 'next action should transition to enter-user-message');
assert.equal(data.queryParams.projectId, '123', 'next action should pass projectId');
assert.equal(data.queryParams.toUserId, '456', 'next action should pass toUserId');
- assert.equal(data.queryParams.shareUserIds, '789,001', 'next action should pass shareUserIds');
}
});
controller.send('next');
@@ -83,14 +80,3 @@ test('it handles toUserSelectionChanged', function(assert) {
});
assert.equal(controller.get('toUser'), toUser);
});
-
-test('it handles shareUsersSelectionChanged', function(assert) {
- let shareUsers = [Ember.Object.create({ id: '123' })];
- let controller = this.subject({
- project: null,
- });
- controller.send('shareUsersSelectionChanged', {
- selectedItems: shareUsers
- });
- assert.equal(controller.get('shareUsers'), shareUsers);
-});
From fecb96fc67402c656dd20a77cc093d18fa1185e7 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 12:17:08 -0400
Subject: [PATCH 17/36] add duke-ds-project model requirement for test
---
tests/unit/models/duke-ds-project-permission-test.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tests/unit/models/duke-ds-project-permission-test.js b/tests/unit/models/duke-ds-project-permission-test.js
index 3cfe423..9bb7853 100644
--- a/tests/unit/models/duke-ds-project-permission-test.js
+++ b/tests/unit/models/duke-ds-project-permission-test.js
@@ -2,7 +2,9 @@ import { moduleForModel, test } from 'ember-qunit';
moduleForModel('duke-ds-project-permission', 'Unit | Model | duke ds project permission', {
// Specify the other units that are required for this test.
- needs: []
+ needs: [
+ 'model:duke-ds-project',
+ ]
});
test('it exists', function(assert) {
From 377c191249084de1131f37d0622f16162013d15c Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 12:34:01 -0400
Subject: [PATCH 18/36] tweak messaging and layout of screens
---
app/templates/deliveries/new/enter-user-message.hbs | 5 ++---
app/templates/deliveries/new/select-project.hbs | 2 --
app/templates/deliveries/new/select-recipient.hbs | 1 -
3 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/app/templates/deliveries/new/enter-user-message.hbs b/app/templates/deliveries/new/enter-user-message.hbs
index 9ba35ed..14e40df 100644
--- a/app/templates/deliveries/new/enter-user-message.hbs
+++ b/app/templates/deliveries/new/enter-user-message.hbs
@@ -1,8 +1,7 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
New Delivery
- Click the Send Delivery button to begin transfering ownership of
- {{project.name}} to {{toUser.fullName}}.
+ Click Send Delivery to begin transferring ownership of your project.
This will send an email to the recipient that includes a link for the recipient to accept or delcine the delivery.
@@ -34,8 +33,8 @@
{{error-message-alert errorMessages}}
{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
-
{{#bs-button type="primary" disabled=disableNext onClick=(action 'saveAndSend') class="pull-right next-button"}}
Send Delivery
{{/bs-button}}
+
{{outlet}}
diff --git a/app/templates/deliveries/new/select-project.hbs b/app/templates/deliveries/new/select-project.hbs
index f5f615b..77f6b52 100644
--- a/app/templates/deliveries/new/select-project.hbs
+++ b/app/templates/deliveries/new/select-project.hbs
@@ -5,7 +5,6 @@
This will transfer ownership of the project to another user.
Once the recipient accepts the delivery you will retain read-only permissions.
-
{{#bs-alert
visible=showUserMissingPrivilegesError
type="danger"
@@ -16,7 +15,6 @@
{{duke-ds-project-list model selectionChanged=(action 'projectSelectionChanged')}}
{{#bs-button type="default" onClick=(action 'back') class="back-button"}}Back{{/bs-button}}
-
{{#bs-button type="primary" disabled=disableNext onClick=(action 'next') class="pull-right next-button"}}Next{{/bs-button}}
{{outlet}}
diff --git a/app/templates/deliveries/new/select-recipient.hbs b/app/templates/deliveries/new/select-recipient.hbs
index fe2e12a..7a33968 100644
--- a/app/templates/deliveries/new/select-recipient.hbs
+++ b/app/templates/deliveries/new/select-recipient.hbs
@@ -1,6 +1,5 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.new"}}
New Delivery
-
Select the user you wish to transfer ownership of {{project.name}} to.
From 193f96041a681bbfeb22b0df01310f784bc1cf90 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 12:49:52 -0400
Subject: [PATCH 19/36] add other model for test
This test only fails on travis.
---
tests/unit/models/duke-ds-project-permission-test.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/unit/models/duke-ds-project-permission-test.js b/tests/unit/models/duke-ds-project-permission-test.js
index 9bb7853..1a37bad 100644
--- a/tests/unit/models/duke-ds-project-permission-test.js
+++ b/tests/unit/models/duke-ds-project-permission-test.js
@@ -4,6 +4,7 @@ moduleForModel('duke-ds-project-permission', 'Unit | Model | duke ds project per
// Specify the other units that are required for this test.
needs: [
'model:duke-ds-project',
+ 'model:duke-ds-user',
]
});
From e6ee8e2bf4962ec6473269c89d21cf62cc9433cb Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 13:18:05 -0400
Subject: [PATCH 20/36] filter out bad users and sort by fullName
---
app/components/duke-ds-user-list.js | 10 ++++++++--
app/controllers/deliveries/new/select-recipient.js | 12 +++++++++---
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/app/components/duke-ds-user-list.js b/app/components/duke-ds-user-list.js
index 5c59f90..1cda5e6 100644
--- a/app/components/duke-ds-user-list.js
+++ b/app/components/duke-ds-user-list.js
@@ -12,8 +12,14 @@ const DukeDSUserList = Ember.Component.extend({
mayBeHidden: false,
className: "select-row-checkbox-column",
},
- { propertyName: "fullName", title: "Name", className: "duke-ds-user-fullName"},
- { propertyName: "email", title: "Email", className: "duke-ds-user-email"}
+ { propertyName: "fullName",
+ title: "Name",
+ className: "duke-ds-user-fullName",
+ sortPrecedence: 0
+ },
+ { propertyName: "email",
+ title: "Email",
+ className: "duke-ds-user-email"}
],
actions: {
displayDataChanged: function (e) {
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index b04b69f..a0db7ce 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -8,12 +8,18 @@ export default Ember.Controller.extend({
}),
application: Ember.inject.controller(),
currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
- otherUsersList: Ember.computed('model.[]', 'currentDukeDsUser', function () {
+ validUsersList: Ember.computed('model.[]', function () {
+ // remove users with invalid fullName values
+ return this.get('model')
+ .rejectBy('fullName', null)
+ .rejectBy('fullName', '(null)');
+ }),
+ otherUsersList: Ember.computed('validUsersList.[]', 'currentDukeDsUser', function () {
const currentDukeDSUser = this.get('currentDukeDsUser');
if (currentDukeDSUser) {
- return this.get('model').rejectBy('id', currentDukeDSUser.get('id'));
+ return this.get('validUsersList').rejectBy('id', currentDukeDSUser.get('id'));
} else {
- return this.get('model');
+ return this.get('validUsersList');
}
}),
toUser: null,
From b4934772a9c104ef2a734ae522e4dc024ab871e0 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 13:38:25 -0400
Subject: [PATCH 21/36] test sorting by user Name
---
.../components/duke-ds-user-list-test.js | 25 +++++++++++--------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/tests/integration/components/duke-ds-user-list-test.js b/tests/integration/components/duke-ds-user-list-test.js
index 330d281..0b60444 100644
--- a/tests/integration/components/duke-ds-user-list-test.js
+++ b/tests/integration/components/duke-ds-user-list-test.js
@@ -5,21 +5,22 @@ moduleForComponent('duke-ds-user-list', 'Integration | Component | duke ds user
integration: true
});
-test('it renders a list of users', function(assert) {
+test('it renders a list of users sorted by fullName', function(assert) {
this.set('users', [
- {fullName: 'Joe', email: 'joe@joe.org'},
- {fullName: 'Jim', email: 'jim@jim.org'},
+ {id:'1', fullName: 'Joe', email: 'joe@joe.org'},
+ {id:'2', fullName: 'Jim', email: 'jim@jim.org'},
]);
+ this.set('externalAction', function () {});
+ this.render(hbs`{{duke-ds-user-list users selectionChanged=(action externalAction)}}`);
- this.render(hbs`{{duke-ds-user-list users}}`);
//assert.equal(this.$().html().trim(), 'Project Name');
assert.equal(this.$('.duke-ds-user-fullName').eq(0).text().trim(), 'Name'); //header
assert.equal(this.$('.duke-ds-user-email').eq(0).text().trim(), 'Email'); //header
// index 1 is the search box
- assert.equal(this.$('.duke-ds-user-fullName').eq(2).text().trim(), 'Joe');
- assert.equal(this.$('.duke-ds-user-email').eq(2).text().trim(), 'joe@joe.org');
- assert.equal(this.$('.duke-ds-user-fullName').eq(3).text().trim(), 'Jim');
- assert.equal(this.$('.duke-ds-user-email').eq(3).text().trim(), 'jim@jim.org');
+ assert.equal(this.$('.duke-ds-user-fullName').eq(2).text().trim(), 'Jim');
+ assert.equal(this.$('.duke-ds-user-email').eq(2).text().trim(), 'jim@jim.org');
+ assert.equal(this.$('.duke-ds-user-fullName').eq(3).text().trim(), 'Joe');
+ assert.equal(this.$('.duke-ds-user-email').eq(3).text().trim(), 'joe@joe.org');
});
test('it sends selected project to selectionChanged action', function(assert) {
@@ -28,7 +29,11 @@ test('it sends selected project to selectionChanged action', function(assert) {
{fullName: 'Joe', email: 'joe@joe.org'},
{fullName: 'Jim', email: 'jim@jim.org'},
]);
- this.set('externalAction', (actionData) => assert.equal(actionData.selectedItems[0].fullName, 'Jim'));
+ this.set('externalAction', function (actionData) {
+ if (actionData.selectedItems[0]) {
+ assert.equal(actionData.selectedItems[0].fullName, 'Jim');
+ }
+ });
this.render(hbs`{{duke-ds-user-list users selectionChanged=(action externalAction)}}`);
- this.$('.duke-ds-user-fullName').eq(3).click(); //click Jim row
+ this.$('.duke-ds-user-fullName').eq(2).click(); //click Jim row
});
From ecb4cc21766c9bdeceb9531c9ed958e6638b4722 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 13:47:19 -0400
Subject: [PATCH 22/36] test changes for filtering out 'null' duke-ds-users
---
.../deliveries/new/select-recipient-test.js | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
index b104d1c..40a8a81 100644
--- a/tests/unit/controllers/deliveries/new/select-recipient-test.js
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -52,10 +52,10 @@ test('it looks up project based on query param', function(assert) {
});
test('it computes a list of users outside of the currentDukeDSUser', function(assert) {
- let currentDukeDsUser = Ember.Object.create({ id: '123' });
+ let currentDukeDsUser = Ember.Object.create({ id: '123', fullName: 'Jane Smith' });
let userList = [
currentDukeDsUser,
- Ember.Object.create({ id: '456' })
+ Ember.Object.create({ id: '456', fullName: 'John Smith' })
];
let controller = this.subject({
application: {
@@ -68,6 +68,19 @@ test('it computes a list of users outside of the currentDukeDSUser', function(as
assert.equal(controller.get('otherUsersList')[0].get('id'), '456');
});
+test('it computes a list of users filtering out those with null fullNames', function(assert) {
+ const goodUser = Ember.Object.create({ id: '123', fullName: 'John Smith' });
+ const badUser1 = Ember.Object.create({ id: '456'});
+ badUser1.set('fullName', null);
+ const badUser2 = Ember.Object.create({ id: '789', fullName: '(null)'});
+ let controller = this.subject({
+ model: [goodUser, badUser1, badUser2],
+ });
+ assert.equal(controller.get('model').length, 3, 'There should be three users in the model');
+ assert.equal(controller.get('otherUsersList').length, 1, 'Only one has a valid fullName');
+ assert.equal(controller.get('otherUsersList')[0].get('id'), '123', 'Good user should be in the list');
+});
+
test('it handles toUserSelectionChanged', function(assert) {
let toUser = Ember.Object.create({ id: '123' });
let controller = this.subject({
From 4b821bb6613371f992a99ad3c63589e809d94258 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 15:24:39 -0400
Subject: [PATCH 23/36] enable case-insensitive projects and users
---
app/templates/components/duke-ds-project-list.hbs | 1 +
app/templates/components/duke-ds-user-list.hbs | 1 +
2 files changed, 2 insertions(+)
diff --git a/app/templates/components/duke-ds-project-list.hbs b/app/templates/components/duke-ds-project-list.hbs
index 8029f8f..a639761 100644
--- a/app/templates/components/duke-ds-project-list.hbs
+++ b/app/templates/components/duke-ds-project-list.hbs
@@ -6,6 +6,7 @@
showGlobalFilter=false
showPageSize=false
pageSize=12
+ filteringIgnoreCase=true
displayDataChangedAction=(action "displayDataChanged")
}}
diff --git a/app/templates/components/duke-ds-user-list.hbs b/app/templates/components/duke-ds-user-list.hbs
index 848993f..f11e50a 100644
--- a/app/templates/components/duke-ds-user-list.hbs
+++ b/app/templates/components/duke-ds-user-list.hbs
@@ -6,6 +6,7 @@
showGlobalFilter=false
showPageSize=false
pageSize=pageSize
+ filteringIgnoreCase=true
displayDataChangedAction=(action "displayDataChanged")
multipleSelect=multipleSelect
}}
From ff92e30cb12ae571a1958282dd65822b8d250015 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 15:46:34 -0400
Subject: [PATCH 24/36] remove unused queryParam
---
app/controllers/deliveries/new/enter-user-message.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index 5c2a42b..86f6343 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -1,7 +1,7 @@
import Ember from 'ember';
export default Ember.Controller.extend({
- queryParams: ['projectId', 'toUserId', 'shareUserIds'],
+ queryParams: ['projectId', 'toUserId'],
projectId: null,
toUserId: null,
userMessage: null,
From 780c7b96467c2d63959da9ee217b048ee31670d4 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 16:15:05 -0400
Subject: [PATCH 25/36] test for select-project showMissingPrivilegesError
---
.../deliveries/new/select-project.js | 1 +
.../deliveries/new/select-project-test.js | 30 +++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index fb0fead..69abcca 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -37,6 +37,7 @@ export default Ember.Controller.extend({
}
return authRole != 'project_admin';
}),
+ showMissingPrivilegesError: false,
actions: {
projectSelectionChanged(actionData) {
var selectedItem = null;
diff --git a/tests/unit/controllers/deliveries/new/select-project-test.js b/tests/unit/controllers/deliveries/new/select-project-test.js
index 44e5b69..efdc6e3 100644
--- a/tests/unit/controllers/deliveries/new/select-project-test.js
+++ b/tests/unit/controllers/deliveries/new/select-project-test.js
@@ -47,3 +47,33 @@ test('it handles projectSelectionChanged', function(assert) {
});
assert.equal(controller.get('project'), project);
});
+
+
+test('it enables showMissingPrivilegesError when user clicks Next but has no permission', function(assert) {
+ let project = Ember.Object.create({ id: '123' });
+ let controller = this.subject({
+ project: project,
+ transitionToRoute: function () {}
+ });
+ assert.equal(controller.get('showMissingPrivilegesError'), false,
+ 'showMissingPrivilegesError defaults to false');
+
+ controller.set('currentUserCanDeliver', false);
+ controller.send('next');
+ assert.equal(controller.get('showMissingPrivilegesError'), true,
+ 'showMissingPrivilegesError is true if user sends and has no permissions');
+
+ // user selects a project
+ controller.send('projectSelectionChanged', {
+ selectedItems: [
+ project
+ ]
+ });
+ assert.equal(controller.get('showMissingPrivilegesError'), false,
+ 'showMissingPrivilegesError resets on selection changed');
+
+ controller.set('currentUserCanDeliver', true);
+ controller.send('next');
+ assert.equal(controller.get('showMissingPrivilegesError'), false,
+ 'showMissingPrivilegesError is false if user sends and has permissions');
+});
From 91c45b5847f148d40bfda1d0c4c33e98a1ae8f16 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Thu, 9 Aug 2018 16:49:40 -0400
Subject: [PATCH 26/36] simplify select-project and add more tests
---
.../deliveries/new/select-project.js | 10 +-
.../deliveries/new/select-project-test.js | 92 ++++++++++++++-----
2 files changed, 75 insertions(+), 27 deletions(-)
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index 69abcca..58d920a 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -1,5 +1,7 @@
import Ember from 'ember';
+const PROJECT_ADMIN_AUTH_ROLE = 'project_admin';
+
export default Ember.Controller.extend({
project: null,
application: Ember.inject.controller(),
@@ -24,7 +26,7 @@ export default Ember.Controller.extend({
}
}),
currentUserCanDeliver: Ember.computed('currentUserProjectAuthRole', function () {
- return this.get('currentUserProjectAuthRole') == 'project_admin';
+ return this.get('currentUserProjectAuthRole') == PROJECT_ADMIN_AUTH_ROLE;
}),
disableNext: Ember.computed.not('currentUserCanDeliver'),
showUserMissingPrivilegesError: Ember.computed('project.id', 'currentUserProjectAuthRole', function () {
@@ -35,9 +37,8 @@ export default Ember.Controller.extend({
if (!authRole) {
return false; //do not show error while we are fetching users auth role for this project
}
- return authRole != 'project_admin';
+ return authRole != PROJECT_ADMIN_AUTH_ROLE;
}),
- showMissingPrivilegesError: false,
actions: {
projectSelectionChanged(actionData) {
var selectedItem = null;
@@ -45,7 +46,6 @@ export default Ember.Controller.extend({
selectedItem = actionData.selectedItems[0];
}
this.set('project', selectedItem);
- this.set('showMissingPrivilegesError', false);
},
back() {
this.transitionToRoute('deliveries');
@@ -55,8 +55,6 @@ export default Ember.Controller.extend({
if (projectId) {
if (this.get('currentUserCanDeliver')) {
this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { projectId: projectId }})
- } else {
- this.set('showMissingPrivilegesError', true);
}
}
}
diff --git a/tests/unit/controllers/deliveries/new/select-project-test.js b/tests/unit/controllers/deliveries/new/select-project-test.js
index efdc6e3..49fd6f2 100644
--- a/tests/unit/controllers/deliveries/new/select-project-test.js
+++ b/tests/unit/controllers/deliveries/new/select-project-test.js
@@ -35,6 +35,19 @@ test('it handles next action', function(assert) {
controller.send('next');
});
+test('it stops next action if user cannot deliver', function(assert) {
+ assert.expect(0);
+ let project = Ember.Object.create({ id: '123' });
+ let controller = this.subject({
+ project: project,
+ currentUserCanDeliver: false,
+ transitionToRoute() {
+ assert('Should not transition if user cannot deliver.');
+ }
+ });
+ controller.send('next');
+});
+
test('it handles projectSelectionChanged', function(assert) {
let project = Ember.Object.create({ id: '123' });
let controller = this.subject({
@@ -48,32 +61,69 @@ test('it handles projectSelectionChanged', function(assert) {
assert.equal(controller.get('project'), project);
});
-
-test('it enables showMissingPrivilegesError when user clicks Next but has no permission', function(assert) {
+test('it computes currentUserProjectPermissions from duke-ds-project-permission', function(assert) {
+ assert.expect(5);
let project = Ember.Object.create({ id: '123' });
+ let currentDukeDsUser = Ember.Object.create({id: '456'});
let controller = this.subject({
- project: project,
- transitionToRoute: function () {}
+ project: null,
+ currentDukeDsUser: null,
+ store: {
+ query: function (modelName, params) {
+ assert.equal(modelName, 'duke-ds-project-permission');
+ assert.equal(params.project, '123');
+ assert.equal(params.user, '456');
+ return [
+ 'permissiondata'
+ ]
+ }
+ }
});
- assert.equal(controller.get('showMissingPrivilegesError'), false,
- 'showMissingPrivilegesError defaults to false');
+ assert.deepEqual(controller.get('currentUserProjectPermissions'), []);
+ controller.set('project', project);
+ controller.set('currentDukeDsUser', currentDukeDsUser);
+ assert.deepEqual(controller.get('currentUserProjectPermissions'), ['permissiondata']);
+});
- controller.set('currentUserCanDeliver', false);
- controller.send('next');
- assert.equal(controller.get('showMissingPrivilegesError'), true,
- 'showMissingPrivilegesError is true if user sends and has no permissions');
+test('it computes currentUserProjectAuthRole from currentUserProjectPermissions array', function(assert) {
+ let controller = this.subject({
+ currentUserProjectPermissions: []
+ });
+ assert.equal(controller.get('currentUserProjectAuthRole'), null)
+ controller.set('currentUserProjectPermissions', [
+ {'auth_role': 'project_admin'}
+ ])
+ assert.equal(controller.get('currentUserProjectAuthRole'), 'project_admin')
+});
- // user selects a project
- controller.send('projectSelectionChanged', {
- selectedItems: [
- project
- ]
+test('it computes currentUserProjectAuthRole from currentUserProjectPermissions array', function(assert) {
+ let controller = this.subject({
+ currentUserProjectPermissions: []
});
- assert.equal(controller.get('showMissingPrivilegesError'), false,
- 'showMissingPrivilegesError resets on selection changed');
+ assert.equal(controller.get('currentUserProjectAuthRole'), null)
+ controller.set('currentUserProjectPermissions', [
+ {'auth_role': 'project_admin'}
+ ])
+ assert.equal(controller.get('currentUserProjectAuthRole'), 'project_admin')
+});
- controller.set('currentUserCanDeliver', true);
- controller.send('next');
- assert.equal(controller.get('showMissingPrivilegesError'), false,
- 'showMissingPrivilegesError is false if user sends and has permissions');
+test('it computes showUserMissingPrivilegesError from project and currentUserProjectAuthRole', function(assert) {
+ let project = Ember.Object.create({ id: '123' });
+ let controller = this.subject({
+ project: null
+ });
+ assert.equal(controller.get('showUserMissingPrivilegesError'), false,
+ 'hide error when no project is selected');
+
+ controller.set('project', project);
+ assert.equal(controller.get('showUserMissingPrivilegesError'), false,
+ 'hide error when currentUserProjectAuthRole is empty');
+
+ controller.set('currentUserProjectAuthRole', 'downloader');
+ assert.equal(controller.get('showUserMissingPrivilegesError'), true,
+ 'show error when currentUserProjectAuthRole is not project admin');
+
+ controller.set('currentUserProjectAuthRole', 'project_admin');
+ assert.equal(controller.get('showUserMissingPrivilegesError'), false,
+ 'hide error when currentUserProjectAuthRole is project admin');
});
From 2ddd7d6cf5c50de5fa8db3afe377138ece6dde75 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Fri, 10 Aug 2018 08:48:13 -0400
Subject: [PATCH 27/36] add newlines to end of two files
---
app/templates/components/select-row-checkbox.hbs | 2 +-
app/templates/deliveries/index.hbs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/templates/components/select-row-checkbox.hbs b/app/templates/components/select-row-checkbox.hbs
index 0193eb3..a05ba52 100644
--- a/app/templates/components/select-row-checkbox.hbs
+++ b/app/templates/components/select-row-checkbox.hbs
@@ -1 +1 @@
-
\ No newline at end of file
+
diff --git a/app/templates/deliveries/index.hbs b/app/templates/deliveries/index.hbs
index b747f98..9cb5515 100644
--- a/app/templates/deliveries/index.hbs
+++ b/app/templates/deliveries/index.hbs
@@ -1,4 +1,4 @@
{{delivery-breadcrumbs selectedRouteName="deliveries.index"}}
All Deliveries
-{{delivery-table model currentDukeDsUser}}
\ No newline at end of file
+{{delivery-table model currentDukeDsUser}}
From 1168694c23d9ff624c3fa24044151d803efebb7f Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Fri, 10 Aug 2018 08:51:25 -0400
Subject: [PATCH 28/36] revert un-necessary pageSize change
---
app/templates/components/delivery-table.hbs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/templates/components/delivery-table.hbs b/app/templates/components/delivery-table.hbs
index 960d59a..f1767c3 100644
--- a/app/templates/components/delivery-table.hbs
+++ b/app/templates/components/delivery-table.hbs
@@ -19,5 +19,5 @@
showColumnsDropdown=false
showGlobalFilter=false
showPageSize=false
- pageSize=12
+ pageSize=20
}}
From ff42d3aaef97641b032cb4c4a595e66f74359e46 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Fri, 10 Aug 2018 09:17:53 -0400
Subject: [PATCH 29/36] reset errors when existing enter-user-message
---
app/controllers/deliveries/new/enter-user-message.js | 11 +++++++++--
app/routes/deliveries/new/enter-user-message.js | 5 +++++
.../routes/deliveries/new/enter-user-message-test.js | 12 ++++++++++++
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index 86f6343..df3b8f3 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -16,25 +16,32 @@ export default Ember.Controller.extend({
}),
errors: null,
errorMessages: Ember.computed.mapBy('errors', 'detail'),
+ disableNext: false,
actions: {
back() {
const projectId = this.get('projectId');
this.transitionToRoute('deliveries.new.select-recipient', { queryParams: { projectId: projectId }});
},
saveAndSend() {
+ this.setProperties({
+ disableNext: true,
+ errorMessage: null
+ });
const delivery = this.get('store').createRecord('delivery', {
project: this.get('project'),
fromUser: this.get('fromUser'),
toUser: this.get('toUser'),
userMessage: this.get('userMessage')
});
- this.set('errorMessage', null);
return delivery.save().then(
savedDelivery => {
return savedDelivery.send();
},
errorResponse => {
- this.set('errors', errorResponse.errors);
+ this.setProperties({
+ errors: errorResponse.errors,
+ disableNext: false
+ });
}).then(sentDelivery => {
this.transitionToRoute('deliveries.show', sentDelivery.get('transfer'));
});
diff --git a/app/routes/deliveries/new/enter-user-message.js b/app/routes/deliveries/new/enter-user-message.js
index 26d9f31..f9e550c 100644
--- a/app/routes/deliveries/new/enter-user-message.js
+++ b/app/routes/deliveries/new/enter-user-message.js
@@ -1,4 +1,9 @@
import Ember from 'ember';
export default Ember.Route.extend({
+ resetController(controller, isExiting) {
+ if (isExiting) {
+ controller.set('errors', null);
+ }
+ }
});
diff --git a/tests/unit/routes/deliveries/new/enter-user-message-test.js b/tests/unit/routes/deliveries/new/enter-user-message-test.js
index 64806e7..cdb57c0 100644
--- a/tests/unit/routes/deliveries/new/enter-user-message-test.js
+++ b/tests/unit/routes/deliveries/new/enter-user-message-test.js
@@ -1,4 +1,5 @@
import { moduleFor, test } from 'ember-qunit';
+import Ember from "ember";
moduleFor('route:deliveries/new/enter-user-message', 'Unit | Route | deliveries/new/enter user message', {
// Specify the other units that are required for this test.
@@ -9,3 +10,14 @@ test('it exists', function(assert) {
let route = this.subject();
assert.ok(route);
});
+
+test('it resets errors when exiting', function(assert) {
+ let route = this.subject({});
+ let controller = Ember.Object.create({
+ errors:'SomeErrors'
+ });
+ route.resetController(controller, false);
+ assert.equal(controller.get('errors'), 'SomeErrors')
+ route.resetController(controller, true);
+ assert.equal(controller.get('errors'), null)
+});
From cba5f8110fdf9391000e41c9cd0aa9959f3abac9 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Fri, 10 Aug 2018 15:35:49 -0400
Subject: [PATCH 30/36] minor improvements
---
app/controllers/deliveries/new/select-project.js | 10 ++++------
app/controllers/deliveries/new/select-recipient.js | 2 +-
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index 58d920a..c1ae049 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -13,8 +13,8 @@ export default Ember.Controller.extend({
return [];
}
return this.get('store').query('duke-ds-project-permission', {
- 'project': projectId,
- 'user': currentUserId,
+ project: projectId,
+ user: currentUserId,
});
}),
currentUserProjectAuthRole: Ember.computed('currentUserProjectPermissions.[]', function () {
@@ -25,9 +25,7 @@ export default Ember.Controller.extend({
return null;
}
}),
- currentUserCanDeliver: Ember.computed('currentUserProjectAuthRole', function () {
- return this.get('currentUserProjectAuthRole') == PROJECT_ADMIN_AUTH_ROLE;
- }),
+ currentUserCanDeliver: Ember.computed.equal('currentUserProjectAuthRole', PROJECT_ADMIN_AUTH_ROLE),
disableNext: Ember.computed.not('currentUserCanDeliver'),
showUserMissingPrivilegesError: Ember.computed('project.id', 'currentUserProjectAuthRole', function () {
if (this.get('project.id') == null) {
@@ -41,7 +39,7 @@ export default Ember.Controller.extend({
}),
actions: {
projectSelectionChanged(actionData) {
- var selectedItem = null;
+ let selectedItem = null;
if (actionData.selectedItems) {
selectedItem = actionData.selectedItems[0];
}
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index a0db7ce..7c47505 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -26,7 +26,7 @@ export default Ember.Controller.extend({
disableNext: Ember.computed.not('toUser'),
actions: {
toUserSelectionChanged(actionData) {
- var selectedItem = null;
+ let selectedItem = null;
if (actionData.selectedItems) {
selectedItem = actionData.selectedItems[0];
}
From 189d9614c1085f504b68860462177c4ca9522d18 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Fri, 10 Aug 2018 15:43:35 -0400
Subject: [PATCH 31/36] authRole camel case changes
---
app/controllers/deliveries/new/select-project.js | 2 +-
app/models/duke-ds-project-permission.js | 2 +-
.../deliveries/new/select-project-test.js | 12 ++++++------
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index c1ae049..d5f4f4b 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -18,7 +18,7 @@ export default Ember.Controller.extend({
});
}),
currentUserProjectAuthRole: Ember.computed('currentUserProjectPermissions.[]', function () {
- const authRoles = this.get('currentUserProjectPermissions').mapBy('auth_role');
+ const authRoles = this.get('currentUserProjectPermissions').mapBy('authRole');
if (authRoles) {
return authRoles[0];
} else {
diff --git a/app/models/duke-ds-project-permission.js b/app/models/duke-ds-project-permission.js
index bbb71bf..5ecbd91 100644
--- a/app/models/duke-ds-project-permission.js
+++ b/app/models/duke-ds-project-permission.js
@@ -3,5 +3,5 @@ import DS from 'ember-data';
export default DS.Model.extend({
project: DS.belongsTo('DukeDsProject'),
user: DS.belongsTo('DukeDsUser'),
- auth_role: DS.attr('string')
+ authRole: DS.attr('string')
});
diff --git a/tests/unit/controllers/deliveries/new/select-project-test.js b/tests/unit/controllers/deliveries/new/select-project-test.js
index 49fd6f2..20043d9 100644
--- a/tests/unit/controllers/deliveries/new/select-project-test.js
+++ b/tests/unit/controllers/deliveries/new/select-project-test.js
@@ -89,10 +89,10 @@ test('it computes currentUserProjectAuthRole from currentUserProjectPermissions
let controller = this.subject({
currentUserProjectPermissions: []
});
- assert.equal(controller.get('currentUserProjectAuthRole'), null)
+ assert.equal(controller.get('currentUserProjectAuthRole'), null);
controller.set('currentUserProjectPermissions', [
- {'auth_role': 'project_admin'}
- ])
+ {authRole: 'project_admin'}
+ ]);
assert.equal(controller.get('currentUserProjectAuthRole'), 'project_admin')
});
@@ -100,10 +100,10 @@ test('it computes currentUserProjectAuthRole from currentUserProjectPermissions
let controller = this.subject({
currentUserProjectPermissions: []
});
- assert.equal(controller.get('currentUserProjectAuthRole'), null)
+ assert.equal(controller.get('currentUserProjectAuthRole'), null);
controller.set('currentUserProjectPermissions', [
- {'auth_role': 'project_admin'}
- ])
+ {authRole: 'project_admin'}
+ ]);
assert.equal(controller.get('currentUserProjectAuthRole'), 'project_admin')
});
From 6f229f952178a9e7676ae77470bad059150ea254 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Fri, 10 Aug 2018 15:53:55 -0400
Subject: [PATCH 32/36] filter out users with empty emails
---
app/controllers/deliveries/new/select-recipient.js | 3 ++-
.../deliveries/new/select-recipient-test.js | 14 +++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index 7c47505..b5e660c 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -12,7 +12,8 @@ export default Ember.Controller.extend({
// remove users with invalid fullName values
return this.get('model')
.rejectBy('fullName', null)
- .rejectBy('fullName', '(null)');
+ .rejectBy('fullName', '(null)')
+ .rejectBy('email', null);
}),
otherUsersList: Ember.computed('validUsersList.[]', 'currentDukeDsUser', function () {
const currentDukeDSUser = this.get('currentDukeDsUser');
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
index 40a8a81..6d3701a 100644
--- a/tests/unit/controllers/deliveries/new/select-recipient-test.js
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -55,7 +55,7 @@ test('it computes a list of users outside of the currentDukeDSUser', function(as
let currentDukeDsUser = Ember.Object.create({ id: '123', fullName: 'Jane Smith' });
let userList = [
currentDukeDsUser,
- Ember.Object.create({ id: '456', fullName: 'John Smith' })
+ Ember.Object.create({ id: '456', fullName: 'John Smith'})
];
let controller = this.subject({
application: {
@@ -81,6 +81,18 @@ test('it computes a list of users filtering out those with null fullNames', func
assert.equal(controller.get('otherUsersList')[0].get('id'), '123', 'Good user should be in the list');
});
+test('it computes a list of users filtering out those with null emails', function(assert) {
+ const goodUser = Ember.Object.create({ id: '123', fullName: 'John Smith' });
+ const badUser1 = Ember.Object.create({ id: '456'});
+ badUser1.set('email', null);
+ let controller = this.subject({
+ model: [goodUser, badUser1],
+ });
+ assert.equal(controller.get('model').length, 2, 'There should be three users in the model');
+ assert.equal(controller.get('otherUsersList').length, 1, 'Only one has a valid email');
+ assert.equal(controller.get('otherUsersList')[0].get('id'), '123', 'Good user should be in the list');
+});
+
test('it handles toUserSelectionChanged', function(assert) {
let toUser = Ember.Object.create({ id: '123' });
let controller = this.subject({
From 2b4f7af8f88ca5d9337c4e7a86cf9a54e849dcb2 Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Fri, 10 Aug 2018 16:36:10 -0400
Subject: [PATCH 33/36] simplify controllers with ember shortcuts
---
.../deliveries/new/select-project.js | 17 +++++------------
.../deliveries/new/select-recipient.js | 6 +-----
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index d5f4f4b..9edd680 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -10,7 +10,7 @@ export default Ember.Controller.extend({
const projectId = this.get('project.id');
const currentUserId = this.get('currentDukeDsUser.id');
if (!projectId || !currentUserId) {
- return [];
+ return Ember.A();
}
return this.get('store').query('duke-ds-project-permission', {
project: projectId,
@@ -18,12 +18,9 @@ export default Ember.Controller.extend({
});
}),
currentUserProjectAuthRole: Ember.computed('currentUserProjectPermissions.[]', function () {
- const authRoles = this.get('currentUserProjectPermissions').mapBy('authRole');
- if (authRoles) {
- return authRoles[0];
- } else {
- return null;
- }
+ return this.get('currentUserProjectPermissions')
+ .mapBy('authRole')
+ .get('firstObject');
}),
currentUserCanDeliver: Ember.computed.equal('currentUserProjectAuthRole', PROJECT_ADMIN_AUTH_ROLE),
disableNext: Ember.computed.not('currentUserCanDeliver'),
@@ -39,11 +36,7 @@ export default Ember.Controller.extend({
}),
actions: {
projectSelectionChanged(actionData) {
- let selectedItem = null;
- if (actionData.selectedItems) {
- selectedItem = actionData.selectedItems[0];
- }
- this.set('project', selectedItem);
+ this.set('project', actionData.selectedItems.get('firstObject'));
},
back() {
this.transitionToRoute('deliveries');
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index b5e660c..382e23e 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -27,11 +27,7 @@ export default Ember.Controller.extend({
disableNext: Ember.computed.not('toUser'),
actions: {
toUserSelectionChanged(actionData) {
- let selectedItem = null;
- if (actionData.selectedItems) {
- selectedItem = actionData.selectedItems[0];
- }
- this.set('toUser', selectedItem);
+ this.set('toUser', actionData.selectedItems.get('firstObject'));
},
back() {
this.transitionToRoute('deliveries.new.select-project');
From 310d18d82aa58ab3d9aac7168cd4ce08aafb907d Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Mon, 13 Aug 2018 10:13:49 -0400
Subject: [PATCH 34/36] add comment for duke-ds-project-permissio adapter
---
app/adapters/duke-ds-project-permission.js | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/app/adapters/duke-ds-project-permission.js b/app/adapters/duke-ds-project-permission.js
index 4d941ca..f220d60 100644
--- a/app/adapters/duke-ds-project-permission.js
+++ b/app/adapters/duke-ds-project-permission.js
@@ -2,6 +2,11 @@ import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
urlForQuery(query) {
+ /*
+ Project permissions are a nested route under the duke-ds-project route.
+ There is not top level route to GET an individual permission.
+ This means querying permissions requires a project id parameter that will be used the build the base url.
+ */
const projectId = query.project;
delete query.project; // remove project from query so it will not be appended to the url
return this.buildURL('duke-ds-project') + projectId + '/permissions/';
From 34b220577148393e1f520bfb1636a66997553b1f Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Mon, 13 Aug 2018 12:16:17 -0400
Subject: [PATCH 35/36] wrap returned promises in DS.Promise* objects
---
.../deliveries/new/enter-user-message.js | 9 +++-
.../deliveries/new/select-project.js | 29 ++++++------
.../deliveries/new/select-recipient.js | 5 ++-
.../deliveries/new/enter-user-message-test.js | 10 +++--
.../deliveries/new/select-project-test.js | 45 ++++---------------
.../deliveries/new/select-recipient-test.js | 5 ++-
6 files changed, 45 insertions(+), 58 deletions(-)
diff --git a/app/controllers/deliveries/new/enter-user-message.js b/app/controllers/deliveries/new/enter-user-message.js
index df3b8f3..7ec7e5f 100644
--- a/app/controllers/deliveries/new/enter-user-message.js
+++ b/app/controllers/deliveries/new/enter-user-message.js
@@ -1,4 +1,5 @@
import Ember from 'ember';
+import DS from 'ember-data';
export default Ember.Controller.extend({
queryParams: ['projectId', 'toUserId'],
@@ -8,11 +9,15 @@ export default Ember.Controller.extend({
application: Ember.inject.controller(),
currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
project: Ember.computed('projectId', function () {
- return this.get('store').findRecord('duke-ds-project', this.get('projectId'));
+ return DS.PromiseObject.create({
+ promise: this.get('store').findRecord('duke-ds-project', this.get('projectId'))
+ });
}),
fromUser: Ember.computed.alias('currentDukeDsUser'),
toUser: Ember.computed('toUserId', function () {
- return this.get('store').findRecord('duke-ds-user', this.get('toUserId'));
+ return DS.PromiseObject.create({
+ promise: this.get('store').findRecord('duke-ds-user', this.get('toUserId'))
+ });
}),
errors: null,
errorMessages: Ember.computed.mapBy('errors', 'detail'),
diff --git a/app/controllers/deliveries/new/select-project.js b/app/controllers/deliveries/new/select-project.js
index 9edd680..021b3fd 100644
--- a/app/controllers/deliveries/new/select-project.js
+++ b/app/controllers/deliveries/new/select-project.js
@@ -1,4 +1,5 @@
import Ember from 'ember';
+import DS from 'ember-data';
const PROJECT_ADMIN_AUTH_ROLE = 'project_admin';
@@ -6,29 +7,31 @@ export default Ember.Controller.extend({
project: null,
application: Ember.inject.controller(),
currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
- currentUserProjectPermissions: Ember.computed('project', 'currentDukeDsUser.id', function () {
+ currentUserProjectPermission: Ember.computed('project', 'currentDukeDsUser.id', function () {
const projectId = this.get('project.id');
const currentUserId = this.get('currentDukeDsUser.id');
if (!projectId || !currentUserId) {
- return Ember.A();
+ return null;
}
- return this.get('store').query('duke-ds-project-permission', {
- project: projectId,
- user: currentUserId,
+ // Filter permissions for our project and user.
+ // This should return an array of one item: our user's permissions.
+ // Return the first item in the array.
+ return DS.PromiseObject.create({
+ promise: this.get('store').query('duke-ds-project-permission', {
+ project: projectId,
+ user: currentUserId,
+ }).then(function (permissions) {
+ return permissions.get('firstObject');
+ })
});
}),
- currentUserProjectAuthRole: Ember.computed('currentUserProjectPermissions.[]', function () {
- return this.get('currentUserProjectPermissions')
- .mapBy('authRole')
- .get('firstObject');
- }),
- currentUserCanDeliver: Ember.computed.equal('currentUserProjectAuthRole', PROJECT_ADMIN_AUTH_ROLE),
+ currentUserCanDeliver: Ember.computed.equal('currentUserProjectPermission.authRole', PROJECT_ADMIN_AUTH_ROLE),
disableNext: Ember.computed.not('currentUserCanDeliver'),
- showUserMissingPrivilegesError: Ember.computed('project.id', 'currentUserProjectAuthRole', function () {
+ showUserMissingPrivilegesError: Ember.computed('project.id', 'currentUserProjectPermission.authRole', function () {
if (this.get('project.id') == null) {
return false; // do not show error when no project is selected
}
- const authRole = this.get('currentUserProjectAuthRole');
+ const authRole = this.get('currentUserProjectPermission.authRole');
if (!authRole) {
return false; //do not show error while we are fetching users auth role for this project
}
diff --git a/app/controllers/deliveries/new/select-recipient.js b/app/controllers/deliveries/new/select-recipient.js
index 382e23e..7d706a9 100644
--- a/app/controllers/deliveries/new/select-recipient.js
+++ b/app/controllers/deliveries/new/select-recipient.js
@@ -1,10 +1,13 @@
import Ember from 'ember';
+import DS from 'ember-data';
export default Ember.Controller.extend({
queryParams: ['projectId'],
projectId: null,
project: Ember.computed('projectId', function () {
- return this.get('store').findRecord('duke-ds-project', this.get('projectId'));
+ return DS.PromiseObject.create({
+ promise: this.get('store').findRecord('duke-ds-project', this.get('projectId'))
+ })
}),
application: Ember.inject.controller(),
currentDukeDsUser: Ember.computed.alias('application.currentDukeDsUser'),
diff --git a/tests/unit/controllers/deliveries/new/enter-user-message-test.js b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
index fbf112a..4b19f28 100644
--- a/tests/unit/controllers/deliveries/new/enter-user-message-test.js
+++ b/tests/unit/controllers/deliveries/new/enter-user-message-test.js
@@ -26,35 +26,37 @@ test('it handles back action', function(assert) {
});
test('it looks up project based on query param', function(assert) {
+ assert.expect(2);
let controller = this.subject({
projectId: '123',
store: {
findRecord(modelName, modelKey) {
if (modelName === 'duke-ds-project') {
assert.equal(modelKey, '123');
- return 'someproject';
+ return Ember.RSVP.resolve('someproject');
}
return null;
}
}
});
- assert.equal(controller.get('project'), 'someproject');
+ controller.get('project').then(project => assert.equal(project, 'someproject'));
});
test('it looks up toUser based on query param', function(assert) {
+ assert.expect(2);
let controller = this.subject({
toUserId: '456',
store: {
findRecord(modelName, modelKey) {
if (modelName === 'duke-ds-user') {
assert.equal(modelKey, '456');
- return 'someuser';
+ return Ember.RSVP.resolve('someuser');
}
return null;
}
}
});
- assert.equal(controller.get('toUser'), 'someuser');
+ controller.get('toUser').then(toUser => assert.equal(toUser, 'someuser'));
});
diff --git a/tests/unit/controllers/deliveries/new/select-project-test.js b/tests/unit/controllers/deliveries/new/select-project-test.js
index 20043d9..88b23b9 100644
--- a/tests/unit/controllers/deliveries/new/select-project-test.js
+++ b/tests/unit/controllers/deliveries/new/select-project-test.js
@@ -61,53 +61,26 @@ test('it handles projectSelectionChanged', function(assert) {
assert.equal(controller.get('project'), project);
});
-test('it computes currentUserProjectPermissions from duke-ds-project-permission', function(assert) {
- assert.expect(5);
+test('it computes currentUserProjectPermission from duke-ds-project-permission', function(assert) {
let project = Ember.Object.create({ id: '123' });
let currentDukeDsUser = Ember.Object.create({id: '456'});
+ const permission = Ember.Object.create({id: '789'});
let controller = this.subject({
project: null,
currentDukeDsUser: null,
store: {
- query: function (modelName, params) {
- assert.equal(modelName, 'duke-ds-project-permission');
- assert.equal(params.project, '123');
- assert.equal(params.user, '456');
- return [
- 'permissiondata'
- ]
+ query: function () {
+ return Ember.RSVP.resolve(Ember.A([permission]));
}
}
});
- assert.deepEqual(controller.get('currentUserProjectPermissions'), []);
+ assert.equal(controller.get('currentUserProjectPermission.authRole'), null);
controller.set('project', project);
controller.set('currentDukeDsUser', currentDukeDsUser);
- assert.deepEqual(controller.get('currentUserProjectPermissions'), ['permissiondata']);
+ controller.get('currentUserProjectPermission').then(permission => assert.equal(permission.id, '789'));
});
-test('it computes currentUserProjectAuthRole from currentUserProjectPermissions array', function(assert) {
- let controller = this.subject({
- currentUserProjectPermissions: []
- });
- assert.equal(controller.get('currentUserProjectAuthRole'), null);
- controller.set('currentUserProjectPermissions', [
- {authRole: 'project_admin'}
- ]);
- assert.equal(controller.get('currentUserProjectAuthRole'), 'project_admin')
-});
-
-test('it computes currentUserProjectAuthRole from currentUserProjectPermissions array', function(assert) {
- let controller = this.subject({
- currentUserProjectPermissions: []
- });
- assert.equal(controller.get('currentUserProjectAuthRole'), null);
- controller.set('currentUserProjectPermissions', [
- {authRole: 'project_admin'}
- ]);
- assert.equal(controller.get('currentUserProjectAuthRole'), 'project_admin')
-});
-
-test('it computes showUserMissingPrivilegesError from project and currentUserProjectAuthRole', function(assert) {
+test('it computes showUserMissingPrivilegesError from project and currentUserProjectPermission', function(assert) {
let project = Ember.Object.create({ id: '123' });
let controller = this.subject({
project: null
@@ -119,11 +92,11 @@ test('it computes showUserMissingPrivilegesError from project and currentUserPro
assert.equal(controller.get('showUserMissingPrivilegesError'), false,
'hide error when currentUserProjectAuthRole is empty');
- controller.set('currentUserProjectAuthRole', 'downloader');
+ controller.set('currentUserProjectPermission', Ember.Object.create({ authRole: 'downloader'}));
assert.equal(controller.get('showUserMissingPrivilegesError'), true,
'show error when currentUserProjectAuthRole is not project admin');
- controller.set('currentUserProjectAuthRole', 'project_admin');
+ controller.set('currentUserProjectPermission', Ember.Object.create({ authRole: 'project_admin'}));
assert.equal(controller.get('showUserMissingPrivilegesError'), false,
'hide error when currentUserProjectAuthRole is project admin');
});
diff --git a/tests/unit/controllers/deliveries/new/select-recipient-test.js b/tests/unit/controllers/deliveries/new/select-recipient-test.js
index 6d3701a..63ff619 100644
--- a/tests/unit/controllers/deliveries/new/select-recipient-test.js
+++ b/tests/unit/controllers/deliveries/new/select-recipient-test.js
@@ -38,17 +38,18 @@ test('it handles next action', function(assert) {
});
test('it looks up project based on query param', function(assert) {
+ assert.expect(3);
let controller = this.subject({
projectId: '123',
store: {
findRecord(modelName, modelKey) {
assert.equal(modelName, 'duke-ds-project');
assert.equal(modelKey, '123');
- return 'someproject';
+ return Ember.RSVP.resolve('someproject');
}
}
});
- assert.equal(controller.get('project'), 'someproject');
+ controller.get('project').then(project => assert.equal(project, 'someproject'));
});
test('it computes a list of users outside of the currentDukeDSUser', function(assert) {
From cb9141db60627b5613a6976713085cb1a2f5c38f Mon Sep 17 00:00:00 2001
From: John Bradley
Date: Mon, 13 Aug 2018 13:04:14 -0400
Subject: [PATCH 36/36] Update duke-ds-project-permission.js
---
app/adapters/duke-ds-project-permission.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/adapters/duke-ds-project-permission.js b/app/adapters/duke-ds-project-permission.js
index f220d60..372308a 100644
--- a/app/adapters/duke-ds-project-permission.js
+++ b/app/adapters/duke-ds-project-permission.js
@@ -4,7 +4,7 @@ export default ApplicationAdapter.extend({
urlForQuery(query) {
/*
Project permissions are a nested route under the duke-ds-project route.
- There is not top level route to GET an individual permission.
+ There is no top level route to GET an individual permission.
This means querying permissions requires a project id parameter that will be used the build the base url.
*/
const projectId = query.project;