-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow admins to invite other staff #251
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: "Staff saved successfully." | ||
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 'Save profile', class: 'btn btn-primary' %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we change button to 'Send Invite' ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, thanks! |
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ | |
</div> | ||
</div> | ||
</div> | ||
</section> | ||
</section> |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the notice to something like "Invite sent!"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both make sense here. The staff account does get saved and the invitation is sent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "Invite sent!" makes more sense from the user perspective. Fixed!
I also changed texts in a couple of other places from "Add staff" to "Invite staff".