Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/one time user colors #735

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from

Conversation

isVivek99
Copy link
Contributor

@isVivek99 isVivek99 commented Oct 6, 2022

This is a one-time PR

Issue Ticket Number:- #712
API Contract: - API contract Real-Dev-Squad/website-api-contracts#147
Frontend PR: Real-Dev-Squad/website-members#396

Backend changes

  • Yes
  • No

Frontend Changes

  • Yes
  • No

Database changes

  • Yes
  • No

Breaking changes (If your feature is breaking/missing something please mention pending tickets)

  • Yes
  • No

Deployment notes
None

Description

  • This PR will add a colors id for each user which will then be used on frontend for users to see their profile is a specific color.

Testing Stats:
file: controllers/userMigrations.js

Screenshot 2023-08-15 at 11 15 11 AM

file: models/userMigrations.js

Screenshot 2023-08-09 at 10 35 55 AM

file utils/helpers.js

Screenshot 2023-08-15 at 11 18 19 AM

models/users.js Outdated Show resolved Hide resolved
utils/users.js Outdated Show resolved Hide resolved
models/users.js Outdated Show resolved Hide resolved
utils/users.js Outdated Show resolved Hide resolved
@pallabez
Copy link
Contributor

Other than the 2 comments above, everything looks good to me. We can proceed with merging after those are resolved. Thanks for the PR.

pallabez
pallabez previously approved these changes Oct 20, 2022
Copy link
Contributor

@pallabez pallabez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ankushdharkar ankushdharkar added the feature task Feature that has to be built label Oct 21, 2022
utils/helpers.js Outdated Show resolved Hide resolved
const { SUPERUSER } = require("../constants/roles");
const migrations = require("../controllers/userMigrations");

router.patch("/user-default-color", authenticate, authorizeRoles([SUPERUSER]), migrations.addDefaultColors);

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [authorization](1), but is not rate-limited. This route handler performs [authorization](2), but is not rate-limited. This route handler performs [authorization](3), but is not rate-limited.
@heyrandhir
Copy link
Contributor

heyrandhir commented Aug 8, 2023

we are modifying user resource here ideally this route should be in users.

this was discussed with @pallabez , again the discussion took place long time ago and it was decided to use this route for migrations. It is a one time PR so the code will not exist after this. Let me know what should be done here

so do you mean that for new users this random color constant are being added. only for the old users this is a 1 time fix ?

Copy link
Contributor

@heyrandhir heyrandhir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add testing stats and follow the standard template for description.

@isVivek99
Copy link
Contributor Author

isVivek99 commented Aug 9, 2023

we are modifying user resource here ideally this route should be in users.

this was discussed with @pallabez , again the discussion took place long time ago and it was decided to use this route for migrations. It is a one time PR so the code will not exist after this. Let me know what should be done here

so do you mean that for new users this random color constant are being added. only for the old users this is a 1 time fix ?

this will only be for existing users, I am not sure if a new user signs up we are adding them a color property, we can also have a follow up PR for that

@heyrandhir
Copy link
Contributor

we are modifying user resource here ideally this route should be in users.

this was discussed with @pallabez , again the discussion took place long time ago and it was decided to use this route for migrations. It is a one time PR so the code will not exist after this. Let me know what should be done here

so do you mean that for new users this random color constant are being added. only for the old users this is a 1 time fix ?

this will only be for existing users, I am not sure if a new user signs up we are adding them a color property, we can also have a follow up PR for that

In this scenario, it seems more logical to write that part initially otherwise, the current script will function for all the current users, but the color property will be missing for new users and the super user will need to run this every time new users are added in the DB. Alternatively, if we add it for new users first, then we can ensure that everyone is covered. Once the script is executed, we can then remove the script for once and for all. What do you think @vivek-geekyants @isVivek99

Copy link
Contributor

@heyrandhir heyrandhir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed model and util tests are missing 👀

expect(res).to.have.status(200);
expect(res.body.usersDetails.totalUsersFetched).to.be.equal(colorBearingUsernames.length);
expect(res.body.usersDetails.totalUsersUpdated).to.be.equal(colorBearingUsernames.length);
expect(res.body.usersDetails.totalUsersUnaffected).to.be.equal(0);
Copy link
Contributor

@heyrandhir heyrandhir Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also write a test in which we test users who have the color property pre-existing are not affected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure , i had that check, but after removing usernames i removed it, ill add it back in some other. way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isVivek99 still can't see the assertion for users who have the color property pre-existing and are not affected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have added a similar test in the model test.
test/unit/models/userMigrations.test.js
does this suffice?

Copy link
Contributor

@heyrandhir heyrandhir Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have added a similar test in the model test. test/unit/models/userMigrations.test.js does this suffice?

it would be great if we could add in integration test. This expansion in coverage will enhance our confidence in the system and would assure everything works end to end. 😊

@isVivek99
Copy link
Contributor Author

Just noticed model tests are missing 👀

will be updating

@isVivek99
Copy link
Contributor Author

yes will raise a seperate PR for that, lets not stop this PR being approved for that.

mailmesriza98
mailmesriza98 previously approved these changes Aug 15, 2023
@isVivek99 isVivek99 requested a review from heyrandhir August 16, 2023 04:14
controllers/userMigrations.js Outdated Show resolved Hide resolved
models/userMigrations.js Outdated Show resolved Hide resolved
const userColorIndex = getRandomIndex(USER_COLORS);
colors.color_id = userColorIndex;
const docId = userModel.doc(user.id);
batchArray[parseInt(batchIndex)].set(docId, { ...user, colors });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Instead of resetting the entire object, we can simply update the colors field. This would be more efficient and would avoid unnecessary changes to the object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, will update

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not resolved @isVivek99 sir 🥲

Comment on lines 19 to 20
const usersSnapshot = await userModel.get();
const usersArr = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be done using data access layer as we are trying to avoid accessing the user model directly !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought we can only access user through id or usernames, ill check it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used the dataAccessLayer for this, but the layer has only provision to fetch un-archived users, but we want to get all users, what should we do in this case?

Copy link
Contributor

@heyrandhir heyrandhir Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your current code should suffice for now. We can proceed without blocking your pull request. Let's create a ticket to keep track of this task, and when you find the time and bandwidth, we can address it after this current work.

CC @mailmesriza98 @prakashchoudhary07 @iamitprakash @ankushdharkar

test/integration/users.test.js Outdated Show resolved Hide resolved
expect(res).to.have.status(200);
expect(res.body.usersDetails.totalUsersFetched).to.be.equal(colorBearingUsernames.length);
expect(res.body.usersDetails.totalUsersUpdated).to.be.equal(colorBearingUsernames.length);
expect(res.body.usersDetails.totalUsersUnaffected).to.be.equal(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isVivek99 still can't see the assertion for users who have the color property pre-existing and are not affected.

@@ -19,6 +19,7 @@ app.use("/users/status", require("./userStatus.js"));
app.use("/users", require("./users.js"));
app.use("/profileDiffs", require("./profileDiffs.js"));
app.use("/wallet", require("./wallets.js"));
app.use("/migrations", require("./userMigrations.js"));
Copy link
Contributor

@heyrandhir heyrandhir Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are aware @ankushdharkar has strongly advised against approving pull requests that don't adhere to the correct naming convention. As migrations isn't a resource, could you kindly consider relocating this route under \users ?

https://discord.com/channels/673083527624916993/729399523268624405/1141334143867822081

utils/helpers.js Outdated Show resolved Hide resolved
utils/helpers.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog feature task Feature that has to be built
Projects
None yet
Development

Successfully merging this pull request may close these issues.