Skip to content

Commit 0d9213f

Browse files
authored
Merge branch 'main' into enhancement/platform-setup-wizard
2 parents c5d2990 + 614d5c2 commit 0d9213f

31 files changed

+1242
-128
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ group :development, :test do
6262
# Fuubar for fancy test progress bar
6363
gem 'fuubar'
6464
# Help with managing translation databasde
65-
gem 'i18n-tasks', '~> 1.0.12'
65+
gem 'i18n-tasks', '~> 1.0.15'
6666
# Pry for a powerful shell alternative to IRB
6767
gem 'pry'
6868
# RuboCop for static code analysis

Gemfile.lock

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ GIT
1919
PATH
2020
remote: .
2121
specs:
22-
better_together (0.6.0)
22+
better_together (0.7.1)
2323
active_storage_svg_sanitizer
2424
active_storage_validations
2525
activerecord-import
@@ -256,8 +256,9 @@ GEM
256256
railties (>= 4.1.0)
257257
responders
258258
warden (~> 1.2.3)
259-
devise-i18n (1.12.1)
259+
devise-i18n (1.13.0)
260260
devise (>= 4.9.0)
261+
rails-i18n
261262
devise-jwt (0.12.1)
262263
devise (~> 4.0)
263264
warden-jwt_auth (~> 0.10)
@@ -343,18 +344,18 @@ GEM
343344
ruby-progressbar (~> 1.4)
344345
globalid (1.2.1)
345346
activesupport (>= 6.1)
346-
google-protobuf (4.29.3-x86_64-linux)
347+
google-protobuf (4.30.0-x86_64-linux)
347348
bigdecimal
348349
rake (>= 13)
349350
groupdate (6.5.1)
350351
activesupport (>= 7)
351352
hashie (5.0.0)
352-
highline (3.1.0)
353+
highline (3.1.2)
353354
reline
354355
htmlentities (4.3.4)
355356
i18n (1.14.7)
356357
concurrent-ruby (~> 1.0)
357-
i18n-tasks (1.0.14)
358+
i18n-tasks (1.0.15)
358359
activesupport (>= 4.0.2)
359360
ast (>= 2.1.0)
360361
erubi
@@ -363,6 +364,7 @@ GEM
363364
parser (>= 3.2.2.1)
364365
rails-i18n
365366
rainbow (>= 2.2.2, < 4.0)
367+
ruby-progressbar (~> 1.8, >= 1.8.1)
366368
terminal-table (>= 1.5.1)
367369
i18n-timezones (1.4.8)
368370
i18n (>= 0.9.3)
@@ -384,7 +386,7 @@ GEM
384386
rdoc (>= 4.0.0)
385387
reline (>= 0.4.2)
386388
jmespath (1.6.2)
387-
json (2.10.1)
389+
json (2.10.2)
388390
json-schema (5.1.1)
389391
addressable (~> 2.8)
390392
bigdecimal (~> 3.1)
@@ -420,7 +422,7 @@ GEM
420422
logger
421423
mime-types-data (~> 3.2015)
422424
mime-types-data (3.2025.0107)
423-
mini_magick (5.1.2)
425+
mini_magick (5.2.0)
424426
benchmark
425427
logger
426428
mini_mime (1.1.5)
@@ -444,7 +446,7 @@ GEM
444446
net-protocol
445447
net-protocol (0.2.2)
446448
timeout
447-
net-smtp (0.5.0)
449+
net-smtp (0.5.1)
448450
net-protocol
449451
nio4r (2.7.4)
450452
nokogiri (1.18.3-x86_64-linux-gnu)
@@ -482,7 +484,7 @@ GEM
482484
pundit (2.5.0)
483485
activesupport (>= 3.0.0)
484486
racc (1.8.1)
485-
rack (3.1.11)
487+
rack (3.1.12)
486488
rack-cors (2.0.2)
487489
rack (>= 2.0.0)
488490
rack-mini-profiler (3.3.1)
@@ -519,7 +521,7 @@ GEM
519521
rails-html-sanitizer (1.6.2)
520522
loofah (~> 2.21)
521523
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
522-
rails-i18n (7.0.9)
524+
rails-i18n (7.0.10)
523525
i18n (>= 0.7, < 2)
524526
railties (>= 6.0.0, < 8)
525527
railties (7.1.5.1)
@@ -607,7 +609,7 @@ GEM
607609
rswag-ui (2.16.0)
608610
actionpack (>= 5.2, < 8.1)
609611
railties (>= 5.2, < 8.1)
610-
rubocop (1.73.2)
612+
rubocop (1.74.0)
611613
json (~> 2.3)
612614
language_server-protocol (~> 3.17.0.2)
613615
lint_roller (~> 1.1.0)
@@ -632,11 +634,11 @@ GEM
632634
ffi (~> 1.12)
633635
logger
634636
rubyzip (2.4.1)
635-
sass-embedded (1.83.4-x86_64-linux-gnu)
637+
sass-embedded (1.85.1-x86_64-linux-gnu)
636638
google-protobuf (~> 4.29)
637639
sassc (2.4.0)
638640
ffi (~> 1.9)
639-
sassc-embedded (1.80.1)
641+
sassc-embedded (1.80.4)
640642
sass-embedded (~> 1.80)
641643
securerandom (0.4.1)
642644
selenium-webdriver (4.29.1)
@@ -645,10 +647,10 @@ GEM
645647
rexml (~> 3.2, >= 3.2.5)
646648
rubyzip (>= 1.2.2, < 3.0)
647649
websocket (~> 1.0)
648-
sentry-rails (5.22.4)
650+
sentry-rails (5.23.0)
649651
railties (>= 5.0)
650-
sentry-ruby (~> 5.22.4)
651-
sentry-ruby (5.22.4)
652+
sentry-ruby (~> 5.23.0)
653+
sentry-ruby (5.23.0)
652654
bigdecimal
653655
concurrent-ruby (~> 1.0, >= 1.0.2)
654656
shoulda-callback-matchers (1.1.4)
@@ -667,7 +669,7 @@ GEM
667669
simplecov_json_formatter (~> 0.1)
668670
simplecov-html (0.12.3)
669671
simplecov_json_formatter (0.1.4)
670-
spring (4.2.1)
672+
spring (4.3.0)
671673
spring-watcher-listen (2.1.0)
672674
listen (>= 2.7, < 4.0)
673675
spring (>= 4)
@@ -685,8 +687,8 @@ GEM
685687
sync (0.5.0)
686688
term-ansicolor (1.11.2)
687689
tins (~> 1.0)
688-
terminal-table (3.0.2)
689-
unicode-display_width (>= 1.1.1, < 3)
690+
terminal-table (4.0.0)
691+
unicode-display_width (>= 1.1.1, < 4)
690692
thor (1.3.2)
691693
thread (0.2.2)
692694
thread_safe (0.3.6)
@@ -707,7 +709,9 @@ GEM
707709
uglifier (4.2.1)
708710
execjs (>= 0.3.0, < 3)
709711
unf (0.2.0)
710-
unicode-display_width (2.6.0)
712+
unicode-display_width (3.1.4)
713+
unicode-emoji (~> 4.0, >= 4.0.4)
714+
unicode-emoji (4.0.4)
711715
uri (1.0.3)
712716
virtus (2.0.0)
713717
axiom-types (~> 0.1)
@@ -758,7 +762,7 @@ DEPENDENCIES
758762
faker
759763
fog-aws
760764
fuubar
761-
i18n-tasks (~> 1.0.12)
765+
i18n-tasks (~> 1.0.15)
762766
i18n_generators
763767
listen (>= 3.0.5, < 3.10)
764768
pg (>= 0.18, < 2.0)

app/controllers/better_together/application_controller.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ApplicationController < ActionController::Base # rubocop:todo Metrics/Clas
2626
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
2727
rescue_from StandardError, with: :handle_error
2828

29-
helper_method :default_url_options, :valid_platform_invitation_token_present?
29+
helper_method :current_invitation, :default_url_options, :valid_platform_invitation_token_present?
3030

3131
def self.default_url_options
3232
super.merge(locale: I18n.locale)
@@ -72,29 +72,33 @@ def set_platform_invitation # rubocop:todo Metrics/CyclomaticComplexity, Metrics
7272
return
7373
end
7474

75-
if params[:invitation_code].present?
76-
# On first visit with the invitation code, update the session with the token and a new expiry.
77-
token = params[:invitation_code]
78-
session[:platform_invitation_token] = token
79-
session[:platform_invitation_expires_at] ||= Time.current + platform_invitation_expiry_time
80-
else
81-
# If no params, simply use the token stored in the session.
82-
token = session[:platform_invitation_token]
83-
end
75+
token = if params[:invitation_code].present?
76+
# On first visit with the invitation code, update the session with the token and a new expiry.
77+
session[:platform_invitation_token] = params[:invitation_code]
78+
else
79+
# If no params, simply use the token stored in the session.
80+
session[:platform_invitation_token]
81+
end
8482

8583
return unless token.present?
8684

8785
@platform_invitation = ::BetterTogether::PlatformInvitation.pending.find_by(token: token)
8886

89-
return if @platform_invitation
90-
91-
session.delete(:platform_invitation_token)
92-
session.delete(:platform_invitation_expires_at)
87+
if @platform_invitation
88+
session[:platform_invitation_expires_at] ||= Time.current + @platform_invitation.session_duration_mins.minutes
89+
else
90+
session.delete(:platform_invitation_token)
91+
session.delete(:platform_invitation_expires_at)
92+
end
9393
end
9494
# rubocop:enable Metrics/AbcSize
9595
# rubocop:enable Metrics/MethodLength
9696
# rubocop:enable Metrics/PerceivedComplexity
9797

98+
def current_invitation
99+
@platform_invitation
100+
end
101+
98102
def check_platform_privacy
99103
return if helpers.host_platform.privacy_public?
100104
return if current_user

app/controllers/better_together/platform_invitations_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def set_platform_invitation
113113
end
114114

115115
def platform_invitation_params
116-
params.require(:platform_invitation).permit(:invitee_email, :platform_role_id, :community_role_id, :locale)
116+
params.require(:platform_invitation).permit(
117+
:invitee_email, :platform_role_id, :community_role_id, :locale,
118+
:valid_from, :valid_until, :greeting, :type, :session_duration_mins
119+
)
117120
end
118121
end
119122
end

app/controllers/better_together/platforms_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ class PlatformsController < FriendlyResourceController # rubocop:todo Style/Docu
66
before_action :authorize_platform, only: %i[show edit update destroy]
77
after_action :verify_authorized, except: :index
88

9+
before_action only: %i[show], if: -> { Rails.env.development? } do
10+
# Make sure that all Platform Invitation subclasses are loaded in dev to generate new block buttons
11+
::BetterTogether::PlatformInvitation.load_all_subclasses
12+
end
13+
914
# GET /platforms
1015
def index
1116
# @platforms = ::BetterTogether::Platform.all

app/helpers/better_together/form_helper.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,39 @@ def required_label(form_or_object, field, **options) # rubocop:todo Metrics/AbcS
9999
# rubocop:enable Metrics/MethodLength
100100

101101
# rubocop:todo Metrics/MethodLength
102-
def type_select_field(form:, model_class:, selected_type: nil, include_blank: true, **options)
102+
# rubocop:todo Metrics/PerceivedComplexity
103+
# rubocop:todo Metrics/AbcSize
104+
# rubocop:todo Metrics/ParameterLists
105+
def type_select_field(form:, model_class:, selected_type: nil, include_model_class: false, include_blank: true,
106+
**options)
107+
# rubocop:enable Metrics/ParameterLists
103108
# Determine if the model is persisted
104109
disabled = form&.object&.persisted? || false
105110

106111
options = {
107-
**options,
108112
required: true,
109113
class: 'form-select',
110-
disabled: # Disable if the model is persisted
114+
disabled:, # Disable if the model is persisted
115+
**options
111116
}
112117

113118
descendants = model_class.descendants.map { |descendant| [descendant.model_name.human, descendant.name] }
114119

120+
dropdown_values = if include_model_class
121+
[[model_class.model_name.human, model_class.name]] + descendants
122+
else
123+
descendants
124+
end
125+
115126
if form
116-
form.select :type, options_for_select(descendants, form.object.type), { include_blank: }, options
127+
form.select :type, options_for_select(dropdown_values, form.object.type), { include_blank: }, options
117128
else
118-
select_tag 'type', options_for_select(descendants, selected_type),
129+
select_tag 'type', options_for_select(dropdown_values, selected_type),
119130
{ include_blank: }.merge(options)
120131
end
121132
end
133+
# rubocop:enable Metrics/AbcSize
134+
# rubocop:enable Metrics/PerceivedComplexity
122135
# rubocop:enable Metrics/MethodLength
123136
end
124137
end

app/mailers/better_together/platform_invitation_mailer.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
module BetterTogether
66
# Sends the email to the recipient to accept or decline their invitation to the platform
77
class PlatformInvitationMailer < ApplicationMailer
8-
def invite(platform_invitation)
8+
def invite(platform_invitation) # rubocop:todo Metrics/MethodLength
99
@platform_invitation = platform_invitation
1010
@platform = platform_invitation.invitable
1111

1212
# Override time zone and locale if necessary
1313
self.locale = platform_invitation.locale
1414

1515
@invitee_email = @platform_invitation.invitee_email
16+
return if @invitee_email.blank?
17+
18+
@greeting = @platform_invitation.greeting
1619
@valid_from = @platform_invitation.valid_from
1720
@valid_until = @platform_invitation.valid_until
1821

19-
@invitation_url = better_together.new_user_registration_url(invitation_code: @platform_invitation.token)
22+
@invitation_url = @platform_invitation.url
2023

2124
mail(to: @invitee_email,
2225
subject: I18n.t('better_together.platform_invitation_mailer.invite.subject',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
module BetterTogether
4+
# Allows for platform managers to allow guest access to the platform
5+
class GuestAccess < PlatformInvitation
6+
def self.model_name
7+
ActiveModel::Name.new(self)
8+
end
9+
10+
def registers_user?
11+
false
12+
end
13+
14+
def url
15+
BetterTogether::Engine.routes.url_helpers.home_page_url(invitation_code: token, locale:)
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)