Skip to content

Commit 6a5ec36

Browse files
authored
Merge branch 'main' into codex/update-for-translation-keys-in-pagescontroller
Signed-off-by: Robert Smith <[email protected]>
2 parents af5ef06 + ee1b855 commit 6a5ec36

File tree

53 files changed

+670
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+670
-218
lines changed

.env.prod.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PORT=5000
2424

2525
RACK_ENV=production
2626
RAILS_ENV=production
27-
RAILS_LOG_LEVEL=debug
27+
RAILS_LOG_LEVEL=info
2828
RAILS_LOG_TO_STDOUT=true
2929
RAILS_SERVE_STATIC_FILES=true
3030

.github/workflows/rubyonrails.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
- ruby: '3.4.4'
1414
rails: '7.1.5.1'
1515
allowed_failure: false # ✅ required
16-
# - ruby: '3.4.4'
17-
# rails: '7.2'
18-
# allowed_failure: true # ⚠️ allowed to fail
1916
- ruby: '3.4.4'
20-
rails: '8.0'
17+
rails: '7.2.2.1'
18+
allowed_failure: false # ⚠️ allowed to fail
19+
- ruby: '3.4.4'
20+
rails: '8.0.2'
2121
allowed_failure: true # ⚠️ allowed to fail
2222

2323
env:

app/controllers/better_together/application_controller.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class ApplicationController < ActionController::Base # rubocop:todo Metrics/Clas
99

1010
protect_from_forgery with: :exception
1111

12+
layout :determine_layout
13+
1214
before_action :check_platform_setup
1315
before_action :set_locale
1416
before_action :store_user_location!, if: :storable_location?
@@ -23,12 +25,13 @@ class ApplicationController < ActionController::Base # rubocop:todo Metrics/Clas
2325
Rack::MiniProfiler.authorize_request if current_user&.permitted_to?('manage_platform')
2426
end
2527

26-
rescue_from ActiveRecord::RecordNotFound, with: :handle404
27-
rescue_from ActionController::RoutingError, with: :handle404
28+
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
29+
rescue_from ActionController::RoutingError, with: :render_not_found
2830
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
2931
rescue_from StandardError, with: :handle_error
3032

31-
helper_method :current_invitation, :default_url_options, :valid_platform_invitation_token_present?
33+
helper_method :current_invitation, :default_url_options, :valid_platform_invitation_token_present?,
34+
:turbo_native_app?
3235

3336
def self.default_url_options
3437
super.merge(locale: I18n.locale)
@@ -126,11 +129,7 @@ def valid_platform_invitation_token_present?
126129

127130
private
128131

129-
def handle404
130-
render_404
131-
end
132-
133-
def render_404 # rubocop:todo Naming/VariableNumber
132+
def render_not_found
134133
render 'errors/404', status: :not_found
135134
end
136135

@@ -254,5 +253,13 @@ def metric_viewable_type
254253
def metric_viewable_id
255254
metric_viewable&.id
256255
end
256+
257+
def determine_layout
258+
turbo_native_app? ? 'better_together/turbo_native' : 'better_together/application'
259+
end
260+
261+
def turbo_native_app?
262+
request.user_agent.to_s.include?('Turbo Native')
263+
end
257264
end
258265
end

app/controllers/better_together/conversations_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def new
2020
authorize @conversation
2121
end
2222

23-
def create # rubocop:todo Metrics/MethodLength
23+
def create # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
2424
@conversation = Conversation.new(conversation_params.merge(creator: helpers.current_person))
2525

2626
authorize @conversation
@@ -33,7 +33,12 @@ def create # rubocop:todo Metrics/MethodLength
3333
format.html { redirect_to @conversation }
3434
end
3535
else
36-
render :new
36+
respond_to do |format|
37+
format.turbo_stream do
38+
render :create_error, status: :unprocessable_entity
39+
end
40+
format.html { render :new, status: :unprocessable_entity }
41+
end
3742
end
3843
end
3944

app/controllers/better_together/friendly_resource_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def set_resource_instance
2323
# 2. By friendly on all available locales
2424
@resource ||= find_by_translatable
2525

26-
handle404 && return if @resource.nil?
26+
render_not_found && return if @resource.nil?
2727

2828
@resource
2929
end

app/controllers/better_together/metrics/link_click_reports_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
4141

4242
respond_to do |format| # rubocop:todo Metrics/BlockLength
4343
if @link_click_report.persisted?
44-
flash[:notice] = 'Report was successfully created.'
44+
flash[:notice] = t('flash.generic.created', resource: t('resources.report'))
4545
format.html { redirect_to metrics_link_click_reports_path, notice: flash[:notice] }
4646
format.turbo_stream do
4747
render turbo_stream: [
@@ -55,7 +55,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5555
]
5656
end
5757
else
58-
flash.now[:alert] = 'Error creating report.'
58+
flash.now[:alert] = t('flash.generic.error_create', resource: t('resources.report'))
5959
format.html { render :new, status: :unprocessable_entity }
6060
format.turbo_stream do
6161
render turbo_stream: [

app/controllers/better_together/metrics/page_view_reports_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
3939

4040
respond_to do |format| # rubocop:todo Metrics/BlockLength
4141
if @page_view_report.persisted?
42-
flash[:notice] = 'Report was successfully created.'
42+
flash[:notice] = t('flash.generic.created', resource: t('resources.report'))
4343
format.html { redirect_to metrics_page_view_reports_path, notice: flash[:notice] }
4444
format.turbo_stream do
4545
render turbo_stream: [
@@ -55,7 +55,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5555
]
5656
end
5757
else
58-
flash.now[:alert] = 'Error creating report.'
58+
flash.now[:alert] = t('flash.generic.error_create', resource: t('resources.report'))
5959
format.html { render :new, status: :unprocessable_entity }
6060
format.turbo_stream do
6161
render turbo_stream: [

app/controllers/better_together/navigation_items_controller.rb

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,30 @@ def edit
3232
authorize @navigation_item
3333
end
3434

35-
def create
35+
def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
3636
@navigation_item = new_navigation_item
3737
@navigation_item.assign_attributes(navigation_item_params)
3838
authorize @navigation_item
39-
40-
if @navigation_item.save
41-
redirect_to @navigation_area, only_path: true, notice: 'Navigation item was successfully created.'
42-
else
43-
render :new
39+
respond_to do |format|
40+
if @navigation_item.save
41+
flash.now[:notice] = 'Navigation item was successfully created.'
42+
format.html do
43+
redirect_to @navigation_area, only_path: true,
44+
notice: 'Navigation item was successfully created.'
45+
end
46+
format.turbo_stream { render :create }
47+
else
48+
format.html { render :new, status: :unprocessable_entity }
49+
format.turbo_stream do
50+
render turbo_stream: [
51+
turbo_stream.update('form_errors', partial: 'layouts/better_together/errors',
52+
locals: { object: @navigation_item }),
53+
turbo_stream.update('navigation_item_form', partial: 'better_together/navigation_items/form',
54+
locals: { navigation_item: @navigation_item,
55+
navigation_area: @navigation_area })
56+
]
57+
end
58+
end
4459
end
4560
end
4661

@@ -74,8 +89,15 @@ def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
7489
def destroy
7590
authorize @navigation_item
7691
@navigation_item.destroy
77-
redirect_to navigation_area_navigation_items_url(@navigation_area),
78-
notice: 'Navigation item was successfully destroyed.'
92+
flash.now[:notice] = 'Navigation item was successfully destroyed.'
93+
94+
respond_to do |format|
95+
format.html do
96+
redirect_to navigation_area_navigation_items_url(@navigation_area),
97+
notice: 'Navigation item was successfully destroyed.'
98+
end
99+
format.turbo_stream { render :destroy }
100+
end
79101
end
80102

81103
private

app/controllers/better_together/pages_controller.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def index
1717

1818
def show
1919
if @page.nil? || !@page.published?
20-
render_404
20+
render_not_found
2121
else
2222
authorize @page
2323
@content_blocks = @page.content_blocks
@@ -37,7 +37,7 @@ def create
3737
authorize @page
3838

3939
if @page.save
40-
redirect_to edit_page_path(@page), notice: t('pages.created')
40+
redirect_to edit_page_path(@page), notice: t('flash.generic.created', resource: t('resources.page'))
4141
else
4242
render :new
4343
end
@@ -53,11 +53,11 @@ def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5353
respond_to do |format|
5454
if @page.update(page_params)
5555
format.html do
56-
flash[:notice] = t('pages.updated')
57-
redirect_to edit_page_path(@page), notice: t('pages.updated')
56+
flash[:notice] = t('flash.generic.updated', resource: t('resources.page'))
57+
redirect_to edit_page_path(@page), notice: t('flash.generic.updated', resource: t('resources.page'))
5858
end
5959
format.turbo_stream do
60-
flash.now[:notice] = t('pages.updated')
60+
flash.now[:notice] = t('flash.generic.updated', resource: t('resources.page'))
6161
render turbo_stream: [
6262
turbo_stream.replace(helpers.dom_id(@page, 'form'), partial: 'form',
6363
locals: { page: @page }),
@@ -77,7 +77,7 @@ def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
7777
def destroy
7878
authorize @page
7979
@page.destroy
80-
redirect_to pages_url, notice: t('pages.destroyed')
80+
redirect_to pages_url, notice: t('flash.generic.destroyed', resource: t('resources.page'))
8181
end
8282

8383
protected
@@ -95,14 +95,14 @@ def id_param
9595

9696
private
9797

98-
def handle404
98+
def render_not_found
9999
path = params[:path]
100100

101101
# If page is not found and the path is one of the variants of the root path, render community engine promo page
102102
if ['home-page', 'home', "/#{I18n.locale}/", "/#{I18n.locale}", I18n.locale.to_s, 'bt', '/'].include?(path)
103103
render 'better_together/static_pages/community_engine'
104104
else
105-
render_404
105+
super
106106
end
107107
end
108108

@@ -122,7 +122,7 @@ def safe_page_redirect_url
122122
def set_page
123123
@page = set_resource_instance
124124
rescue ActiveRecord::RecordNotFound
125-
handle404
125+
render_not_found && return
126126
end
127127

128128
def page_params # rubocop:todo Metrics/MethodLength

app/controllers/better_together/person_community_memberships_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
1313

1414
respond_to do |format|
1515
if @person_community_membership.save
16-
flash[:notice] = 'Member was successfully added.'
16+
flash[:notice] = t('flash.generic.created', resource: t('resources.member'))
1717
format.html { redirect_to @community, notice: flash[:notice] }
1818
format.turbo_stream do
1919
render turbo_stream: [
@@ -26,7 +26,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
2626
]
2727
end
2828
else
29-
flash.now[:alert] = 'Error adding member.'
29+
flash.now[:alert] = t('flash.generic.error_create', resource: t('resources.member'))
3030
format.html { redirect_to @community, alert: @person_community_membership.errors.full_messages.to_sentence }
3131
format.turbo_stream do
3232
render turbo_stream: [
@@ -44,7 +44,7 @@ def destroy # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
4444
authorize @person_community_membership
4545

4646
if @person_community_membership.destroy
47-
flash.now[:notice] = 'Member was successfully removed.'
47+
flash.now[:notice] = t('flash.generic.removed', resource: t('resources.member'))
4848
respond_to do |format|
4949
format.html { redirect_to @community }
5050
format.turbo_stream do
@@ -56,7 +56,7 @@ def destroy # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
5656
end
5757
end
5858
else
59-
flash.now[:error] = 'Failed to remove member.'
59+
flash.now[:error] = t('flash.generic.error_remove', resource: t('resources.member'))
6060
respond_to do |format|
6161
format.html { redirect_to @community, alert: flash.now[:error] }
6262
format.turbo_stream do

0 commit comments

Comments
 (0)