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

Allow admins to reject resource suggestions #38

Closed

Conversation

farzaneh-haghani
Copy link

@farzaneh-haghani farzaneh-haghani commented May 15, 2024

closes #13

This is a:

  • ✨ New feature - new behaviour has been implemented
  • πŸ› Bug fix - existing behaviour has been made to behave
  • ♻️ Refactor - the behaviour has not changed, just the implementation
  • βœ… Test backfill - tests for existing behaviour were added but the behaviour itself hasn't changed
  • βš™οΈ Chore - maintenance task, behaviour and implementation haven't changed

Description

It will show a reject button to allow admin to reject a resource in the draft. It will delete the resource from db.

  • Purpose -

Allow admin to reject a suggested resource.

  • How to check -

Log in as astronaut, go to suggest tab and fill the from. Then log out and log in as admin and go to draft and find your suggestion. Previously did not have a reject button but now it have and work.

Links

Author checklist

  • I have written a title that reflects the relevant ticket
  • I have written a description that says what the PR does and how to validate it
  • I have linked to the project board ticket (and any related PRs/issues) in the Links section
  • I have added a link to this PR to the ticket
  • I have made the PR to main from a branch named <category>/<name>, e.g. feature/edit-spaceships or bugfix/restore-oxygen
  • I have manually tested that the app still works correctly
  • I have requested reviewers here and in my team chat channel
  • I have spoken with my PM or TL about any parts of this task that may have become out-of-scope, or any additional improvements that I now realise may benefit my project
  • I have added tests, or new tests were not required
  • I have updated any documentation (e.g. diagrams, schemas), or documentation updates were not required

@kfklein15 kfklein15 requested a review from textbook May 21, 2024 18:24
Copy link
Member

@textbook textbook left a comment

Choose a reason for hiding this comment

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

Generally, this is very impressive: well done! πŸ‘

As an iteration, I'd like to see:

  • πŸ§ͺ At least one additional test at a different level (i.e. E2E or API integration, not just the frontend React tests)
  • πŸ“š Document the API endpoint (either as-is, or you can update as suggested and document the new version)
  • ❓ How would you meet the implied requirement of soft deletion (you don't have to implement it, but I'd be interested to hear how you'd approach it)?

(If you'd like to practice on implementing any of the other feedback then you're welcome to, but don't feel you have to.)


Functionality

If I Suggest a draft (as admin or regular user), then visit the Drafts page as an admin, I see:

Screenshot 2024-05-21 at 21 38 42

  • βœ… If I click the "Reject" button, the resource is removed from the Drafts page

  • βœ… The resource doesn't appear on the home page either

  • ❌ The resource is hard-deleted from the DB, note the story links:

  • ❌ UI/UX of deletion could be improved:

    1. Action buttons feel weirdly far apart, it might make more sense to have the buttons in a shared container in the bottom right hand corner
    2. Action buttons are the same colour, easy to mix up at a glance
    3. It's a good principle of interaction design (especially given point 2 and the hard delete) to require confirmation (even a basic window.confirm would do) before doing things that could lead to data loss

Implementation

  • βœ… Generally very good; you've put things in sensible places and everything works as you intended

  • ❌ From an API design perspective, a DELETE request would generally:

    • Have no request body (the resource ID is already in the path)
    • Have no response body (the resource is now "gone" so there's nothing to return)
    • Have a status of 204 No Content
  • ❌ No E2E test of the new functionality

  • ❌ No integration test or documentation of the new API endpoint, which has a few cases to cover (401 Unauthorized, 403 Forbidden, 404 Not Found and the successful delete -> 200 OK (as-is)/204 No Content (to-be))


Key

  • βœ… Nothing to change, just commenting
  • πŸ’‘ Possible change, or suggestion to think about in the future
  • ❓ Discussion required before approval
  • ❌ Change required before approval

server/resources/resourcesController.js Outdated Show resolved Hide resolved
Comment on lines 87 to 91
validated({
body: Joi.object({
draft: Joi.any().valid(false),
}),
}),
Copy link
Member

Choose a reason for hiding this comment

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

❌ In line with the feedback about API design there shouldn't be any required body/validation

}),
asyncHandler(async (req, res) => {
try {
res.send(await service.reject(req.params.id));
Copy link
Member

Choose a reason for hiding this comment

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

❌ And rather than 200 OK with a body, 204 No Content is more idiomatic

Comment on lines 96 to 99
if (err instanceof service.MissingResource) {
logger.info(err.message);
return res.sendStatus(404);
}
Copy link
Member

Choose a reason for hiding this comment

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

βœ… Nice to see the error handling pattern being used, and 404 is an appropriate response status code here πŸ‘

❌ If it's not a MissingResource, the error has now been caught but the request has still not been responded to, you need to:

Suggested change
if (err instanceof service.MissingResource) {
logger.info(err.message);
return res.sendStatus(404);
}
if (err instanceof service.MissingResource) {
logger.info(err.message);
return res.sendStatus(404);
}
throw err;

so it reaches the global error handler and becomes a 500 Internal Server Error or the request will hang indefinitely.

server/db.js Show resolved Hide resolved
@farzaneh-haghani
Copy link
Author

farzaneh-haghani commented May 28, 2024

Hi @textbook, Can I change the schema of resources? As I understood form the other issue, when the admin reject a resource, user should still see it in another tab to track all own suggested resources. In resources table, we have a draft column which is true by default, then after publish, it would change to false. So how should I flag it as a rejected? Wasn't better if we had a status column (draft / published / rejected)?
status | status-changed-by | status-changed-date
I am not sure if user can edit the rejected resource in the future and suggest it again. In this case, we need to have status table separate from resource table to keep all tracks.

@textbook
Copy link
Member

Can I change the schema of resources?

The migrations are there to allow us to evolve the schema as needed.

So how should I flag it as a rejected? Wasn't better if we had a status column (draft / published / rejected)?

Yes, that would be a way to do it - with a boolean we can only represent two states, "draft" or "not draft" (approved). Moving to something with more than two possible values (maybe an enum or look it up from another table, see e.g. https://stackoverflow.com/q/24680744/3001761 for trade offs) allows representing a wider range of states, including "rejected".

I am not sure if user can edit the rejected resource in the future and suggest it again. In this case, we need to have status table separate from resource table to keep all tracks.

Currently there's no editing supported and none of the issues propose it, so I wouldn't spend time planning for that now.

@farzaneh-haghani farzaneh-haghani force-pushed the feature/reject branch 2 times, most recently from 5eb8f5e to f5cd727 Compare May 30, 2024 19:52
@farzaneh-haghani farzaneh-haghani force-pushed the feature/reject branch 4 times, most recently from a76c3d9 to b5caa96 Compare May 31, 2024 22:14
@farzaneh-haghani
Copy link
Author

@textbook Could you please review my changes again.

@textbook
Copy link
Member

textbook commented Jun 9, 2024

I haven't reviewed it in as much detail this time, but overall that's a good iteration, thank you!

  • πŸ§ͺ At least one additional test at a different level (i.e. E2E or API integration, not just the frontend React tests)

βœ… Added E2E test "lets admin users reject drafts"

  • πŸ“š Document the API endpoint (either as-is, or you can update as suggested and document the new version)

βœ… Existing docs were updated (DELETE endpoint was removed, so no docs needed)

❌ OpenAPI lets you document enums directly, not just as string: https://swagger.io/docs/specification/data-models/enums/

  • ❓ How would you meet the implied requirement of soft deletion (you don't have to implement it, but I'd be interested to hear how you'd approach it)?

βœ… Implemented by switching from boolean to enum status, so rejection sets resources to "rejected", leaving them in the DB but not returning them to the ?status=drafted or (usually implicit) ?status=published queries (although admins can access them by hitting the resource list endpoint - curl -H 'Authorization: Bearer secretsquirrel' 'http://localhost:4202/api/resources?status=rejected')

❌ As in the docs string is too broad for the status parameter, Joi also lets you represent enums https://joi.dev/api/?v=17.13.0#anyvalidvalues---aliases-equal

@textbook textbook closed this Jun 9, 2024
@farzaneh-haghani
Copy link
Author

farzaneh-haghani commented Jun 9, 2024

@textbook Thank you. Why did you close it? I can improve it to be merged?

@textbook
Copy link
Member

textbook commented Jun 9, 2024

It's just an exercise, a work simulation. If we merged all of the applications I'd have to keep coming up with new stories (and keep the PR review task branch up-to-date with the changes)!

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

Successfully merging this pull request may close these issues.

Allow admins to reject resource suggestions
2 participants