summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-04 03:31:46 -0500
committerPeter Kozak <spag@golwen.net>2013-03-04 03:31:46 -0500
commitd15047f9965803ba021eba226241c43d133930cb (patch)
tree68df453767e71c54ee515213a4d16d0ea1951aaf
parent295ca363ad12150b7a029075e915574afd61c82e (diff)
permission_targets method added
-rw-r--r--misc/freeswitch/scripts/common/group.lua23
1 files changed, 23 insertions, 0 deletions
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