Skip to content

Commit 172db83

Browse files
allow users to accept invitations
1 parent 3308e02 commit 172db83

File tree

9 files changed

+32
-45
lines changed

9 files changed

+32
-45
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
class ApplicationController < ActionController::Base
2-
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
3-
# allow_browser versions: :modern
42
end

app/rodauth/hacker_rodauth_plugin.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ class HackerRodauthPlugin < RodauthPlugin
181181
redirect "/hacker_dashboard"
182182
end
183183

184+
# Redirect to home after login.
185+
create_account_redirect "/hacker_dashboard"
186+
184187
# Redirect to home after login.
185188
login_redirect "/hacker_dashboard"
186189

packages/hackathon/app/models/hackathon/invitation.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def send_invitation
4646
invited! if pending?
4747
end
4848

49+
def usable?
50+
!accepted? && !declined?
51+
end
52+
4953
private
5054

5155
def generate_token

packages/hacker_dashboard_portal/app/controllers/hacker_dashboard_portal/concerns/controller.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Controller
1111
before_action :ensure_profile_completed
1212
before_action :ensure_emergency_contact_exists
1313
before_action :ensure_joined_team
14+
before_action :check_pending_invitation
1415
end
1516

1617
private
@@ -40,6 +41,25 @@ def ensure_emergency_contact_exists
4041
redirect_to resource_url_for(::Hackathon::HealthAndSafety, action: :new)
4142
end
4243
end
44+
45+
def current_invitation
46+
return unless cookies.encrypted[:invite_token]
47+
48+
@invitation ||= ::Hackathon::Invitation.find_by(
49+
token: cookies.encrypted[:invite_token]
50+
)
51+
end
52+
53+
# Complete team membership for invited hacker by allowing them select
54+
# their role in the team.
55+
def check_pending_invitation
56+
return unless current_invitation&.usable?
57+
58+
redirect_to resource_url_for(
59+
::Hackathon::TeamMembership, action: :new,
60+
parent: current_invitation.team
61+
)
62+
end
4363
end
4464
end
4565
end

packages/hacker_dashboard_portal/app/controllers/hacker_dashboard_portal/hackathon/health_and_safeties_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class HackerDashboardPortal::Hackathon::HealthAndSafetiesController < ::Hackatho
33

44
skip_before_action :ensure_emergency_contact_exists, only: [:new, :create]
55
skip_before_action :ensure_joined_team, only: [:new, :create]
6+
skip_before_action :check_pending_invitation, only: [:new, :create]
67

78
layout :resolve_layout
89

packages/hacker_dashboard_portal/app/controllers/hacker_dashboard_portal/hackathon/team_memberships_controller.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ class HackerDashboardPortal::Hackathon::TeamMembershipsController < ::Hackathon:
44
authorize :invitation, through: :current_invitation
55

66
skip_before_action :ensure_joined_team, only: [:new, :create]
7-
after_action :cleanup_invitation, only: [:create]
7+
skip_before_action :check_pending_invitation, only: [:new, :create]
88

99
def present_scoped_entity? = true
1010

11-
def set_page_title(title)
12-
if title == "Create #{resource_class.model_name.human.titleize}"
13-
super("Join #{current_parent.name}")
14-
else
15-
super
16-
end
17-
end
18-
1911
private
2012

2113
def resource_params
@@ -26,18 +18,6 @@ def resource_params
2618
end
2719
end
2820

29-
def current_invitation
30-
return unless cookies.encrypted[:invite_token]
31-
32-
@invitation ||= ::Hackathon::Invitation.find_by(
33-
token: cookies.encrypted[:invite_token]
34-
)
35-
end
36-
37-
def cleanup_invitation
38-
cookies.delete(:invite_token)
39-
end
40-
4121
def redirect_url_after_submit
4222
if (return_to = url_from(params[:return_to]))
4323
return return_to

packages/hacker_dashboard_portal/app/controllers/hacker_dashboard_portal/hackathon/teams_controller.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ class HackerDashboardPortal::Hackathon::TeamsController < ::Hackathon::TeamsCont
22
include HackerDashboardPortal::Concerns::Controller
33

44
skip_before_action :ensure_joined_team, only: [:new, :create]
5-
before_action :check_invitation, only: [:new, :create]
65

76
def present_scoped_entity? = true
87

@@ -16,25 +15,4 @@ def new
1615

1716
super
1817
end
19-
20-
private
21-
22-
# Complete team membership for invited hacker by allowing them select
23-
# their role in the team.
24-
def check_invitation
25-
return unless current_invitation
26-
27-
redirect_to resource_url_for(
28-
::Hackathon::TeamMembership, action: :new,
29-
parent: current_invitation.team
30-
)
31-
end
32-
33-
def current_invitation
34-
return unless cookies.encrypted[:invite_token]
35-
36-
@invitation ||= ::Hackathon::Invitation.find_by(
37-
token: cookies.encrypted[:invite_token]
38-
)
39-
end
4018
end

packages/hacker_dashboard_portal/app/controllers/hacker_dashboard_portal/profiles_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class HackerDashboardPortal::ProfilesController < ::ProfilesController
55
skip_before_action :ensure_profile_completed, only: [:edit, :update]
66
skip_before_action :ensure_emergency_contact_exists, only: [:new, :create]
77
skip_before_action :ensure_joined_team, only: [:new, :create]
8+
skip_before_action :check_pending_invitation, only: [:new, :create]
89

910
def new
1011
authorize_current! resource_class

packages/hacker_dashboard_portal/app/definitions/hacker_dashboard_portal/hackathon/team_membership_definition.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class HackerDashboardPortal::Hackathon::TeamMembershipDefinition < ::Hackathon::
44
new_page_title -> {
55
render_title "Join #{current_parent.name}"
66
}
7+
new_page_description "Select your role on the team to complete your invitation"
8+
79
edit_page_title "Update Membership Role"
810

911
new_page_breadcrumbs false

0 commit comments

Comments
 (0)