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

[Users] Add delete user mutation fixes(#134) #138

Merged
merged 1 commit into from
Jun 18, 2020

Conversation

jugshaurya
Copy link
Contributor

@jugshaurya jugshaurya commented Jun 10, 2020

Issue

fixes: #134

Solution

  • deletedAt property is used to soft delete the fields and can be used to restore them.

Screenshots (Desktop)

Screenshots (Mobile)

Checklist

PR will only be reviewed if the checklist is completed

  • I have done extensive testing for my changes.
  • I have self-reviewed my PR and removed all un-necessary changes.
  • My changes works well on both desktop and mobile environments.
  • I have made sure that my changes solves the actual problem mentioned in the issue.
  • The PR contains only 1 commit and have been updated with master.

@boss-contributions-bot
Copy link

Thanks @jugshaurya, for opening the pull request! 🙌

One of our mentors will review the pull request soon. ✅

Star ⭐ this project and tweet 🐦 about your contributions.

@jugshaurya
Copy link
Contributor Author

jugshaurya commented Jun 10, 2020

@hereisnaman please review,

@@ -10,7 +10,7 @@ import Availability from './Loaders/Availability';

export default class User extends BaseModelService {
static findByUsername(username) {
return Models.User.findOne({ where: { username } });
return Models.User.findOne({ where: { username }, paranoid: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

expect options as a second arg and spread it. While calling from the login callback pass the paranoid as false from there inside the options 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.

done

@jugshaurya jugshaurya force-pushed the userDisable-mutation branch from f5726f4 to fcd00c2 Compare June 10, 2020 17:26
@jugshaurya
Copy link
Contributor Author

@hereisnaman, please review. Changes done

@jugshaurya
Copy link
Contributor Author

jugshaurya commented Jun 11, 2020

@hereisnaman , testing required means, you are going to test it or I am?

@jugshaurya
Copy link
Contributor Author

jugshaurya commented Jun 12, 2020

@hereisnaman, can you help me out how can I test it as no frontend for it is written yet? maybe a new issue should be raised to add this feature with a checklist so that I can add that as well accordingly and test later on! and move on to issue #135 and assign that to me.

@thenamankumar
Copy link
Contributor

@hereisnaman, can you help me out how can I test it as no frontend for it is written yet? maybe a new issue should be raised to add this feature with a checklist so that I can add that as well accordingly and test later on! and move on to issue #135 and assign that to me.

visit localhost:3000/api/graphql in browser and test from there.

@jugshaurya
Copy link
Contributor Author

jugshaurya commented Jun 13, 2020

@hereisnaman Testing please review:

Test a: Add a mutation userDisable to delete the user.
1a
deleted_at got filled
1b

Test b: The action should only be allowed to admins.
non-admin-viewer
2a
unauthorized
2b

Test c: Update login callback to not create a user if a deleted entity for that user is present
How to test this ?
By the way in impersonating form:- once a user is deleted it is not showing there to log in as him/her.

@thenamankumar
Copy link
Contributor

@jugshaurya for impersonation and user listing, you'll need to handle few tasks from #134

Lets include the last 2 tasks from that issue in this PR.

@jugshaurya
Copy link
Contributor Author

jugshaurya commented Jun 14, 2020

@jugshaurya for impersonation and user listing, you'll need to handle few tasks from #134

Lets include the last 2 tasks from that issue in this PR.

@hereisnaman, i already included the last 2 tasks from issue #134 in this PR where if deleted_at property is not null, we redirect to homepage. And for cheking for admins test-b is also passing. You can see that in above screenshots

@thenamankumar
Copy link
Contributor

@jugshaurya for impersonation and user listing, you'll need to handle few tasks from #134
Lets include the last 2 tasks from that issue in this PR.

@hereisnaman, i already included the last 2 tasks from issue #134 in this PR where if deleted_at property is not null, we redirect to homepage. And for cheking for admins test-b is also passing. You can see that in above screenshots

Then why is " By the way in impersonating form:- once a user is deleted it is not showing there to log in as him/her." this an issue. You can pass the required arguments in the query to display those right.

@jugshaurya
Copy link
Contributor Author

jugshaurya commented Jun 14, 2020

@hereisnaman, i already included the last 2 tasks from issue #134 in this PR where if deleted_at property is not null, we redirect to homepage. And for cheking for admins test-b is also passing. You can see that in above screenshots

Then why is " By the way in impersonating form:- once a user is deleted it is not showing there to log in as him/her." this an issue. You can pass the required arguments in the query to display those right.

@hereisnaman , No that was not an issue, actually, i was saying for the test case c . Once the user is deleted and delete_at is filled, the users that are deleted are not showing in the form , which is what we want. So everything is fine. I was just giving explaination for test case c.
also for the point 3 in the checklist, I just used these two lines

   await user.loadByUsername(profile.username, { paranoid: false });
    if (user.deleted_at) return App.redirectToHome(res);

@@ -0,0 +1,5 @@
mutation UserDisable($id: ID!) {
disableUser: UserDisable(id: $id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The mutation name is userDisable, fix the casing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh sorry for that typo

- Add a mutation userDisable to delete the user.
- The action should only be allowed to admins.
- Update login callback to not create a user, if a deleted entity for that user is present
@jugshaurya jugshaurya force-pushed the userDisable-mutation branch from fcd00c2 to d785ec9 Compare June 15, 2020 17:26
@jugshaurya
Copy link
Contributor Author

@hereisnaman, please review

@jugshaurya jugshaurya requested a review from thenamankumar June 15, 2020 17:28
@jugshaurya
Copy link
Contributor Author

@hereisnaman, require some more changes?

@thenamankumar thenamankumar merged commit 87a464f into coding-blocks:master Jun 18, 2020
@boss-contributions-bot
Copy link

Congratualtions @jugshaurya, your pull request is merged! 🎉

Thanks for your contributions and participating in BOSS 2020. 🙌

You can claim your bounty points here. 💰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Users] Add delete user mutation
2 participants