-
-
Notifications
You must be signed in to change notification settings - Fork 963
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
Fixed #1750: Unexpected behavior when updation of talawa admin members profile. #1762
Conversation
Our Pull Request Approval ProcessWe have these basic policies to make the approval process smoother for our volunteer team. Testing Your CodePlease make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:
The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.
@EshaanAgg @xoldyckk Can you review this PR? |
@@ -59,7 +59,7 @@ export const updateUserProfile: MutationResolvers["updateUserProfile"] = async ( | |||
// Update User | |||
const updatedUser = await User.findOneAndUpdate( | |||
{ | |||
_id: context.userId, | |||
_id: args.data?.id || context.userId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would you allow anyone to update any user's profile they want to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this api call would be done by the admin only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this restriction isn't put in place, right now it allows any user to call this mutation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be resolved. Only the profile's user, Admins and Super Admins must be able to edit profile settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, on it
src/typeDefs/inputs.ts
Outdated
@@ -339,6 +339,8 @@ export const inputs = gql` | |||
lastName: String | |||
maritalStatus: MaritalStatus | |||
phone: UserPhoneInput | |||
applangcode: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appLanguageCode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey,
Regarding the variable name; that the frontend uses applangcode
, so should I change it there also, otherwise it would give errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please do that @Devesh326
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Devesh326 stop using abbreviations, it helps no one reading abbreviations to make sense of things, most of the time your code should be self documenting
in that light actually make it applicationLanguageCode
if frontend makes wrong assumptions about things, it doesn't mean it will be enforced on the backend design, if frontend wants to make changes it has to first open an issue/feature request
@@ -102,6 +102,9 @@ export const updateUserProfile: MutationResolvers["updateUserProfile"] = async ( | |||
firstName: args.data?.firstName | |||
? args.data.firstName | |||
: currentUser?.firstName, | |||
appLanguageCode: args.data?.applangcode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args.data?.appLanguageCode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this hasn't been resolved still
@@ -339,6 +339,8 @@ export const inputs = gql` | |||
lastName: String | |||
maritalStatus: MaritalStatus | |||
phone: UserPhoneInput | |||
applangcode: String | |||
id: ID | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename input UpdateUserInput
to input UpdateUserProfileInput
make following changes for mutation:-
type UpdateUserProfilePayload {
user: User
}
type Mutation {
updateUserProfile(input: UpdateUserProfileInput!): UpdateUserProfilePayload
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please renamed to suit the conventions @Devesh326
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -339,6 +339,8 @@ export const inputs = gql` | |||
lastName: String | |||
maritalStatus: MaritalStatus | |||
phone: UserPhoneInput | |||
applangcode: String | |||
id: ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the id
field from here, the update will only be applied for a user with _id === context.userId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this mutation is to be allowed to be triggered by both normal users and superadmins, some changes have to be made:-
-
if
args.input.id
is not provided(it isnull
orundefined
), the update will be carried out on the user withuser._id
equals tocontext.userId
-
if
args.input.id
is provided, there are two scenarios:-- if it's a normal user,
context.userId
must be equal toargs.input.id
- if it's a superadmin there are no restrictions, they can update any user with
user._id
equals toargs.input.id
- if it's a normal user,
some things to confirm with @palisadoes :-
- can one superadmin update other superadmin's user data?
- is this allowed only for superadmins, or admins of organizations too? the thing to remember is that a user is not tied to any one organization, they can be members/admins of many organizations simultaneously, this functionality doesn't exist in talawa-api right now because of existence of
userType === "ADMIN"
field on a user object, when in actuality the relationship between a user and an organization should exist on a junction between them, joining table in sql it is called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @xoldyckk is correct on the userType to organization relationship. This should be fixed in this issue.
- Senior usertypes should be able to edit or demote users of junior rank. They should be able to promote junior ranks to no more than their rank. Super Admins will need privileges to do this for everyone. I'm broadly basing this on Google's guidelines for their apps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @xoldyckk,
I included the id
in the mutation because during the API call to edit a specific user, in the backend context.userId
only contained the id
of the logged-in user. As a result, the profile being updated was that of the current user rather than the intended one. To address this, I passed the id
of the user that requires editing/updating in the API call.
Following this logic, if args.input.id
is null
, it indicates the root user; otherwise, it's the id
of the user whose profile needs updating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. then it looks fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Devesh326 take some time and contemplate about what i said previously, the current logic as it stands allows a normal user to update user fields of any other user, they just need to pass in the other user's id
in the input, frontend application can't prevent normal users from making these requests
understand the authentication/authorization flows, self review your code and possible edge cases, only then ask for reviews from other contributers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes noted.
README.md
Outdated
|
||
- [Talawa API](#talawa-api) | ||
- [Talawa Components](#talawa-components) | ||
- [Documentation](#documentation) | ||
- [Installation](#installation) | ||
- [Image Upload](#image-upload) | ||
- [Talawa Components](#talawa-components) | ||
- [Documentation](#documentation) | ||
- [Installation](#installation) | ||
- [Image Upload](#image-upload) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah apologies, I dont know why was this a part of the commit, i'll do the necessary changes. Thanks!
@Devesh326, please make the reviewed changes ASAP? All the PRs in the |
Sorry for the delayed response. I was travelling, so I wasn't able to make changes to the PR. Will update and resolve the requested changes ASAP. |
NOTE Read very carefully
This will help to reduce the number of future merge conflicts for your PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the small changes in comments. Then it's ready to be merged.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1762 +/- ##
========================================
Coverage 98.32% 98.32%
========================================
Files 322 322
Lines 20296 20299 +3
Branches 1606 1631 +25
========================================
+ Hits 19956 19959 +3
+ Misses 323 322 -1
- Partials 17 18 +1 ☔ View full report in Codecov by Sentry. |
@Devesh326, are you still actively working on this? The completion of this pull request is crucial, as it is causing failures in the workflow checks for all pull requests in the admin. Please prioritize and resolve this issue as soon as possible. // @Cioppolo14 |
yeah okay, fixing the necessary changes |
@@ -59,7 +59,7 @@ export const updateUserProfile: MutationResolvers["updateUserProfile"] = async ( | |||
// Update User | |||
const updatedUser = await User.findOneAndUpdate( | |||
{ | |||
_id: context.userId, | |||
_id: args.data?.id || context.userId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be resolved. Only the profile's user, Admins and Super Admins must be able to edit profile settings.
@palisadoes if one user could join multiple organizations under the same user profile, why would admin of any one organization be able to edit their user profile? that profile change would be reflected in all other organizations for that particular user. shouldn't this only be allowed to superadmins? |
The design philosophy of making users become members of any organization means that operationally if a member asks an admin to update their information, such as a phone number (or possibly in the future credit card information) the admin won’t be able to do it for them. At some future date we’ll need to think of ways of restricting this to superadmins on a per organization basis. |
Please try to get the code coverage for the patch closer to that of the repository |
We would like to merge this PR, however you haven’t addressed the reviewer questions. Please address each one and mark them as resolved when the work is completed. Only then will they be able to approve your work so that it can be merged into the code base. Please also try to get the code coverage for the patch higher. 80% coverage is much lower than the 98% enjoyed by the project |
This is an update on the PR merging freeze:
We decided to do this at the beginning of the weekend to give us all time to adjust PR code and create bug fixes that may arise. Update your code at or after midnight GMT on the morning of March 23, 2024. (5:30am IST). If your PRs have already been approved, request a re-review after fixing the conflicts and refactoring to the new |
The PR merging freeze is lifted.
Background:
|
@Devesh326 Please fix the conflicting files. |
I'm going to close this as abandoned. There have been no commits for over a month. |
What kind of change does this PR introduce?
bugfix
Issue Number:
Fixes #1750
Did you add tests for your changes?
No
Snapshots/Videos:
Palisadoes.Foundation.Talawa.Members.mp4
Summary
Solves the following issues:
Have you read the contributing guide?
Yes