Skip to content

Commit

Permalink
Merge branch 'feature/samvera-deprecated#310-lastname-firstname' into…
Browse files Browse the repository at this point in the history
… feature/samvera-deprecated#391-facet-buffer-overflow
  • Loading branch information
hortongn committed Aug 17, 2015
2 parents 4659b1d + 88ddade commit fc0bafa
Show file tree
Hide file tree
Showing 30 changed files with 124 additions and 69 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/curate/link_users.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
$.getJSON $targetElement.data('url'), { q: request.term + "*" }, ( data, status, xhr ) ->
matches = []
$.each data.response.docs, (idx, val) ->
matches.push {label: val['desc_metadata__name_tesim'][0], value: val['id']}
matches.push {label: (val['desc_metadata__first_name_tesim'] + " " + val['desc_metadata__last_name_tesim']), value: val['id']}
response( matches )
minLength: 2
focus: ( event, ui ) ->
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/curate/proxy_rights.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
$.getJSON $targetElement.data('url'), { q: request.term, user: true}, ( data, status, xhr ) ->
matches = []
$.each data.response.docs, (idx, val) ->
matches.push {label: val['desc_metadata__name_tesim'][0], value: val['id']}
matches.push {label: (val['desc_metadata__first_name_tesim'] + " " + val['desc_metadata__last_name_tesim']), value: val['id']}
response( matches )
minLength: 2
focus: ( event, ui ) ->
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/curate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def render_response_for_error(wrapper)

def configure_permitted_parameters
full_list = [:email, :password, :password_confirmation, :current_password,
:name, :email, :alternate_email,
:name, :last_name, :first_name, :email, :alternate_email,
:date_of_birth, :gender, :title,
:campus_phone_number, :alternate_phone_number,
:personal_webpage, :blog, :files]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/curate/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.search_config
initialized_config = Curate.configuration.search_config['people']
# If the hash is empty, set reasonable defaults for this search type
if initialized_config.nil?
Hash['qf' => 'desc_metadata__name_tesim','fl' => 'desc_metadata__name_tesim id','qt' => 'search','rows' => 10]
Hash['qf' => 'desc_metadata__first_name_tesim desc_metadata__last_name_tesim','fl' => 'desc_metadata__first_name_tesim desc_metadata__last_name_tesim id','qt' => 'search','rows' => 10]
else
initialized_config
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def after_create_response
# Override setup_form in concrete controllers to get the form ready for display
def setup_form
if curation_concern.respond_to?(:creator)
curation_concern.creator << current_user.name if curation_concern.creator.empty? && !current_user.can_make_deposits_for.any?
curation_concern.creator << current_user.inverted_name if curation_concern.creator.empty? && !current_user.can_make_deposits_for.any?
end

curation_concern.editors << current_user.person if curation_concern.editors.blank?
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/blacklight_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ module BlacklightHelper
def application_name
t('sufia.product_name')
end

## Override the default seperator used to display multivalue fields on the index view
def field_value_separator
tag(:br)
end
end
2 changes: 1 addition & 1 deletion app/helpers/curate/collections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def collection_line_item(collection, terminate, options={})

def creators(work)
if work.respond_to?(:creator)
"(#{work.creator.to_a.join(', ')})"
"(#{work.creator.to_a.join('; ')})"
else
''
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def profile_title
end

def sync_profile_title_to_name(update_attributes)
return true unless update_attributes[:name]
return true unless update_attributes[:last_name] or update_attributes[:first_name]
profile.update(title: profile_title)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/classify_concern.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'active_attr'
class ClassifyConcern
UPCOMING_CONCERNS = ['ETD']
UPCOMING_CONCERNS = []

def self.normalize_concern_name(name)
name.to_s.classify
Expand Down
10 changes: 9 additions & 1 deletion app/models/curate/user_behavior/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ def manager_usernames
end

def name
read_attribute(:name) || user_key
name = "#{read_attribute(:first_name)} #{read_attribute(:last_name)}"
return name unless name.blank?
user_key
end

def inverted_name
name = "#{read_attribute(:last_name)}, #{read_attribute(:first_name)}"
return name unless read_attribute(:last_name).blank? or read_attribute(:first_name).blank?
""
end

def groups
Expand Down
8 changes: 8 additions & 0 deletions app/repository_datastreams/person_metadata_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ class PersonMetadataDatastream < ActiveFedora::NtriplesRDFDatastream
index.as :stored_searchable
end

map.first_name(to: "firstName", in: RDF::FOAF) do |index|
index.as :stored_searchable
end

map.last_name(to: "lastName", in: RDF::FOAF) do |index|
index.as :stored_searchable
end

map.title(to: "title", in: RDF::FOAF) do |index|
index.as :stored_searchable
end
Expand Down
24 changes: 12 additions & 12 deletions app/repository_models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class Person < ActiveFedora::Base
datastream: :descMetadata, multiple: false,
label: "Name"

attribute :first_name,
datastream: :descMetadata, multiple: false

attribute :last_name,
datastream: :descMetadata, multiple: false

attribute :email,
datastream: :descMetadata, multiple: false

Expand Down Expand Up @@ -53,6 +59,12 @@ class Person < ActiveFedora::Base
attribute :gender,
datastream: :descMetadata, multiple: false

def name
name = "#{self.first_name} #{self.last_name}"
return name unless name.blank? or self.first_name.blank? or self.last_name.blank?
user_key
end

def validate_work(work)
!work.is_a?(Person) && !work.is_a?(Collection) && work.is_a?(CurationConcern::Work)
end
Expand Down Expand Up @@ -88,18 +100,6 @@ def date_uploaded
Time.new(create_date).strftime("%Y-%m-%d")
end

def first_name
name_parser.given
end

def last_name
name_parser.family
end

def name_parser
Namae.parse(self.name).first
end

def user_key
if user
user.user_key
Expand Down
2 changes: 1 addition & 1 deletion app/views/curate/people/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<dl class="person-attribtues <%= dom_class(@person) %>">

<% @person.terms_for_display.reject{|attribute| (attribute == :name) || (attribute == :title)}.each do |attribute_name| %>
<% @person.terms_for_display.reject{|attribute| (attribute == :last_name) || (attribute == :first_name) || (attribute == :name) || (attribute == :title)}.each do |attribute_name| %>
<% if @person.send(attribute_name).present? %>
<dt class="attribute"><%= derived_label_for( @person, attribute_name) %>:</dt>
<% [@person.send(attribute_name)].flatten.compact.each do |value| %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
<%= f.input :creator,
as: :multi_value,
label: 'Author',
required: true,
input_html: { value: "@current_user.name" } %>
required: true %>
</div>
<%= render 'form_input_help_block', help_text: I18n.t('sufia.work.input_field.creator.help', work_type: curation_concern.human_readable_type) %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
<div class="span6">
<%= f.input :creator,
as: :multi_value,
required: true,
input_html: { value: "@current_user.name" } %>
required: true %>
</div>
<%= render 'form_input_help_block', help_text: I18n.t('sufia.work.input_field.creator.help', work_type: curation_concern.human_readable_type) %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
<div class="span6">
<%= f.input :creator,
as: :multi_value,
required: true,
input_html: { value: "@current_user.name" } %>
required: true %>
</div>
<%= render 'form_input_help_block', help_text: I18n.t('sufia.work.input_field.creator.help', work_type: curation_concern.human_readable_type) %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
<div class="span6">
<%= f.input :creator,
as: :multi_value,
required: true,
input_html: { value: "@current_user.name" } %>
required: true %>
</div>
<%= render 'form_input_help_block', help_text: I18n.t('sufia.work.input_field.creator.help', work_type: curation_concern.human_readable_type) %>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/registrations/_form_attributes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<fieldset class="span6">
<legend>Personal Information</legend>

<%= f.input :name %>
<%= f.input :first_name, hint: 'Please include any middle names or initials here, if desired', required: true %>
<%= f.input :last_name, required: true %>
<%= f.input :title, label: 'Job Title' %>
<%= f.input :personal_webpage %>
<%= f.input :blog %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/registrations/_form_password_management.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<legend>Authorize Your Changes</legend>
<p><em>Enter your current password to confirm your changes</em></p>

<%= f.input :current_password, required: true %>
<%= f.input :current_password, required: true, input_html: { autocomplete: "off" } %>

</fieldset>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/sufia.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ en:
coverage_temporal:
help: "<p>Enter the period or date associated with the subject of your %{work_type}.</p><p>Examples:</p><li>19th century</li><li>Middle Ages</li><li>Jurassic Period</li>"
creator:
help: "<p>Enter the names of creators of the %{work_type}. This could include important authors, co-authors, or other significant contributors.</p>"
help: "<p>Enter the names of creators of the %{work_type}, in <i>LastName, FirstName</i> format. These could include important authors, co-authors, or other significant contributors.</p>"
cultural_context:
help: "<p>Enter the name of culture, people, or adjectival form of country associated with the subject of your %{work_type}.</p><p>Examples:</p><li>American</li><li>Vietnamese</li><li>Inuit</li>"
date_created:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddFamilyNameAndGivenNameToUser < ActiveRecord::Migration
def change
add_column User.table_name, :first_name, :string
add_column User.table_name, :last_name, :string
end
end
12 changes: 6 additions & 6 deletions spec/controllers/curate/people_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@

describe "searching via json" do
before(:each) do
@katie = FactoryGirl.create(:person, name: 'Katie F. White-Kopp')
@alvin = FactoryGirl.create(:person, name: 'A. S. Mitchell')
@john = FactoryGirl.create(:person_with_user, name: 'John Corcoran III')
@katie = FactoryGirl.create(:person, first_name: 'Katie F.', last_name: 'White-Kopp')
@alvin = FactoryGirl.create(:person, first_name: 'A. S.', last_name: 'Mitchell')
@john = FactoryGirl.create(:person_with_user, first_name: 'John', last_name: 'Corcoran III')
end

it "should return results on full first name match" do
get :index, q: 'Katie', format: :json
json = JSON.parse(response.body)
json['response']['docs'].should == [{"id"=>@katie.pid, "desc_metadata__name_tesim"=>["Katie F. White-Kopp"]}]
json['response']['docs'].should == [{"id"=>@katie.pid, "desc_metadata__first_name_tesim"=>["Katie F."], "desc_metadata__last_name_tesim"=>["White-Kopp"]}]
end

it "should return results on full last name match" do
get :index, q: 'Mitchell', format: :json
json = JSON.parse(response.body)
json['response']['docs'].should == [{"id"=>@alvin.pid, "desc_metadata__name_tesim"=>["A. S. Mitchell"]}]
json['response']['docs'].should == [{"id"=>@alvin.pid, "desc_metadata__first_name_tesim"=>["A. S."], "desc_metadata__last_name_tesim"=>["Mitchell"]}]
end

describe "when constrained to users" do
it "should return users" do
get :index, q: '', user: true, format: :json
json = JSON.parse(response.body)
json['response']['docs'].should == [{"id"=>@john.pid, "desc_metadata__name_tesim"=>["John Corcoran III"]}]
json['response']['docs'].should == [{"id"=>@john.pid, "desc_metadata__first_name_tesim"=>["John"], "desc_metadata__last_name_tesim"=>["Corcoran III"]}]
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/curate/internal/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
FactoryGirl.define do
factory :user do
sequence(:email) {|n| "email-#{srand}@test.com" }
sequence(:name) {|n| "User Named #{n}" }
sequence(:first_name) {|n| "First #{n}" }
sequence(:last_name) {|n| "Last #{n}" }
agreed_to_terms_of_service true
user_does_not_require_profile_update true
password 'a password'
Expand Down
5 changes: 2 additions & 3 deletions spec/features/generic_work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,13 @@
end

describe 'When I click on the link to create a work: ' do
let(:account) { FactoryGirl.create(:account, name: 'Iron Man') }
let(:account) { FactoryGirl.create(:account, first_name: 'Iron', last_name: 'Man') }
let(:user) { account.user }
let(:person) { account.person }
before { login_as(user) }
it 'should have my name set in the creator/contributor list' do
visit new_curation_concern_generic_work_path
page.should have_css("a[href$='people/#{person.to_param}']")
page.should have_tag("a[href$='people/#{person.to_param}']", text: "Iron Man")
page.should have_tag("input", value: "Man, Iron")
end
end

8 changes: 5 additions & 3 deletions spec/features/manager_profile_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

visit edit_user_path(user.id)

new_name = 'Frodo Baggins'
new_first_name = 'Frodo'
new_last_name = 'Baggins'
new_pref = '[email protected]'
new_alt = '[email protected]'
new_title = 'student'
Expand All @@ -24,7 +25,8 @@
new_blog = 'blog.example.com'

within('form.edit_user') do
fill_in("user[name]", with: new_name)
fill_in("user[first_name]", with: new_first_name)
fill_in("user[last_name]", with: new_last_name)
fill_in("user[email]", with: new_pref)
fill_in("user[alternate_email]", with: new_alt)
fill_in("user[title]", with: new_title)
Expand All @@ -43,7 +45,7 @@
user.person.reload

# Verify that everything got updated
user.name.should == new_name
user.name.should == "#{new_first_name} #{new_last_name}"
user.email.should == new_pref
user.alternate_email.should == new_alt
user.title.should == new_title
Expand Down
Loading

0 comments on commit fc0bafa

Please sign in to comment.