Files
growstuff/app/controllers/application_controller.rb
Brenda WallaceandDaniel O'Connor 8474bdd416 remove newsletter (#4974)
* Remove unused bluecloth gem

Last released in 2011. It was only required, never called; kramdown
renders the markdown.

* Add specs for Tilt markdown rendering and posts markdown partial

* Remove rails_12factor gem

Last released in 2014. Rails 5+ does this via RAILS_SERVE_STATIC_FILES
and RAILS_LOG_TO_STDOUT, which production.rb already reads.

* Remove memcachier gem from Gemfile and Gemfile.lock

* Remove unused webrat gem

Last released in 2011. Nothing requires it; the specs use Rails'
assert_select and Capybara matchers. Only generator comments mention it.

* Remove crowdin-cli gem

Last released in 2018. Crowdin now ships its own standalone CLI, which
reads crowdin.yml and doesn't need the gem. Also drops the dependencies
only it used (rest-client, gli, crowdin-api and friends).

* Removes the crowdin-cli gem (last released 2018), the dependencies only
it needed, and crowdin.yml. Crowdin was never set up: the config still
has a placeholder project ID and nothing else in the repo mentions it.

Assisted by Claude

* Remove newsletter functionality and associated views and tests

* Remove newsletter functionality and related code across the application

* keep the column

* Remove stale test step

* add back newsletter

* Add migration to update newsletter column comment in members table

---------

Co-authored-by: Daniel O'Connor <daniel.oconnor@gmail.com>
2026-10-26 11:48:36 +10:30

104 lines
3.6 KiB
Ruby

# frozen_string_literal: true
class ApplicationController < ActionController::Base
protect_from_forgery
# Working from codespaces, we want to turn off validation
skip_before_action :verify_authenticity_token if Rails.env.development? && ENV['CODESPACE_NAME']
include ApplicationHelper
after_action :store_location
before_action :set_locale
around_action :use_browser_time_zone
rescue_from ActiveRecord::RecordNotFound, with: :not_found
def store_location
unless request.path.in?(["/members/sign_in",
"/members/sign_up",
"/members/password/new",
"/members/password/edit",
"/members/confirmation",
"/members/sign_out"]) || request.xhr?
store_location_for(:member, request.fullpath) if request.format == :html
end
end
def not_found
render file: 'app/views/errors/404.html', status: :not_found, layout: false
end
def after_sign_in_path_for(_resource)
stored_location_for(:member) || root_path
end
def after_sign_out_path_for(_resource_or_scope)
request.referer
end
# tweak CanCan defaults because we don't have a "current_user" method
# this means that we use current_user in specs but current_member everywhere
# else in the code.
def current_ability
@current_ability ||= Ability.new(current_member)
end
# CanCan error handling
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.json { render json: { error: exception.message }, status: :forbidden }
format.any { redirect_to request.referer || root_url, alert: exception.message }
end
end
# The member's today isn't always the server's (UTC), so dates are worked out in
# the time zone their browser says it is in; see application.js.
def use_browser_time_zone(&block)
zone = ActiveSupport::TimeZone[cookies[:timezone].to_s]
zone ? Time.use_zone(zone, &block) : block.call
end
def set_locale
I18n.locale = params[:locale] || extract_locale_from_subdomain || I18n.default_locale
end
def extract_locale_from_subdomain
parsed_locale = request.subdomains.first
I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale : nil
end
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) do |member|
member.permit(:login_name, :email, :password, :password_confirmation,
:remember_me, :login,
# terms of service
:tos_agreement,
# profile stuff
:bio, :location, :latitude, :longitude,
# email settings
:show_email, :send_notification_email, :send_planting_reminder, :send_harvest_reminder)
end
devise_parameter_sanitizer.permit(:account_update) do |member|
member.permit(:login_name, :email, :password, :password_confirmation,
:remember_me, :login,
# terms of service
:tos_agreement,
# profile stuff
:bio, :location, :latitude, :longitude,
:website_url, :instagram_handle, :facebook_handle, :bluesky_handle, :other_url,
# email settings
:show_email, :send_notification_email, :send_planting_reminder, :send_harvest_reminder,
# update password
:current_password)
end
end
def expire_homepage
expire_fragment("homepage_stats")
end
end