Skip to content

Commit

Permalink
AO3-5502 Fix page title of the adult content warning for chapters (#5012
Browse files Browse the repository at this point in the history
)

* AO3-5502 correct page title on adult content warning chapters

* AO3-5502 add Cucumber test

* AO3-5502 satisfy Rubocop

* AO3-5578 ActiveStorage copy script performance fixes (#5015)

* AO3-5578 ActiveStorage copy script performance fixes

* Flush $stdout to force message visibility

* AO3-6873 Upgrade Elasticsearch for dev and automated tests (#5016)

* AO3-5578 Avoid unnecessary DB writes when copying icons (#5017)

* AO3-5578 Avoid unnecessary DB writes when copying icons

* Rubocop :fistshake:

* AO3-5578 Add a transaction to Psued image migration (#5018)

Add a transaction

* AO3-5578 Try to be nicer to the database when copying icons (#5019)

* Test listing in s3

* Other tasks & fixes

* Experiment with delayed upload

* Fixes

* Upload after txn

* Rubocop things

* Fixes

* Avoid duplicate attachments

* Revert "Avoid duplicate attachments"

This reverts commit 476bd02.

* AO3-5502 satisfy Rubocop again...?

* AO3-5502 satisfy more Rubocop

* AO3-5502 formatting improvements

* AO3-5502 make sure it's the adult notice page in the test

* AO3-5502 add another indent i forgot

---------

Co-authored-by: Brian Austin <[email protected]>
Co-authored-by: Bilka <[email protected]>
Co-authored-by: james_ <[email protected]>
  • Loading branch information
4 people authored Jan 22, 2025
1 parent fb325da commit f452488
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 63 deletions.
108 changes: 53 additions & 55 deletions app/controllers/chapters_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ChaptersController < ApplicationController
# only registered users and NOT admin should be able to create new chapters
before_action :users_only, except: [ :index, :show, :destroy, :confirm_delete ]
before_action :users_only, except: [:index, :show, :destroy, :confirm_delete]
before_action :check_user_status, only: [:new, :create, :update, :update_positions]
before_action :check_user_not_suspended, only: [:edit, :confirm_delete, :destroy]
before_action :load_work
Expand Down Expand Up @@ -28,53 +28,55 @@ def manage
# GET /work/:work_id/chapters/:id.xml
def show
@tag_groups = @work.tag_groups
if params[:view_adult]
cookies[:view_adult] = "true"
elsif @work.adult? && !see_adult?
render "works/_adult", layout: "application" and return
end

if params[:selected_id]
redirect_to url_for(controller: :chapters, action: :show, work_id: @work.id, id: params[:selected_id]) and return
end
redirect_to url_for(controller: :chapters, action: :show, work_id: @work.id, id: params[:selected_id]) and return if params[:selected_id]

@chapters = @work.chapters_in_order(
include_content: false,
include_drafts: (logged_in_as_admin? ||
@work.user_is_owner_or_invited?(current_user))
)
if !@chapters.include?(@chapter)

unless @chapters.include?(@chapter)
access_denied
return
end

chapter_position = @chapters.index(@chapter)
if @chapters.length > 1
@previous_chapter = @chapters[chapter_position - 1] unless chapter_position.zero?
@next_chapter = @chapters[chapter_position + 1]
end

if @work.unrevealed?
@page_title = t(".unrevealed") + t(".chapter_position", position: @chapter.position.to_s)
else
chapter_position = @chapters.index(@chapter)
if @chapters.length > 1
@previous_chapter = @chapters[chapter_position-1] unless chapter_position == 0
@next_chapter = @chapters[chapter_position+1]
end
fandoms = @tag_groups["Fandom"]
fandom = fandoms.empty? ? t(".unspecified_fandom") : fandoms[0].name
title_fandom = fandoms.size > 3 ? t(".multifandom") : fandom
author = @work.anonymous? ? t(".anonymous") : @work.pseuds.sort.collect(&:byline).join(", ")
@page_title = get_page_title(title_fandom, author, @work.title + t(".chapter_position", position: @chapter.position.to_s))
end

if @work.unrevealed?
@page_title = t(".unrevealed") + t(".chapter_position", position: @chapter.position.to_s)
else
fandoms = @tag_groups["Fandom"]
fandom = fandoms.empty? ? t(".unspecified_fandom") : fandoms[0].name
title_fandom = fandoms.size > 3 ? t(".multifandom") : fandom
author = @work.anonymous? ? t(".anonymous") : @work.pseuds.sort.collect(&:byline).join(", ")
@page_title = get_page_title(title_fandom, author, @work.title + t(".chapter_position", position: @chapter.position.to_s))
end
if params[:view_adult]
cookies[:view_adult] = "true"
elsif @work.adult? && !see_adult?
render "works/_adult", layout: "application" and return
end

@kudos = @work.kudos.with_user.includes(:user)
@kudos = @work.kudos.with_user.includes(:user)

if current_user.respond_to?(:subscriptions)
@subscription = current_user.subscriptions.where(subscribable_id: @work.id,
subscribable_type: 'Work').first ||
current_user.subscriptions.build(subscribable: @work)
end
# update the history.
Reading.update_or_create(@work, current_user) if current_user
if current_user.respond_to?(:subscriptions)
@subscription = current_user.subscriptions.where(subscribable_id: @work.id,
subscribable_type: "Work").first ||
current_user.subscriptions.build(subscribable: @work)
end
# update the history.
Reading.update_or_create(@work, current_user) if current_user

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

Expand All @@ -86,14 +88,14 @@ def new

# GET /work/:work_id/chapters/1/edit
def edit
if params["remove"] == "me"
@chapter.creatorships.for_user(current_user).destroy_all
if @work.chapters.any? { |c| current_user.is_author_of?(c) }
flash[:notice] = ts("You have been removed as a creator from the chapter.")
redirect_to @work
else # remove from work if no longer co-creator on any chapter
redirect_to edit_work_path(@work, remove: "me")
end
return unless params["remove"] == "me"

@chapter.creatorships.for_user(current_user).destroy_all
if @work.chapters.any? { |c| current_user.is_author_of?(c) }
flash[:notice] = ts("You have been removed as a creator from the chapter.")
redirect_to @work
else # remove from work if no longer co-creator on any chapter
redirect_to edit_work_path(@work, remove: "me")
end
end

Expand Down Expand Up @@ -250,7 +252,7 @@ def chapter_cannot_be_saved?
# fetch work these chapters belong to from db
def load_work
@work = params[:work_id] ? Work.find_by(id: params[:work_id]) : Chapter.find_by(id: params[:id]).try(:work)
unless @work.present?
if @work.blank?
flash[:error] = ts("Sorry, we couldn't find the work you were looking for.")
redirect_to root_path and return
end
Expand All @@ -263,18 +265,15 @@ def load_work
def load_chapter
@chapter = @work.chapters.find_by(id: params[:id])

unless @chapter
flash[:error] = ts("Sorry, we couldn't find the chapter you were looking for.")
redirect_to work_path(@work)
end
end
return if @chapter

flash[:error] = ts("Sorry, we couldn't find the chapter you were looking for.")
redirect_to work_path(@work)
end

def post_chapter
if !@work.posted
@work.update_attribute(:posted, true)
end
flash[:notice] = ts('Chapter has been posted!')
@work.update_attribute(:posted, true) unless @work.posted
flash[:notice] = ts("Chapter has been posted!")
end

private
Expand All @@ -284,6 +283,5 @@ def chapter_params
:"published_at(2i)", :"published_at(1i)", :summary,
:notes, :endnotes, :content, :published_at,
author_attributes: [:byline, ids: [], coauthors: []])

end
end
28 changes: 20 additions & 8 deletions features/other_a/page_title.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,34 @@ Scenario: user reads a TOS or FAQ page
Scenario: Page title should respect user preference

Given I am logged in as "author"
And I go to my preferences page
And I fill in "Browser page title format" with "FANDOM - AUTHOR - TITLE"
And I press "Update"
And I post the work "New Story" with fandom "Stargate"
And I go to my preferences page
And I fill in "Browser page title format" with "FANDOM - AUTHOR - TITLE"
And I press "Update"
And I post the work "New Story" with fandom "Stargate"
When I view the work "New Story"
Then the page title should include "Stargate - author - New Story"

Scenario: Page title should change when tags are edited

Given I am logged in as "author"
And I post the work "New Story" with fandom "Stargate"
And I post the work "New Story" with fandom "Stargate"
When I view the work "New Story"
Then the page title should include "Stargate"
When I edit the work "New Story"
And I fill in "Fandoms" with "Harry Potter"
And I press "Post"
And I fill in "Fandoms" with "Harry Potter"
And I press "Post"
When I view the work "New Story"
Then the page title should include "Harry Potter"
And the page title should not include "Stargate"
And the page title should not include "Stargate"

Scenario: Page title should be informative on the adult content notice page

Given I am logged in as "author"
And I post the 2 chapter work "New Story" with fandom "Stargate" with rating "Mature"
When I am logged out
And I view the work "New Story"
Then I should see "This work could have adult content"
And the page title should include "New Story - author - Stargate"
When I follow the recent chapter link for the work "New Story"
Then I should see "This work could have adult content"
And the page title should include "New Story - Chapter 2 - author - Stargate"

0 comments on commit f452488

Please sign in to comment.