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

feat: 🎸 methods and db changes to publish single map and batch-publish multiple maps (no interface yet) #1772

Merged
merged 4 commits into from
Jul 1, 2022

Conversation

PeculiarE
Copy link
Contributor

@PeculiarE PeculiarE commented Jun 29, 2022

Fixes #1771

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/mapknitter-reviewers for help, in a comment below

@gitpod-io
Copy link

gitpod-io bot commented Jun 29, 2022

app/controllers/spam_controller.rb Show resolved Hide resolved
app/controllers/spam_controller.rb Show resolved Hide resolved
app/controllers/spam_controller.rb Show resolved Hide resolved
@codeclimate
Copy link

codeclimate bot commented Jun 29, 2022

Code Climate has analyzed commit 0eec279 and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 4

View more on Code Climate.

@codecov
Copy link

codecov bot commented Jun 29, 2022

Codecov Report

Merging #1772 (7bfa104) into main (833eb37) will increase coverage by 0.70%.
The diff coverage is 100.00%.

❗ Current head 7bfa104 differs from pull request most recent head fd1bc22. Consider uploading reports for the commit fd1bc22 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1772      +/-   ##
==========================================
+ Coverage   64.72%   65.43%   +0.70%     
==========================================
  Files          40       40              
  Lines        1219     1244      +25     
==========================================
+ Hits          789      814      +25     
  Misses        430      430              
Impacted Files Coverage Δ
app/controllers/application_controller.rb 91.66% <100.00%> (ø)
app/controllers/spam_controller.rb 100.00% <100.00%> (ø)
app/models/map.rb 91.92% <100.00%> (+0.10%) ⬆️
app/models/user.rb 100.00% <100.00%> (ø)

@map = Map.find(params[:id])
if publish_check(@map)
notice_text = 'Map published.'
notice_text.chop! << ' and author unbanned.' if unban_check(@map)
Copy link
Member

Choose a reason for hiding this comment

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

I like the use of #chop here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you 😄

Copy link
Member

Choose a reason for hiding this comment

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

yes, very nice!!!

unbanned_authors << map.user.id if unban_check(map)
end
end
flash[:notice] = helpers.pluralize(published_maps, 'map') + ' published and ' + helpers.pluralize(unbanned_authors.size, 'author') + ' unbanned.'
Copy link
Member

@TildaDares TildaDares Jun 29, 2022

Choose a reason for hiding this comment

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

Since we're only using the unbaned_authors variable for pluralization, maybe we should keep count of the unbanned authors instead of the authors themselves.

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'm sorry @TildaDares, but could you please explain further as I'm not exactly sure what to change? I am keeping count of the unbanned authors and not the total number of authors.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for not clarifying. I mean the unbanned_authors is currently storing an array of unbanned author's ids. Since we're only using the unbanned_authors variable for pluralization, we don't actually need the unbanned author's object. We only need to keep count of how many authors are being unbanned just like you did for published_maps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I totally get now. Made the change. Does this work fine?

Copy link
Member

Choose a reason for hiding this comment

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

Yes this works. Thanks @PeculiarE!

@@ -53,7 +53,7 @@ def logged_in?

def logged_in_as(roles, action)
unless current_user && roles.any? { |role| current_user.role == role }
flash[:error] = "Only #{roles.collect { |role| role.pluralize }.join(' and ')} can #{action}."
flash[:error] = "Only #{roles.collect(&:pluralize).join(" and ")} can #{action}."
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

ooh cool!

@TildaDares
Copy link
Member

@PeculiarE Seems like Rubocop has a few complaints about the comments. Not really important.

@PeculiarE
Copy link
Contributor Author

@PeculiarE Seems like Rubocop has a few complaints about the comments. Not really important.

Yeah. I've fixed it though in the latest commit I just pushed.

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

Just a thought on method naming. If you prefer to just leave as-is, let me know! Otherwise are we ready to merge? Thank you!!!

map.user.ban unless map.anonymous? || map.user.status == User::Status::BANNED
end

def publish_check(map)
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it's worth using a longer method name that reads more like human speech, like check_and_publish? Just an idea. The comments make it clear but i'm thinking when it's used in other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's definitely worth it. I'm all for longer method-names for better readability. Will use your suggestions and re-push. Thank you ❤️

@map = Map.find(params[:id])
if publish_check(@map)
notice_text = 'Map published.'
notice_text.chop! << ' and author unbanned.' if unban_check(@map)
Copy link
Member

Choose a reason for hiding this comment

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

yes, very nice!!!


user.unban
assert_equal User::Status::NORMAL, user.status
assert user.status_updated_at.to_f >= old_time.to_f
Copy link
Member

Choose a reason for hiding this comment

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

Love all the tests, very thorough. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you 😄 !

@PeculiarE
Copy link
Contributor Author

Just a thought on method naming. If you prefer to just leave as-is, let me know! Otherwise are we ready to merge? Thank you!!!

I've renamed the methods, and I believe we're ready to merge 😄...Thank you!

@PeculiarE PeculiarE requested a review from jywarren June 30, 2022 14:00
@jywarren
Copy link
Member

jywarren commented Jul 1, 2022

Looks super, thank you!!!

@jywarren jywarren merged commit 0d2e311 into publiclab:main Jul 1, 2022
PeculiarE added a commit to PeculiarE/mapknitter that referenced this pull request Jul 6, 2022
…h multiple maps (no interface yet) (publiclab#1772)

* feat: 🎸 publish single map and batch-publish multiple maps

* style: 💄 implemented code style suggestions & refactored routes

* refactor: 💡 discarded authors' object and used count instead

* refactor: 💡 made method names more readable
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.

Create batch-publish and single publish endpoints
3 participants