-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add collaborator actions to Admin::Users#edit
- Loading branch information
1 parent
7d273e6
commit dd96fa1
Showing
13 changed files
with
200 additions
and
3 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
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,46 @@ | ||
class Admin::Users::CollaboratorsController < Admin::BaseController | ||
expose(:user) do | ||
User.find(params[:user_id]) | ||
end | ||
|
||
expose(:collaborator) do | ||
User.find(params[:collaborator_id]) | ||
end | ||
|
||
expose(:search_users) do | ||
AdminActions::SearchCollaboratorCandidates.new(existing_collaborators: user.account.users, params: search_params) | ||
end | ||
|
||
expose(:add_collaborator_interactor) do | ||
AdminActions::AddCollaborator.new(account: user.account, collaborator:) | ||
end | ||
|
||
expose(:candidates) do | ||
search_users.candidates | ||
end | ||
|
||
def search | ||
authorize user, :can_add_collaborators_to_account? | ||
search_users.run if search_users.valid? | ||
end | ||
|
||
def create | ||
authorize user, :can_add_collaborators_to_account? | ||
|
||
add_collaborator_interactor.run.tap do |result| | ||
if result.success? | ||
redirect_to edit_admin_user_path(user), notice: "#{collaborator.email} successfully added to Collaborators!" | ||
else | ||
redirect_to edit_admin_user_path(user), notice: "#{collaborator.email} could not be added to Collaborators!" | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def search_params | ||
return if params[:search].blank? | ||
|
||
params.require(:search).permit(:query) | ||
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
27 changes: 27 additions & 0 deletions
27
app/views/admin/users/collaborators/_search_form.html.slim
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,27 @@ | ||
= simple_form_for :search, | ||
url: search_admin_user_collaborators_url(resource), | ||
remote: true, | ||
method: :get, | ||
as: nil, | ||
html: { class: "admin-search-collaborators-form" } do |f| | ||
|
||
.form-container | ||
label.form-label for="admin-search-collaborators-query" Add collaborator | ||
|
||
.alert.alert-danger.hidden.js-admin-search-collaborators-error-box role="alert" | ||
|
||
ul.list-unstyled.list-actions.hidden.js-admin-search-collaborators-results-box | ||
|
||
.form-block | ||
.row | ||
.col-md-12 | ||
= f.input :query, | ||
as: :string, | ||
label: false, | ||
input_html: { class: "form-control", id: "admin-search-collaborators-query" }, | ||
wrapper_html: { class: 'pull-left col-md-10 admin-search-collaborators-query' }, | ||
placeholder: "Type part of email, first name or last name" | ||
|
||
.text-right | ||
= f.submit "Search", class: "btn btn-primary pull-right" | ||
.clear |
10 changes: 10 additions & 0 deletions
10
app/views/admin/users/collaborators/_search_results.html.slim
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,10 @@ | ||
- if candidates.present? | ||
- candidates.each do |candidate| | ||
li id="user_#{candidate.id}" | ||
= link_to "#{candidate.full_name} (#{candidate.email})", edit_admin_user_path(candidate) | ||
- if candidate.can_be_added_to_collaborators_to_another_account? | ||
= link_to "Add", admin_user_collaborators_url(collaborator_id: candidate.id), method: :post, class: "pull-right btn btn-default" | ||
- else | ||
br | ||
i.cant_add_to_collaborators_message | ||
| can not be added as linked with another account! |
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,6 @@ | ||
- if search_users.valid? | ||
| $('.js-admin-search-collaborators-results-box').html("#{j render("search_results")}").removeClass("hidden"); | ||
| $(".js-admin-search-collaborators-error-box").addClass("hidden"); | ||
- else | ||
| $('.js-admin-search-collaborators-results-box').addClass("hidden"); | ||
| $(".js-admin-search-collaborators-error-box").text("#{search_users.error.html_safe}").removeClass("hidden"); |
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,76 @@ | ||
require "rails_helper" | ||
|
||
describe "Collaborators", ' | ||
As a an Admin | ||
I want to be able to add collaborators to any account | ||
So that they can collaborate applications | ||
' do | ||
include ActiveJob::TestHelper | ||
|
||
let!(:admin) { create(:admin) } | ||
let(:existing_user) { create(:user, :completed_profile) } | ||
|
||
before do | ||
login_admin admin | ||
visit edit_admin_user_path(existing_user) | ||
end | ||
|
||
describe "Add new Collaborator" do | ||
describe "Invalid Attempts", js: true do | ||
describe "Attempt to add person, which is already associated with another account which has application" do | ||
let!(:user_associated_with_another_account) do | ||
create :user, | ||
:completed_profile, | ||
first_name: "Applicant with account", | ||
role: "account_admin" | ||
end | ||
|
||
let!(:another_form_answer) do | ||
create :form_answer, | ||
:innovation, | ||
:submitted, | ||
user: user_associated_with_another_account | ||
end | ||
|
||
before do | ||
find("a[aria-controls='section-collaborators']").click | ||
|
||
within(".admin-search-collaborators-form") do | ||
fill_in "search[query]", with: "plicant with acc" | ||
first("input[type='submit']").click | ||
end | ||
end | ||
|
||
it "can't add" do | ||
within(".js-admin-search-collaborators-results-box") do | ||
expect_to_see(user_associated_with_another_account.first_name) | ||
expect_to_see("can not be added as linked with another account!") | ||
expect(page).to have_no_link("Add") | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe "Success Add to Collaborators", js: true do | ||
let(:email) { generate(:email) } | ||
let!(:user) { create(:user, email: email) } | ||
|
||
before do | ||
find("a[aria-controls='section-collaborators']").click | ||
|
||
within(".admin-search-collaborators-form") do | ||
fill_in "search[query]", with: email.to_s[2..-2] | ||
first("input[type='submit']").click | ||
end | ||
end | ||
|
||
it "should add user to collaborators with regular role" do | ||
within(".js-admin-search-collaborators-results-box") do | ||
expect_to_see(user.email) | ||
expect_to_see_no("can not be added as linked with another account!") | ||
expect(page).to have_link("Add") | ||
end | ||
end | ||
end | ||
end | ||
end |