Skip to content

Commit 17897bf

Browse files
committed
Set admin user as creator of host community during host platform setup wizard step.
Assign retrieved records to instance variables inside helper methods to allow modifying them without assigning to a local variable after calling the helper.
1 parent 2fa65a7 commit 17897bf

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

app/controllers/better_together/setup_wizard_steps_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@ def create_admin # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
7878
member: user.person,
7979
role: ::BetterTogether::Role.find_by(identifier: 'platform_manager')
8080
)
81+
82+
# TODO: This should be moved into a separate method somewhere
8183
helpers.host_community.person_community_memberships.create!(
8284
member: user.person,
8385
role: ::BetterTogether::Role.find_by(identifier: 'community_governance_council')
8486
)
87+
helpers.host_community.creator = user.person
88+
helpers.host_community.save!
89+
8590
# If Devise's :confirmable is enabled, this will send a confirmation email
8691
user.send_confirmation_instructions(confirmation_url: user_confirmation_path)
8792
mark_current_step_as_completed

app/helpers/better_together/application_helper.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,35 @@ def base_path_with_locale
2323
# Returns the current active identity for the user.
2424
# This is a placeholder and should be updated to support active identity features.
2525
def current_identity
26-
current_person
26+
@current_identity ||= current_person
2727
end
2828

2929
# Retrieves the current person associated with the signed-in user.
3030
# Returns nil if no user is signed in or the user has no associated person.
3131
def current_person
3232
return unless user_signed_in? && current_user.person
3333

34-
current_user.person
34+
@current_person ||= current_user.person
3535
end
3636

3737
# Finds the platform marked as host or returns a new default host platform instance.
3838
# This method ensures there is always a host platform available, even if not set in the database.
3939
def host_platform
40-
::BetterTogether::Platform.find_by(host: true) ||
41-
::BetterTogether::Platform.new(name: 'Better Together Community Engine', url: base_url)
40+
@host_platform ||= ::BetterTogether::Platform.find_by(host: true) ||
41+
::BetterTogether::Platform.new(name: 'Better Together Community Engine', url: base_url)
4242
end
4343

4444
# Finds the community marked as host or returns a new default host community instance.
4545
def host_community
46-
::BetterTogether::Community.find_by(host: true) ||
47-
::BetterTogether::Community.new(name: 'Better Together')
46+
@host_community ||= ::BetterTogether::Community.find_by(host: true) ||
47+
::BetterTogether::Community.new(name: 'Better Together')
4848
end
4949

5050
# Retrieves the setup wizard for hosts or raises an error if not found.
5151
# This is crucial for initial setup processes and should be pre-configured.
5252
def host_setup_wizard
53-
::BetterTogether::Wizard.find_by(identifier: 'host_setup') ||
54-
raise(StandardError, 'Host Setup Wizard not configured. Please run rails db:seed')
53+
@host_setup_wizard ||= ::BetterTogether::Wizard.find_by(identifier: 'host_setup') ||
54+
raise(StandardError, 'Host Setup Wizard not configured. Please run rails db:seed')
5555
end
5656

5757
# Handles missing method calls for route helpers related to BetterTogether.

0 commit comments

Comments
 (0)