From b593db2150df7339c5fbdfb251068b18b553847a Mon Sep 17 00:00:00 2001 From: SabreCat Date: Wed, 10 Aug 2022 16:20:32 -0500 Subject: [PATCH 1/9] feat(admin): show subscription data --- .../admin-panel/user-support/index.vue | 6 ++ .../user-support/subscriptionAndPerks.vue | 68 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue diff --git a/website/client/src/components/admin-panel/user-support/index.vue b/website/client/src/components/admin-panel/user-support/index.vue index d94d6d44c4..7506b91b48 100644 --- a/website/client/src/components/admin-panel/user-support/index.vue +++ b/website/client/src/components/admin-panel/user-support/index.vue @@ -17,6 +17,10 @@ :reset-counter="resetCounter" /> + + +
+

+ Subscription, Monthly Perks +

+
+
+ Payment Method: + {{ subscription.paymentMethod }} +
+
+ Payment Schedule ("basic-earned" is monthly): + {{ subscription.planId }} +
+
+ Creation Date: + {{ moment(subscription.dateCreated).format('YYYY/MM/DD') }} +
+
+ Termination Date: + {{ moment(subscription.dateTerminated).format('YYYY/MM/DD') }} +
+
+ Consecutive Months: + {{ subscription.consecutive.count }} +
+
+ Months Until Renewal: + {{ subscription.consecutive.offset }} +
+
+ Gem Cap: + {{ subscription.consecutive.gemCapExtra + 25 }} +
+
+ Additional Credit (applied upon cancellation): + {{ subscription.extraMonths }} +
+
+ Mystery Items: + + {{ item }}, + {{ item }} + +
+
+
+ + + From 0aadee550e23ecc7f73e3db5494e96173a3ee4a4 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Thu, 11 Aug 2022 14:16:27 -0500 Subject: [PATCH 2/9] fix(admin): add data value for expand state --- .../admin-panel/user-support/subscriptionAndPerks.vue | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue index 924a445b12..0211a0f531 100644 --- a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue +++ b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue @@ -64,5 +64,10 @@ export default { required: true, }, }, + data () { + return { + expand: false, + }; + }, }; From 09d6dae75cd0cffd85a4f5708424db6e0ce5661c Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 30 Aug 2022 15:35:50 -0500 Subject: [PATCH 3/9] feat(admin): provide reset cron button --- .../admin-panel/user-support/cronAndAuth.vue | 10 ++++++++++ website/server/controllers/api-v3/hall.js | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/website/client/src/components/admin-panel/user-support/cronAndAuth.vue b/website/client/src/components/admin-panel/user-support/cronAndAuth.vue index 1a28b044c7..260bc46177 100644 --- a/website/client/src/components/admin-panel/user-support/cronAndAuth.vue +++ b/website/client/src/components/admin-panel/user-support/cronAndAuth.vue @@ -36,6 +36,12 @@ ("auth.timestamps.loggedin" and "lastCron" dates are different). +
Time zone: {{ hero.preferences.timezoneOffset | formatTimeZone }} @@ -218,6 +224,10 @@ export default { await this.saveHero({ hero: this.hero, msg: 'API Token' }); this.tokenModified = true; }, + resetCron () { + this.hero.resetCron = true; + this.saveHero({ hero: this.hero, msg: 'Last Cron', clearData: true }); + }, }, }; diff --git a/website/server/controllers/api-v3/hall.js b/website/server/controllers/api-v3/hall.js index 2ee18a6044..a05b1e4f0f 100644 --- a/website/server/controllers/api-v3/hall.js +++ b/website/server/controllers/api-v3/hall.js @@ -331,6 +331,13 @@ api.updateHero = { hero.apiToken = common.uuid(); } + if (updateData.resetCron) { + // Set last cron to yesterday. Quick approach so we don't need moment() for one line + const yesterday = new Date(new Date().setDate(new Date().getDate() - 1)); + hero.lastCron = yesterday; + hero.auth.timestamps.loggedin = yesterday; // so admin panel doesn't gripe about mismatch + } + const savedHero = await hero.save(); const heroJSON = savedHero.toJSON(); heroJSON.secret = savedHero.getSecretData(); From ae23ac12ffd2c1f1477f40393c480f81ee2297e1 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 30 Aug 2022 16:55:10 -0500 Subject: [PATCH 4/9] feat(admin): interactive subscription section fields --- .../admin-panel/user-support/index.vue | 2 +- .../user-support/subscriptionAndPerks.vue | 155 +++++++++++++----- website/server/controllers/api-v3/hall.js | 9 + 3 files changed, 121 insertions(+), 45 deletions(-) diff --git a/website/client/src/components/admin-panel/user-support/index.vue b/website/client/src/components/admin-panel/user-support/index.vue index 7506b91b48..8d156077f2 100644 --- a/website/client/src/components/admin-panel/user-support/index.vue +++ b/website/client/src/components/admin-panel/user-support/index.vue @@ -18,7 +18,7 @@ />
-
- Payment Method: - {{ subscription.paymentMethod }} -
-
- Payment Schedule ("basic-earned" is monthly): - {{ subscription.planId }} -
-
- Creation Date: - {{ moment(subscription.dateCreated).format('YYYY/MM/DD') }} -
-
- Termination Date: - {{ moment(subscription.dateTerminated).format('YYYY/MM/DD') }} -
-
- Consecutive Months: - {{ subscription.consecutive.count }} -
-
- Months Until Renewal: - {{ subscription.consecutive.offset }} -
-
- Gem Cap: - {{ subscription.consecutive.gemCapExtra + 25 }} -
-
- Additional Credit (applied upon cancellation): - {{ subscription.extraMonths }} -
-
- Mystery Items: - +
+ Payment method: + {{ hero.purchased.plan.paymentMethod }} +
+
+ Payment schedule ("basic-earned" is monthly): + {{ hero.purchased.plan.planId }} +
+
+ Creation date: + {{ dateFormat(hero.purchased.plan.dateCreated) }} +
+
+ Termination date: + + {{ dateFormat(hero.purchased.plan.dateTerminated) }} + + None +
+
+ Consecutive months: + {{ hero.purchased.plan.consecutive.count }} +
+
+ Months until renewal: + {{ hero.purchased.plan.consecutive.offset || 1}} +
+
+ Next Mystic Hourglass: + {{ nextHourGlassDate }} +
+
+ +
+
+ Gem cap: + {{ hero.purchased.plan.consecutive.gemCapExtra + 25 }} +
+
+ +
+
- {{ item }}, - {{ item }} - -
+ Additional credit (applied upon cancellation): + {{ hero.purchased.plan.extraMonths }} +
+
+ Mystery Items: + + + + {{ item }}, + + {{ item }} + + + + None + +
+ +
diff --git a/website/server/controllers/api-v3/hall.js b/website/server/controllers/api-v3/hall.js index a05b1e4f0f..e3f950b08a 100644 --- a/website/server/controllers/api-v3/hall.js +++ b/website/server/controllers/api-v3/hall.js @@ -273,6 +273,15 @@ api.updateHero = { hero.balance = updateData.balance; } + if (updateData.purchased && updateData.purchased.plan) { + if (updateData.purchased.plan.gemsBought) { + hero.purchased.plan.gemsBought = updateData.purchased.plan.gemsBought; + } + if (updateData.purchased.plan.consecutive && updateData.purchased.plan.consecutive.trinkets) { + hero.purchased.plan.consecutive.trinkets = updateData.purchased.plan.consecutive.trinkets; + } + } + // give them gems if they got an higher level // tier = level in this context let newTier = updateData.contributor && updateData.contributor.level; From f364b3c06fe70a5c781e488bfbef272d03a8caed Mon Sep 17 00:00:00 2001 From: SabreCat Date: Wed, 31 Aug 2022 16:09:20 -0500 Subject: [PATCH 5/9] feat(admin): consecutive months editable field and automatic calcs --- .../admin-panel/user-support/cronAndAuth.vue | 24 ++++--- .../user-support/subscriptionAndPerks.vue | 69 +++++++++++++++---- website/server/controllers/api-v3/hall.js | 9 ++- 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/website/client/src/components/admin-panel/user-support/cronAndAuth.vue b/website/client/src/components/admin-panel/user-support/cronAndAuth.vue index 260bc46177..8b107ebf21 100644 --- a/website/client/src/components/admin-panel/user-support/cronAndAuth.vue +++ b/website/client/src/components/admin-panel/user-support/cronAndAuth.vue @@ -22,11 +22,6 @@ Account created: {{ hero.auth.timestamps.created | formatDate }} -
- Most recent cron: - {{ hero.auth.timestamps.loggedin | formatDate }} - ("auth.timestamps.loggedin") -
"lastCron" value: {{ hero.lastCron | formatDate }} @@ -36,12 +31,19 @@ ("auth.timestamps.loggedin" and "lastCron" dates are different).
- +
+
+ Most recent cron: + {{ hero.auth.timestamps.loggedin | formatDate }} + ("auth.timestamps.loggedin") +
+ +
Time zone: {{ hero.preferences.timezoneOffset | formatTimeZone }} diff --git a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue index 61abb08294..05856a31c5 100644 --- a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue +++ b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue @@ -8,7 +8,7 @@ Subscription, Monthly Perks
-
+
Payment method: {{ hero.purchased.plan.paymentMethod }} @@ -30,9 +30,20 @@ None
-
- Consecutive months: - {{ hero.purchased.plan.consecutive.count }} +
+ + + Updates Hourglasses and Gem cap automatically. Next Mystic Hourglass updates on save. +
Months until renewal: @@ -59,16 +70,16 @@ {{ hero.purchased.plan.consecutive.gemCapExtra + 25 }}
-
diff --git a/website/server/controllers/api-v3/hall.js b/website/server/controllers/api-v3/hall.js index e3f950b08a..6473f30ab0 100644 --- a/website/server/controllers/api-v3/hall.js +++ b/website/server/controllers/api-v3/hall.js @@ -277,8 +277,13 @@ api.updateHero = { if (updateData.purchased.plan.gemsBought) { hero.purchased.plan.gemsBought = updateData.purchased.plan.gemsBought; } - if (updateData.purchased.plan.consecutive && updateData.purchased.plan.consecutive.trinkets) { - hero.purchased.plan.consecutive.trinkets = updateData.purchased.plan.consecutive.trinkets; + if (updateData.purchased.plan.consecutive) { + if (updateData.purchased.plan.consecutive.trinkets) { + hero.purchased.plan.consecutive.trinkets = updateData.purchased.plan.consecutive.trinkets; + } + if (updateData.purchased.plan.consecutive.gemCapExtra) { + hero.purchased.plan.consecutive.gemCapExtra = updateData.purchased.plan.consecutive.gemCapExtra; // eslint-disable-line max-len + } } } From 008314676d7957c4f35841d6e9ae744b8ff6b08c Mon Sep 17 00:00:00 2001 From: SabreCat Date: Thu, 1 Sep 2022 17:16:51 -0500 Subject: [PATCH 6/9] fix(admin): reactivity on next hourglass --- .../user-support/subscriptionAndPerks.vue | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue index 05856a31c5..9b4970586b 100644 --- a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue +++ b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue @@ -41,9 +41,6 @@ step="1" > - - Updates Hourglasses and Gem cap automatically. Next Mystic Hourglass updates on save. -
Months until renewal: @@ -51,7 +48,7 @@
Next Mystic Hourglass: - {{ nextHourGlassDate }} + {{ nextHourglassDate }}
Months until renewal: - {{ hero.purchased.plan.consecutive.offset || 1}} + {{ hero.purchased.plan.consecutive.offset }}
Next Mystic Hourglass: From 0081bad831a8c51980ca334fc997aa717350c89a Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 6 Sep 2022 16:15:04 -0500 Subject: [PATCH 8/9] feat(admin): track hourglasses as transactions --- website/common/locales/en/settings.json | 3 ++- website/server/controllers/api-v3/hall.js | 5 +++++ website/server/models/transaction.js | 2 +- website/server/models/user/methods.js | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/website/common/locales/en/settings.json b/website/common/locales/en/settings.json index eeca1cd565..3f8a2371bc 100644 --- a/website/common/locales/en/settings.json +++ b/website/common/locales/en/settings.json @@ -213,5 +213,6 @@ "transaction_release_mounts": "Released mounts", "transaction_reroll": "Used Fortify Potion", "transaction_subscription_perks": "From subscription perk", - "transaction_admin_update_balance": "Admin given" + "transaction_admin_update_balance": "Admin given", + "transaction_admin_update_hourglasses": "Admin updated" } diff --git a/website/server/controllers/api-v3/hall.js b/website/server/controllers/api-v3/hall.js index 6473f30ab0..15183c686f 100644 --- a/website/server/controllers/api-v3/hall.js +++ b/website/server/controllers/api-v3/hall.js @@ -279,6 +279,11 @@ api.updateHero = { } if (updateData.purchased.plan.consecutive) { if (updateData.purchased.plan.consecutive.trinkets) { + await hero.updateHourglasses( + updateData.purchased.plan.consecutive.trinkets + - hero.purchased.plan.consecutive.trinkets, + 'admin_update_hourglasses', '', 'Updated by Habitica staff', + ); hero.purchased.plan.consecutive.trinkets = updateData.purchased.plan.consecutive.trinkets; } if (updateData.purchased.plan.consecutive.gemCapExtra) { diff --git a/website/server/models/transaction.js b/website/server/models/transaction.js index 56687f86c9..88a3ca8550 100644 --- a/website/server/models/transaction.js +++ b/website/server/models/transaction.js @@ -5,7 +5,7 @@ import baseModel from '../libs/baseModel'; const { Schema } = mongoose; export const currencies = ['gems', 'hourglasses']; -export const transactionTypes = ['buy_money', 'buy_gold', 'spend', 'gift_send', 'gift_receive', 'debug', 'create_challenge', 'create_bank_challenge', 'create_guild', 'change_class', 'rebirth', 'release_pets', 'release_mounts', 'reroll', 'contribution', 'subscription_perks', 'admin_update_balance']; +export const transactionTypes = ['buy_money', 'buy_gold', 'spend', 'gift_send', 'gift_receive', 'debug', 'create_challenge', 'create_bank_challenge', 'create_guild', 'change_class', 'rebirth', 'release_pets', 'release_mounts', 'reroll', 'contribution', 'subscription_perks', 'admin_update_balance', 'admin_update_hourglasses']; export const schema = new Schema({ currency: { $type: String, enum: currencies, required: true }, diff --git a/website/server/models/user/methods.js b/website/server/models/user/methods.js index f339cff896..bb25eea9b5 100644 --- a/website/server/models/user/methods.js +++ b/website/server/models/user/methods.js @@ -577,3 +577,22 @@ schema.methods.updateBalance = async function updateBalance (amount, currentAmount: this.balance, }); }; + +schema.methods.updateHourglasses = async function updateHourglasses ( + amount, + transactionType, + reference, + referenceText, +) { + this.purchased.plan.consecutive.trinkets += amount; + + await Transaction.create({ + currency: 'hourglasses', + userId: this._id, + transactionType, + amount, + reference, + referenceText, + currentAmount: this.purchased.plan.consecutive.trinkets, + }); +}; From fb780c9a2daa71545526537d990028813c351d5e Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 13 Sep 2022 15:52:03 -0500 Subject: [PATCH 9/9] fix(admin): reactivity with subscriptions --- .../user-support/subscriptionAndPerks.vue | 27 ++++--------------- website/server/controllers/api-v3/hall.js | 3 +++ 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue index ae0f5a59aa..50c3c1b135 100644 --- a/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue +++ b/website/client/src/components/admin-panel/user-support/subscriptionAndPerks.vue @@ -8,7 +8,7 @@ Subscription, Monthly Perks
- +
Payment method: {{ hero.purchased.plan.paymentMethod }} @@ -34,7 +34,7 @@