community-platform icon indicating copy to clipboard operation
community-platform copied to clipboard

[bug] Cant post update in Research Module

Open davehakkens opened this issue 1 year ago • 10 comments

Describe the bug Two (out of three) users reported they can't upload an update to a research on Project Kamp. It's gives the message beta-tester role required to access this page We tried refreshing and using another browser.

Expected behaviour all three users have a beta-tester role. marionagimenez can post updates kevincheung and kaegh can not. afbeelding

Screenshots

afbeelding

Additional context All three are added as a contributor to an existing research topic

davehakkens avatar May 06 '23 17:05 davehakkens

Interesting 🤔 I am seeing a similar bug in an e2e test.

Somewhat related, do we think that Research should still only be for beta-users?

thisislawatts avatar May 06 '23 17:05 thisislawatts

Something cache related?

iSCJT avatar May 06 '23 17:05 iSCJT

@davehakkens Can you include which Research article this was?

thisislawatts avatar May 06 '23 20:05 thisislawatts

this one for kaegh: https://community.projectkamp.com/research/making-a-sturdy-single-person-tent this one for kevincheung https://community.projectkamp.com/research/can-we-turn-invasive-trees-mimosa-into-something-useful

Somewhat related, do we think that Research should still only be for beta-users?

Dont think we are ready yet to release public on Project Kamp. The mission + moderation is not yet in place. Would be more ready for Precious Plastic though

davehakkens avatar May 06 '23 20:05 davehakkens

Interesting both of these humans have 2 entries in the v3_users table associated with their usernames.

Screenshot 2023-05-07 at 13 41 27

I will need to root around in the code bit more to understand the why here. But I believe that there is a manual intervention I can make that will fix this.

Note the creation dates on kaegh 2 user objects:

  • 2023-04-03T17:18:47.891Z
  • 2023-04-03T17:18:47.891Z

thisislawatts avatar May 07 '23 11:05 thisislawatts

Thanks for digging. This double entries for certain usernames gets a bit messy.. I thought it was a thing from the past, but still seems to happen with newer accounts as well. I'd be up for manual intervention for now!

davehakkens avatar May 07 '23 11:05 davehakkens

Any idea how these accounts were created? I attempted to recreate the issue by going via the Join use flow and ended up with a single entry in v3_users each time.

thisislawatts avatar May 07 '23 12:05 thisislawatts

In the meantime I have removed the user accounts, so the ones remaining have the userName as the _id

thisislawatts avatar May 07 '23 12:05 thisislawatts

Any idea how these accounts were created? I attempted to recreate the issue by going via the Join use flow and ended up with a single entry in v3_users each time.

Not sure.. But this also reflects in the admin panel. Maybe a duplicate for everyone that gets a beta-tester role? afbeelding

I think @chrismclarke knows more about this.

davehakkens avatar May 07 '23 12:05 davehakkens

I would welcome a second set of eyes here, but this looks to be the bug to me. We're writing User documents using the ._authID property rather than the _id property. https://github.com/search?q=repo%3AONEARMY%2Fcommunity-platform%20doc(updatedUser._authID)&type=code

Hypothesis: Notifications result in a new duplicate User document being created that has the _authID rather than the userName attribute for the document ID.

This is being compounded by this code which ties an auth user session to a User document. When there are duplicate profiles available the function will resolve to lookup2.

// TODO
// this is a bit messy due to legacy users having mismatched firebase data and ids
// should resolve all users so that a single lookup is successful
// to fix a script should be run to update all firebase_auth display names to correct format
// which could then be used as a single lookup
public async getUserProfile(_authID: string) {
  const lookup = await this.db
    .collection<IUserPP>(COLLECTION_NAME)
    .getWhere('_authID', '==', _authID)
  if (lookup.length === 1) {
    return lookup[0]
  }
  const lookup2 = await this.db
    .collection<IUserPP>(COLLECTION_NAME)
    .getWhere('_id', '==', _authID)
  return lookup2[0]
}

thisislawatts avatar May 07 '23 16:05 thisislawatts

Duplicate user issues have been addressed through various pr's and manual data fixes.

iSCJT avatar Jun 22 '23 12:06 iSCJT