summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch/scripts/common')
-rw-r--r--misc/freeswitch/scripts/common/group.lua46
-rw-r--r--misc/freeswitch/scripts/common/object.lua106
2 files changed, 147 insertions, 5 deletions
diff --git a/misc/freeswitch/scripts/common/group.lua b/misc/freeswitch/scripts/common/group.lua
index ac2f542..db56129 100644
--- a/misc/freeswitch/scripts/common/group.lua
+++ b/misc/freeswitch/scripts/common/group.lua
@@ -87,6 +87,7 @@ 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 {};
@@ -100,18 +101,36 @@ function Group.permission_targets(self, group_ids, permission)
AND `b`.`active` IS TRUE \
GROUP BY `a`.`target_group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS;
-
- local groups = {};
+ local group_names = {};
+ local group_ids = {};
self.database:query(sql_query, function(account_entry)
- groups[account_entry.id] = account_entry.name;
+ table.insert(group_names, account_entry.name);
+ table.insert(group_ids, tonumber(account_entry.id));
end);
- return groups;
+ return group_names, group_ids;
+end
+
+
+function Group.is_target(self, group_id, permission)
+ if not group_id or not permission then
+ return nil;
+ end
+
+ local sql_query = 'SELECT `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` = ' .. tonumber(group_id) .. ' \
+ AND `b`.`active` IS TRUE \
+ LIMIT 1';
+
+ return self.database:query_return_value(sql_query);
end
-function Group.combine(self, ...)
+function Group.union(self, ...)
local groups = {};
local group_sets = {...};
for set_index=1, #group_sets do
@@ -130,3 +149,20 @@ function Group.combine(self, ...)
return group_ids;
end
+
+
+function Group.intersection(self, set_one, set_two)
+ local basic_set = {};
+ for index=1, #set_one do
+ basic_set[set_one[index]] = true;
+ end
+
+ local final_set = {};
+ for index=1, #set_two do
+ if basic_set[set_two[index]] then
+ table.insert(final_set, set_two[index]);
+ end
+ end
+
+ return final_set;
+end
diff --git a/misc/freeswitch/scripts/common/object.lua b/misc/freeswitch/scripts/common/object.lua
new file mode 100644
index 0000000..5183b9f
--- /dev/null
+++ b/misc/freeswitch/scripts/common/object.lua
@@ -0,0 +1,106 @@
+-- Gemeinschaft 5 module: object class
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+Object = {}
+
+-- create object object ;)
+function Object.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.class = 'object';
+ self.log = arg.log;
+ self.database = arg.database;
+ return object;
+end
+
+-- find object
+function Object.find(self, attributes)
+ if not attributes.class then
+ return nil;
+ end
+
+ local object = nil;
+
+ require 'common.str';
+ local class = common.str.downcase(attributes.class);
+
+ if class == 'user' then
+ require 'dialplan.user';
+ if tonumber(attributes.id) then
+ object = dialplan.user.User:new{ log = self.log, database = self.database }:find_by_id(attributes.id);
+ elseif not common.str.blank(attributes.uuid) then
+ object = dialplan.user.User:new{ log = self.log, database = self.database }:find_by_uuid(attributes.uuid);
+ end
+
+ if object then
+ object.user_groups = object:list_groups();
+ end
+ elseif class == 'tenant' then
+ require 'dialplan.tenant';
+ if tonumber(attributes.id) then
+ object = dialplan.tenant.Tenant:new{ log = self.log, database = self.database }:find_by_id(attributes.id);
+ elseif not common.str.blank(attributes.uuid) then
+ object = dialplan.tenant.Tenant:new{ log = self.log, database = self.database }:find_by_uuid(attributes.uuid);
+ end
+ elseif class == 'sipaccount' then
+ require 'common.sip_account';
+ if not common.str.blank(attributes.auth_name) then
+ object = common.sip_account.SipAccount:new{ log = self.log, database = self.database }:find_by_auth_name(attributes.auth_name, attributes.domain);
+ elseif tonumber(attributes.id) then
+ object = common.sip_account.SipAccount:new{ log = self.log, database = self.database }:find_by_id(attributes.id);
+ elseif not common.str.blank(attributes.uuid) then
+ object = common.sip_account.SipAccount:new{ log = self.log, database = self.database }:find_by_uuid(attributes.uuid);
+ end
+
+ if object then
+ object.owner = self:find{class = object.record.sip_accountable_type, id = tonumber(object.record.sip_accountable_id)};
+ end
+ elseif class == 'huntgroup' then
+ require 'dialplan.hunt_group';
+
+ if tonumber(attributes.id) then
+ object = dialplan.hunt_group.HuntGroup:new{ log = self.log, database = self.database }:find_by_id(attributes.id);
+ elseif not common.str.blank(attributes.uuid) then
+ object = dialplan.hunt_group.HuntGroup:new{ log = self.log, database = self.database }:find_by_uuid(attributes.uuid);
+ end
+
+ if object then
+ object.owner = self:find{class = 'tenant', id = tonumber(object.record.tenant_id)};
+ end
+ elseif class == 'automaticcalldistributor' then
+ require 'dialplan.acd';
+
+ if tonumber(attributes.id) then
+ object = dialplan.acd.AutomaticCallDistributor:new{ log = self.log, database = self.database, domain = self.domain }:find_by_id(attributes.id);
+ elseif not common.str.blank(attributes.uuid) then
+ object = dialplan.acd.AutomaticCallDistributor:new{ log = self.log, database = self.database, domain = self.domain }:find_by_uuid(attributes.uuid);
+ end
+
+ if object then
+ object.owner = self:find{class = object.record.automatic_call_distributorable_type, id = tonumber(object.record.automatic_call_distributorable_id)};
+ end
+ elseif class == 'faxaccount' then
+ require 'dialplan.fax';
+ if tonumber(attributes.id) then
+ fax_account = dialplan.fax.Fax:new{ log = self.log, database = self.database }:find_by_id(attributes.id);
+ elseif not common.str.blank(attributes.uuid) then
+ fax_account = dialplan.fax.Fax:new{ log = self.log, database = self.database }:find_by_uuid(attributes.uuid);
+ end
+
+ if object then
+ object.owner = self:find{class = fax_account.record.fax_accountable_type, id = tonumber(fax_account.record.fax_accountable_id)};
+ end
+ end
+
+ if object then
+ require 'common.group';
+ object.groups, object.group_ids = common.group.Group:new{ log = self.log, database = self.database }:name_id_by_member(object.id, object.class);
+ end
+
+ return object;
+end