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-6308 fix user suspension end time #4338

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 25 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,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 @@ -91,11 +91,12 @@ en:
destroy:
unmuted: You have unmuted the user %{name}.
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 @@ -106,5 +107,4 @@ 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.
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"
Loading