From 1bcb85853b282606f28f1c9cd7f4e13d494a7290 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 03:44:36 -0500 Subject: presence permissions for softkeys added --- app/models/softkey.rb | 26 ++++++++++++++++++++++++++ app/views/softkeys/_form_core.html.haml | 5 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 470605c..6063017 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -42,6 +42,10 @@ class Softkey < ActiveRecord::Base return call_forwards end + def possible_blf_sip_accounts + self.sip_account.target_sip_accounts_by_permission('presence') + end + def to_s if self.softkeyable.blank? if ['log_out', 'log_in'].include?(self.softkey_function.name) @@ -77,7 +81,29 @@ class Softkey < ActiveRecord::Base if self.softkey_function_id != nil case self.softkey_function.name when 'blf' + has_permission = false self.softkeyable = PhoneNumber.where(:number => self.number, :phone_numberable_type => 'SipAccount').first.try(:phone_numberable) + if self.softkeyable + self.sip_account.groups.each do |group| + if group.has_permission(self.softkeyable.class.name, self.softkeyable.id, :presence) + has_permission = true + break + end + end + if !has_permission && self.sip_account.sip_accountable + self.sip_account.sip_accountable.groups.each do |group| + if group.has_permission(self.softkeyable.class.name, self.softkeyable.id, :presence) + has_permission = true + break + end + end + end + end + + if !has_permission + self.softkeyable = nil + self.number = nil + end when 'conference' self.softkeyable = PhoneNumber.where(:number => self.number, :phone_numberable_type => 'Conference').first.try(:phone_numberable) when 'call_forwarding' diff --git a/app/views/softkeys/_form_core.html.haml b/app/views/softkeys/_form_core.html.haml index 7c1dd4a..f447aa6 100644 --- a/app/views/softkeys/_form_core.html.haml +++ b/app/views/softkeys/_form_core.html.haml @@ -6,7 +6,8 @@ .inputs = f.input :softkey_function_id, :as => :select, :collection => @softkey_functions.map {|x| [I18n.t("softkeys.functions.#{x}"), x.id] }, :label => t('softkeys.form.function.label'), :hint => conditional_hint('softkeys.form.function.hint'), :include_blank => false - - if @softkey.possible_call_forwards && @softkey.possible_call_forwards.count > 0 - = f.association :softkeyable, :collection => @softkey.possible_call_forwards, :label => t('softkeys.form.call_forward.label'), :hint => conditional_hint('softkeys.form.call_forward.hint'), :include_blank => false + - call_forwards = @softkey.possible_call_forwards + - if call_forwards && call_forwards.count > 0 + = f.association :softkeyable, :collection => call_forwards, :label => t('softkeys.form.call_forward.label'), :hint => conditional_hint('softkeys.form.call_forward.hint'), :include_blank => false = f.input :number, :label => t('softkeys.form.number.label'), :hint => conditional_hint('softkeys.form.number.hint') = f.input :label, :label => t('softkeys.form.label.label'), :hint => conditional_hint('softkeys.form.label.hint') -- cgit v1.2.3