Skip to content

Commit

Permalink
Merge branch 'master' into AO3-6613
Browse files Browse the repository at this point in the history
  • Loading branch information
denerose committed Jan 4, 2024
2 parents e317ac6 + 5cb3009 commit 173b5aa
Show file tree
Hide file tree
Showing 144 changed files with 2,461 additions and 1,313 deletions.
4 changes: 4 additions & 0 deletions .erb-lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
EnableDefaultLinters: true
linters:
AllowedScriptType:
allowed_types:
- "text/javascript"
- "speculationrules"
DeprecatedClasses:
enabled: true
rule_set:
Expand Down
5 changes: 2 additions & 3 deletions .github/labeler/awaiting.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"Awaiting Review":
- "**/*"
- ".*"
- ".*/**/*"
- changed-files:
- any-glob-to-any-file: "**/*"
15 changes: 8 additions & 7 deletions .github/labeler/contents.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"Gem Updates":
- "Gemfile"
- "Gemfile.lock"
- changed-files:
- any-glob-to-any-file: ["Gemfile", "Gemfile.lock"]

"Has Migrations":
- "db/migrate/**/*"
- changed-files:
- any-glob-to-any-file: "db/migrate/**/*"

"Scope: i18n Only":
- all:
- "config/locales/**/*"
- changed-files:
- any-glob-to-all-files: "config/locales/**/*"

"Scope: Tests Only":
- all:
- "{factories,features,spec,test,.github}/**/*"
- changed-files:
- any-glob-to-all-files: "{factories,features,spec,test,.github}/**/*"
11 changes: 6 additions & 5 deletions .github/labeler/review.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Label to be added when the PR is updated:
"Coder Has Actioned Review":
- "**/*"
- ".*"
- ".*/**/*"
- changed-files:
- any-glob-to-any-file: "**/*"

# Label to be removed when the PR is updated:
"Reviewed: Action Needed": []
# Condition is always false so the label is removed when the PR is updated:
"Reviewed: Action Needed":
- changed-files:
- any-glob-to-any-file: "!**/*"
7 changes: 0 additions & 7 deletions .github/workflows/automated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ jobs:
sudo apt-get install -y redis-server
./script/gh-actions/multiple_redis.sh
- name: Cache wkhtmltopdf package
if: ${{ matrix.tests.ebook }}
uses: actions/cache@v3
with:
path: wkhtmltopdf
key: wkhtmltopdf-${{ hashFiles('script/gh-actions/ebook_converters.sh') }}

- name: Install ebook converters
if: ${{ matrix.tests.ebook }}
run: ./script/gh-actions/ebook_converters.sh
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ jobs:
steps:

- name: Content-Based
uses: actions/labeler@v4
uses: actions/labeler@v5
with:
configuration-path: ".github/labeler/contents.yml"
repo-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Awaiting Review
uses: actions/labeler@v4
uses: actions/labeler@v5
if: github.event.action == 'opened'
with:
configuration-path: ".github/labeler/awaiting.yml"
repo-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Coder Has Actioned Review
uses: actions/labeler@v4
uses: actions/labeler@v5
# https://github.community/t/do-something-if-a-particular-label-is-set/17149/4
if: "contains(github.event.pull_request.labels.*.name, 'Reviewed: Action Needed')"
with:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ permissions:
checks: write

jobs:
rubocop:
name: Rubocop
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Ruby and run bundle install
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: rubocop
uses: reviewdog/action-rubocop@e70b014b8062c447d6b515ee0209f834ea93e696
with:
use_bundler: true
reporter: github-pr-check
skip_install: true

erb-lint:
name: ERB Lint runner
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions .hound.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ jshint:
ignore_file: .jshintignore

rubocop:
version: 1.22.1
config_file: .rubocop.yml
enabled: false
2 changes: 1 addition & 1 deletion app/controllers/admin_posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def index
@admin_posts ||= AdminPost
if params[:language_id].present? && (@language = Language.find_by(short: params[:language_id]))
@admin_posts = @admin_posts.where(language_id: @language.id)
@tags = AdminPostTag.joins(:admin_posts).where(admin_posts: { language_id: @language.id })
@tags = AdminPostTag.distinct.joins(:admin_posts).where(admin_posts: { language_id: @language.id }).order(:name)
else
@admin_posts = @admin_posts.non_translated
@tags = AdminPostTag.order(:name)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/collection_participants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def add

if @participants_invited.empty? && @participants_added.empty?
if pseud_results[:banned_pseuds].present?
flash[:error] =
ts("%{name} is currently banned and cannot participate in challenges.",
flash[:error] = ts("%{name} cannot participate in challenges.",
name: pseud_results[:banned_pseuds].to_sentence
)
else
Expand Down
31 changes: 27 additions & 4 deletions app/controllers/invite_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,40 @@ def index
# GET /invite_requests/1
def show
@invite_request = InviteRequest.find_by(email: params[:email])
@position_in_queue = @invite_request.position if @invite_request.present?
unless (request.xml_http_request?) || @invite_request
flash[:error] = "You can search for the email address you signed up with below. If you can't find it, your invitation may have already been emailed to that address; please check your email spam folder as your spam filters may have placed it there."
redirect_to status_invite_requests_path and return

if @invite_request.present?
@position_in_queue = @invite_request.position
else
@invitation = Invitation.unredeemed.from_queue.find_by(invitee_email: params[:email])
end

respond_to do |format|
format.html
format.js
end
end

def resend
@invitation = Invitation.unredeemed.from_queue.find_by(invitee_email: params[:email])

if @invitation.nil?
flash[:error] = t("invite_requests.resend.not_found")
elsif !@invitation.can_resend?
flash[:error] = t("invite_requests.resend.not_yet",
count: ArchiveConfig.HOURS_BEFORE_RESEND_INVITATION)
else
@invitation.send_and_set_date(resend: true)

if @invitation.errors.any?
flash[:error] = @invitation.errors.full_messages.first
else
flash[:notice] = t("invite_requests.resend.success", email: @invitation.invitee_email)
end
end

redirect_to status_invite_requests_path
end

# POST /invite_requests
def create
unless AdminSetting.current.invite_from_queue_enabled?
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/languages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ def index
@languages = Language.default_order
end

def show
@language = Language.find_by(short: params[:id])
@works = @language.works.recent.visible.limit(ArchiveConfig.NUMBER_OF_ITEMS_VISIBLE_IN_DASHBOARD)
end

def new
@language = Language.new
authorize @language
Expand All @@ -35,7 +30,7 @@ def update
authorize @language
if @language.update(language_params)
flash[:notice] = t('successfully_updated', default: 'Language was successfully updated.')
redirect_to @language
redirect_to languages_path
else
render action: "new"
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_permitted_parameters

def new
@page_title = "Create Account" # Displays "New Registration" otherwise
super do |resource|
if params[:invitation_token]
@invitation = Invitation.find_by(token: params[:invitation_token])
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,8 @@ def load_owner
end
end
end
@owner = @pseud || @user || @collection || @tag
@language = Language.find_by(short: params[:language_id]) if params[:language_id].present?
@owner = @pseud || @user || @collection || @tag || @language
end

def load_work
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def allow_tinymce?(controller)
# see: http://www.w3.org/TR/wai-aria/states_and_properties#aria-valuenow
def generate_countdown_html(field_id, max)
max = max.to_s
span = content_tag(:span, max, id: "#{field_id}_counter", class: "value", "data-maxlength" => max, "aria-live" => "polite", "aria-valuemax" => max, "aria-valuenow" => field_id)
content_tag(:p, span + ts(' characters left'), class: "character_counter")
span = content_tag(:span, max, id: "#{field_id}_counter", class: "value", "data-maxlength" => max)
content_tag(:p, span + ts(' characters left'), class: "character_counter", "tabindex" => 0)
end

# expand/contracts all expand/contract targets inside its nearest parent with the target class (usually index or listbox etc)
Expand Down
5 changes: 3 additions & 2 deletions app/helpers/comments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_commenter_pseud_or_name(comment)
link_to comment.pseud.byline, [comment.pseud.user, comment.pseud]
end
else
comment.name
content_tag(:span, comment.name) + content_tag(:span, " #{ts('(Guest)')}", class: "role")
end
end

Expand Down Expand Up @@ -328,8 +328,9 @@ def css_classes_for_comment(comment)
unreviewed = "unreviewed" if comment.unreviewed?
commenter = commenter_id_for_css_classes(comment)
official = "official" if commenter && comment&.pseud&.user&.official
guest = "guest" unless comment.pseud_id

"#{unavailable} #{official} #{unreviewed} comment group #{commenter}".squish
"#{unavailable} #{official} #{guest} #{unreviewed} comment group #{commenter}".squish
end

# find the parent of the commentable
Expand Down
24 changes: 24 additions & 0 deletions app/helpers/mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def style_link(body, url, html_options = {})
link_to(body.html_safe, url, html_options)
end

def style_role(text)
tag.em(tag.strong(text))
end

# For work, chapter, and series links
def style_creation_link(title, url, html_options = {})
html_options[:style] = "color:#990000"
Expand Down Expand Up @@ -176,6 +180,26 @@ def style_work_tag_metadata(tags)
"#{label}#{style_work_tag_metadata_list(tags)}".html_safe
end

def commenter_pseud_or_name_link(comment)
if comment.comment_owner.nil?
t("roles.guest_commenter_name_html", name: style_bold(comment.comment_owner_name), role: style_role(t("roles.guest_with_parens")))
elsif comment.by_anonymous_creator?
style_bold(t("roles.anonymous_creator"))
else
style_pseud_link(comment.pseud)
end
end

def commenter_pseud_or_name_text(comment)
if comment.comment_owner.nil?
t("roles.guest_commenter_name_text", name: comment.comment_owner_name, role: t("roles.guest_with_parens"))
elsif comment.by_anonymous_creator?
t("roles.anonymous_creator")
else
text_pseud(comment.pseud)
end
end

private

# e.g., 1 word or 50 words
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def search_header(collection, search, item_name, parent=nil)
header << ts("by %{byline}", byline: parent.byline)
when User
header << ts("by %{username}", username: parent.login)
when Language
header << ts("in %{language}", language: parent.name)
end

header << ts("in %{tag_link}", tag_link: link_to_tag_with_text(parent, parent.name)) if parent.is_a?(Tag)
Expand Down
38 changes: 38 additions & 0 deletions app/helpers/share_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ def get_tweet_text_for_bookmark(bookmark)
"Bookmark of #{bookmark.bookmarkable.title} by #{names} - #{fandoms}".truncate(83)
end

# JavaScript-less share buttons from https://sharingbuttons.io/
# We use medium, solid, rectangular buttons.
def sharing_button(site, address, text, target: nil)
return unless %w[twitter tumblr].include?(site)

tag.a(
tag.div(
tag.div(
sharing_svg(site),
class: "resp-sharing-button__icon resp-sharing-button__icon--solid",
aria: { hidden: true }
) + text,
class: "resp-sharing-button resp-sharing-button--#{site} resp-sharing-button--medium"
),
href: address,
target: target,
class: "resp-sharing-button__link",
aria: { label: text }
)
end

private

def short_fandom_string(work)
Expand All @@ -37,4 +58,21 @@ def short_fandom_string(work)
def remove_newlines(html)
html.delete("\n")
end

def sharing_svg(site)
return unless %w[twitter tumblr].include?(site)

path = case site
when "twitter"
tag.path d: "M23.44 4.83c-.8.37-1.5.38-2.22.02.93-.56.98-.96 1.32-2.02-.88.52-1.86.9-2.9 1.1-.82-.88-2-1.43-3.3-1.43-2.5 0-4.55 2.04-4.55 4.54 0 .36.03.7.1 1.04-3.77-.2-7.12-2-9.36-4.75-.4.67-.6 1.45-.6 2.3 0 1.56.8 2.95 2 3.77-.74-.03-1.44-.23-2.05-.57v.06c0 2.2 1.56 4.03 3.64 4.44-.67.2-1.37.2-2.06.08.58 1.8 2.26 3.12 4.25 3.16C5.78 18.1 3.37 18.74 1 18.46c2 1.3 4.4 2.04 6.97 2.04 8.35 0 12.92-6.92 12.92-12.93 0-.2 0-.4-.02-.6.9-.63 1.96-1.22 2.56-2.14z"
when "tumblr"
tag.path d: "M13.5.5v5h5v4h-5V15c0 5 3.5 4.4 6 2.8v4.4c-6.7 3.2-12 0-12-4.2V9.5h-3V6.7c1-.3 2.2-.7 3-1.3.5-.5 1-1.2 1.4-2 .3-.7.6-1.7.7-3h3.8z"
end

tag.svg(
path,
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 24 24"
)
end
end
33 changes: 33 additions & 0 deletions app/helpers/works_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,39 @@ def get_inspired_by(work)
work.approved_related_works.where(translation: false)
end

def related_work_note(related_work, relation, download: false)
work_link = link_to related_work.title, polymorphic_url(related_work)
language = tag.span(related_work.language.name, lang: related_work.language.short) if related_work.language
default_locale = download ? :en : nil

creator_link = if download
byline(related_work, visibility: "public", only_path: false)
else
byline(related_work)
end

if related_work.respond_to?(:unrevealed?) && related_work.unrevealed?
if relation == "translated_to"
t(".#{relation}.unrevealed_html",
language: language)
else
t(".#{relation}.unrevealed",
locale: default_locale)
end
elsif related_work.restricted? && (download || !logged_in?)
t(".#{relation}.restricted_html",
language: language,
locale: default_locale,
creator_link: creator_link)
else
t(".#{relation}.revealed_html",
language: language,
locale: default_locale,
work_link: work_link,
creator_link: creator_link)
end
end

# Can the work be downloaded, i.e. is it posted and visible to all registered
# users.
def downloadable?
Expand Down
Loading

0 comments on commit 173b5aa

Please sign in to comment.