mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-14 18:27:44 +02:00
Server: Disable beta account once expired
This commit is contained in:
parent
89d4d5e642
commit
785248b27f
@ -138,4 +138,26 @@ describe('UserModel', function() {
|
||||
stripeConfig().enabled = false;
|
||||
});
|
||||
|
||||
test('should disable beta account once expired', async function() {
|
||||
stripeConfig().enabled = true;
|
||||
const { user: user1 } = await createUserAndSession(1, false, { email: 'toto@example.com' });
|
||||
const range = betaUserDateRange();
|
||||
await models().user().save({
|
||||
id: user1.id,
|
||||
created_time: range[0],
|
||||
account_type: AccountType.Pro,
|
||||
});
|
||||
|
||||
Date.now = jest.fn(() => range[0] + 8640000 * 1000); // 100 days later
|
||||
|
||||
await models().user().handleBetaUserEmails();
|
||||
|
||||
expect((await models().email().all()).length).toBe(4);
|
||||
const email = (await models().email().all()).pop();
|
||||
expect(email.subject.indexOf('beta account is expired') > 0).toBe(true);
|
||||
|
||||
const reloadedUser = await models().user().load(user1.id);
|
||||
expect(reloadedUser.can_upload).toBe(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -320,7 +320,7 @@ export default class UserModel extends BaseModel<User> {
|
||||
.where('created_time', '>=', range[0])
|
||||
.andWhere('created_time', '<=', range[1]);
|
||||
|
||||
const reminderIntervals = [14, 3];
|
||||
const reminderIntervals = [14, 3, 0];
|
||||
|
||||
for (const user of betaUsers) {
|
||||
if (!(await isBetaUser(this.models(), user.id))) continue;
|
||||
@ -344,6 +344,10 @@ export default class UserModel extends BaseModel<User> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (remainingDays <= 0) {
|
||||
await this.save({ id: user.id, can_upload: 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,8 +248,13 @@ export const postHandlers: PostHandlers = {
|
||||
logger.info(`Setting up Beta user subscription: ${existingUser.email}`);
|
||||
|
||||
// First set the account type correctly (in case the
|
||||
// user also upgraded or downgraded their account)
|
||||
await models.user().save({ id: existingUser.id, account_type: accountType });
|
||||
// user also upgraded or downgraded their account). Also
|
||||
// re-enable upload if it was disabled.
|
||||
await models.user().save({
|
||||
id: existingUser.id,
|
||||
account_type: accountType,
|
||||
can_upload: 1,
|
||||
});
|
||||
|
||||
// Then save the subscription
|
||||
await models.subscription().save({
|
||||
|
@ -7,9 +7,27 @@ interface TemplateView {
|
||||
}
|
||||
|
||||
export default function(view: TemplateView): EmailSubjectBody {
|
||||
return {
|
||||
subject: `Your ${config().appName} beta account will expire in ${view.expireDays} days`,
|
||||
body: `
|
||||
if (view.expireDays <= 0) {
|
||||
return {
|
||||
subject: `Your ${config().appName} beta account is expired`,
|
||||
body: `
|
||||
|
||||
Your ${config().appName} beta account is expired.
|
||||
|
||||
To continue using it, please start the subscription by following the link below.
|
||||
|
||||
From that page, select either monthly or yearly payments and click "Buy now".
|
||||
|
||||
${view.startSubUrl}
|
||||
|
||||
If you have any question please contact support at ${config().supportEmail}.
|
||||
|
||||
`.trim(),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
subject: `Your ${config().appName} beta account will expire in ${view.expireDays} days`,
|
||||
body: `
|
||||
|
||||
Your ${config().appName} beta account will expire in ${view.expireDays} days.
|
||||
|
||||
@ -22,5 +40,6 @@ ${view.startSubUrl}
|
||||
If you have any question please contact support at ${config().supportEmail}.
|
||||
|
||||
`.trim(),
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user