From d15047f9965803ba021eba226241c43d133930cb Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 4 Mar 2013 03:31:46 -0500 Subject: permission_targets method added --- misc/freeswitch/scripts/common/group.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/misc/freeswitch/scripts/common/group.lua b/misc/freeswitch/scripts/common/group.lua index c4125bc..5bd866e 100644 --- a/misc/freeswitch/scripts/common/group.lua +++ b/misc/freeswitch/scripts/common/group.lua @@ -86,3 +86,26 @@ function Group.name_id_by_member(self, member_id, member_type) return group_names, group_ids; end + +function Group.permission_targets(self, group_ids, permission) + if not group_ids or not permission then + return {}; + end + + local sql_query = 'SELECT DISTINCT `b`.`id`, `b`.`name` \ + FROM `group_permissions` `a` \ + JOIN `groups` `b` ON `b`.`id` = `a`.`target_group_id` \ + WHERE `a`.`permission` = ' .. self.database:escape(permission, '"') .. ' \ + AND `a`.`group_id` IN (' .. table.concat(group_ids, ',') .. ') \ + AND `b`.`active` IS TRUE \ + GROUP BY `a`.`target_group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; + + + local groups = {}; + + self.database:query(sql_query, function(account_entry) + groups[account_entry.id] = account_entry.name; + end); + + return groups; +end -- cgit v1.2.3