Skip to content

Commit

Permalink
AO3-6308 fix user suspension end time (#4338)
Browse files Browse the repository at this point in the history
* fix user suspension end time

* please hound

* date localization suggestion

* avoid html in translation string

* fix translation file issues

* fix merge conflict part 2

* address linter

* add unit test

* make reset_blocked_html use different locale key

* Update app/controllers/application_controller.rb

Co-authored-by: Bilka <[email protected]>

* Update app/controllers/application_controller.rb

Co-authored-by: Bilka <[email protected]>

* Update features/users/suspensions.feature

Co-authored-by: Bilka <[email protected]>

* Update features/users/suspensions.feature

Co-authored-by: Bilka <[email protected]>

---------

Co-authored-by: Bilka <[email protected]>
  • Loading branch information
Cesium-Ice and Bilka2 authored Dec 10, 2024
1 parent 493f91e commit b5e71b6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
31 changes: 25 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,20 +393,39 @@ def use_caching?
# Prevents banned and suspended users from adding/editing content
def check_user_status
if current_user.is_a?(User) && (current_user.suspended? || current_user.banned?)
flash[:error] = if current_user.suspended?
t("users.status.suspension_notice_html", contact_abuse_link: view_context.link_to(t("users.status.contact_abuse"), new_abuse_report_path), suspended_until: localize(current_user.suspended_until))
else
t("users.status.ban_notice_html", contact_abuse_link: view_context.link_to(t("users.status.contact_abuse"), new_abuse_report_path))
end
if current_user.suspended?
suspension_end = current_user.suspended_until

# Unban threshold is 6:51pm, 12 hours after the unsuspend_users rake task located in schedule.rb is run at 6:51am
unban_theshold = DateTime.new(suspension_end.year, suspension_end.month, suspension_end.day, 18, 51, 0, "+00:00")

# If the stated suspension end date is after the unban threshold we need to advance a day
suspension_end = suspension_end.next_day(1) if suspension_end > unban_theshold
localized_suspension_end = view_context.date_in_zone(suspension_end)
flash[:error] = t("users.status.suspension_notice_html", suspended_until: localized_suspension_end, contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path))

else
flash[:error] = t("users.status.ban_notice_html", contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path))
end
redirect_to current_user
end
end

# Prevents temporarily suspended users from deleting content
def check_user_not_suspended
return unless current_user.is_a?(User) && current_user.suspended?

suspension_end = current_user.suspended_until

# Unban threshold is 6:51pm, 12 hours after the unsuspend_users rake task located in schedule.rb is run at 6:51am
unban_theshold = DateTime.new(suspension_end.year, suspension_end.month, suspension_end.day, 18, 51, 0, "+00:00")

# If the stated suspension end date is after the unban threshold we need to advance a day
suspension_end = suspension_end.next_day(1) if suspension_end > unban_theshold
localized_suspension_end = view_context.date_in_zone(suspension_end)

flash[:error] = t("users.status.suspension_notice_html", contact_abuse_link: view_context.link_to(t("users.status.contact_abuse"), new_abuse_report_path), suspended_until: localize(current_user.suspended_until))
flash[:error] = t("users.status.suspension_notice_html", suspended_until: localized_suspension_end, contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path))

redirect_to current_user
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def create
end

if user.prevent_password_resets?
flash[:error] = t(".reset_blocked", contact_abuse_link: view_context.link_to(t(".contact_abuse"), new_abuse_report_path)).html_safe
flash[:error] = t(".reset_blocked_html", contact_abuse_link: view_context.link_to(t(".contact_abuse"), new_abuse_report_path))
redirect_to root_path and return
elsif user.password_resets_limit_reached?
available_time = ApplicationController.helpers.time_in_zone(
user.password_resets_available_time, nil, user
)

flash[:error] = t(".reset_cooldown", reset_available_time: available_time).html_safe
flash[:error] = t(".reset_cooldown_html", reset_available_time: available_time)
redirect_to root_path and return
end

Expand Down
6 changes: 3 additions & 3 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ en:
index:
page_subtitle: fandoms
users:
contact_abuse: contact Policy & Abuse
passwords:
create:
contact_abuse: contact Policy & Abuse
reset_blocked: Password resets are disabled for that user. For more information, please %{contact_abuse_link}.
reset_cooldown: You cannot reset your password at this time. Please try again after %{reset_available_time}.
reset_blocked_html: Password resets are disabled for that user. For more information, please %{contact_abuse_link}.
reset_cooldown_html: You cannot reset your password at this time. Please try again after %{reset_available_time}.
send_cooldown_period:
one: After that, you will need to wait %{count} hour before requesting another reset.
other: After that, you will need to wait %{count} hours before requesting another reset.
Expand All @@ -133,7 +134,6 @@ en:
user_not_found: We couldn't find an account with that email address or username. Please try again.
status:
ban_notice_html: Your account has been banned. You are not permitted to add or edit archive content. Please %{contact_abuse_link} for more information.
contact_abuse: contact Abuse
suspension_notice_html: Your account has been suspended until %{suspended_until}. You may not add or edit content until your suspension has been resolved. Please %{contact_abuse_link} for more information.
works:
drafts:
Expand Down
17 changes: 17 additions & 0 deletions features/users/suspensions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Suspensions

Scenario: Users suspended on 2024-01-11 before the unban threshold can see they will be unbanned on 2024-02-10
Given the user "mrparis" exists and is activated
And it is currently 2024-01-11 01:00 AM
And the user "mrparis" is suspended
And I am logged in as "mrparis"
And I go to the new work page
Then I should see "suspended until Sat 10 Feb 2024"

Scenario: Users suspended on 2024-01-11 after the unban threshold can see they will be unbanned on 2024-02-11
Given the user "mrparis" exists and is activated
And it is currently 2024-01-11 08:00 PM
And the user "mrparis" is suspended
And I am logged in as "mrparis"
And I go to the new work page
Then I should see "suspended until Sun 11 Feb 2024"

0 comments on commit b5e71b6

Please sign in to comment.