diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ability.rb | 5 | ||||
-rw-r--r-- | app/models/call_route.rb | 2 | ||||
-rw-r--r-- | app/models/sip_account.rb | 6 | ||||
-rw-r--r-- | app/models/switchboard.rb | 16 | ||||
-rw-r--r-- | app/models/switchboard_entry.rb | 31 | ||||
-rw-r--r-- | app/models/user.rb | 2 |
6 files changed, 61 insertions, 1 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb index fe67547..2dd96b8 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -183,6 +183,11 @@ class Ability # can :manage, VoicemailMessage can :manage, VoicemailSetting + + # Switchboard + # + can :read, Switchboard, :id => user.switchboard_ids + can :read, SwitchboardEntry, :switchboard_id => user.switchboard_ids end end else diff --git a/app/models/call_route.rb b/app/models/call_route.rb index 8bc811a..6c54549 100644 --- a/app/models/call_route.rb +++ b/app/models/call_route.rb @@ -7,7 +7,7 @@ class CallRoute < ActiveRecord::Base has_many :route_elements, :dependent => :destroy, :order => :position validates :name, - :presence => true + :presence => true validates :routing_table, :presence => true, diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index bb45a4c..cea5f0e 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -42,6 +42,7 @@ class SipAccount < ActiveRecord::Base has_many :b_call_legs, :class_name => 'Call', :foreign_key => 'b_sip_account_id' has_many :acd_agents, :as => :destination, :dependent => :destroy + has_many :switchboard_entries, :dependent => :destroy # Delegations: # @@ -212,6 +213,11 @@ class SipAccount < ActiveRecord::Base return states end + def non_e164_phone_numbers + array_of_phone_numbers_as_strings = self.phone_numbers.map{ |phone_number| phone_number.number.to_s }.sort + self.phone_numbers.where(:number => array_of_phone_numbers_as_strings.select { |phone_number| phone_number[0] != '+' }) + end + private def save_value_of_to_s diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb new file mode 100644 index 0000000..74e2767 --- /dev/null +++ b/app/models/switchboard.rb @@ -0,0 +1,16 @@ +class Switchboard < ActiveRecord::Base + # https://github.com/rails/strong_parameters + include ActiveModel::ForbiddenAttributesProtection + + validates :name, + :presence => true, + :uniqueness => {:scope => :user_id} + + belongs_to :user, :touch => true + has_many :switchboard_entries, :dependent => :destroy + has_many :sip_accounts, :through => :switchboard_entries + + def to_s + self.name.to_s + end +end diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb new file mode 100644 index 0000000..76d002f --- /dev/null +++ b/app/models/switchboard_entry.rb @@ -0,0 +1,31 @@ +class SwitchboardEntry < ActiveRecord::Base + # https://github.com/rails/strong_parameters + include ActiveModel::ForbiddenAttributesProtection + + belongs_to :switchboard, :touch => true + belongs_to :sip_account, :touch => true + + validates :switchboard, + :presence => true + + validates :sip_account, + :presence => true + + validates :name, + :length => { :maximum => 10 }, + :uniqueness => {:scope => :switchboard_id}, + :allow_blank => true, + :allow_nil => true + + acts_as_list :scope => [ :switchboard_id ] + + default_scope order(:position) + + def to_s + if self.name.blank? && !self.sip_account.to_s.blank? + self.sip_account.to_s + else + self.name.to_s + end + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 913d75f..6091e32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,6 +94,8 @@ class User < ActiveRecord::Base has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true has_many :groups, :through => :group_memberships + has_many :switchboards, :dependent => :destroy + # Avatar like photo mount_uploader :image, ImageUploader |