-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow admins to invite other staff (#251)
* Allow admins to invite other staff * Add invite staff test * Implement CR remarks
- Loading branch information
Showing
20 changed files
with
310 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Organizations::InvitationsController < Devise::InvitationsController | ||
before_action :require_organization_admin, only: [:new, :create] | ||
layout "dashboard", only: [:new, :create] | ||
|
||
def new | ||
@user = User.new | ||
@staff = StaffAccount.new(user: @user) | ||
end | ||
|
||
def create | ||
@user = User.new(user_params.merge(password: SecureRandom.hex(8)).except(:staff_account_attributes)) | ||
@user.staff_account = StaffAccount.new(verified: true) | ||
|
||
if @user.save | ||
@user.staff_account.add_role(user_params[:staff_account_attributes][:roles]) | ||
@user.invite!(current_user) | ||
redirect_to staff_index_path, notice: "Invite sent!" | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user) | ||
.permit(:first_name, :last_name, :email, | ||
staff_account_attributes: [:roles]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!-- form --> | ||
<%= bootstrap_form_with model: user, url: invitation_path(user) do |form| %> | ||
|
||
<div class="row gx-3"> | ||
<!-- form group --> | ||
<div class="mb-3 col-md-6 col-12"> | ||
<div class="input-group me-3"> | ||
<%= form.text_field :first_name, class: 'form-control', required: true %> | ||
</div> | ||
</div> | ||
<!-- form group --> | ||
<div class="mb-3 col-md-6 col-12"> | ||
<div class="input-group me-3"> | ||
<%= form.text_field :last_name, class: 'form-control', required: true %> | ||
</div> | ||
</div> | ||
<!-- form group --> | ||
<div class="mb-3 col-12"> | ||
<div class="input-group"> | ||
<%= form.text_field :email, class: 'form-control', required: true %> | ||
</div> | ||
</div> | ||
|
||
<!-- form group --> | ||
<%= form.fields_for :staff_account do |staff_subform| %> | ||
<div class="mb-3 col-md-6 col-12"> | ||
<div class="input-group me-3"> | ||
<%= staff_subform.select :roles, options_for_select([['Staff', :staff], ['Admin', :admin]]), class: 'form-control', required: true %> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
<!-- button --> | ||
<div class="col-12 mt-3"> | ||
<%= form.submit 'Send invite', class: 'btn btn-primary' %> | ||
</div> | ||
</div> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h2><%= t "devise.invitations.edit.header" %></h2> | ||
|
||
<%= form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :put }) do |f| %> | ||
<%= f.hidden_field :invitation_token, readonly: true %> | ||
|
||
<% if f.object.class.require_password_on_accepting %> | ||
<div class="field"> | ||
<%= f.label :password %><br /> | ||
<%= f.password_field :password %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= f.label :password_confirmation %><br /> | ||
<%= f.password_field :password_confirmation %> | ||
</div> | ||
<% end %> | ||
|
||
<div class="actions"> | ||
<%= f.submit t("devise.invitations.edit.submit_button") %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/views/organizations/mailer/invitation_instructions.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<p><%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %></p> | ||
|
||
<p><%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %></p> | ||
|
||
<p><%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token) %></p> | ||
|
||
<% if @resource.invitation_due_at %> | ||
<p><%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %></p> | ||
<% end %> | ||
|
||
<p><%= t("devise.mailer.invitation_instructions.ignore") %></p> |
11 changes: 11 additions & 0 deletions
11
app/views/organizations/mailer/invitation_instructions.text.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %> | ||
|
||
<%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %> | ||
|
||
<%= accept_invitation_url(@resource, invitation_token: @token) %> | ||
|
||
<% if @resource.invitation_due_at %> | ||
<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %> | ||
<% end %> | ||
|
||
<%= t("devise.mailer.invitation_instructions.ignore") %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.