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

AO3-5502 Fix page title of the adult content warning for chapters #5012

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
# 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 [email protected]?(@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 @@

# 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.")

Check warning on line 95 in app/controllers/chapters_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer Rails built-in `t` helper over `ts` and move the text into the yml file. `ts` is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards Raw Output: app/controllers/chapters_controller.rb:95:24: C: I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts` and move the text into the yml file. `ts` is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards
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 @@
# 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_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.")

Check warning on line 270 in app/controllers/chapters_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer Rails built-in `t` helper over `ts` and move the text into the yml file. `ts` is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards Raw Output: app/controllers/chapters_controller.rb:270:21: C: I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts` and move the text into the yml file. `ts` is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards
redirect_to work_path(@work)
end

def post_chapter
if [email protected]
@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!")

Check warning on line 276 in app/controllers/chapters_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer Rails built-in `t` helper over `ts` and move the text into the yml file. `ts` is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards Raw Output: app/controllers/chapters_controller.rb:276:22: C: I18n/DeprecatedHelper: Prefer Rails built-in `t` helper over `ts` and move the text into the yml file. `ts` is not actually translatable. For more information, refer to https://github.com/otwcode/otwarchive/wiki/Internationalization-(i18n)-Standards
end

private
Expand All @@ -284,6 +283,5 @@
:"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"
Loading