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 10 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 = localize(suspension_end.to_date)
Cesium-Ice marked this conversation as resolved.
Show resolved Hide resolved
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 = localize(suspension_end.to_date)
Cesium-Ice marked this conversation as resolved.
Show resolved Hide resolved

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("users.contact_abuse"), new_abuse_report_path))
Copy link
Contributor

@Bilka2 Bilka2 Sep 21, 2024

Choose a reason for hiding this comment

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

Apologies for coming back to this after already approving, but I had some discussion with the Translation team:

It would be nice if reset_blocked_html would continue to use a different locale key for the policy and abuse link text than the status texts. That allows translators to translate the link differently in context, since the sentence in reset_blocked is different than the one used in suspension_notice_html and ban_notice_html.

Suggested change
flash[:error] = t(".reset_blocked_html", contact_abuse_link: view_context.link_to(t("users.contact_abuse"), new_abuse_report_path))
flash[:error] = t(".reset_blocked_html", contact_abuse_link: view_context.link_to(t(".contact_abuse"), new_abuse_report_path))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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
7 changes: 3 additions & 4 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ 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 +106,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.
Loading