Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeorm interpreter builds a wrong query with "empty" condition #23

Open
ccatterina opened this issue Jun 17, 2021 · 1 comment
Open

Comments

@ccatterina
Copy link
Contributor

ccatterina commented Jun 17, 2021

Hi again, I'm using rulesToAST to convert an Ability to an AST condition and then I translate the condition in a typeorm query with ucast/sql.

I found that the Interpreter builds a wrong query when the ability has a rule with no conditions (e.g. can("read", "User")), indeed the ability is translated into r { operator: 'and', value: [] } AST condition that the interpreter translates into .where('()', []).

async function main() {
  const conn = await createConnection();

  const ability = defineAbility((can) => {
    can('read', 'User');
  });

  const astCondition = rulesToAST(ability, 'read', 'User');
  console.log(astCondition)
  // r { operator: 'and', value: [] }

  let query = interpret(astCondition, User.createQueryBuilder());
  await query.getMany()
  // SELECT "User"."id" AS "User_id", "User"."firstName" AS "User_firstName", "User"."lastName" AS "User_lastName", "User"."age" AS "User_age" FROM "users" "User" WHERE ()

  conn.close()
}

Is this the correct usage of rulesToAST and ucast/sql?

@stalniy
Copy link
Owner

stalniy commented Jun 17, 2021

thanks for the issue. I think that I need to add more validation to mongodb parser. { and: [] } is probably a mistake in another place and should not be just ignored

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants