Skip to content

fix: Revert session state on failure #4642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions app/controllers/events/view/sessions/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,32 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
}

@action
changeState(session_id, state, sendEmail) {
async changeState(session_id, state, sendEmail) {
const session = this.store.peekRecord('session', session_id, { backgroundReload: false });
const oldState = session.state;
session.setProperties({
sendEmail,
state,
isMailSent: sendEmail
});
this.set('isLoading', true);
session.save()
.then(() => {
sendEmail ? this.notify.success(this.l10n.t(`Session has been ${state} and speaker has been notified via email.`),
{
id: 'session_state_email'
})
: this.notify.success(this.l10n.t(`Session has been ${state}`),
{
id: 'session_state'
});
this.refreshModel.bind(this)();
})
.catch(() => {
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'session_state_unexpected'
});
})
.finally(() => {
this.set('isLoading', false);

try {
await session.save();
const message = `Session has been ${state}` + (sendEmail ? ' and speaker has been notified via email.' : '');
this.notify.success(this.l10n.t(message), {
id: 'session_state'
});
this.refreshModel.bind(this)();
} catch (e) {
session.set('state', oldState);
console.error('Error while changing session state in organizer session list', e);
this.notify.error(this.l10n.t('An unexpected error has occurred.'), {
id: 'session_state_unexpected'
});
} finally {
this.set('isLoading', false);
}
}

@action
Expand Down