diff --git a/app/assets/javascripts/templates/partials/contact.html.haml b/app/assets/javascripts/templates/partials/contact.html.haml index bdde30b8bb..12aa5ff061 100644 --- a/app/assets/javascripts/templates/partials/contact.html.haml +++ b/app/assets/javascripts/templates/partials/contact.html.haml @@ -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"} diff --git a/app/assets/javascripts/templates/registration/contact.html.haml b/app/assets/javascripts/templates/registration/contact.html.haml index b2a2164910..6e7389d73a 100644 --- a/app/assets/javascripts/templates/registration/contact.html.haml +++ b/app/assets/javascripts/templates/registration/contact.html.haml @@ -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 diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 34a5d22f5b..033b4b79d7 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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}).") diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 287ebfe872..3210c1d2af 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -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 diff --git a/app/views/admin/enterprises/_new_form.html.haml b/app/views/admin/enterprises/_new_form.html.haml index 3ab9392712..fbb5a6efc1 100644 --- a/app/views/admin/enterprises/_new_form.html.haml +++ b/app/views/admin/enterprises/_new_form.html.haml @@ -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 diff --git a/app/views/admin/enterprises/form/_contact.html.haml b/app/views/admin/enterprises/form/_contact.html.haml index df28b6a921..28bbd6014b 100644 --- a/app/views/admin/enterprises/form/_contact.html.haml +++ b/app/views/admin/enterprises/form/_contact.html.haml @@ -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 diff --git a/app/views/admin/enterprises/form/_users.html.haml b/app/views/admin/enterprises/form/_users.html.haml index 289a85d7a1..42e25fad0a 100644 --- a/app/views/admin/enterprises/form/_users.html.haml +++ b/app/views/admin/enterprises/form/_users.html.haml @@ -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' diff --git a/app/views/json/partials/_enterprise.rabl b/app/views/json/partials/_enterprise.rabl index 6e17cf3c58..ca99b9d14c 100644 --- a/app/views/json/partials/_enterprise.rabl +++ b/app/views/json/partials/_enterprise.rabl @@ -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 diff --git a/app/views/order_cycles/_orders_closed.html.haml b/app/views/order_cycles/_orders_closed.html.haml index ae0568ae2d..782c680add 100644 --- a/app/views/order_cycles/_orders_closed.html.haml +++ b/app/views/order_cycles/_orders_closed.html.haml @@ -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 diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index c1de090978..9faa239c02 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -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" } diff --git a/app/views/shopping_shared/_contact.html.haml b/app/views/shopping_shared/_contact.html.haml index a88c421270..100d64d958 100644 --- a/app/views/shopping_shared/_contact.html.haml +++ b/app/views/shopping_shared/_contact.html.haml @@ -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? diff --git a/db/migrate/20160205044930_add_email_address_to_enterprises.rb b/db/migrate/20160205044930_add_email_address_to_enterprises.rb new file mode 100644 index 0000000000..b1047fe4b8 --- /dev/null +++ b/db/migrate/20160205044930_add_email_address_to_enterprises.rb @@ -0,0 +1,5 @@ +class AddEmailAddressToEnterprises < ActiveRecord::Migration + def change + add_column :enterprises, :email_address, :string + end +end diff --git a/db/migrate/20160212092908_set_enterprise_email_address.rb b/db/migrate/20160212092908_set_enterprise_email_address.rb new file mode 100644 index 0000000000..a43591624a --- /dev/null +++ b/db/migrate/20160212092908_set_enterprise_email_address.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 465530b949..57fbf4f52d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"