Skip to content

Commit

Permalink
Merge pull request #4072 from cancelei/4066-add-partner-users-name
Browse files Browse the repository at this point in the history
4066  - Add Partner User's Name when setting up new users
  • Loading branch information
awwaiid authored Mar 3, 2024
2 parents a46d781 + ae8eb39 commit fd551b6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/controllers/partners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def invite

def invite_partner_user
partner = current_organization.partners.find(params[:partner])
UserInviteService.invite(email: params[:email],
UserInviteService.invite(name: params[:name],
email: params[:email],
roles: [Role::PARTNER],
resource: partner)

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def future_distributed
end

def recently_added_user_display_text(user)
(user.name == "Name Not Provided") ? user.email : user.name
(user.name.blank? || user.name == "Name Not Provided") ? user.email : user.name
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/services/user_invite_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.invite(email:, resource:, name: nil, roles: [], force: false)
end

User.invite!(email: email) do |user1|
user1.name = name if name # Does this get persisted somewhere up the line? - CLF 20230203
user1.name = name.presence || "Name Not Provided"
add_roles(user1, resource: resource, roles: roles)
user1.skip_invitation = user1.errors[:email].any?
end
Expand Down
8 changes: 6 additions & 2 deletions app/views/partners/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@
<%= form_tag invite_partner_user_partner_path do %>
<div class="input-group">
<span class="input-group-text" id="spn_env_fa_icon"><%= fa_icon "envelope" %></span>
<input type="email" name="email" class="form-control" placeholder="Email" aria-describedby="spn_env_fa_icon" autocomplete="on">
<input type="email" name="email" class="form-control" placeholder="Email" aria-describedby="spn_env_fa_icon" required autocomplete="off">
</div>
<div class="input-group mt-3">
<span class="input-group-text" id="spn_env_fa_icon"><%= fa_icon "user" %></span>
<input type="text" name="name" class="form-control" placeholder="Name" aria-describedby="name_icon" required autocomplete="off">
<%= hidden_field_tag :partner, @partner.id %><br>
</div>
<br>
Expand All @@ -331,7 +335,7 @@
<%= form_tag partner_user_reset_password_users_path do %>
<div class="input-group">
<span class="input-group-text" id="spn_env_fa_icon"><%= fa_icon "envelope" %></span>
<input type="email" name="email" class="form-control" placeholder="Email" aria-describedby="spn_env_fa_icon" autocomplete="on">
<input type="email" name="email" class="form-control" placeholder="Email" aria-describedby="spn_env_fa_icon" autocomplete="off">
<%= hidden_field_tag :partner_id, @partner.id %><br>
</div>
<br>
Expand Down
4 changes: 3 additions & 1 deletion spec/requests/partners_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,10 @@
end

describe "POST #invite_partner_user" do
subject { -> { post invite_partner_user_partner_path(default_params.merge(id: partner.id, partner: partner.id, email: email)) } }
subject { -> { post invite_partner_user_partner_path(default_params.merge(id: partner.id, partner: partner.id, email: email, name: name)) } }
let(:partner) { create(:partner, organization: @organization) }
let(:email) { Faker::Internet.email }
let(:name) { Faker::Name.unique.name }

context 'when the invite successfully' do
before do
Expand All @@ -297,6 +298,7 @@
subject.call
expect(UserInviteService).to have_received(:invite).with(
email: email,
name: name,
roles: [Role::PARTNER],
resource: partner
)
Expand Down
47 changes: 47 additions & 0 deletions spec/services/user_invite_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,52 @@
expect(result).to have_role(Role::ORG_ADMIN, organization)
expect(result).not_to have_role(Role::PARTNER, :any)
end

it "should create the user without name with role" do
expect {
@result = UserInviteService.invite(
email: "email2@email.com",
roles: [Role::PARTNER],
resource: @partner
)
}.to change { ActionMailer::Base.deliveries.count }.by(1)

user = User.find_by(email: "email2@email.com")
expect(user.name).to eq("Name Not Provided")
expect(user.email).to eq("email2@email.com")
expect(user).to have_role(Role::PARTNER, @partner)
end
end

it "should invite a user with the partner role" do
expect {
@result = UserInviteService.invite(
name: "Partner User",
email: "partner@example.com",
roles: [Role::PARTNER],
resource: @partner
)
}.to change { ActionMailer::Base.deliveries.count }.by(1)

user = User.find_by(email: "partner@example.com")
expect(user.name).to eq("Partner User")
expect(user).not_to be_nil
expect(user).to have_role(Role::PARTNER, @partner)
end

it "should create the user without a name with default role" do
result = nil
expect {
result = described_class.invite(
name: nil,
email: "email2@example.com",
roles: [Role::ORG_USER],
resource: organization
)
}.to change(ActionMailer::Base.deliveries, :count).by(1)

expect(result.reload.name).to eq("Name Not Provided")
expect(result.email).to eq("email2@example.com")
expect(result.has_role?(:org_user, organization)).to be true
end
end

0 comments on commit fd551b6

Please sign in to comment.