mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Update enterprise managers and contact role
This commit is contained in:
committed by
Rob Harrington
parent
5dc8f21b7b
commit
15b781b271
@@ -1,12 +1,12 @@
|
||||
angular.module("admin.enterprises")
|
||||
.controller "enterpriseCtrl", ($scope, $window, NavigationCheck, enterprise, EnterprisePaymentMethods, EnterpriseShippingMethods, SideMenu, StatusMessage) ->
|
||||
.controller "enterpriseCtrl", ($scope, $window, NavigationCheck, enterprise, enterpriseRoles, EnterprisePaymentMethods, EnterpriseShippingMethods, SideMenu, StatusMessage) ->
|
||||
$scope.Enterprise = enterprise
|
||||
$scope.EnterpriseRoles = enterpriseRoles
|
||||
$scope.PaymentMethods = EnterprisePaymentMethods.paymentMethods
|
||||
$scope.ShippingMethods = EnterpriseShippingMethods.shippingMethods
|
||||
$scope.navClear = NavigationCheck.clear
|
||||
$scope.menu = SideMenu
|
||||
$scope.newManager = { id: '', email: (t('add_manager')) }
|
||||
|
||||
$scope.StatusMessage = StatusMessage
|
||||
|
||||
$scope.$watch 'enterprise_form.$dirty', (newValue) ->
|
||||
@@ -35,7 +35,7 @@ angular.module("admin.enterprises")
|
||||
|
||||
$scope.removeManager = (manager) ->
|
||||
if manager.id?
|
||||
if manager.id == $scope.Enterprise.owner.id
|
||||
if manager.id == $scope.Enterprise.owner.id or manager.id == parseInt($scope.receivesNotifications)
|
||||
return
|
||||
for i, user of $scope.Enterprise.users when user.id == manager.id
|
||||
$scope.Enterprise.users.splice i, 1
|
||||
|
||||
@@ -1 +1 @@
|
||||
angular.module("admin.enterprises", [
|
||||
angular.module("admin.enterprises", [
|
||||
@@ -4,10 +4,18 @@ form[name="enterprise_form"] {
|
||||
}
|
||||
|
||||
table.managers {
|
||||
i.confirmation {
|
||||
i.role {
|
||||
float: right;
|
||||
margin-left: 0.5em;
|
||||
font-size: 1.5em;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
i.confirmation {
|
||||
margin-left: 0.2em;
|
||||
font-size: 1.2em;
|
||||
cursor: pointer;
|
||||
vertical-align: bottom;
|
||||
|
||||
&.confirmed {
|
||||
color: #1ece1e;
|
||||
|
||||
@@ -11,6 +11,7 @@ module Admin
|
||||
before_filter :load_methods_and_fees, :only => [:edit, :update]
|
||||
before_filter :load_groups, :only => [:new, :edit, :update, :create]
|
||||
before_filter :load_taxons, :only => [:new, :edit, :update, :create]
|
||||
before_filter :load_roles, only: :edit
|
||||
before_filter :check_can_change_sells, only: :update
|
||||
before_filter :check_can_change_bulk_sells, only: :bulk_update
|
||||
before_filter :check_can_change_owner, only: :update
|
||||
@@ -39,6 +40,7 @@ module Admin
|
||||
invoke_callbacks(:update, :before)
|
||||
tag_rules_attributes = params[object_name].delete :tag_rules_attributes
|
||||
update_tag_rules(tag_rules_attributes) if tag_rules_attributes.present?
|
||||
update_enterprise_notifications
|
||||
if @object.update_attributes(params[object_name])
|
||||
invoke_callbacks(:update, :after)
|
||||
flash[:success] = flash_message_for(@object, :successfully_updated)
|
||||
@@ -184,6 +186,11 @@ module Admin
|
||||
@taxons = Spree::Taxon.order(:name)
|
||||
end
|
||||
|
||||
def load_roles
|
||||
@enterprise_roles = EnterpriseRole.find_all_by_enterprise_id(@enterprise.id)
|
||||
@notification_user = EnterpriseRole.receives_notifications_for(@enterprise.id).try(:id)
|
||||
end
|
||||
|
||||
def update_tag_rules(tag_rules_attributes)
|
||||
# Due to the combination of trying to use nested attributes and type inheritance
|
||||
# we cannot apply all attributes to tag rules in one hit because mass assignment
|
||||
@@ -198,6 +205,13 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def update_enterprise_notifications
|
||||
notify_user = params[:receives_notifications]
|
||||
if notify_user.present?
|
||||
EnterpriseRole.set_notification_user notify_user, @object.id
|
||||
end
|
||||
end
|
||||
|
||||
def create_calculator_for(rule, attrs)
|
||||
if attrs[:calculator_type].present? && attrs[:calculator_attributes].present?
|
||||
rule.update_attributes(calculator_type: attrs[:calculator_type])
|
||||
|
||||
@@ -6,4 +6,23 @@ class EnterpriseRole < ActiveRecord::Base
|
||||
validates_uniqueness_of :enterprise_id, scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error)
|
||||
|
||||
scope :by_user_email, joins(:user).order('spree_users.email ASC')
|
||||
|
||||
def self.receives_notifications_for(enterprise_id)
|
||||
manager = EnterpriseRole.find_by_enterprise_id_and_receives_notifications(enterprise_id, true)
|
||||
Spree::User.find(manager.user_id)
|
||||
end
|
||||
|
||||
def self.set_notification_user(user_id, enterprise_id)
|
||||
managers_for(enterprise_id).map do |m|
|
||||
if m.user_id == user_id.to_i
|
||||
m.update_attributes receives_notifications: true
|
||||
elsif m.user_id != user_id.to_i && m.receives_notifications
|
||||
m.update_attributes receives_notifications: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.managers_for(enterprise_id)
|
||||
EnterpriseRole.where(enterprise_id: enterprise_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Api::Admin::EnterpriseRoleSerializer < ActiveModel::Serializer
|
||||
attributes :id, :user_id, :enterprise_id, :user_email, :enterprise_name
|
||||
attributes :id, :user_id, :enterprise_id, :user_email, :enterprise_name, :receives_notifications
|
||||
|
||||
def user_email
|
||||
object.user.email
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
= admin_inject_enterprise
|
||||
= admin_inject_enterprise_roles
|
||||
= admin_inject_taxons
|
||||
= admin_inject_payment_methods
|
||||
= admin_inject_shipping_methods
|
||||
|
||||
@@ -10,30 +10,23 @@
|
||||
%a= t('admin.whats_this')
|
||||
.eight.columns.omega
|
||||
- if full_permissions
|
||||
= f.hidden_field :owner_id, class: "select2 fullwidth", 'user-select' => 'Enterprise.owner'
|
||||
= f.hidden_field :owner_id, class: "select2 fullwidth", 'user-select' => 'Enterprise.owner', 'ng-model' => 'Enterprise.owner'
|
||||
- else
|
||||
= owner_email
|
||||
|
||||
.row
|
||||
.three.columns.alpha
|
||||
=f.label :user_ids, t('.contact')
|
||||
- if full_permissions
|
||||
%span.required *
|
||||
%div{'ofn-with-tip' => t('.contact_tip')}
|
||||
%a= t('admin.whats_this')
|
||||
|
||||
-# TODO: add contact field, possibly re-use some of these tooltip keys
|
||||
|
||||
-#.row
|
||||
-# .three.columns.alpha
|
||||
-# = f.label :email, t('.notifications')
|
||||
-# - if full_permissions
|
||||
-# %span.required *
|
||||
-# .with-tip{'data-powertip' => t('.notifications_tip')}
|
||||
-# %a= t('admin.whats_this')
|
||||
-# .eight.columns.omega
|
||||
-# - if full_permissions
|
||||
-# = f.text_field :email, { placeholder: t('.notifications_placeholder'), "ng-model" => "Enterprise.email" }
|
||||
-# - else
|
||||
-# = @enterprise.email
|
||||
-#.row{ ng: { hide: "pristineEmail == null || pristineEmail == Enterprise.email"} }
|
||||
-# .alpha.three.columns
|
||||
-#
|
||||
-# .omega.eight.columns
|
||||
-# = t('.notifications_note')
|
||||
- if full_permissions
|
||||
.eight.columns.omega
|
||||
%select.select2.fullwidth{name: 'receives_notifications', ng: {model: 'receivesNotifications', init: "receivesNotifications = '#{@notification_user}'"}}
|
||||
%option{ng: {repeat: 'user in Enterprise.users', selected: "user.id == #{@notification_user}", hide: '!user.confirmed'}, value: '{{user.id}}'}
|
||||
{{user.email}}
|
||||
|
||||
.row
|
||||
.three.columns.alpha
|
||||
@@ -57,8 +50,11 @@
|
||||
{{ manager.email }}
|
||||
%i.confirmation.confirmed.fa.fa-check-circle{ 'ofn-with-tip' => t('.email_confirmed'), ng: {show: 'manager.confirmed'} }
|
||||
%i.confirmation.unconfirmed.fa.fa-exclamation-triangle{ 'ofn-with-tip' => t('.email_not_confirmed'), ng: {show: '!manager.confirmed'} }
|
||||
%i.role.contact.fa.fa-envelope-o{ 'ofn-with-tip' => t('.contact'), ng: {show: 'manager.id == receivesNotifications'} }
|
||||
%i.role.owner.fa.fa-star{ 'ofn-with-tip' => t('.owner'), ng: {show: 'manager.id == Enterprise.owner.id'} }
|
||||
%td.actions
|
||||
%a{ ng: {click: 'removeManager(manager)', class: "{disabled: manager.id == Enterprise.owner.id}"}, :class => "icon-trash no-text" }
|
||||
%a{ ng: {click: 'removeManager(manager)', class: "{disabled: manager.id == Enterprise.owner.id || manager.id == receivesNotifications}"}, :class => "icon-trash no-text" }
|
||||
|
||||
- else
|
||||
- @enterprise.users.each do |manager|
|
||||
= manager.email
|
||||
|
||||
@@ -563,6 +563,8 @@ en:
|
||||
email_confirmation_notice_html: "Email confirmation is pending. We've sent a confirmation email to %{email}."
|
||||
resend: Resend
|
||||
owner: 'Owner'
|
||||
contact: "Contact"
|
||||
contact_tip: "The manager who will receive enterprise emails for orders and notifications. Must have a confirmed email adress."
|
||||
owner_tip: The primary user responsible for this enterprise.
|
||||
notifications: Notifications
|
||||
notifications_tip: Notifications about orders will be send to this email address.
|
||||
|
||||
Reference in New Issue
Block a user