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

Added device group type check to rule validation logic for add_device_group API endpoint. #13212

Closed
wants to merge 5 commits into from

Conversation

DanielMuller-TN
Copy link
Contributor

@DanielMuller-TN DanielMuller-TN commented Sep 9, 2021

A simple fix for the error I was encountering with submitting statically assigned device groups via the API. I've placed the dynamic rule logic validation within a conditional check so it only executes for device groups of type 'dynamic'. It's pretty low hanging fruit, sorry.

DO NOT DELETE THE UNDERLYING TEXT

Please note

Please read this information carefully. You can run ./lnms dev:check to check your code before submitting.

  • Have you followed our code guidelines?
  • If my Pull Request does some changes/fixes/enhancements in the WebUI, I have inserted a screenshot of it.

Testers

If you would like to test this pull request then please run: ./scripts/github-apply <pr_id>, i.e ./scripts/github-apply 5926
After you are done testing, you can remove the changes with ./scripts/github-remove. If there are schema changes, you can ask on discord how to revert.

@CLAassistant
Copy link

CLAassistant commented Sep 9, 2021

CLA assistant check
All committers have signed the CLA.

$query = QueryBuilderParser::fromJson($data['rules'])->toSql();
if (empty($query)) {
return api_error(500, "We couldn't parse your rule");
if ($data['type'] == 'dynamic') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, actually static groups can have rules, they are just unused until you change the type to dynamic. We should check if (! empty($data['rules'])) { instead of the type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@murrant - Absolutely, if the desired behaviour is to allow the definition of rules for static groups then wrapping the QueryBuilderParser::fromJson() call and accompanying api_error validation in the conditional you've suggested would be the way to go. I'll drop this pull request, test it and submit a new one with the change included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to close this, just update it :)

@murrant
Copy link
Member

murrant commented Oct 2, 2021

you messed up your branch a bit, try doing a rebase against upstream master.

@DanielMuller-TN
Copy link
Contributor Author

you messed up your branch a bit, try doing a rebase against upstream master.

Yeah, I see that - the noob strikes again. Sorry.. monkey behind the keyboard. Fixing it now.

@murrant
Copy link
Member

murrant commented Oct 6, 2021

No worries @DanielMuller-TN if you are having issues feel free to make a new branch and PR with the changes and close this one.

@DanielMuller-TN
Copy link
Contributor Author

The noob will try again with a fresh pull request, apologises.

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.

None yet

3 participants