Skip to content

FOUR-16161: Add support for raw query conditions to advanced filters #6876

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

Merged
merged 5 commits into from
Jun 18, 2024

Conversation

runyan-co
Copy link
Contributor

@runyan-co runyan-co commented May 24, 2024

Issue

Advanced Filters need to be able to support raw() filtering query conditions to allow for more granular filtering, e.g. raw(NOW() + 1 INTERVAL DAY) which can be used to query tasks which will expire in the next 24 hours (but is not limited to just that, of course).

Reproduction Steps

  1. Have 250+ tasks with case numbers
  2. Navigate to the /tasks page
  3. Create an Advanced Filter to the "Case Number" column by adding a simple operator (one of the comparison operators or the between operator) and then set the value to be a SQL query wrapped with raw(), for example: raw(1 + 10). This is the one I used since SQL can do basic arithmetic and is useful to test against the integer value of the "Case Number" column.
  4. Verify the correct number of results based on your query/filters.

Testing in Tinker

You can also test more granularly by opening tinker (php artisan tinker) and creating a new ProcessMaker\Filters\Filter instance.

Here is some example code you can use, but you can do much more than this if you'd like:

// Authenticate the super administrator so the permissions/gates work properly
Auth::login(User::find(1));

// Create a JSON-valid string representing the advanced filter
// This one looks for tasks coming due in less than 30 days
$advancedFilter = '[{"subject":{"type":"Status"},"operator":"=","value":"In Progress"},{"subject":{"type":"Field","value":"due_at"},"operator":"<","value":"raw(NOW() + INTERVAL 30 DAY)"}]'

// Create a new query builder instance (similar to the one in the API TaskController)
$query = \ProcessMaker\Models\ProcessRequestToken::with(['processRequest', 'user', 'draft']);

// Create the filter (this returns null because it directly updates the $query instance)
$filter = \ProcessMaker\Filters\Filter::filter($query, $advancedFilter);

// Check the result count and verify it's correct for the conditions set
$query->count();

// You can also review the entire query's parsed SQL this way as well:
$query->toRawSql();

// If you want the actual results, you can retrieve them this way
$query->get();

Solution

  • Create a new ProcessMaker\Traits\InteractsWithRawFilter trait to contain the logic/query updates
  • Updated the ProcessMaker\Filters\Filter to check for and appropriately implement any raw() filter values found

How to Test

All of the reproduction steps (for the UI and for tinker) would be best.

CICD

ci:next

Related Tickets & Packages

Code Review Checklist

  • I have pulled this code locally and tested it on my instance, along with any associated packages.
  • This code adheres to ProcessMaker Coding Guidelines.
  • This code includes a unit test or an E2E test that tests its functionality, or is covered by an existing test.
  • This solution fixes the bug reported in the original ticket.
  • This solution does not alter the expected output of a component in a way that would break existing Processes.
  • This solution does not implement any breaking changes that would invalidate documentation or cause existing Processes to fail.
  • This solution has been tested with enterprise packages that rely on its functionality and does not introduce bugs in those packages.
  • This code does not duplicate functionality that already exists in the framework or in ProcessMaker.
  • This ticket conforms to the PRD associated with this part of ProcessMaker.

@runyan-co runyan-co self-assigned this May 24, 2024
@runyan-co runyan-co requested a review from nolanpro May 24, 2024 16:02
@runyan-co
Copy link
Contributor Author

Other todo: resolve failing unit tests

runyan-co added 2 commits May 29, 2024 09:19
…upport for "between" operator, since it is not needed yet. Simplified new code
Copy link

@nolanpro nolanpro changed the base branch from next to next2-recommendations June 18, 2024 16:51
@nolanpro nolanpro merged commit 915f06d into next2-recommendations Jun 18, 2024
17 of 21 checks passed
@nolanpro nolanpro deleted the improvement/FOUR-16161 branch June 18, 2024 16:51
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

Successfully merging this pull request may close these issues.

2 participants