-
Notifications
You must be signed in to change notification settings - Fork 211
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
jywarren
merged 4 commits into
publiclab:main
from
PeculiarE:ft-single-and-batch-publish
Jul 1, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0eec279
feat: 🎸 publish single map and batch-publish multiple maps
PeculiarE 1ae3abf
style: 💄 implemented code style suggestions & refactored routes
PeculiarE e23d056
refactor: 💡 discarded authors' object and used count instead
PeculiarE fd1bc22
refactor: 💡 made method names more readable
PeculiarE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,80 @@ | ||
class SpamController < ApplicationController | ||
module ModerationGuards | ||
def spam_check(map) | ||
#check and spam only unspammed maps | ||
def check_and_spam(map) | ||
# check and spam only unspammed maps | ||
map.spam unless map.status == Map::Status::BANNED | ||
end | ||
def ban_check(map) | ||
#check and ban only unbanned non-anonymous authors | ||
|
||
def check_and_ban(map) | ||
# check and ban only unbanned non-anonymous authors | ||
map.user.ban unless map.anonymous? || map.user.status == User::Status::BANNED | ||
end | ||
|
||
def check_and_publish(map) | ||
# check and publish only spammed or moderated maps | ||
map.publish unless map.status == Map::Status::NORMAL | ||
end | ||
|
||
def check_and_unban(map) | ||
# check and unban only banned non-anonymous authors | ||
map.user.unban unless map.anonymous? || map.user.status != User::Status::BANNED | ||
end | ||
end | ||
|
||
include ModerationGuards | ||
|
||
require 'set' | ||
|
||
before_action :require_login | ||
before_action { logged_in_as(['admin', 'moderator'], 'moderate maps and users') } | ||
|
||
def spam_map | ||
@map = Map.find(params[:id]) | ||
if spam_check(@map) | ||
if check_and_spam(@map) | ||
notice_text = 'Map marked as spam.' | ||
notice_text.chop! << ' and author banned.' if ban_check(@map) | ||
notice_text.chop! << ' and author banned.' if check_and_ban(@map) | ||
else | ||
notice_text = 'Map already marked as spam.' | ||
end | ||
flash[:notice] = notice_text | ||
redirect_back(fallback_location: root_path) | ||
end | ||
|
||
def batch_spam_map | ||
def batch_spam_maps | ||
PeculiarE marked this conversation as resolved.
Show resolved
Hide resolved
|
||
spammed_maps = 0 | ||
banned_authors = Set.new | ||
banned_authors = 0 | ||
params[:ids].split(',').uniq.each do |id| | ||
map = Map.find(id) | ||
if spam_check(map) | ||
if check_and_spam(map) | ||
spammed_maps += 1 | ||
banned_authors << map.user.id if ban_check(map) | ||
banned_authors += 1 if check_and_ban(map) | ||
end | ||
end | ||
flash[:notice] = helpers.pluralize(spammed_maps, 'map') + ' spammed and ' + helpers.pluralize(banned_authors, 'author') + ' banned.' | ||
redirect_back(fallback_location: root_path) | ||
end | ||
|
||
def publish_map | ||
PeculiarE marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@map = Map.find(params[:id]) | ||
if check_and_publish(@map) | ||
notice_text = 'Map published.' | ||
notice_text.chop! << ' and author unbanned.' if check_and_unban(@map) | ||
else | ||
notice_text = 'Map already published.' | ||
end | ||
flash[:notice] = notice_text | ||
redirect_back(fallback_location: root_path) | ||
end | ||
|
||
def batch_publish_maps | ||
PeculiarE marked this conversation as resolved.
Show resolved
Hide resolved
|
||
published_maps = 0 | ||
unbanned_authors = 0 | ||
params[:ids].split(',').uniq.each do |id| | ||
map = Map.find(id) | ||
if check_and_publish(map) | ||
published_maps += 1 | ||
unbanned_authors += 1 if check_and_unban(map) | ||
end | ||
end | ||
flash[:notice] = helpers.pluralize(spammed_maps, 'map') + ' spammed and ' + helpers.pluralize(banned_authors.size, 'author') + ' banned.' | ||
flash[:notice] = helpers.pluralize(published_maps, 'map') + ' published and ' + helpers.pluralize(unbanned_authors, 'author') + ' unbanned.' | ||
redirect_back(fallback_location: root_path) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,4 +299,8 @@ def authors | |
def spam | ||
update!(status: Status::BANNED) | ||
end | ||
|
||
def publish | ||
update!(status: Status::NORMAL) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddStatusUpdateTimeToUsers < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :users, :status_updated_at, :datetime, null: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice!
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.
Thank you!
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.
ooh cool!