diff options
Diffstat (limited to 'misc/freeswitch/scripts')
-rw-r--r-- | misc/freeswitch/scripts/common/group.lua | 31 | ||||
-rw-r--r-- | misc/freeswitch/scripts/dialplan/dialplan.lua | 2 |
2 files changed, 10 insertions, 23 deletions
diff --git a/misc/freeswitch/scripts/common/group.lua b/misc/freeswitch/scripts/common/group.lua index b89585a..1a2d315 100644 --- a/misc/freeswitch/scripts/common/group.lua +++ b/misc/freeswitch/scripts/common/group.lua @@ -36,32 +36,19 @@ function Group.find_by_id(self, id) end -- list groups by member permissions -function Group.name_id_by_member_permissions(self, member_id, member_type, permissions, targets) +function Group.name_id_by_permission(self, member_id, member_type, permission) if not tonumber(member_id) then return {}; end - local sql_query = nil; - - if targets then - sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ - FROM `group_permissions` `a` \ - JOIN `group_memberships` `b` ON `a`.`target_group_id` = `b`.`group_id` \ - JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ - WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ - AND `b`.`item_id` = ' .. member_id .. ' \ - AND `a`.`permission` IN ("' .. table.concat(permissions, ',') .. '") \ - GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; - else - sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ - FROM `group_permissions` `a` \ - JOIN `group_memberships` `b` ON `a`.`group_id` = `b`.`group_id` \ - JOIN `groups` `c` ON `c`.`id` = `a`.`group_id` \ - WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ - AND `b`.`item_id` = ' .. member_id .. ' \ - AND `a`.`permission` IN ("' .. table.concat(permissions, ',') .. '") \ - GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; - end + local sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ + FROM `group_permissions` `a` \ + JOIN `group_memberships` `b` ON `a`.`target_group_id` = `b`.`group_id` \ + JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ + WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ + AND `b`.`item_id` = ' .. member_id .. ' \ + AND `a`.`permission` = ' .. self.database:escape(permission, '"') .. ' \ + GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; local group_names = {}; local group_ids = {}; diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 93a952d..7945516 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -390,7 +390,7 @@ function Dialplan.dial(self, destination) table.insert(destination.pickup_groups, 's' .. destination.account.id ); end require 'common.group'; - local group_names, group_ids = common.group.Group:new{ log = self.log, database = self.database }:name_id_by_member_permissions(destination.id, destination.type, {'pickup'}, true) + local group_names, group_ids = common.group.Group:new{ log = self.log, database = self.database }:name_id_by_permission(destination.id, destination.type, 'pickup') self.log:debug('DESTINATION_GROUPS - pickup_groups: ', table.concat(group_names, ',')); for index=1, #group_ids do table.insert(destination.pickup_groups, 'g' .. group_ids[index]); |