From d353dc6e751e69c6e5cf76958906f6409c42adf2 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 12 Oct 2015 15:05:02 -0700 Subject: [PATCH] Clear store on role change Fixes #18. --- app/pods/protected/users/edit/controller.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/pods/protected/users/edit/controller.js b/app/pods/protected/users/edit/controller.js index 903eefd..3d4940c 100644 --- a/app/pods/protected/users/edit/controller.js +++ b/app/pods/protected/users/edit/controller.js @@ -6,8 +6,17 @@ export default Ember.Controller.extend({ let user = this.get('model'); if (user.get('hasDirtyAttributes')) { + let attrs = user.changedAttributes(), roleChanged = false; + if (attrs.role) { + roleChanged = true; + } user.save().then((user) => { this.get('flashMessages').clearMessages(); + if (roleChanged) { + // Need to clear the store so that canEdit and canAdd + // attributes reflect the new role. + this.get('store').unloadAll(); + } this.transitionToRoute('protected.users.show', user); }, (err) => { err.errors.forEach((error) => {