diff --git a/app/controllers/accounts/invitations_controller.rb b/app/controllers/accounts/invitations_controller.rb
deleted file mode 100644
index 2c5110b..0000000
--- a/app/controllers/accounts/invitations_controller.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-module Accounts
- class InvitationsController < KiqrController
- def index
- @invitations = current_account.account_invitations.pending
- @account = current_account
- end
-
- def new
- @invitation = current_account.account_invitations.new
- end
-
- def create
- @invitation = current_account.account_invitations.new(invitation_params)
-
- if @invitation.valid?
- Kiqr::Services::Invitations::Create.call!(invitation: @invitation, user: current_user)
- kiqr_flash_message(:notice, :invitation_sent, email: @invitation.email)
- redirect_to invitations_path(account_id: current_account)
- else
- render :new, status: :unprocessable_entity
- end
- end
-
- def destroy
- @invitation = current_account.account_invitations.find_puid!(params[:id])
- @invitation.destroy
- redirect_to invitations_path, notice: t(".deleted")
- end
-
- private
-
- def invitation_params
- params.require(:account_invitation).permit(:email)
- end
- end
-end
diff --git a/app/views/accounts/members/index.html.erb b/app/views/accounts/members/index.html.erb
index 59870e0..c56201b 100644
--- a/app/views/accounts/members/index.html.erb
+++ b/app/views/accounts/members/index.html.erb
@@ -33,7 +33,7 @@
- <%= link_to t(".buttons.invite"), new_invitation_path, class: "button" %>
- <%= link_to t(".buttons.view_pending"), invitations_path, class: "text-primary" %>
+ <%= link_to t(".buttons.invite"), new_account_invitation_path, class: "button" %>
+ <%= link_to t(".buttons.view_pending"), account_invitations_path, class: "text-primary" %>
<% end %>
diff --git a/app/views/accounts/invitations/_form.html.erb b/app/views/kiqr/accounts/invitations/_form.html.erb
similarity index 100%
rename from app/views/accounts/invitations/_form.html.erb
rename to app/views/kiqr/accounts/invitations/_form.html.erb
diff --git a/app/views/accounts/invitations/index.html.erb b/app/views/kiqr/accounts/invitations/index.html.erb
similarity index 78%
rename from app/views/accounts/invitations/index.html.erb
rename to app/views/kiqr/accounts/invitations/index.html.erb
index 9b46699..4290530 100644
--- a/app/views/accounts/invitations/index.html.erb
+++ b/app/views/kiqr/accounts/invitations/index.html.erb
@@ -24,7 +24,7 @@
<%= invitation.email %> |
<%= user_invitation_url(invitation, account_id: nil) %> |
- <%= button_to t(".table.remove"), invitation_path(id: invitation), class: "button xs danger", method: :delete, data: { confirm: t(".confirm_delete", email: invitation.email), turbo_confirm: t(".confirm_delete", email: invitation.email) } %>
+ <%= button_to t(".table.remove"), account_invitation_path(id: invitation), class: "button xs danger", method: :delete, data: { confirm: t(".confirm_delete", email: invitation.email), turbo_confirm: t(".confirm_delete", email: invitation.email) } %>
|
<% end %>
@@ -39,6 +39,6 @@
<%= link_to members_path, class: "button alt" do %>
<%= t(".buttons.back") %>
<% end %>
- <%= link_to t(".buttons.invite"), new_invitation_path, class: "button" %>
+ <%= link_to t(".buttons.invite"), new_account_invitation_path, class: "button" %>
<% end %>
diff --git a/app/views/accounts/invitations/new.html.erb b/app/views/kiqr/accounts/invitations/new.html.erb
similarity index 91%
rename from app/views/accounts/invitations/new.html.erb
rename to app/views/kiqr/accounts/invitations/new.html.erb
index d531a3b..c98e727 100644
--- a/app/views/accounts/invitations/new.html.erb
+++ b/app/views/kiqr/accounts/invitations/new.html.erb
@@ -11,7 +11,7 @@
<%= t(".instructions") %>
- <%= simple_form_for(@invitation, url: invitations_path) do |f| %>
+ <%= simple_form_for(@invitation, url: account_invitations_path) do |f| %>
<%= f.input :email, placeholder: t(".form.email.placeholder"), required: true, autofocus: true %>
<%= f.button :submit, t(".form.submit") %>
diff --git a/app/views/partials/navigations/_settings.html.erb b/app/views/partials/navigations/_settings.html.erb
index 9a7a0ef..a20b8c1 100644
--- a/app/views/partials/navigations/_settings.html.erb
+++ b/app/views/partials/navigations/_settings.html.erb
@@ -16,7 +16,7 @@
description: t('.items.members.description'),
icon: "fa fa-users",
path: members_path,
- active: current_base_path?(members_path) || current_base_path?(invitations_path)
+ active: current_base_path?(members_path) || current_base_path?(account_invitations_path)
)) %>
<% end %>
diff --git a/config/routes/authentication.rb b/config/routes/authentication.rb
index 64a8e3b..418e14b 100644
--- a/config/routes/authentication.rb
+++ b/config/routes/authentication.rb
@@ -21,5 +21,4 @@
scope "(/team/:account_id)", account_id: %r{[^/]+} do
resources :members, controller: "accounts/members", only: [:index, :edit, :update, :destroy]
- resources :invitations, controller: "accounts/invitations", only: [:index, :new, :create, :destroy]
end
diff --git a/gems/kiqr/app/controllers/kiqr/accounts/invitations_controller.rb b/gems/kiqr/app/controllers/kiqr/accounts/invitations_controller.rb
new file mode 100644
index 0000000..e60ffe8
--- /dev/null
+++ b/gems/kiqr/app/controllers/kiqr/accounts/invitations_controller.rb
@@ -0,0 +1,38 @@
+module Kiqr
+ module Accounts
+ class InvitationsController < KiqrController
+ def index
+ @invitations = current_account.account_invitations.pending
+ @account = current_account
+ end
+
+ def new
+ @invitation = current_account.account_invitations.new
+ end
+
+ def create
+ @invitation = current_account.account_invitations.new(invitation_params)
+
+ if @invitation.valid?
+ Kiqr::Services::Invitations::Create.call!(invitation: @invitation, user: current_user)
+ kiqr_flash_message(:notice, :invitation_sent, email: @invitation.email)
+ redirect_to account_invitations_path(account_id: current_account)
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+ def destroy
+ @invitation = current_account.account_invitations.find_puid!(params[:id])
+ @invitation.destroy
+ redirect_to account_invitations_path, notice: t(".deleted")
+ end
+
+ private
+
+ def invitation_params
+ params.require(:account_invitation).permit(:email)
+ end
+ end
+ end
+end
diff --git a/gems/kiqr/lib/kiqr/rails/routes.rb b/gems/kiqr/lib/kiqr/rails/routes.rb
index a08ac59..35f0d7b 100644
--- a/gems/kiqr/lib/kiqr/rails/routes.rb
+++ b/gems/kiqr/lib/kiqr/rails/routes.rb
@@ -7,6 +7,10 @@ def kiqr_routes(options = {})
account_routes(options)
devise_routes(options)
+
+ teamable_scope do
+ resources :account_invitations, controller: "kiqr/accounts/invitations", only: [:index, :new, :create, :destroy]
+ end
end
private
diff --git a/test/controllers/accounts/invitations_controller_test.rb b/test/controllers/accounts/invitations_controller_test.rb
index b995dbf..b5233d8 100644
--- a/test/controllers/accounts/invitations_controller_test.rb
+++ b/test/controllers/accounts/invitations_controller_test.rb
@@ -9,10 +9,10 @@ class Accounts::InvitationsControllerTest < ActionDispatch::IntegrationTest
sign_in user
assert_difference -> { account.account_invitations.count } do
- post invitations_path(account_id: account), params: {account_invitation: {email: "foobar@agag.com"}}
+ post account_invitations_path(account_id: account), params: {account_invitation: {email: "foobar@agag.com"}}
end
- assert_redirected_to invitations_path(account_id: account)
+ assert_redirected_to account_invitations_path(account_id: account)
end
test "can't invite a user to someone else team" do
@@ -25,7 +25,7 @@ class Accounts::InvitationsControllerTest < ActionDispatch::IntegrationTest
sign_in user
assert_raises(PublicUid::RecordNotFound) do
- post invitations_path(account_id: foreign_account), params: {account_invitation: {email: "foobar@agag.com"}}
+ post account_invitations_path(account_id: foreign_account), params: {account_invitation: {email: "foobar@agag.com"}}
end
end
@@ -36,11 +36,11 @@ class Accounts::InvitationsControllerTest < ActionDispatch::IntegrationTest
sign_in user
- post invitations_path(account_id: account), params: {account_invitation: {email: "foobar@foobar.com"}}
- assert_redirected_to invitations_path(account_id: account)
+ post account_invitations_path(account_id: account), params: {account_invitation: {email: "foobar@foobar.com"}}
+ assert_redirected_to account_invitations_path(account_id: account)
assert_no_difference -> { account.account_invitations.count } do
- post invitations_path(account_id: account), params: {account_invitation: {email: "foobar@foobar.com"}}
+ post account_invitations_path(account_id: account), params: {account_invitation: {email: "foobar@foobar.com"}}
end
end
@@ -52,7 +52,7 @@ class Accounts::InvitationsControllerTest < ActionDispatch::IntegrationTest
sign_in user
assert_no_difference -> { account.account_invitations.count } do
- post invitations_path(account_id: account), params: {account_invitation: {email: "foo"}}
+ post account_invitations_path(account_id: account), params: {account_invitation: {email: "foo"}}
end
assert_response :unprocessable_entity