mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
d5077ac1bf
refs https://linear.app/tryghost/issue/ENG-599 - member count is based on the cache which only updates ~every minute - forced cache clear on manual member add/delete (not import) - tests were failing based on the assumption that a new site that adds a member has a nonzero member count, although the cache did not reflect this quickly enough for the test to pass Previously on a new site if you tried to publish a newsletter, it would require at least one member. If you quickly added a member and tried to send a newsletter, it would stop you saying you need at least one member, requiring a browser refresh. This was a bug that is resolved with this changes, as well as odd behaviour to try to write tests around.
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default class GhMembersNoMembersComponent extends Component {
|
|
@service session;
|
|
@service store;
|
|
@service notifications;
|
|
@service settings;
|
|
@service membersCountCache;
|
|
|
|
@action
|
|
addYourself() {
|
|
return this.addTask.perform();
|
|
}
|
|
|
|
@task({drop: true})
|
|
*addTask() {
|
|
const user = yield this.session.user;
|
|
const defaultNewsletters = yield this.store.query('newsletter', {filter: 'status:active+subscribe_on_signup:true+visibility:members'});
|
|
|
|
const member = this.store.createRecord('member', {
|
|
email: user.get('email'),
|
|
name: user.get('name'),
|
|
newsletters: defaultNewsletters
|
|
});
|
|
|
|
try {
|
|
yield member.save();
|
|
|
|
if (this.args.afterCreate) {
|
|
this.args.afterCreate();
|
|
}
|
|
|
|
this.notifications.showNotification('Member added',
|
|
{
|
|
description: 'You\'ve successfully added yourself as a member.'
|
|
}
|
|
);
|
|
|
|
// force update the member count; this otherwise only updates every minute
|
|
yield this.membersCountCache.count({});
|
|
|
|
return member;
|
|
} catch (error) {
|
|
if (error) {
|
|
this.notifications.showAPIError(error, {key: 'member.save'});
|
|
}
|
|
}
|
|
}
|
|
}
|