Skip to content

Permissions library fails on some projections #741

@jonathonmcmurray

Description

@jonathonmcmurray

In the permissions library (https://github.com/DataIntellectTech/TorQ/blob/master/code/handlers/permissions.q), there is some logic to handle projections. Specifically in the function .pm.pdict https://github.com/DataIntellectTech/TorQ/blob/master/code/handlers/permissions.q#L76-L87, there is this code:

        /if projection first obtain a list of function and fixed parameters (fnfp) 
        104h=type value f; [fnfp:value value f; (value[fnfp 0][1])!fnfp[1],a];

The context here is that f is a function name as a symbol, and a are the arguments that the user is passing. Here, where f is pointing to a projection, the code needs to combine the fixed parameters with the user's arguments a.

However, the current implementation makes some assumptions

  1. There is only one fixed parameter (fnfp[1])
  2. The fixed parameter is the first parameter (we prefix a with fixed param)

That means that this breaks on any projection with either multiple fixed params and/or fixed params other than first param.

For example, if we define following function & corresponding projections:

f:{[a;b;c;d]}
g:f[1]
h:f[1;2]
i:f[;2;3]
j:f[;;;4]

Only g works correctly with .pm.pdict. The others either throw an error (h, i), or give the incorrect output (j):

q).pm.dict[`g;2 3 4] /works
 | ::
a| 1
b| 2
c| 3
d| 4
q).pm.dict[`i;3 4] /error
'length
  [2]  /home/jmcmurray/a.q:9: .pm.dict:
        /if projection first obtain a list of function and fixed parameters (fnfp)
        104h=type value f; [fnfp:value value f; (value[fnfp 0][1])!fnfp[1],a];
                                                                  ^
        /get paramaters and make a dictionary with the arguments
q))\
q).pm.dict[`j;1 4] /error
'length
  [2]  /home/jmcmurray/a.q:9: .pm.dict:
        /if projection first obtain a list of function and fixed parameters (fnfp)
        104h=type value f; [fnfp:value value f; (value[fnfp 0][1])!fnfp[1],a];
                                                                  ^
        /get paramaters and make a dictionary with the arguments
q))\
q).pm.dict[`g;1 2 3] /incorrect result - b should be 2, c should be 3, d should be 4
 | ::
a| 1
b| 1
c| 2
d| 3
q)

Each of the above cases should be supported, and unit tests covering each should be added to https://github.com/DataIntellectTech/TorQ/blob/master/tests/permissions/permissions.csv

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions