diff --git a/app/pods/protected/users/show/controller.js b/app/pods/protected/users/show/controller.js index 3c6c549..26c243d 100644 --- a/app/pods/protected/users/show/controller.js +++ b/app/pods/protected/users/show/controller.js @@ -1,9 +1,9 @@ import Ember from 'ember'; +import DeleteModel from '../../../../mixins/delete-model'; -export default Ember.Controller.extend({ - currentUser: Ember.inject.service('session-account'), +const { Controller } = Ember; - isUser: Ember.computed('model.id', 'currentUser.account.id', function() { - return this.get('model.id') === this.get('currentUser.account.id'); - }), +export default Controller.extend(DeleteModel, { + // Required for DeleteModel mixin + transitionRoute: 'protected.index', }); diff --git a/app/pods/protected/users/show/route.js b/app/pods/protected/users/show/route.js index a0c9fd9..798787d 100644 --- a/app/pods/protected/users/show/route.js +++ b/app/pods/protected/users/show/route.js @@ -1,21 +1,25 @@ import Ember from 'ember'; -export default Ember.Route.extend({ - currentUser: Ember.inject.service('session-account'), +const { Route, inject: { service } } = Ember; +export default Route.extend({ + currentUser: service('session-account'), + + // Not using ElevatedAccess Mixin because the rules for viewing user accounts + // is slightly different. beforeModel: function(transition) { this._super(transition); - this.get('currentUser.account').then((currentUser) => { - let user_id = transition.params['protected.users.show'].user_id; - if (!currentUser.get('isAdmin') && currentUser.get('id') !== user_id) { + this.get('currentUser.account').then((user) => { + const user_id = transition.params['protected.users.show'].user_id; + if (!user.get('isAdmin') && user.get('id') !== user_id) { this.transitionTo('protected.users.index'); } }); }, model: function(params) { - return this.store.findRecord('user', params.user_id, { reload: true }); + return this.store.findRecord('user', params.user_id); }, }); diff --git a/app/pods/protected/users/show/template.hbs b/app/pods/protected/users/show/template.hbs index ca89688..a8648c4 100644 --- a/app/pods/protected/users/show/template.hbs +++ b/app/pods/protected/users/show/template.hbs @@ -1,53 +1,5 @@ -
-
- - {{model.name}} - - - {{! ROW 1 }} -
-
-
Email
-
- {{model.email}} -
-
-
-
Role
-
- {{model.fullRole}} -
-
-
- - {{! ROW 2 }} -
-
-
Record Created
-
{{null-time model.createdAt 'LL'}}
-
-
-
Record Updated
-
{{null-time model.updatedAt 'LL'}}
-
-
-
-
-
-
- {{#if isUser}} -
- {{#link-to 'protected.users.changepassword' model.id class="button-gray smaller"}} - Change Password - {{/link-to}} -
- {{/if}} - -
- {{#if model.canEdit}} - {{#link-to 'protected.users.edit' model.id class="button-gray smaller"}} - Edit - {{/link-to}} - {{/if}} -
-
+{{ + protected/users/show/user-card + user=model + on-delete=(action 'delete') +}} diff --git a/app/pods/protected/users/show/user-card/component.js b/app/pods/protected/users/show/user-card/component.js new file mode 100644 index 0000000..41dcaef --- /dev/null +++ b/app/pods/protected/users/show/user-card/component.js @@ -0,0 +1,11 @@ +import Ember from 'ember'; + +const { Component, computed, inject: { service } } = Ember; + +export default Component.extend({ + currentUser: service('session-account'), + + isUser: computed('model.id', 'currentUser.account.id', function() { + return this.get('model.id') === this.get('currentUser.account.id'); + }), +}); diff --git a/app/pods/protected/users/show/user-card/template.hbs b/app/pods/protected/users/show/user-card/template.hbs new file mode 100644 index 0000000..6aa0d84 --- /dev/null +++ b/app/pods/protected/users/show/user-card/template.hbs @@ -0,0 +1,53 @@ +
+
+ + {{user.name}} + + + {{! ROW 1 }} +
+
+
Email
+
+ {{user.email}} +
+
+
+
Role
+
+ {{user.fullRole}} +
+
+
+ + {{! ROW 2 }} +
+
+
Record Created
+
{{null-time user.createdAt 'LL'}}
+
+
+
Record Updated
+
{{null-time user.updatedAt 'LL'}}
+
+
+
+
+
+
+ {{#if isUser}} +
+ {{#link-to 'protected.users.changepassword' user.id class="button-gray smaller"}} + Change Password + {{/link-to}} +
+ {{/if}} + +
+ {{#if model.canEdit}} + {{#link-to 'protected.users.edit' user.id class="button-gray smaller"}} + Edit + {{/link-to}} + {{/if}} +
+