def _did_set_call_rights(agi, cursor, args):
    srcnum = agi.get_variable('XIVO_SRCNUM')
    incall_id = agi.get_variable('XIVO_INCALL_ID')

    cursor.query("SELECT ${columns} FROM rightcallexten",
                 ('rightcallid', 'exten'))
    res = cursor.fetchall()

    if not res:
        call_rights.allow(agi)

    rightcallidset = set((row['rightcallid'] for row in res if call_rights.extension_matches(srcnum, row['exten'])))

    if not rightcallidset:
        call_rights.allow(agi)

    rightcallids = '(' + ','.join((str(el) for el in rightcallidset)) + ')'
    cursor.query("SELECT ${columns} FROM rightcall "
                 "INNER JOIN rightcallmember "
                 "ON rightcall.id = rightcallmember.rightcallid "
                 "INNER JOIN incall "
                 "ON CAST(rightcallmember.typeval AS integer) = incall.id "
                 "WHERE rightcall.id IN " + rightcallids + " "
                 "AND rightcallmember.type = 'incall' "
                 "AND incall.id = %s "
                 "AND rightcall.commented = 0",
                 (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME),
                 [incall_id])
    res = cursor.fetchall()
    call_rights.apply_rules(agi, res)
    call_rights.allow(agi)
Esempio n. 2
0
def _did_set_call_rights(agi, cursor, args):
    srcnum = agi.get_variable('XIVO_SRCNUM')
    context = agi.get_variable('XIVO_CONTEXT')
    exten_pattern = agi.get_variable('XIVO_EXTENPATTERN')

    cursor.query("SELECT ${columns} FROM rightcallexten",
                 ('rightcallid', 'exten'))
    res = cursor.fetchall()

    if not res:
        call_rights.allow(agi)

    rightcallidset = set((row['rightcallid'] for row in res if call_rights.extension_matches(srcnum, row['exten'])))

    if not rightcallidset:
        call_rights.allow(agi)

    rightcallids = '(' + ','.join((str(el) for el in rightcallidset)) + ')'
    contextinclude = objects.Context(agi, cursor, context).include
    cursor.query("SELECT ${columns} FROM rightcall "
                 "INNER JOIN rightcallmember "
                 "ON rightcall.id = rightcallmember.rightcallid "
                 "INNER JOIN incall "
                 "ON CAST(rightcallmember.typeval AS integer) = incall.id "
                 "WHERE rightcall.id IN " + rightcallids + " "
                 "AND rightcallmember.type = 'incall' "
                 "AND incall.exten = %s "
                 "AND incall.context IN (" + ", ".join(["%s"] * len(contextinclude)) + ") "
                 "AND rightcall.commented = 0",
                 (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME),
                 [exten_pattern] + contextinclude)
    res = cursor.fetchall()
    call_rights.apply_rules(agi, res)
    call_rights.allow(agi)
def _did_set_call_rights(agi, cursor, args):
    srcnum = agi.get_variable('XIVO_SRCNUM')
    context = agi.get_variable('XIVO_CONTEXT')
    exten_pattern = agi.get_variable('XIVO_EXTENPATTERN')

    cursor.query("SELECT ${columns} FROM rightcallexten",
                 ('rightcallid', 'exten'))
    res = cursor.fetchall()

    if not res:
        call_rights.allow(agi)

    rightcallidset = set(
        (row['rightcallid'] for row in res
         if call_rights.extension_matches(srcnum, row['exten'])))

    if not rightcallidset:
        call_rights.allow(agi)

    rightcallids = '(' + ','.join((str(el) for el in rightcallidset)) + ')'
    contextinclude = objects.Context(agi, cursor, context).include
    cursor.query(
        "SELECT ${columns} FROM rightcall "
        "INNER JOIN rightcallmember "
        "ON rightcall.id = rightcallmember.rightcallid "
        "INNER JOIN incall "
        "ON rightcallmember.typeval = incall.id "
        "WHERE rightcall.id IN " + rightcallids + " "
        "AND rightcallmember.type = 'incall' "
        "AND incall.exten = %s "
        "AND incall.context IN (" + ", ".join(["%s"] * len(contextinclude)) +
        ") "
        "AND rightcall.commented = 0",
        (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME,
         call_rights.RIGHTCALL_PASSWD_COLNAME),
        [exten_pattern] + contextinclude)
    res = cursor.fetchall()
    call_rights.apply_rules(agi, res)
    call_rights.allow(agi)
def _user_set_call_rights(agi, cursor, args):
    userid = agi.get_variable('XIVO_USERID')
    dstnum = agi.get_variable('XIVO_DSTNUM')
    outcallid = agi.get_variable('XIVO_OUTCALLID')

    cursor.query("SELECT ${columns} FROM rightcallexten",
                 ('rightcallid', 'exten'))
    res = cursor.fetchall()

    if not res:
        call_rights.allow(agi)

    rightcallidset = set((row['rightcallid'] for row in res if call_rights.extension_matches(dstnum, row['exten'])))

    if not rightcallidset:
        call_rights.allow(agi)

    rightcallids = '(' + ','.join((str(el) for el in rightcallidset)) + ')'

    try:
        user = objects.User(agi, cursor, int(userid))
    except (ValueError, LookupError):
        if not outcallid:
            call_rights.allow(agi)
    else:
        cursor.query("SELECT ${columns} FROM rightcall "
                     "INNER JOIN rightcallmember "
                     "ON rightcall.id = rightcallmember.rightcallid "
                     "WHERE rightcall.id IN " + rightcallids + " "
                     "AND rightcallmember.type = 'user' "
                     "AND rightcallmember.typeval = %s "
                     "AND rightcall.commented = 0",
                     (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME),
                     (user.id,))
        res = cursor.fetchall()
        call_rights.apply_rules(agi, res)

        cursor.query("SELECT ${columns} FROM groupfeatures "
                     "INNER JOIN queuemember "
                     "ON groupfeatures.name = queuemember.queue_name "
                     "INNER JOIN queue "
                     "ON queue.name = queuemember.queue_name "
                     "WHERE groupfeatures.deleted = 0 "
                     "AND queuemember.userid = %s "
                     "AND queuemember.usertype = 'user' "
                     "AND queuemember.category = 'group' "
                     "AND queuemember.commented = 0 "
                     "AND queue.category = 'group' "
                     "AND queue.commented = 0",
                     ('groupfeatures.id',),
                     (user.id,))
        res = cursor.fetchall()

        if res:
            groupids = [row['groupfeatures.id'] for row in res]
            cursor.query("SELECT ${columns} FROM rightcall "
                         "INNER JOIN rightcallmember "
                         "ON rightcall.id = rightcallmember.rightcallid "
                         "WHERE rightcall.id IN " + rightcallids + " "
                         "AND rightcallmember.type = 'group' "
                         "AND rightcallmember.typeval IN (" + ", ".join(["%s"] * len(res)) + ") "
                         "AND rightcall.commented = 0",
                         (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME),
                         groupids)
            res = cursor.fetchall()
            call_rights.apply_rules(agi, res)

    if outcallid:
        cursor.query("SELECT ${columns} FROM rightcall "
                     "INNER JOIN rightcallmember "
                     "ON rightcall.id = rightcallmember.rightcallid "
                     "INNER JOIN outcall "
                     "ON rightcallmember.typeval = outcall.id "
                     "WHERE rightcall.id IN " + rightcallids + " "
                     "AND rightcallmember.type = 'outcall' "
                     "AND outcall.id = %s "
                     "AND rightcall.commented = 0",
                     (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME),
                     outcallid)
        res = cursor.fetchall()
        call_rights.apply_rules(agi, res)

    call_rights.allow(agi)