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

GraphQL - Post Lock #875

Merged
merged 27 commits into from
Nov 11, 2020
Merged

GraphQL - Post Lock #875

merged 27 commits into from
Nov 11, 2020

Conversation

toyhammered
Copy link
Member

What

Allow posts to be locked. When a post is locked only admin will be able to make comments.
Locking/Unlocking a post will be done through a GraphQL Mutation.

Why

Certain people don't know how to be nice to others. 🖕 them.

Checklist

  • All files pass Rubocop
  • Any complex logic is commented
  • Any new systems have thorough documentation
  • Any user-facing changes are behind a feature flag (or: explain why they can't be)
  • All the tests pass
  • Tests have been added to cover the new code

@toyhammered toyhammered self-assigned this Oct 30, 2020
@wopian
Copy link
Member

wopian commented Oct 30, 2020

Will need to be adjusted for #874

db/migrate/20201030020815_add_lock_unlock_to_post.rb Outdated Show resolved Hide resolved
spec/factories/posts.rb Outdated Show resolved Hide resolved
@toyhammered
Copy link
Member Author

Will need to be adjusted for #874

Yup, will let @NuckChorris merge in first and then fix mine up.

app/models/post.rb Outdated Show resolved Hide resolved
app/policies/post_policy.rb Outdated Show resolved Hide resolved
Comment on lines +11 to +13
post = ::Post.find(value.id)
post.assign_attributes(value.to_model)
post
Copy link
Member

Choose a reason for hiding this comment

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

I'm distinctly not a fan of this thing where you get the changes from some other file and then shove them in over here... It seems like indirection without purpose

Copy link
Member Author

Choose a reason for hiding this comment

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

Funny enough this is how it was originally done (by Matt). I liked it so I kinda just started using it also lol.

Comment on lines +21 to +29
post.save

if post.errors.any?
Errors::RailsModel.graphql_error(post)
else
{
post: post
}
end
Copy link
Member

Choose a reason for hiding this comment

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

FWIW I added an Errors::ActiveRecord::RecordInvalid in #880 that should do this for us in future with post.save!

We can change it once both are merged

Comment on lines +5 to +7
def to_model
to_h.merge(locked_at: DateTime.current, locked_by: current_user)
end
Copy link
Member

Choose a reason for hiding this comment

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

This feels way too magical for me

Copy link
Member Author

@toyhammered toyhammered Nov 2, 2020

Choose a reason for hiding this comment

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

kyubey

@codeclimate
Copy link

codeclimate bot commented Nov 6, 2020

Code Climate has analyzed commit 5e9c031 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

Copy link
Member

@wopian wopian left a comment

Choose a reason for hiding this comment

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

LGTM from a feature perspective for frontend. Will need Emma's review for code quality

Copy link
Member

@NuckChorris NuckChorris left a comment

Choose a reason for hiding this comment

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

My comments still stand, I'd like to see improvements to the way we do GraphQL — but for now, this works

@toyhammered toyhammered merged commit db0da1e into the-future Nov 11, 2020
@toyhammered toyhammered deleted the feature/post-locking branch November 11, 2020 02:21
@wopian wopian mentioned this pull request Nov 22, 2020
5 tasks
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.

3 participants