diff --git a/app/controllers/join_codes_controller.rb b/app/controllers/join_codes_controller.rb index 6d790c232..863522893 100644 --- a/app/controllers/join_codes_controller.rb +++ b/app/controllers/join_codes_controller.rb @@ -29,10 +29,14 @@ class JoinCodesController < ApplicationController private def set_join_code - @join_code ||= Account::JoinCode.active.find_by(code: params.expect(:code), account: Current.account) + @join_code ||= Account::JoinCode.find_by(code: params.expect(:code), account: Current.account) end def ensure_join_code_is_valid - head :not_found unless @join_code&.active? + if @join_code.nil? + head :not_found + elsif !@join_code.active? + render :inactive, status: :gone + end end end diff --git a/app/views/join_codes/inactive.html.erb b/app/views/join_codes/inactive.html.erb new file mode 100644 index 000000000..1bddb6e42 --- /dev/null +++ b/app/views/join_codes/inactive.html.erb @@ -0,0 +1,15 @@ +<% @page_title = "You can't join #{@join_code.account.name} right now." %> + +
+

<%= @page_title %>

+ +

This join code has no invitations left on it.

+ +

+ <%= link_to "Check out Fizzy", "https://www.fizzy.do" %>. +

+
+ +<% content_for :footer do %> + <%= render "sessions/footer" %> +<% end %> diff --git a/test/controllers/join_codes_controller_test.rb b/test/controllers/join_codes_controller_test.rb index 173e3b5d2..de126abd8 100644 --- a/test/controllers/join_codes_controller_test.rb +++ b/test/controllers/join_codes_controller_test.rb @@ -24,7 +24,8 @@ class JoinCodesControllerTest < ActionDispatch::IntegrationTest get join_path(code: @join_code.code, script_name: @account.slug) - assert_response :not_found + assert_response :gone + assert_in_body "This join code has no invitations left on it" end test "create" do