mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Introduce contact email address for enterprises
Add a new column email_address to enterprises. Use this new field for public display of contact details. The old field enterprise.email is still used internally. It is still displayed on orders and emails sent to customers. A new enterprise has the owner's email address by default now. Fix GH #757
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
%div.contact-container{bindonce: true}
|
||||
%div.modal-centered{"bo-if" => "enterprise.email || enterprise.website || enterprise.phone"}
|
||||
%div.modal-centered{"bo-if" => "enterprise.email_address || enterprise.website || enterprise.phone"}
|
||||
%p.modal-header {{'contact' | t}}
|
||||
%p{"bo-if" => "enterprise.phone", "bo-text" => "enterprise.phone"}
|
||||
|
||||
%p.word-wrap{"ng-if" => "enterprise.email"}
|
||||
%a{"bo-href" => "enterprise.email | stripUrl", target: "_blank", mailto: true}
|
||||
%span.email{"bo-bind" => "enterprise.email | stripUrl"}
|
||||
%p.word-wrap{"ng-if" => "enterprise.email_address"}
|
||||
%a{"bo-href" => "enterprise.email_address | stripUrl", target: "_blank", mailto: true}
|
||||
%span.email{"bo-bind" => "enterprise.email_address | stripUrl"}
|
||||
|
||||
%p.word-wrap{"ng-if" => "enterprise.website"}
|
||||
%a{"bo-href-i" => "http://{{enterprise.website | stripUrl}}", target: "_blank", "bo-bind" => "enterprise.website | stripUrl"}
|
||||
|
||||
@@ -26,19 +26,6 @@
|
||||
%label{ for: 'enterprise_phone' } {{'enterprise_phone' | t}}:
|
||||
%input.chunky.small-12.columns{ id: 'enterprise_phone', name: 'phone', placeholder: "eg. (03) 1234 5678", ng: { model: 'enterprise.phone' } }
|
||||
.small-12.medium-12.large-5.hide-for-small-only
|
||||
/ %h6
|
||||
/ Contact display
|
||||
/ %i.ofn-i_013-help.has-tip{ 'data-tooltip' => true, title: "Choose how you want to display your contact details on the Open Food Network."}
|
||||
/ .row
|
||||
/ .small-12.columns
|
||||
/ %label.indent-checkbox
|
||||
/ %input{ type: 'checkbox', id: 'contact_name_profile', ng: { model: 'enterprise.name_in_profile' } } Display name in profile
|
||||
/ .small-12.columns
|
||||
/ %label.indent-checkbox
|
||||
/ %input{ type: 'checkbox', id: 'contact_email_profile', ng: { model: 'enterprise.email_in_profile' } } Display email in profile
|
||||
/ .small-12.columns
|
||||
/ %label.indent-checkbox
|
||||
/ %input{ type: 'checkbox', id: 'contact_phone_profile', ng: { model: 'enterprise.phone_in_profile' } } Display phone in profile
|
||||
|
||||
.row.buttons
|
||||
.small-12.columns
|
||||
|
||||
@@ -75,6 +75,7 @@ class Enterprise < ActiveRecord::Base
|
||||
|
||||
before_validation :initialize_permalink, if: lambda { permalink.nil? }
|
||||
before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? }
|
||||
before_validation :ensure_email_set
|
||||
before_validation :set_unused_address_fields
|
||||
after_validation :geocode_address
|
||||
|
||||
@@ -395,6 +396,10 @@ class Enterprise < ActiveRecord::Base
|
||||
users << owner unless users.include?(owner) || owner.admin?
|
||||
end
|
||||
|
||||
def ensure_email_set
|
||||
self.email = owner.email if email.blank?
|
||||
end
|
||||
|
||||
def enforce_ownership_limit
|
||||
unless owner.can_own_more_enterprises?
|
||||
errors.add(:owner, "^#{owner.email} is not permitted to own any more enterprises (limit is #{owner.enterprise_limit}).")
|
||||
|
||||
@@ -41,7 +41,7 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :name, :id, :description, :latitude, :longitude,
|
||||
:long_description, :website, :instagram, :linkedin, :twitter,
|
||||
:facebook, :is_primary_producer, :is_distributor, :phone, :visible,
|
||||
:email, :hash, :logo, :promo_image, :path, :pickup, :delivery,
|
||||
:email_address, :hash, :logo, :promo_image, :path, :pickup, :delivery,
|
||||
:icon, :icon_font, :producer_icon_font, :category, :producers, :hubs
|
||||
|
||||
attributes :taxons, :supplied_taxons
|
||||
@@ -67,8 +67,8 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
services ? services[:delivery] : false
|
||||
end
|
||||
|
||||
def email
|
||||
object.email.to_s.reverse
|
||||
def email_address
|
||||
object.email_address.to_s.reverse
|
||||
end
|
||||
|
||||
def hash
|
||||
|
||||
@@ -50,13 +50,9 @@
|
||||
= f.text_field :contact, { placeholder: "eg. Gustav Plum"}
|
||||
.row
|
||||
.alpha.three.columns
|
||||
= f.label :email
|
||||
= f.label :email_address
|
||||
.omega.nine.columns
|
||||
= f.text_field :email, { placeholder: "eg. gustav@truffles.com", "ng-model" => "Enterprise.email" }
|
||||
.alert-box
|
||||
%i.icon-info-sign
|
||||
If we don't recognise this email address we'll send you a confirmation email to make sure it belongs to you. You'll need to use the link in the email we send to fully activate your new enterprise.
|
||||
%a.close{ href: "" } ×
|
||||
= f.text_field :email_address, { placeholder: "eg. gustav@truffles.com", "ng-model" => "Enterprise.email_address" }
|
||||
.row
|
||||
.alpha.three.columns
|
||||
= f.label :phone
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
-if @enterprise.pending_any_confirmation?
|
||||
.alert-box
|
||||
- email = @enterprise.confirmed? ? @enterprise.unconfirmed_email : @enterprise.email
|
||||
Email confirmation is pending.
|
||||
We've sent a confirmation email to
|
||||
%strong= "#{email}."
|
||||
= link_to('Resend', main_app.enterprise_confirmation_path(enterprise: { id: @enterprise.id, email: email } ), method: :post)
|
||||
%a.close{ href: "#" } ×
|
||||
.row
|
||||
.alpha.three.columns
|
||||
= f.label :contact, 'Name'
|
||||
@@ -13,15 +5,9 @@
|
||||
= f.text_field :contact, { placeholder: "eg. Gustav Plum"}
|
||||
.row
|
||||
.alpha.three.columns
|
||||
= f.label :email
|
||||
%span.required *
|
||||
= f.label :email_address
|
||||
.omega.eight.columns
|
||||
= f.text_field :email, { placeholder: "eg. gustav@truffles.com", "ng-model" => "Enterprise.email" }
|
||||
.row{ ng: { hide: "pristineEmail == null || pristineEmail == Enterprise.email"} }
|
||||
.alpha.three.columns
|
||||
|
||||
.omega.eight.columns
|
||||
Note: A new email address may need to be confirmed prior to use
|
||||
= f.text_field :email_address, { placeholder: "eg. gustav@truffles.com" }
|
||||
.row
|
||||
.alpha.three.columns
|
||||
= f.label :phone
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
- owner_email = @enterprise.andand.owner.andand.email || ""
|
||||
- full_permissions = (spree_current_user.admin? || spree_current_user == @enterprise.andand.owner)
|
||||
|
||||
-if @enterprise.pending_any_confirmation?
|
||||
.alert-box
|
||||
- email = @enterprise.confirmed? ? @enterprise.unconfirmed_email : @enterprise.email
|
||||
Email confirmation is pending.
|
||||
We've sent a confirmation email to
|
||||
%strong= "#{email}."
|
||||
= link_to('Resend', main_app.enterprise_confirmation_path(enterprise: { id: @enterprise.id, email: email } ), method: :post)
|
||||
%a.close{ href: "#" } ×
|
||||
|
||||
.row
|
||||
.three.columns.alpha
|
||||
=f.label :owner_id, 'Owner'
|
||||
@@ -14,6 +23,24 @@
|
||||
- else
|
||||
= owner_email
|
||||
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :email, 'Notifications'
|
||||
- if full_permissions
|
||||
%span.required *
|
||||
.with-tip{'data-powertip' => "Notifications about orders will be send to this email address."}
|
||||
%a What's this?
|
||||
.eight.columns.omega
|
||||
- if full_permissions
|
||||
= f.text_field :email, { placeholder: "eg. gustav@truffles.com", "ng-model" => "Enterprise.email" }
|
||||
- else
|
||||
= @enterprise.email
|
||||
.row{ ng: { hide: "pristineEmail == null || pristineEmail == Enterprise.email"} }
|
||||
.alpha.three.columns
|
||||
|
||||
.omega.eight.columns
|
||||
Note: A new email address may need to be confirmed prior to use
|
||||
|
||||
.row
|
||||
.three.columns.alpha
|
||||
=f.label :user_ids, 'Managers'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook, :is_primary_producer, :is_distributor, :phone
|
||||
|
||||
node :email do |enterprise|
|
||||
enterprise.email.to_s.reverse
|
||||
node :email_address do |enterprise|
|
||||
enterprise.email_address.to_s.reverse
|
||||
end
|
||||
|
||||
child :address do
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
= t :ocs_closed_opens, time: distance_of_time_in_words_to_now(next_oc.orders_open_at)
|
||||
|
||||
%p
|
||||
= t(:ocs_closed_email, email: current_distributor.email) if current_distributor.email
|
||||
= t(:ocs_closed_email, email: current_distributor.email_address) if current_distributor.email_address
|
||||
%br/
|
||||
= t(:ocs_closed_phone, phone: current_distributor.phone) if current_distributor.phone
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
%div.show-for-medium-up{"ng-if" => "producer.supplied_taxons.length==0"}
|
||||
|
||||
|
||||
%div{"bo-if" => "producer.email || producer.website || producer.phone"}
|
||||
%div{"bo-if" => "producer.email_address || producer.website || producer.phone"}
|
||||
%label
|
||||
= t :producers_contact
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
= t :producers_contact_phone
|
||||
%span{"bo-text" => "producer.phone"}
|
||||
|
||||
%p.word-wrap{"bo-if" => "producer.email"}
|
||||
%a{"bo-href" => "producer.email | stripUrl", target: "_blank", mailto: true}
|
||||
%span.email{"bo-bind" => "producer.email | stripUrl"}
|
||||
%p.word-wrap{"bo-if" => "producer.email_address"}
|
||||
%a{"bo-href" => "producer.email_address | stripUrl", target: "_blank", mailto: true}
|
||||
%span.email{"bo-bind" => "producer.email_address | stripUrl"}
|
||||
|
||||
%p.word-wrap{"bo-if" => "producer.website"}
|
||||
%a{"bo-href-i" => "http://{{producer.website | stripUrl}}", target: "_blank" }
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
= current_distributor.address.zipcode
|
||||
|
||||
.small-12.large-4.columns
|
||||
- if current_distributor.website || current_distributor.email
|
||||
- if current_distributor.website || current_distributor.email_address
|
||||
%div.center
|
||||
.header
|
||||
= t :shopping_contact_web
|
||||
@@ -27,10 +27,10 @@
|
||||
%a{href: "http://#{current_distributor.website}", target: "_blank" }
|
||||
= current_distributor.website
|
||||
%br
|
||||
- unless current_distributor.email.blank?
|
||||
%a{href: current_distributor.email.reverse, mailto: true}
|
||||
- unless current_distributor.email_address.blank?
|
||||
%a{href: current_distributor.email_address.reverse, mailto: true}
|
||||
%span.email
|
||||
= current_distributor.email.reverse
|
||||
= current_distributor.email_address.reverse
|
||||
|
||||
.small-12.large-4.columns
|
||||
- if current_distributor.twitter.present? || current_distributor.facebook.present? || current_distributor.linkedin.present? || current_distributor.instagram.present?
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddEmailAddressToEnterprises < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :enterprises, :email_address, :string
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class SetEnterpriseEmailAddress < ActiveRecord::Migration
|
||||
def up
|
||||
Enterprise.all.each do |enterprise|
|
||||
enterprise.email_address = enterprise.email
|
||||
enterprise.save
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20151128185900) do
|
||||
ActiveRecord::Schema.define(:version => 20160212092908) do
|
||||
|
||||
create_table "account_invoices", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
@@ -346,6 +346,7 @@ ActiveRecord::Schema.define(:version => 20151128185900) do
|
||||
t.boolean "producer_profile_only", :default => false
|
||||
t.string "permalink", :null => false
|
||||
t.boolean "charges_sales_tax", :default => false, :null => false
|
||||
t.string "email_address"
|
||||
end
|
||||
|
||||
add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id"
|
||||
|
||||
Reference in New Issue
Block a user