mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Use receives_notifications flag for enterprise contact
This commit is contained in:
committed by
Rob Harrington
parent
9e270690ef
commit
4d11485283
@@ -2,7 +2,6 @@ module Api
|
||||
class EnterprisesController < Spree::Api::BaseController
|
||||
|
||||
before_filter :override_owner, only: [:create, :update]
|
||||
before_filter :set_contact, only: [:create]
|
||||
before_filter :check_type, only: :update
|
||||
before_filter :override_sells, only: [:create, :update]
|
||||
before_filter :override_visible, only: [:create, :update]
|
||||
@@ -54,10 +53,6 @@ module Api
|
||||
params[:enterprise][:owner_id] = current_api_user.id
|
||||
end
|
||||
|
||||
def set_contact
|
||||
params[:enterprise][:contact_id] = current_api_user.id
|
||||
end
|
||||
|
||||
def check_type
|
||||
params[:enterprise].delete :type unless current_api_user.admin?
|
||||
end
|
||||
|
||||
@@ -33,7 +33,6 @@ class Enterprise < ActiveRecord::Base
|
||||
has_many :enterprise_roles, :dependent => :destroy
|
||||
has_many :users, through: :enterprise_roles
|
||||
belongs_to :owner, class_name: 'Spree::User', foreign_key: :owner_id, inverse_of: :owned_enterprises
|
||||
belongs_to :contact, class_name: 'Spree::User', foreign_key: :contact_id, inverse_of: :contact_enterprises
|
||||
has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id'
|
||||
has_many :distributor_shipping_methods, foreign_key: :distributor_id
|
||||
has_many :shipping_methods, through: :distributor_shipping_methods
|
||||
@@ -82,7 +81,7 @@ class Enterprise < ActiveRecord::Base
|
||||
after_validation :geocode_address
|
||||
|
||||
after_touch :touch_distributors
|
||||
before_create :set_default_contact
|
||||
after_create :set_default_contact
|
||||
after_create :relate_to_owners_enterprises
|
||||
after_create :send_welcome_email
|
||||
|
||||
@@ -178,6 +177,10 @@ class Enterprise < ActiveRecord::Base
|
||||
count(distinct: true)
|
||||
end
|
||||
|
||||
def contact
|
||||
EnterpriseRole.receives_notifications_for self.id
|
||||
end
|
||||
|
||||
def activated?
|
||||
contact.confirmed? && sells != 'unspecified'
|
||||
end
|
||||
@@ -384,7 +387,7 @@ class Enterprise < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def set_default_contact
|
||||
self.contact_id = self.owner_id if self.contact_id.nil?
|
||||
EnterpriseRole.set_notification_user self.owner_id, self.id
|
||||
end
|
||||
|
||||
def relate_to_owners_enterprises
|
||||
|
||||
@@ -6,7 +6,6 @@ Spree.user_class.class_eval do
|
||||
has_many :enterprise_roles, :dependent => :destroy
|
||||
has_many :enterprises, through: :enterprise_roles
|
||||
has_many :owned_enterprises, class_name: 'Enterprise', foreign_key: :owner_id, inverse_of: :owner
|
||||
has_many :contact_enterprises, class_name: 'Enterprise', foreign_key: :contact_id, inverse_of: :contact
|
||||
has_many :owned_groups, class_name: 'EnterpriseGroup', foreign_key: :owner_id, inverse_of: :owner
|
||||
has_many :account_invoices
|
||||
has_many :billable_periods, foreign_key: :owner_id, inverse_of: :owner
|
||||
|
||||
@@ -67,7 +67,7 @@ feature "Registration", js: true do
|
||||
expect(e.address.address1).to eq "123 Abc Street"
|
||||
expect(e.sells).to eq "unspecified"
|
||||
expect(e.is_primary_producer).to eq true
|
||||
expect(e.contact_id).to eq e.owner_id
|
||||
expect(e.contact.id).to eq e.owner_id
|
||||
|
||||
# Filling in about
|
||||
fill_in 'enterprise_description', with: 'Short description'
|
||||
|
||||
Reference in New Issue
Block a user