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 7 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
25 changes: 22 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,18 @@ def use_caching?
def check_user_status
if current_user.is_a?(User) && (current_user.suspended? || current_user.banned?)
if current_user.suspended?
flash[:error] = t("suspension_notice", default: "Your account has been suspended until %{suspended_until}. You may not add or edit content until your suspension has been resolved. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.", suspended_until: localize(current_user.suspended_until)).html_safe
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 = localize(suspension_end.to_date)
Cesium-Ice marked this conversation as resolved.
Show resolved Hide resolved
flash[:error] = t("users.status.suspension_notice", suspended_until: localized_suspension_end, contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path)).html_safe
Copy link
Contributor

@Bilka2 Bilka2 May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be nice to have the key end in _html so that the html_safe call isn't needed:

Suggested change
flash[:error] = t("users.status.suspension_notice", suspended_until: localized_suspension_end, contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path)).html_safe
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))

This also needs a change in the locale file. Same applies to the other t() calls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: This change was done in 61a4f52 with some other work. So you should merge the master branch into your branch to get the updated locale key and locale files.


else
flash[:error] = t("ban_notice", default: "Your account has been banned. You are not permitted to add or edit archive content. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.").html_safe
flash[:error] = t("users.status.ban_notice", contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path)).html_safe
end
redirect_to current_user
end
Expand All @@ -401,8 +410,18 @@ def check_user_status
# 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 = localize(suspension_end.to_date)
Cesium-Ice marked this conversation as resolved.
Show resolved Hide resolved

flash[:error] = t("suspension_notice", default: "Your account has been suspended until %{suspended_until}. You may not add or edit content until your suspension has been resolved. Please <a href=\"#{new_abuse_report_path}\">contact Abuse</a> for more information.", suspended_until: localize(current_user.suspended_until)).html_safe
flash[:error] = t("users.status.suspension_notice", suspended_until: localized_suspension_end, contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path)).html_safe

redirect_to current_user
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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", contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path)).html_safe
redirect_to root_path and return
elsif user.password_resets_limit_reached?
available_time = ApplicationController.helpers.time_in_zone(
Expand Down
5 changes: 4 additions & 1 deletion config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ 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}.
send_cooldown_period:
Expand All @@ -101,3 +101,6 @@ en:
one: You may reset your password %{count} more time.
other: You may reset your password %{count} more times.
user_not_found: We couldn't find an account with that email address or username. Please try again.
status:
ban_notice: Your account has been banned. You are not permitted to add or edit archive content. Please %{contact_abuse_link} for more information.
suspension_notice: 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.
Loading