- <%= form_for(User.new, url: admin_invitations_path) do |f| %>
-
- <%= f.label "Email:" %>
- <%= f.text_field :email, required: true, class: "form-control", placeholder: "Email of invitee" %>
- <%= f.label "Name:" %>
- <%= f.text_field :name, required: true, class: "form-control", placeholder: "Name of invitee" %>
+<% smtp_enabled = ForemInstance.smtp_enabled? %>
+
+<% unless smtp_enabled %>
+
+
+
Setup SMTP to invite users
+
+ SMTP settings are required so that your Forem can send emails.
+ If you wish to send invites, email digests and activity notifications you will need to
+ specify which email host will relay those messages for you. You can
+
read more about SMTP Settings in our admin guide.
- <%= f.submit class: "btn btn-primary" %>
- <% end %>
+
+ Please note that you will need to reload this page after configuring your SMTP Settings.
+
+
+ <%= link_to "Configure your SMTP Settings here.", admin_config_path(anchor: "smtp-section"), target: "_blank", rel: :noopener %>
+
+
-
+<% end %>
+
+<% if smtp_enabled %>
+
Invite Users
+ <%= form_for(User.new, url: admin_invitations_path) do |f| %>
+
+ <%= f.label :email, class: "crayons-field__label" %>
+ <%= f.text_field :email,
+ class: "crayons-textfield",
+ placeholder: "Email of invitee",
+ required: true %>
+
+
+ <%= f.label :name, class: "crayons-field__label" %>
+ <%= f.text_field :name,
+ class: "crayons-textfield",
+ placeholder: "Name of invitee",
+ required: true %>
+
+
+ <%= f.submit "Invite User", class: "crayons-btn" %>
+
+ <% end %>
+<% end %>
diff --git a/app/views/admin/settings/forms/_smtp.html.erb b/app/views/admin/settings/forms/_smtp.html.erb
index 3a7650be8..eb57f6763 100644
--- a/app/views/admin/settings/forms/_smtp.html.erb
+++ b/app/views/admin/settings/forms/_smtp.html.erb
@@ -1,7 +1,7 @@
<%= form_for(Settings::SMTP.new,
url: admin_settings_smtp_settings_path,
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
-
+
<%= render partial: "admin/shared/card_header",
locals: { header: "SMTP Settings", state: "collapse", target: "smtpSettingsBodyContainer", expanded: false } %>
diff --git a/spec/requests/admin/invitations_spec.rb b/spec/requests/admin/invitations_spec.rb
index 6cd5c4a20..108b6f9d9 100644
--- a/spec/requests/admin/invitations_spec.rb
+++ b/spec/requests/admin/invitations_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe "/admin/invitations", type: :request do
before do
sign_in(admin)
+ allow(ForemInstance).to receive(:smtp_enabled?).and_return(true)
end
describe "GET /admin/invitations" do
@@ -19,7 +20,8 @@ RSpec.describe "/admin/invitations", type: :request do
describe "GET /admin/invitations/new" do
it "renders to appropriate page" do
get new_admin_invitation_path
- expect(response.body).to include("Email:")
+ expect(response.body).to include("Email")
+ expect(response.body).to include("Name")
end
end
diff --git a/spec/system/admin/admin_invites_user_spec.rb b/spec/system/admin/admin_invites_user_spec.rb
new file mode 100644
index 000000000..052d89923
--- /dev/null
+++ b/spec/system/admin/admin_invites_user_spec.rb
@@ -0,0 +1,61 @@
+require "rails_helper"
+
+RSpec.describe "Admin invites user", type: :system do
+ let(:admin) { create(:user, :super_admin) }
+
+ before do
+ sign_in admin
+ end
+
+ context "when SMTP is not configured" do
+ before do
+ allow(ForemInstance).to receive(:smtp_enabled?).and_return(false)
+ visit new_admin_invitation_path
+ end
+
+ it "shows a header" do
+ header = "Setup SMTP to invite users"
+ expect(page).to have_content(header)
+ end
+
+ it "shows a banner" do
+ message = "SMTP settings are required so that your Forem can send emails. If you wish to send invites, "\
+ "email digests and activity notifications you will need to specify which email host will relay those "\
+ "messages for you."
+ expect(page).to have_content(message)
+ end
+
+ it "contains a link to the documentation" do
+ expect(page).to have_link("read more about SMTP Settings in our admin guide", href: "https://admin.forem.com/docs/advanced-customization/config/smtp-settings")
+ end
+
+ it "contains a link to configure SMTP settings" do
+ expect(page).to have_link("Configure your SMTP Settings", href: admin_config_path(anchor: "smtp-section"))
+ end
+
+ it "does not contain any for fields" do
+ expect(page).not_to have_field "Email"
+ expect(page).not_to have_field "Name"
+ end
+
+ it "does not contain any submit buttons" do
+ expect(page).not_to have_button "Invite User"
+ end
+ end
+
+ context "when SMTP is configured" do
+ before do
+ allow(ForemInstance).to receive(:smtp_enabled?).and_return(true)
+ visit new_admin_invitation_path
+ end
+
+ it "shows the input fields" do
+ expect(page).to have_field "Email"
+ expect(page).to have_field "Name"
+ end
+
+ it "shows the submit button" do
+ expect(page).to have_button "Invite User"
+ end
+ end
+end