app/models/entities/contact.rb in fat_free_crm-0.16.4 vs app/models/entities/contact.rb in fat_free_crm-0.17.1
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
@@ -88,11 +90,11 @@
acts_as_taggable_on :tags
has_paper_trail class_name: 'Version', ignore: [:subscribed_users]
has_fields
exportable
- sortable by: ["first_name ASC", "last_name ASC", "created_at DESC", "updated_at DESC"], default: "created_at DESC"
+ sortable by: ["first_name ASC", "last_name ASC", "created_at DESC", "updated_at DESC"], default: "created_at DESC"
validates_presence_of :first_name, message: :missing_first_name, if: -> { Setting.require_first_names }
validates_presence_of :last_name, message: :missing_last_name, if: -> { Setting.require_last_names }
validate :users_for_shared_access
@@ -196,21 +198,21 @@
private
# Make sure at least one user has been selected if the contact is being shared.
#----------------------------------------------------------------------------
def users_for_shared_access
- errors.add(:access, :share_contact) if self[:access] == "Shared" && !permissions.any?
+ errors.add(:access, :share_contact) if self[:access] == "Shared" && permissions.none?
end
# Handles the saving of related accounts
#----------------------------------------------------------------------------
def save_account(params)
account_params = params[:account]
- if !account_params || account_params[:id] == "" || account_params[:name] == ""
- self.account = nil
- else
- self.account = Account.create_or_select_for(self, account_params)
- end
+ self.account = if account_params && account_params[:id] != "" && account_params[:name] != ""
+ Account.create_or_select_for(self, account_params)
+ else
+ nil
+ end
end
ActiveSupport.run_load_hooks(:fat_free_crm_contact, self)
end