Skip to content

Commit

Permalink
Merge branch 'master' into AO3-5901
Browse files Browse the repository at this point in the history
# Conflicts:
#	config/locales/views/en.yml
  • Loading branch information
neuroalien committed Jun 23, 2023
2 parents 854a62e + 754e816 commit 5917722
Show file tree
Hide file tree
Showing 236 changed files with 8,746 additions and 12,143 deletions.
1 change: 0 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ exclude_paths:
- "public/**/*.min.js"
- "public/javascripts/bootstrap/"
- "public/javascripts/tinymce/"
- "public/system/dewplayer/"
- "script/"
- "spec/"
- "test/"
1 change: 0 additions & 1 deletion .jshintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ coverage
public/**/*.min.js
public/javascripts/bootstrap
public/javascripts/tinymce
public/system/dewplayer
3 changes: 0 additions & 3 deletions .phrase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ phrase:
- file: ./config/locales/phrase-exports/ko.yml
params:
locale_id: ko
- file: ./config/locales/phrase-exports/ky.yml
params:
locale_id: ky
- file: ./config/locales/phrase-exports/lt.yml
params:
locale_id: lt
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ group :test, :development do
gem 'whiny_validation'
gem "factory_bot_rails"
gem 'minitest'
gem "i18n-tasks", require: false
end

group :development do
Expand Down
16 changes: 15 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
i18n-tasks (1.0.12)
activesupport (>= 4.0.2)
ast (>= 2.1.0)
better_html (>= 1.0, < 3.0)
erubi
highline (>= 2.0.0)
i18n
parser (>= 2.2.3.0)
rails-i18n
rainbow (>= 2.2.2, < 4.0)
terminal-table (>= 1.5.1)
jmespath (1.6.1)
json (2.6.1)
kgio (2.10.0)
Expand Down Expand Up @@ -356,7 +367,7 @@ GEM
netrc (0.11.0)
newrelic_rpm (8.16.0)
nio4r (2.5.8)
nokogiri (1.14.0)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
orm_adapter (0.5.0)
Expand Down Expand Up @@ -531,6 +542,8 @@ GEM
activesupport (>= 5.2)
sprockets (>= 3.0.0)
stringex (2.8.5)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
terrapin (0.6.0)
climate_control (>= 0.0.3, < 1.0)
test-unit (3.5.3)
Expand Down Expand Up @@ -627,6 +640,7 @@ DEPENDENCIES
google_visualr!
htmlentities
httparty
i18n-tasks
kgio (= 2.10.0)
kt-paperclip (>= 5.2.0)
launchy
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/abuse_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
@abuse_report.ip_address = request.remote_ip
if @abuse_report.save
@abuse_report.email_and_send
flash[:notice] = ts("Your abuse report was sent to the Abuse team.")
flash[:notice] = ts("Your report was submitted to the Policy & Abuse team. A confirmation message has been sent to the email address you provided.")
redirect_to root_path
else
render action: "new"
Expand Down
10 changes: 1 addition & 9 deletions app/controllers/admin/admin_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def set_roles
def show
@user = authorize User.find_by!(login: params[:id])
@hide_dashboard = true
@page_subtitle = t(".page_title", login: @user.login)
@log_items = @user.log_items.sort_by(&:created_at).reverse
end

Expand Down Expand Up @@ -167,13 +168,4 @@ def activate
redirect_to action: :show
end
end

def send_activation
@user = User.find_by(login: params[:id])
authorize @user
# send synchronously to avoid getting caught in mail queue
UserMailer.signup_notification(@user.id).deliver_now
flash[:notice] = ts("Activation email sent")
redirect_to action: :show
end
end
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def transform_sanitized_hash_to_ac_params(key, value)
helper_method :current_admin
helper_method :logged_in?
helper_method :logged_in_as_admin?
helper_method :guest?

# Title helpers
helper_method :process_title
Expand Down
28 changes: 20 additions & 8 deletions app/controllers/collection_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@ class CollectionItemsController < ApplicationController

def index

# TODO: AO3-6507 Refactor to use send instead of case statements.
if @collection && @collection.user_is_maintainer?(current_user)
@collection_items = @collection.collection_items.include_for_works
@collection_items = case
when params[:approved]
@collection_items = case params[:status]
when "approved"
@collection_items.approved_by_both
when params[:rejected]
when "rejected_by_collection"
@collection_items.rejected_by_collection
when params[:invited]
when "rejected_by_user"
@collection_items.rejected_by_user
when "unreviewed_by_user"
@collection_items.invited_by_collection
else
@collection_items.unreviewed_by_collection
end
elsif params[:user_id] && (@user = User.find_by(login: params[:user_id])) && @user == current_user
@collection_items = CollectionItem.for_user(@user).includes(:collection)
@collection_items = case
when params[:approved]
@collection_items = case params[:status]
when "approved"
@collection_items.approved_by_both
when params[:rejected]
when "rejected_by_collection"
@collection_items.rejected_by_collection
when "rejected_by_user"
@collection_items.rejected_by_user
when "unreviewed_by_collection"
@collection_items.approved_by_user.unreviewed_by_collection
else
@collection_items.unreviewed_by_user
end
Expand Down Expand Up @@ -127,7 +134,10 @@ def create
unless invited_collections.empty?
invited_collections.each do |needs_user_approval|
flash[:notice] ||= ""
flash[:notice] = ts("This work has been <a href=\"#{collection_items_path(needs_user_approval)}?invited=true\">invited</a> to your collection (#{needs_user_approval.title}).").html_safe
flash[:notice] = t(".invited_to_collections_html",
invited_link: view_context.link_to(t(".invited"),
collection_items_path(needs_user_approval, status: :unreviewed_by_user)),
collection_title: needs_user_approval.title)
end
end
unless unapproved_collections.empty?
Expand Down Expand Up @@ -179,6 +189,8 @@ def update_multiple_with_params(allowed_items:, update_params:, success_path:)
allowed_items.where(id: update_params.keys).each do |item|
item_data = update_params[item.id]
if item_data[:remove] == "1"
next unless item.user_allowed_to_destroy?(current_user)

@collection_items << item unless item.destroy
else
@collection_items << item unless item.update(item_data)
Expand Down
20 changes: 17 additions & 3 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CommentsController < ApplicationController
before_action :check_ownership, only: [:edit, :update, :cancel_comment_edit]
before_action :check_permission_to_edit, only: [:edit, :update ]
before_action :check_permission_to_delete, only: [:delete_comment, :destroy]
before_action :check_guest_comment_admin_setting, only: [:new, :create, :add_comment_reply]
before_action :check_parent_comment_permissions, only: [:new, :create, :add_comment_reply]
before_action :check_unreviewed, only: [:add_comment_reply]
before_action :check_frozen, only: [:new, :create, :add_comment_reply]
Expand Down Expand Up @@ -130,6 +131,15 @@ def check_parent_comment_permissions
end
end

def check_guest_comment_admin_setting
admin_settings = AdminSetting.current

return unless admin_settings.guest_comments_off? && guest?

flash[:error] = t("comments.commentable.guest_comments_disabled")
redirect_back(fallback_location: root_path)
end

def check_unreviewed
return unless @commentable.respond_to?(:unreviewed?) && @commentable.unreviewed?

Expand Down Expand Up @@ -195,7 +205,7 @@ def check_permission_to_delete
# Comments cannot be edited after they've been replied to or if they are frozen.
def check_permission_to_edit
if @comment&.iced?
flash[:error] = t("comment.check_permission_to_edit.error.frozen")
flash[:error] = t("comments.check_permission_to_edit.error.frozen")
redirect_back(fallback_location: root_path)
elsif !@comment&.count_all_comments&.zero?
flash[:error] = ts("Comments with replies cannot be edited")
Expand All @@ -211,14 +221,18 @@ def check_permission_to_edit
def check_permission_to_modify_frozen_status
return if permission_to_modify_frozen_status

flash[:error] = t(".permission_denied")
# i18n-tasks-use t('comments.freeze.permission_denied')
# i18n-tasks-use t('comments.unfreeze.permission_denied')
flash[:error] = t("comments.#{action_name}.permission_denied")
redirect_back(fallback_location: root_path)
end

def check_permission_to_modify_hidden_status
return if policy(@comment).can_hide_comment?

flash[:error] = t(".permission_denied")
# i18n-tasks-use t('comments.hide.permission_denied')
# i18n-tasks-use t('comments.unhide.permission_denied')
flash[:error] = t("comments.#{action_name}.permission_denied")
redirect_back(fallback_location: root_path)
end

Expand Down
22 changes: 21 additions & 1 deletion app/controllers/tag_wranglers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class TagWranglersController < ApplicationController
include ExportsHelper

before_action :check_user_status
before_action :check_permission_to_wrangle
before_action :check_permission_to_wrangle, except: [:report_csv]

def index
@wranglers = Role.find_by(name: "tag_wrangler").users.alphabetical
Expand Down Expand Up @@ -50,6 +52,24 @@ def show
end
end

def report_csv
authorize :tag_wrangler, :report_csv?

wrangler = User.find_by!(login: params[:id])
wrangled_tags = Tag
.where(last_wrangler: wrangler)
.limit(ArchiveConfig.WRANGLING_REPORT_LIMIT)
.includes(:merger, :parents)
results = [%w[Name Last\ Updated Type Merger Fandoms Unwrangleable]]
wrangled_tags.find_each(order: :desc) do |tag|
merger = tag.merger&.name || ""
fandoms = tag.parents.filter_map { |parent| parent.name if parent.is_a?(Fandom) }.join(", ")
results << [tag.name, tag.updated_at, tag.type, merger, fandoms, tag.unwrangleable]
end
filename = "wrangled_tags_#{wrangler.login}_#{Time.now.utc.strftime('%Y-%m-%d-%H%M')}.csv"
send_csv_data(results, filename)
end

def create
unless params[:tag_fandom_string].blank?
names = params[:tag_fandom_string].gsub(/$/, ',').split(',').map(&:strip)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def new
set_work_form_fields

if params[:import]
@page_subtitle = ts('import')
@page_subtitle = ts("Import New Work")
render(:new_import)
elsif @work.persisted?
render(:edit)
Expand Down Expand Up @@ -878,6 +878,8 @@ def build_options(params)
post_without_preview: params[:post_without_preview],
importing_for_others: params[:importing_for_others],
restricted: params[:restricted],
moderated_commenting_enabled: params[:moderated_commenting_enabled],
comment_permissions: params[:comment_permissions],
override_tags: params[:override_tags],
detect_tags: params[:detect_tags] == "true",
fandom: params[:work][:fandom_string],
Expand Down
39 changes: 39 additions & 0 deletions app/helpers/collections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,43 @@ def collection_item_display_title(collection_item)
ts('Deleted or unknown item')
end
end

def collection_item_approval_options_label(actor:, item_type:)
item_type = item_type.downcase
actor = actor.downcase

case actor
when "user"
t("collections_helper.collection_item_approval_options_label.user.#{item_type}")
when "collection"
t("collections_helper.collection_item_approval_options_label.collection")
end
end

# i18n-tasks-use t('collections_helper.collection_item_approval_options.collection.approved')
# i18n-tasks-use t('collections_helper.collection_item_approval_options.collection.rejected')
# i18n-tasks-use t('collections_helper.collection_item_approval_options.collection.unreviewed')
# i18n-tasks-use t('collections_helper.collection_item_approval_options.user.bookmark.approved')
# i18n-tasks-use t('collections_helper.collection_item_approval_options.user.bookmark.rejected')
# i18n-tasks-use t('collections_helper.collection_item_approval_options.user.bookmark.unreviewed')
# i18n-tasks-use t('collections_helper.collection_item_approval_options.user.work.approved')
# i18n-tasks-use t('collections_helper.collection_item_approval_options.user.work.rejected')
# i18n-tasks-use t('collections_helper.collection_item_approval_options.user.work.unreviewed')
def collection_item_approval_options(actor:, item_type:)
item_type = item_type.downcase
actor = actor.downcase

key = case actor
when "user"
"collections_helper.collection_item_approval_options.user.#{item_type}"
when "collection"
"collections_helper.collection_item_approval_options.collection"
end

[
[t("#{key}.unreviewed"), :unreviewed],
[t("#{key}.approved"), :approved],
[t("#{key}.rejected"), :rejected]
]
end
end
5 changes: 4 additions & 1 deletion app/helpers/comments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ def show_hide_comments_link(commentable, options={})
#### HELPERS FOR CHECKING WHICH BUTTONS/FORMS TO DISPLAY #####

def can_reply_to_comment?(comment)
admin_settings = AdminSetting.current

!(comment.unreviewed? ||
comment.iced? ||
comment.hidden_by_admin? ||
parent_disallows_comments?(comment) ||
comment_parent_hidden?(comment) ||
blocked_by_comment?(comment) ||
blocked_by?(comment.ultimate_parent))
blocked_by?(comment.ultimate_parent) ||
guest? && admin_settings.guest_comments_off?)
end

def can_edit_comment?(comment)
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def creation_word_count(creation)
def work_tag_metadata_label(tags)
return if tags.empty?

# i18n-tasks-use t('activerecord.models.archive_warning')
# i18n-tasks-use t('activerecord.models.character')
# i18n-tasks-use t('activerecord.models.fandom')
# i18n-tasks-use t('activerecord.models.freeform')
# i18n-tasks-use t('activerecord.models.rating')
# i18n-tasks-use t('activerecord.models.relationship')
type = tags.first.type
t("activerecord.models.#{type.underscore}", count: tags.count) + t("mailer.general.metadata_label_indicator")
end
Expand Down
Loading

0 comments on commit 5917722

Please sign in to comment.