From a6bdc4fa24c2738e29585345a618aa6ca23828d5 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:37:01 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20action=20errors=20on=20au?= =?UTF-8?q?th-method=20refresh=20(#2268)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scopes/scope/auth-methods/index.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ui/admin/app/controllers/scopes/scope/auth-methods/index.js b/ui/admin/app/controllers/scopes/scope/auth-methods/index.js index e81aae706..520c1f49e 100644 --- a/ui/admin/app/controllers/scopes/scope/auth-methods/index.js +++ b/ui/admin/app/controllers/scopes/scope/auth-methods/index.js @@ -19,6 +19,7 @@ export default class ScopesScopeAuthMethodsIndexController extends Controller { @service router; @service can; @service intl; + @service store; // =attributes @@ -144,7 +145,8 @@ export default class ScopesScopeAuthMethodsIndexController extends Controller { await authMethod.destroyRecord(); // Reload the scope, since this is where the primary_auth_method_id is // stored. An auth method deletion could affect this field. - await this.scopeModel.reload(); + const scope = this.store.peekRecord('scope', authMethod.scopeID); + await scope.reload(); this.router.replaceWith('scopes.scope.auth-methods'); await this.router.refresh(); } @@ -161,14 +163,15 @@ export default class ScopesScopeAuthMethodsIndexController extends Controller { }) @notifyError(({ message }) => message, { catch: true }) @notifySuccess('resources.auth-method.notifications.make-primary-success') - async makePrimary({ id }) { - this.scopeModel.primary_auth_method_id = id; + async makePrimary(authMethod) { + const scope = this.store.peekRecord('scope', authMethod.scopeID); + scope.primary_auth_method_id = authMethod.id; // Attempt to save the change to the scope. If this operation fails, // we rollback the change and rethrow the error so the user can be notified. try { - await this.scopeModel.save(); + await scope.save(); } catch (e) { - this.scopeModel.rollbackAttributes(); + scope.rollbackAttributes(); throw e; } await this.router.refresh(); @@ -190,13 +193,14 @@ export default class ScopesScopeAuthMethodsIndexController extends Controller { 'resources.auth-method.notifications.remove-as-primary-success', ) async removeAsPrimary(authMethod) { - this.scopeModel.primary_auth_method_id = null; + const scope = this.store.peekRecord('scope', authMethod.scopeID); + scope.primary_auth_method_id = null; // Attempt to save the change to the scope. If this operation fails, // we rollback the change and rethrow the error so the user can be notified. try { - await this.scopeModel.save(); + await scope.save(); } catch (e) { - this.scopeModel.rollbackAttributes(); + scope.rollbackAttributes(); throw e; } await authMethod.reload();