Class: Www::ReviewsController
- Inherits:
-
BasePortalController
- Object
- ActionController::Base
- ApplicationController
- BasePortalController
- Www::ReviewsController
- Defined in:
- app/controllers/www/reviews_controller.rb
Overview
Controller: reviews.
Constant Summary collapse
- REVIEWS_PER_PAGE =
Reviews per page.
24- SORT_OPTIONS =
Available sort options.
{ 'newest' => 'Newest First', 'oldest' => 'Oldest First', 'highest' => 'Highest Rated', 'lowest' => 'Lowest Rated' }.freeze
Constants included from Controllers::MasqueradeGuarded
Controllers::MasqueradeGuarded::DEFAULT_BLOCK_MESSAGE
Constants included from Controllers::AnalyticsEvents
Controllers::AnalyticsEvents::MAX_QUEUED_EVENTS, Controllers::AnalyticsEvents::SESSION_KEY
Constants included from Controllers::ErrorRendering
Controllers::ErrorRendering::NON_CONTENT_PATH_PREFIXES
Instance Method Summary collapse
-
#create_by_order_email ⇒ Object
Actions that originally only flashed + redirected (no mailer).
- #create_from_support_email ⇒ void
-
#create_order_item_review ⇒ Object
Actions that originally sent a mailer notification.
-
#index ⇒ void
Paginated, filterable public review index.
-
#item ⇒ void
Renders the per-item review partial.
- #new_order_items_review ⇒ void
- #new_order_review ⇒ void
- #new_support_review ⇒ void
-
#product_index ⇒ Object
Legacy route: 301 redirects to new hierarchical URL.
-
#show ⇒ void
Legacy per-review page.
-
#snooze ⇒ void
Pushes an order's review reminder out by a month.
Methods inherited from BasePortalController
#current_ability, #portal_party, #set_catalog, #set_webpack
Methods included from Controllers::MasqueradeGuarded
block_while_masquerading, #masquerade_blocks?
Methods inherited from ApplicationController
#account_impersonated?, #add_to_flash, #after_sign_in_path_for, #bypass_forgery_protection?, #chat_enabled?, #cloudflare_cleared?, #default_catalog, #default_url_options, #enable_turbo_frames, #find_publication, #fix_invalid_accept_header, #init_js_utils, #is_globals_call?, #layout_by_resource, #locale_store, #redirect_to, #require_employee_for_crm, #set_base_host, #set_real_ip, #set_report_errors_for, #should_render_layout?, #skip_layout_for_turbo_frame?, #stamp_impersonation_context, #tab_frame_breakout_request?, #warmlyyours_canada_ip?, #warmlyyours_ip?, #y
Methods included from Controllers::ReturnPathHandling
#check_for_return_path, #redirect_to_return_path_or_default
Methods included from Controllers::AnalyticsEvents
#consume_queued_analytics_events, #registration_lead_type, #track_event
Methods included from Controllers::DeviceDetection
Methods included from Controllers::SubdomainDetection
#is_crm_request?, #is_www_request?, #json_request?
Methods included from Controllers::TurboSafeRedirect
Methods included from Controllers::TrackingDetection
#bot_request?, #gdpr_country?, #gdpr_country_data, #prevent_bots, #set_tracking_cookie, #track_visitor?
Methods included from Controllers::AcceleratedFileSending
#send_file_accelerated, #send_upload_accelerated
Methods included from Controllers::ErrorRendering
#excp_string, #mail_to_for_error_reporting, #render_400, #render_404, #render_406, #render_410, #render_500, #render_invalid_authenticity_token, #render_ip_spoof_error, #render_unpermitted_parameters, #safe_referer_or_fallback
Methods included from Controllers::TurnstileVerification
#load_turnstile_script_tag, #turnstile_lazy_widget, #turnstile_script_tag, #turnstile_widget, #validate_turnstile!
Methods included from Controllers::CloudflareCaching
edge_cached, #edge_cached_action?, #reset_cloudflare_cache, #set_cloudflare_cache, #skip_edge_cache!, #skip_session
Methods included from Controllers::Webpackable
#preload_webpack_fonts, #webpack_css_include, #webpack_css_url, #webpack_js_include, #wpd_is_running?
Methods included from Controllers::Localizable
#cloudflare_country_locale, #determine_request_locale, #geocoder_locale, #guest_user_locale_check, #locale_optional_www_auth_path?, #param_locale, #set_locale, #set_request_locale, #skip_localization?, #warmlyyours_ip_locale
Methods included from Controllers::Authenticable
#access_denied, #authenticate_account, #authenticate_account!, #authenticate_account_from_login_token!, #check_is_a_manager, #check_is_a_sales_manager, #check_is_an_admin, #check_is_an_employee, #check_party, #clear_mismatched_guest_user, #create_guest_user, #credentials?, #current_or_guest_user, #current_or_guest_user_id_read_only, #current_user, #devise_mapping, #fully_logged_in?, #generate_bot_id, #guest_user, #identifiable?, #init_current_user, #initialize_guest, #load_context_user, #logging_in, #resource, #resource_name, #restrict_access_for_non_employees, #scrubbed_request_path, #user_object, #warn_on_session_guest_id_leak
Methods included from UrlsHelper
#catalog_breadcrumb_links, #catalog_link, #catalog_link_for_product_line, #catalog_link_for_sku, #cms_link, #delocalized_path, #path_to_sales_product_sku, #path_to_sales_product_sku_for_product_line, #path_to_sales_product_sku_for_product_line_slug, #product_line_from_catalog_link, #protocol_neutral_url, #sanitize_external_url, #valid_external_url?
Instance Method Details
#create_by_order_email ⇒ Object
Actions that originally only flashed + redirected (no mailer)
239 240 |
# File 'app/controllers/www/reviews_controller.rb', line 239 def create_by_order_email = legacy_review_flash_redirect # @return [void] |
#create_from_support_email ⇒ void
This method returns an undefined value.
241 |
# File 'app/controllers/www/reviews_controller.rb', line 241 def create_from_support_email = legacy_review_flash_redirect |
#create_order_item_review ⇒ Object
Actions that originally sent a mailer notification
244 245 |
# File 'app/controllers/www/reviews_controller.rb', line 244 def create_order_item_review = legacy_review_redirect('create_order_item_review') # @return [void] |
#index ⇒ void
This method returns an undefined value.
Paginated, filterable public review index. Serves a keyset-paginated page of
visible Reviews.io records, short-circuiting on a 304 when nothing changed.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/www/reviews_controller.rb', line 28 def index @sort = params[:sort].presence_in(SORT_OPTIONS.keys) || 'newest' @min_rating = params[:min_rating].to_i.clamp(0, 5) scope = build_review_scope begin @pagy, @reviews = pagy(:keyset, scope, page: params[:after].presence, limit: REVIEWS_PER_PAGE) rescue ArgumentError, JSON::ParserError redirect_to url_for(request.query_parameters.except('after')) and return end @next_cursor = @pagy.next # Single cheap query drives both ETag and freshness check. # If the CDN revalidates and nothing has changed we skip all expensive queries. last_touched = ReviewsIo.active.visible.maximum(:updated_at) || 1.year.ago unless stale?(etag: [@reviews.map(&:id), @sort, @min_rating, I18n.locale], last_modified: last_touched, public: true) return end @avatar_urls = Image.avatar_thumbnail_urls(@reviews) @professions = batch_review_professions(@reviews) # Global stats — always for all visible reviews, not filtered @review_avg = ReviewsIo.active.visible.average(:rating)&.round(2) @review_count = ReviewsIo.active.visible.count @review_dist = ReviewsIo.active.visible.group(:rating).count # Filtered count — used to give feedback when star filter is active @matched_count = @min_rating > 0 ? scope.unscope(:order).count : nil # Vary on Accept so HTML and turbo-stream responses get separate cache buckets. response.set_header('Vary', 'Accept') # public_cache_expires_in: 0 lets browsers always revalidate via If-None-Match # (stale? responds with 304 when data is unchanged — skips expensive queries). # Cloudflare edge still caches for 10 min via Cloudflare-CDN-Cache-Control. set_cloudflare_cache( time_in_secs: 10.minutes.to_i, public_cache_expires_in: 0, tags: ['reviews-index'] ) respond_to do |format| format.html { @reviews_schema = build_reviews_schema } format.turbo_stream end end |
#item ⇒ void
This method returns an undefined value.
Renders the per-item review partial. All state comes from +set_catalog+.
90 |
# File 'app/controllers/www/reviews_controller.rb', line 90 def item; end |
#new_order_items_review ⇒ void
This method returns an undefined value.
248 249 |
# File 'app/controllers/www/reviews_controller.rb', line 248 def new_order_items_review = legacy_review_redirect('new_order_items_review') # @return [void] |
#new_order_review ⇒ void
This method returns an undefined value.
246 247 |
# File 'app/controllers/www/reviews_controller.rb', line 246 def new_order_review = legacy_review_redirect('new_order_review') # @return [void] |
#new_support_review ⇒ void
This method returns an undefined value.
250 |
# File 'app/controllers/www/reviews_controller.rb', line 250 def new_support_review = legacy_review_redirect('new_support_review') |
#product_index ⇒ Object
Legacy route: 301 redirects to new hierarchical URL
113 114 115 116 117 118 119 120 |
# File 'app/controllers/www/reviews_controller.rb', line 113 def product_index result = CatalogPathResolver.new.resolve_legacy_product_line(params[:product_line_url], section: :reviews) if result.redirect? redirect_to result.redirect_to, status: :moved_permanently else redirect_to cms_link('/products'), notice: result. || 'Reviews not found.' end end |
#show ⇒ void
This method returns an undefined value.
Legacy per-review page. The individual review view was retired with the move
to Reviews.io, so this only flashes and redirects to the widget index.
81 82 83 84 85 |
# File 'app/controllers/www/reviews_controller.rb', line 81 def show # Legacy review pages - redirect to Reviews.io widget page flash[:info] = 'Our review system has been updated. Please browse our latest reviews below.' redirect_to cms_link('/reviews') end |
#snooze ⇒ void
This method returns an undefined value.
Pushes an order's review reminder out by a month. Reached from a link in the
review-request email, so the order reference arrives encrypted.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/www/reviews_controller.rb', line 96 def snooze if params[:order_reference_number].present? encrypted_order_reference_number = params.delete(:order_reference_number) @order = Order.find_by(reference_number: Encryption.decrypt_string(encrypted_order_reference_number)) if @order.reviewed flash[:info] = 'This order has been reviewed already and it cannot be snoozed.' else @order.update(review_snoozed_until: Date.current + 1.month) flash[:info] = 'We snoozed this review for now. We will send you a new reminder in 30 days.' end else flash[:error] = 'Order # not present. Please make sure you have the correct url.' end redirect_to cms_link('/') end |