From 6121451b5d4ca109fa81770a1d0934eec8f6b4ee Mon Sep 17 00:00:00 2001 From: Naz <hi@nazavo.com> Date: Tue, 23 Aug 2022 12:29:55 +0800 Subject: [PATCH] Reused _resolveContextSource method in member update refs https://github.com/TryGhost/Toolbox/issues/386 - Reusing tontext mapping logic to improve maintainability. It seems like the `update` method was not updated properly or intentionally was left out from 'import' source as that should not ever happen theoretically. Probably the latter is most likely. - My reasoning on reusing same context to source mapping is: it is better to attribute an appropriate "import" source here. Who knows, maybe we'll have logic in the future where the importer updates instead of skipping existing members. It would not make sense to attribute the source to 'member' in that case, amirite? - This refactor also makes maintainability of this code way easier --- ghost/members-api/lib/repositories/member.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/ghost/members-api/lib/repositories/member.js b/ghost/members-api/lib/repositories/member.js index 8e1eccedaa..a2ac6256f7 100644 --- a/ghost/members-api/lib/repositories/member.js +++ b/ghost/members-api/lib/repositories/member.js @@ -479,16 +479,7 @@ module.exports = class MemberRepository { // Add subscribe events for all (un)subscribed newsletters const context = options && options.context || {}; - let source; - if (context.internal) { - source = 'system'; - } else if (context.user) { - source = 'admin'; - } else if (context.api_key) { - source = 'api'; - } else { - source = 'member'; - } + const source = this._resolveContextSource(context); for (const newsletterToAdd of newslettersToAdd) { await this._MemberSubscribeEvent.add({