Commit f5d90cbc authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻 Committed by Kaspar
Browse files

adding contact primary email and phone fields everywhere

parent cc660e93
......@@ -8,6 +8,7 @@ module ContactAttributes
[
:id, :first_name, :last_name, :_destroy, :contactable_id,
:contactable_type, :street, :extended, :city, :postal_code,
:primary_email, :primary_phone, :title,
contact_emails_attributes: contact_point_attrs,
contact_phones_attributes: contact_point_attrs
]
......
......@@ -9,6 +9,7 @@ module VolunteerAttributes
:strengths, :skills, :interests, :state, :duration, :man, :woman,
:family, :kid, :sport, :creative, :music, :culture, :training,
:german_course, :adults, :teenagers, :children, :region, :state,
:working_percent, :volunteer_experience_desc, :region_specific,
contact_attributes, language_skills_attributes, schedules_attributes
]
end
......
......@@ -38,7 +38,7 @@ class VolunteersController < ApplicationController
return render :edit unless @volunteer.update(volunteer_params)
if state_was_registered && @volunteer.accepted? && invite_volunteer_user
redirect_to volunteers_path,
notice: t('invite_sent', email: @volunteer.contact.contact_emails.first.body)
notice: t('invite_sent', email: @volunteer.contact.primary_email)
else
redirect_to @volunteer, make_notice
end
......@@ -53,7 +53,7 @@ class VolunteersController < ApplicationController
def invite_volunteer_user
new_user = User.new(
email: @volunteer.contact.contact_emails.first.body, password: Devise.friendly_token,
email: @volunteer.contact.primary_email, password: Devise.friendly_token,
role: 'volunteer', volunteer: @volunteer
)
new_user.save && new_user.invite!
......
......@@ -3,12 +3,15 @@ class Contact < ApplicationRecord
has_many :contact_emails
accepts_nested_attributes_for :contact_emails, allow_destroy: true
has_many :contact_phones
accepts_nested_attributes_for :contact_phones, allow_destroy: true
validates :last_name, presence: true
validates :first_name, presence: true, unless: :department?
validates :primary_email, presence: true, unless: :requires_primary_email?
def to_s
last_name
end
......@@ -21,6 +24,10 @@ class Contact < ApplicationRecord
[street, extended, postal_code, city].reject(&:blank?).join(', ')
end
def requires_primary_email?
['Department', 'Profile'].include? contactable_type
end
def department?
contactable_type == 'Department'
end
......
......@@ -34,7 +34,7 @@ class VolunteerPolicy < ApplicationPolicy
user && user.superadmin?
end
def can_edit_state?
def supervisor_privileges?
user && user.superadmin?
end
......
.row
- if controller_name == 'departments'
- if f.object.department?
.col-xs-12.col-md-6= f.input :last_name, label: t('.name')
- else
.col-xs-12.col-md-2= f.input :title
.col-xs-12.col-md-5= f.input :first_name
.col-xs-12.col-md-5= f.input :first_name, required: true
.col-xs-12.col-md-5= f.input :last_name, label: t('.last_name')
.row
......@@ -21,6 +21,11 @@
.col-xs-8
= f.input :city
- unless f.object.department?
.col-xs-12
= f.input :primary_email, required: true
.col-xs-12
= f.input :primary_phone
.row
.col-xs-12
......
......@@ -9,6 +9,14 @@ tr
td= t_attr(:city, Contact)
td #{contact.postal_code} #{contact.city}
- unless contact.department?
tr
td= t_attr(:primary_email, Contact)
td= contact.primary_email
tr
td= t_attr(:primary_phone, Contact)
td= contact.primary_phone
- contact.contact_emails.each do |email|
tr
td
......
......@@ -6,4 +6,4 @@
.row
.col-xs-12
= button_link t('back'), profiles_path(params[:id])
= link_to t('back'), profile_path(params[:id]), class: 'btn btn-default'
- if policy(Volunteer).can_edit_state?
= simple_error_notice f
- if policy(Volunteer).supervisor_privileges?
.row
.col-xs-12
= f.input :state, collection: Volunteer.state_collection, default: :registered
......@@ -7,8 +9,6 @@
.col-xs-12
= f.input :rejection_text
= simple_error_notice f
= f.simple_fields_for :contact do |c|
= render 'contacts/fields', f: c
......
- state_filter = request.GET[:q] && request.GET[:q][:state_cont].present? ? request.GET[:q][:state_cont] : 'all'
.btn-group
button.btn.btn-default.dropdown-toggle type='button' data-toggle='dropdown' aria-label="#{t_attr(:state)}" aria-haspopup='true' aria-expanded='false' class="btn-md"
= "#{t_attr(:state)} : "
= "#{t_attr(:state, Volunteer)} : "
= t(state_filter, scope: [:simple_form, :options, :volunteer, :state]) + ' '
span.caret aria-hidden='true'
ul.dropdown-menu
......
......@@ -64,6 +64,9 @@
tr
td= t_attr(:region)
td= t("region.#{@volunteer.region}") if @volunteer.region.present?
tr
td= t_attr(:region_specific)
td= @volunteer.region_specific
h3= t_attr(:single_accompaniment)
.table-responsive
......
......@@ -39,6 +39,8 @@ de:
first_name: Vorname
last_name: Name
postal_code: PLZ
primary_email: Primäre Mailadresse
primary_phone: Primäre Telefonnummer
street: Strasse
title: Anrede
contact_email:
......
......@@ -3,14 +3,11 @@ Rails.application.routes.draw do
get :thanks, on: :collection
end
# Authenticated routes start here
devise_for :users
resources :volunteers
resources :users
resources :clients
resources :departments
resources :users, :clients, :departments, :volunteers
resources :profiles, except: [:destroy, :index]
resources :users
root 'application#home'
end
class AddPrimaryEmailToContact < ActiveRecord::Migration[5.1]
def change
change_table :contacts do |t|
t.string :primary_email
t.string :primary_phone
end
end
end
class CreateVolunteerEmails < ActiveRecord::Migration[5.1]
def change
create_table :volunteer_emails do |t|
t.string :subject
t.string :title
t.text :body
t.references :user, foreign_key: true
t.boolean :active
t.datetime :deleted_at
t.timestamps
end
add_index :volunteer_emails, :deleted_at
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170628085858) do
ActiveRecord::Schema.define(version: 20170704093044) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -65,6 +65,8 @@ ActiveRecord::Schema.define(version: 20170628085858) do
t.string "first_name"
t.string "last_name"
t.string "title"
t.string "primary_email"
t.string "primary_phone"
t.index ["contactable_type", "contactable_id"], name: "index_contacts_on_contactable_type_and_contactable_id"
t.index ["deleted_at"], name: "index_contacts_on_deleted_at"
end
......@@ -167,6 +169,19 @@ ActiveRecord::Schema.define(version: 20170628085858) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
create_table "volunteer_emails", force: :cascade do |t|
t.string "subject"
t.string "title"
t.text "body"
t.bigint "user_id"
t.boolean "active"
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["deleted_at"], name: "index_volunteer_emails_on_deleted_at"
t.index ["user_id"], name: "index_volunteer_emails_on_user_id"
end
create_table "volunteers", force: :cascade do |t|
t.date "date_of_birth"
t.string "gender"
......@@ -216,5 +231,6 @@ ActiveRecord::Schema.define(version: 20170628085858) do
add_foreign_key "clients", "users"
add_foreign_key "contact_points", "contacts"
add_foreign_key "profiles", "users"
add_foreign_key "volunteer_emails", "users"
add_foreign_key "volunteers", "users"
end
......@@ -8,18 +8,6 @@ def random_relation
].sample
end
def make_person_data(subject)
subject.first_name = Faker::Name.first_name
subject.last_name = Faker::Name.last_name
subject.date_of_birth = Faker::Date.birthday(18, 75)
subject.zip = Faker::Address.zip_code
subject.city = Faker::Address.city
subject.street = Faker::Address.street_address
subject.email = Faker::Internet.email
subject.phone = Faker::PhoneNumber.phone_number
subject.gender = ['male', 'female'].sample
end
def make_relatives
Array.new(2).map do
Relative.new do |relative|
......@@ -58,7 +46,9 @@ User.role_collection.each do |role|
last_name: Faker::Name.last_name,
postal_code: Faker::Address.zip_code,
city: Faker::Address.city,
street: Faker::Address.street_address
street: Faker::Address.street_address,
primary_email: Faker::Internet.email,
primary_phone: Faker::PhoneNumber.phone_number
)
profile.contact.contact_phones.build(
body: Faker::PhoneNumber.phone_number
......@@ -77,7 +67,9 @@ User.where(role: ['superadmin', 'social_worker']).each do |user|
Client.new do |client|
client.build_contact(
first_name: Faker::Name.first_name,
last_name: Faker::Name.last_name
last_name: Faker::Name.last_name,
primary_email: Faker::Internet.email,
primary_phone: Faker::PhoneNumber.phone_number
)
client.contact.contact_emails.build(
......@@ -102,6 +94,8 @@ if Department.count < 1
c.street = Faker::Address.street_address
c.postal_code = Faker::Address.zip_code
c.city = Faker::Address.city
c.primary_email = Faker::Internet.email
c.primary_phone = Faker::PhoneNumber.phone_number
c.contact_emails = Array.new(3).map do
ContactEmail.new do |email|
email.body = Faker::Internet.email
......@@ -129,7 +123,9 @@ Volunteer.state_collection.each do |state|
last_name: Faker::Name.last_name,
postal_code: Faker::Address.zip_code,
city: Faker::Address.city,
street: Faker::Address.street_address
street: Faker::Address.street_address,
primary_email: Faker::Internet.email,
primary_phone: Faker::PhoneNumber.phone_number
)
volunteer.contact.contact_emails.build(
body: Faker::Internet.unique.email
......
......@@ -5,12 +5,14 @@ FactoryGirl.define do
street 'Strassenstr. 223'
extended 'asdfadsf'
city 'Zürich'
sequence :primary_email { |n| "primary_#{n}@example.com" }
sequence :primary_phone { |n| "+99 99 999 999#{n}" }
postal_code '8047'
contact_emails do |e|
Array.new(3).map { e.association(:contact_email) }
Array.new(2).map { e.association(:contact_email) }
end
contact_phones do |p|
Array.new(3).map { p.association(:contact_phone) }
Array.new(2).map { p.association(:contact_phone) }
end
end
end
......@@ -21,8 +21,7 @@ class ClientsTest < ApplicationSystemTestCase
fill_in 'Zip', with: '8002'
fill_in 'City', with: 'Zürich'
click_link 'Add Email address'
fill_in 'Email address', with: 'gurke@gurkenmail.com'
fill_in 'Primary email', with: 'gurke@gurkenmail.com'
click_link 'Add Phone number'
fill_in 'Phone number', with: '0123456789'
......
......@@ -87,9 +87,9 @@ class UsersTest < ApplicationSystemTestCase
assert_difference 'User.count', 1 do
click_button 'Update Volunteer'
end
assert page.has_text? "Invitation sent to #{volunteer.contact.contact_emails.first.body}"
assert page.has_text? "Invitation sent to #{volunteer.contact.primary_email}"
assert_equal 1, ActionMailer::Base.deliveries.size
email = ActionMailer::Base.deliveries.last
assert_equal volunteer.contact.contact_emails.first.body, email['to'].to_s
assert_equal volunteer.contact.primary_email, email['to'].to_s
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment