Add a new permissions variable.

This commit is contained in:
FusionPBX 2022-01-17 10:09:12 -07:00 committed by GitHub
parent 3779b4a93e
commit c084373d0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 31 deletions

View File

@ -15,7 +15,7 @@
-- The Initial Developer of the Original Code is
-- Mark J Crane <markjcrane@fusionpbx.com>
-- Portions created by the Initial Developer are Copyright (C) 2019
-- Portions created by the Initial Developer are Copyright (C) 2019 - 2021
-- the Initial Developer. All Rights Reserved.
-- load config
@ -34,9 +34,13 @@
domain_name = session:getVariable("domain_name");
domain_uuid = session:getVariable("domain_uuid");
context = session:getVariable("context");
permissions = session:getVariable("permissions")
user = session:getVariable("sip_auth_username")
or session:getVariable("username");
--set the default
if (not permissions) then permissions = 'false'; end
--get the argv values
destination = argv[2];
@ -64,7 +68,9 @@
local dbh = Database.new('system');
-- search for the phone number in database using the speed dial
local sql = [[
if (permissions == 'true') then
--advanced, check on user and group permissions
sql = [[
-- find all contacts with correct user or withot users and groups at all
select t0.phone_number --, t6.extension, 'GROUP:' || t3.group_name as user_name
from v_contact_phones t0
@ -77,7 +83,7 @@
where t0.domain_uuid = :domain_uuid and t0.phone_speed_dial = :phone_speed_dial
and ( (1 = 0)
or (t6.domain_uuid = :domain_uuid and (t6.extension = :user or t6.number_alias = :user))
or (t2.contact_uuid is null and not exists(select 1 from v_contact_users t where t.contact_uuid = t0.contact_uuid) )
or (t2.contact_uuid is null and not exists(select 1 from v_contact_users t where t.contact_uuid = t0.contact_uuid))
)
union
@ -96,6 +102,16 @@
or (t2.contact_user_uuid is null and not exists(select 1 from v_contact_groups t where t.contact_uuid = t0.contact_uuid))
)
]];
log.noticef("[speed dial] advanced");
else
-- simple, skip looking up user or group permissions
sql = [[select phone_number
from v_contact_phones
where domain_uuid = :domain_uuid
and phone_speed_dial = :phone_speed_dial
]];
log.noticef("[speed dial] simple");
end
local params = {phone_speed_dial = destination, domain_uuid = domain_uuid, user = user};
if (debug["sql"]) then