bulltrackers-module 1.0.558 → 1.0.559

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -290,6 +290,9 @@ async function getDevOverrideStatus(req, res, dependencies, config) {
290
290
  * Get the effective CID to use for a developer account
291
291
  * Returns impersonateCid if set, otherwise returns the actual userCid
292
292
  * Only works for developer accounts
293
+ *
294
+ * Note: If pretendToBePI is false, impersonation will not be used for PI-related checks
295
+ * to prevent unintended impersonation when the user doesn't want to pretend to be a PI
293
296
  */
294
297
  async function getEffectiveCid(db, userCid, config, logger = null) {
295
298
  if (!isDeveloperAccount(userCid)) {
@@ -297,8 +300,20 @@ async function getEffectiveCid(db, userCid, config, logger = null) {
297
300
  }
298
301
 
299
302
  const devOverride = await getDevOverride(db, userCid, config, logger);
300
- // Only use impersonation if dev override is enabled
303
+ // Only use impersonation if dev override is enabled AND impersonateCid is set
304
+ // BUT: If pretendToBePI is explicitly false, don't use impersonation (user doesn't want to be treated as PI)
301
305
  if (devOverride && devOverride.enabled && devOverride.impersonateCid) {
306
+ // Check if user explicitly doesn't want to pretend to be a PI
307
+ // If pretendToBePI is false, don't use impersonation (respects user intent)
308
+ if (devOverride.pretendToBePI === false) {
309
+ if (logger && logger.log) {
310
+ logger.log('INFO', `[getEffectiveCid] DEV OVERRIDE: User ${userCid} has impersonateCid set but pretendToBePI=false, using actual CID ${userCid} instead`);
311
+ } else {
312
+ console.log(`[getEffectiveCid] DEV OVERRIDE: User ${userCid} has impersonateCid set but pretendToBePI=false, using actual CID ${userCid} instead`);
313
+ }
314
+ return Number(userCid);
315
+ }
316
+
302
317
  if (logger && logger.log) {
303
318
  logger.log('INFO', `[getEffectiveCid] DEV OVERRIDE: User ${userCid} impersonating CID ${devOverride.impersonateCid}`);
304
319
  } else {
@@ -96,8 +96,19 @@ async function getSignedInUserPIPersonalizedMetrics(req, res, dependencies, conf
96
96
  }
97
97
 
98
98
  try {
99
- const effectiveCid = await getEffectiveCid(db, userCid, config, logger);
100
99
  const devOverride = await getDevOverride(db, userCid, config, logger);
100
+
101
+ // For PI-related checks, respect pretendToBePI flag
102
+ // If pretendToBePI is false, use actual userCid even if impersonateCid is set
103
+ let effectiveCid;
104
+ if (devOverride && devOverride.enabled && devOverride.pretendToBePI === false) {
105
+ // User explicitly doesn't want to pretend to be a PI, use actual CID
106
+ effectiveCid = Number(userCid);
107
+ } else {
108
+ // Use normal effective CID logic (may use impersonateCid if set)
109
+ effectiveCid = await getEffectiveCid(db, userCid, config, logger);
110
+ }
111
+
101
112
  const isImpersonating = devOverride && devOverride.enabled && devOverride.impersonateCid && effectiveCid !== Number(userCid);
102
113
 
103
114
  // Check if user is a PI
@@ -128,8 +128,19 @@ async function checkIfUserIsPopularInvestor(req, res, dependencies, config) {
128
128
 
129
129
  try {
130
130
  // Check for dev override impersonation
131
- const effectiveCid = await getEffectiveCid(db, userCid, config, logger);
132
131
  const devOverride = await getDevOverride(db, userCid, config, logger);
132
+
133
+ // For PI-related checks, respect pretendToBePI flag
134
+ // If pretendToBePI is false, use actual userCid even if impersonateCid is set
135
+ let effectiveCid;
136
+ if (devOverride && devOverride.enabled && devOverride.pretendToBePI === false) {
137
+ // User explicitly doesn't want to pretend to be a PI, use actual CID
138
+ effectiveCid = Number(userCid);
139
+ } else {
140
+ // Use normal effective CID logic (may use impersonateCid if set)
141
+ effectiveCid = await getEffectiveCid(db, userCid, config, logger);
142
+ }
143
+
133
144
  const isImpersonating = devOverride && devOverride.enabled && devOverride.impersonateCid && effectiveCid !== Number(userCid);
134
145
 
135
146
  // Use effective CID (impersonated or actual) to check PI status
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.558",
3
+ "version": "1.0.559",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [