diff options
author | Peter Kozak <spag@golwen.net> | 2013-03-06 09:13:17 -0500 |
---|---|---|
committer | Peter Kozak <spag@golwen.net> | 2013-03-06 09:13:17 -0500 |
commit | bc3f8ae65689046f2b41123c7b392c4718d48dfd (patch) | |
tree | 9d6b9696f5b48c12eeef7da2f14aff17fac85556 /app | |
parent | 5ebafb77ecbfdb2cb22a6d3acdd4a9b56dca8ad0 (diff) |
target_sip_accounts_by_permission method added
Diffstat (limited to 'app')
-rw-r--r-- | app/models/sip_account.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 5660e37..1499d62 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -156,6 +156,24 @@ class SipAccount < ActiveRecord::Base end + def target_sip_accounts_by_permission(permission) + target_groups = Group.union(self.groups.collect{|g| g.permission_targets(permission)}) + target_groups = target_groups + Group.union(self.sip_accountable.groups.collect{|g| g.permission_targets(permission)}) + sip_accounts = [] + GroupMembership.where(:group_id => target_groups).each do |group_membership| + if group_membership.item.class == User || group_membership.item.class == Tenant + sip_accounts = sip_accounts + group_membership.item.sip_accounts + elsif group_membership.item.class == SipAccount + sip_accounts << group_membership.item + end + + sip_accounts = sip_accounts.uniq + end + + return sip_accounts + end + + private def save_value_of_to_s |