Skip to content

Commit

Permalink
Add first last name to form (#542)
Browse files Browse the repository at this point in the history
* SRCH-1266 - Create first_name last_name column in users table
  • Loading branch information
peggles2 authored Mar 11, 2020
1 parent 81b26e8 commit 1c57930
Show file tree
Hide file tree
Showing 48 changed files with 698 additions and 571 deletions.
17 changes: 11 additions & 6 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
class Admin::UsersController < Admin::AdminController
active_scaffold :user do |config|
config.actions.exclude :create, :delete
config.columns = [:email, :contact_name, :memberships, :default_affiliate, :created_at, :updated_at, :approval_status]
config.update.columns = [:email, :contact_name, :organization_name, :is_affiliate_admin, :is_affiliate, :approval_status, :default_affiliate, :welcome_email_sent]
config.columns = %I[email first_name last_name
memberships default_affiliate created_at
updated_at approval_status]
config.update.columns = %I[ email first_name last_name organization_name
is_affiliate_admin is_affiliate approval_status
default_affiliate welcome_email_sent]
config.list.sorting = { :created_at => :desc }
config.columns[:is_affiliate_admin].description = "Set this to true to make the user an Administrator, and give them access to the Admin Center."
config.columns[:is_affiliate].description = "Set this to true to make the user an Affiliate, and give them access to the Affiliate Center."
Expand All @@ -13,10 +17,11 @@ class Admin::UsersController < Admin::AdminController
config.actions.add :export
config.actions.exclude :search
config.actions.add :field_search
config.field_search.columns = %i(id email contact_name approval_status)
config.field_search.columns = %i[id email first_name last_name approval_status]

export.columns = %i(email contact_name affiliate_names last_login_at last_login_ip last_request_at
created_at updated_at organization_name is_affiliate_admin is_affiliate approval_status
welcome_email_sent)
export.columns = %i[email first_name last_name affiliate_names
last_login_at last_login_ip last_request_at
created_at updated_at organization_name is_affiliate_admin
is_affiliate approval_status welcome_email_sent]
end
end
8 changes: 5 additions & 3 deletions app/controllers/concerns/accountable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

module Accountable
def incomplete_account_error
if current_user&.contact_name.blank?
current_user.errors[:contact_name] << 'You must supply a contact name'
if current_user&.first_name.blank?
current_user.errors[:first_name] << 'You must supply a first name'
elsif current_user&.last_name.blank?
current_user.errors[:last_name] << 'You must supply a last name'
elsif current_user&.organization_name.blank?
current_user.errors[:organization_name] << 'You must supply an organization name'
end
Expand All @@ -19,7 +21,7 @@ def check_user_account_complete
edit_account_path,
flash: {
error:
'To complete your registration, please make sure Name, and '\
'To complete your registration, please make sure First name, Last name, and '\
'Government agency are not empty'
}
)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sites/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def destroy
private

def user_params
@user_params ||= params.require(:user).permit(:contact_name, :email).to_h
@user_params ||= params.require(:user).permit(:first_name, :last_name, :email).to_h
end
end
6 changes: 3 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def update
end
end

def developer_redirect
end
def developer_redirect; end

private

Expand All @@ -65,7 +64,8 @@ def set_user
end

def user_params
params.require(:user).permit(:contact_name,
params.require(:user).permit(:first_name,
:last_name,
:organization_name,
:email).to_h
end
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/sites_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module SitesHelper
def site_data
{
user: {
contact_name: current_user.contact_name,
first_name: current_user.first_name,
last_name: current_user.last_name,
email: current_user.email,
id: current_user.id
}
Expand Down
28 changes: 16 additions & 12 deletions app/mailers/emailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ class Emailer < ApplicationMailer

def new_user_to_admin(user)
@user = user
@user_contact_name = user.contact_name.presence || user.email
@user_contact_name = get_contact_name(user)

if @user.affiliates.any?
@user_inviter_contact_name = @user.inviter.contact_name.presence ||
@user.inviter.email
@user_inviter_contact_name = get_contact_name(@user.inviter)
end

setup_email('[email protected]', __method__)
Expand All @@ -34,38 +33,38 @@ def new_feature_adoption_to_admin
def account_deactivation_warning(user, date)
@user = user
@remaining_days = (date - 90.days.ago.to_date).to_i
@user_contact_name = user.contact_name.presence || user.email
@user_contact_name = get_contact_name(user)
generic_user_html_email(user, __method__)
end

def user_approval_removed(user)
@user = user
@user_contact_name = user.contact_name.presence || user.email
@user_contact_name = get_contact_name(user)
setup_email("[email protected]", __method__)
send_mail(:text)
end

def account_deactivated(user)
@user = user
@user_contact_name = user.contact_name.presence || user.email
@user_contact_name = get_contact_name(user)
generic_user_html_email(user, __method__)
end

def welcome_to_new_user(user)
@new_site_url = new_site_url
@user_contact_name = user.contact_name.presence || user.email
@user_contact_name = get_contact_name(user)
generic_user_html_email(user, __method__)
end

def new_affiliate_site(affiliate, user)
@affiliate = affiliate
@user_contact_name = user.contact_name.presence || user.email
@user_contact_name = get_contact_name(user)
generic_user_text_email(user, __method__)
end

def new_affiliate_user(affiliate, user, current_user)
@added_by_contact_name = current_user.contact_name.presence || current_user.email
@added_user_contact_name = user.contact_name.presence || user.email
@added_by_contact_name = get_contact_name(current_user)
@added_user_contact_name = get_contact_name(user)
@affiliate_display_name = affiliate.display_name
@affiliate_name = affiliate.name
@affiliate_site_url = site_url(affiliate)
Expand All @@ -75,8 +74,8 @@ def new_affiliate_user(affiliate, user, current_user)

def welcome_to_new_user_added_by_affiliate(affiliate, user, current_user)
@account_url = account_url
@added_by_contact_name = current_user.contact_name.presence || current_user.email
@added_user_contact_name = user.contact_name.presence || user.email
@added_by_contact_name = get_contact_name(current_user)
@added_user_contact_name = get_contact_name(user)
@added_user_email = user.email
@affiliate_display_name = affiliate.display_name
@affiliate_site_url = site_url(affiliate)
Expand Down Expand Up @@ -200,4 +199,9 @@ def generic_user_html_email(user, method)
setup_email(user.email, method)
send_mail(:html)
end

def get_contact_name(user)
full_name = "#{user.first_name} #{user.last_name}"
full_name.presence || user.email
end
end
2 changes: 1 addition & 1 deletion app/models/affiliate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def make_unavailable(template_ids)
end

has_many :available_templates, through: :affiliate_templates, source: :template
has_many :users, -> { order 'contact_name' }, through: :memberships
has_many :users, -> { order 'first_name' }, through: :memberships

has_many :default_users,
class_name: 'User',
Expand Down
7 changes: 4 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class User < ApplicationRecord

validates :email, presence: true
validates :approval_status, inclusion: APPROVAL_STATUSES
validates :contact_name, presence: true, on: :update_account
validates :first_name, presence: true, on: :update_account
validates :last_name, presence: true, on: :update_account
validates :organization_name, presence: true, on: :update_account
has_many :memberships, dependent: :destroy
has_many :affiliates, lambda {
Expand Down Expand Up @@ -73,11 +74,11 @@ class User < ApplicationRecord
# end

def complete?
contact_name.present? && organization_name.present?
last_name.present? && first_name.present? && organization_name.present?
end

def to_label
"#{contact_name} <#{email}>"
"#{first_name} #{last_name} <#{email}>"
end

def is_affiliate_or_higher
Expand Down
9 changes: 4 additions & 5 deletions app/models/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ def email_template
end

def metadata_hash
{
affiliate: affiliate.name,
{ affiliate: affiliate.name,
affiliate_id: affiliate.id,
affiliate_homepage_url: affiliate.website,
alert_name: name,
user_email: user.email,
user_id: user.id,
user_contact_name: user.contact_name,
watcher_type: self.class.name
}
user_first_name: user.first_name,
user_last_name: user.last_name,
watcher_type: self.class.name }
end
end
3 changes: 2 additions & 1 deletion app/views/sites/users/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
- @users.each do |user|
%tr{ user_row_css_class_hash(user) }
%td
%span #{user.contact_name}
%span #{user.first_name}
%span #{user.last_name}
%br
%span.muted
#{user.email}
Expand Down
6 changes: 4 additions & 2 deletions app/views/sites/users/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

= render_flash_message
= render_error_messages(@user)
= f.label :contact_name, 'Name', class: 'required'
= f.text_field :contact_name, class: 'required input-primary'
= f.label :first_name, 'First name', class: 'required'
= f.text_field :first_name, class: 'required input-primary'
= f.label :last_name, 'Last name', class: 'required'
= f.text_field :last_name, class: 'required input-primary'
= f.label :email, 'Email', class: 'required'
= f.text_field :email, class: 'required'
8 changes: 6 additions & 2 deletions app/views/users/_form.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
= render_flash_message
= render_error_messages(@user)

= form.label :contact_name, 'Name', class: 'required'
= form.text_field :contact_name, class: 'required input-primary'
= form.label :first_name, 'First name', class: 'required'
= form.text_field :first_name, class: 'required input-primary'

= form.label :last_name, 'Last name', class: 'required'
= form.text_field :last_name, class: 'required input-primary'

= form.label :organization_name, 'Government agency'
= form.text_field :organization_name
= form.label :email, 'Email', class: 'required'
Expand Down
8 changes: 6 additions & 2 deletions app/views/users/_new_form.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
= render_error_messages(@user)
= form.label :contact_name, 'Your full name'
= form.text_field :contact_name, placeholder: 'Your full name'
= form.label :first_name, 'First name'
= form.text_field :first_name, 'First name', placeholder: 'Your first name'

= form.label :last_name, 'Last name'
= form.text_field :last_name, 'Last name', placeholder: 'Your last name'

= form.label :organization_name, 'Federal government agency'
= form.text_field :organization_name, placeholder: 'Federal government agency'
= form.label :email
Expand Down
7 changes: 5 additions & 2 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
= render_flash_message

%dl
%dt Name
%dd= @user.contact_name
%dt First name
%dd= @user.first_name
%dl
%dt Last name
%dd= @user.last_name
%dl
%dt Agency
%dd= @user.organization_name
Expand Down
2 changes: 1 addition & 1 deletion db/email_templates/update_external_tracking_code.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Site: <%= @affiliate.display_name %> (<%= edit_admin_affiliate_url(@affiliate, :anchor => "record_external_tracking_code_#{@affiliate.id}") %>)
Requested by: <%= "#{@current_user.contact_name} <#{@current_user.email}>" %>
Requested by: <%= "#{@current_user.first_name} #{@current_user.last_name} <#{@current_user.email}>" %>

External tracking code:
<!-- BEGIN -->
Expand Down
18 changes: 9 additions & 9 deletions features/admin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Feature: Administration

Scenario: Visiting the affiliate admin page as an admin
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name | website |
| agency site | agency.gov | one@foo.gov | One Foo | http://beta.agency.gov |
| display_name | name | contact_email | first_name | last_name | website |
| agency site | agency.gov | one@foo.gov | One | Foo | http://beta.agency.gov |
And the following "site domains" exist for the affiliate agency.gov:
| domain | site_name |
| www1.agency-site.gov | Agency Website |
Expand All @@ -49,8 +49,8 @@ Feature: Administration
@javascript
Scenario: Editing an affiliate as an admin
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name | website |
| agency site | agency.gov | one@foo.gov | One Foo | http://beta.agency.gov |
| display_name | name | contact_email | first_name | last_name | website |
| agency site | agency.gov | one@foo.gov | One | Foo | http://beta.agency.gov |
When I go to the admin sites page
When I follow "Edit" within the first scaffold row
Then I should see "Settings (Show)"
Expand Down Expand Up @@ -80,8 +80,8 @@ Feature: Administration

Scenario: Viewing Boosted Content (both affiliate and Search.USA.gov)
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name |
| bar site | bar.gov | aff@bar.gov | John Bar |
| display_name | name | contact_email | first_name | last_name |
| bar site | bar.gov | aff@bar.gov | John | Bar |
And the following Boosted Content entries exist for the affiliate "bar.gov"
| title | url | description | keywords |
| Bar Emergency Page | http://www.bar.gov/911 | This should not show up in results | safety |
Expand All @@ -95,9 +95,9 @@ Feature: Administration

Scenario: Comparing Search Results
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name |
| agency site | aff.gov | one@foo.gov | One Foo |
| agency site 2 | aff2.gov | two@foo.gov | Two Foo |
| display_name | name | contact_email | first_name | last_name |
| agency site | aff.gov | one@foo.gov | One | Foo |
| agency site 2 | aff2.gov | two@foo.gov | Two | Foo |
And the following "site domains" exist for the affiliate aff.gov:
| domain | site_name |
| aff.gov | Agency Website |
Expand Down
20 changes: 10 additions & 10 deletions features/admin_center_activate_search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Feature: Activate Search

Scenario: Getting an embed code for my affiliate site search
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name |
| aff site | aff.gov | aff@bar.gov | John Bar |
| display_name | name | contact_email | first_name | last_name |
| aff site | aff.gov | aff@bar.gov | John | Bar |
And I am logged in with email "[email protected]"
When I go to the aff.gov's Activate Search page
Then I should see "Form Snippet"
Expand All @@ -12,25 +12,25 @@ Feature: Activate Search

Scenario: Getting an embed code for my affiliate site search in Spanish
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name | locale |
| aff site | aff.gov | aff@bar.gov | John Bar | es |
| display_name | name | contact_email | first_name | last_name | locale |
| aff site | aff.gov | aff@bar.gov | John | Bar | es |
And I am logged in with email "[email protected]"
When I go to the aff.gov's Activate Search page
Then I should see the code for Spanish language sites

Scenario: Visiting the Site API Access Key
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name | api_access_key |
| aff site | aff.gov | aff@bar.gov | John Bar | MY_AWESOME_KEY |
| display_name | name | contact_email | first_name | last_name | api_access_key |
| aff site | aff.gov | aff@bar.gov | John | Bar | MY_AWESOME_KEY |
And I am logged in with email "[email protected]"
When I go to the aff.gov's Activate Search page
And I follow "API Access Key"
Then I should see "MY_AWESOME_KEY"

Scenario: Visiting the Site API Instructions
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name |
| aff site | aff.gov | aff@bar.gov | John Bar |
| display_name | name | contact_email | first_name | last_name |
| aff site | aff.gov | aff@bar.gov | John | Bar |
And affiliate "aff.gov" has the following RSS feeds:
| name | url |
| News-1 | https://www.usa.gov/feed/news-1 |
Expand All @@ -48,8 +48,8 @@ Feature: Activate Search

Scenario: Visiting the Site i14y Content Indexing API Instructions
Given the following Affiliates exist:
| display_name | name | contact_email | contact_name | gets_i14y_results |
| aff site | aff.gov | aff@bar.gov | John Bar | true |
| display_name | name | contact_email | first_name | last_name | gets_i14y_results |
| aff site | aff.gov | aff@bar.gov | John Bar | Bar | true |
And I am logged in with email "[email protected]"
When I go to the aff.gov's Activate Search page
And I follow "i14y Content Indexing API Instructions"
Expand Down
Loading

0 comments on commit 1c57930

Please sign in to comment.