Repository navigation
Accept all notification rule fields on creation - #7627
volodymyr-jdev wants to merge 1 commit into
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | -9 |
🟢 Coverage 98.40% diff coverage · +0.11% coverage variation
Metric Results Coverage variation ✅ +0.11% coverage variation (-1.00%) Diff coverage ✅ 98.40% diff coverage (70.00%) Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (e1e3c8f) 45958 40366 87.83% Head commit (a23856d) 46019 (+61) 40468 (+102) 87.94% (+0.11%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#7627) 125 123 98.40% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
nscuro
left a comment
There was a problem hiding this comment.
PUT /api/v1/notification/rule/scheduled has the same issue: it only accepts name, scope, notificationLevel and publisher, so notifyOn, publisherConfig and scheduleCron still require a subsequent POST. It is intentionally left unchanged to keep this PR focused. If the same change is desired there, it can be tracked in a separate issue.
Please do it in this PR, so the API surface remains consistent.
| * @param command the rule to create | ||
| * @return the created {@link NotificationRule} | ||
| * @throws IllegalArgumentException when {@code notifyOn} contains groups not supported for event-triggered rules | ||
| * @since 5.2.0 |
There was a problem hiding this comment.
| * @since 5.2.0 | |
| * @since 5.3.0 |
| * @param tags Tags to limit the rule to, or {@code null} for none | ||
| * @since 5.2.0 | ||
| */ | ||
| public record CreateNotificationRuleCommand( |
There was a problem hiding this comment.
This is probably overkill here, since there are no fields that NotificationRule doesn't have. You could simply construct a transient NotificationRule object instead.
There was a problem hiding this comment.
Done, createNotificationRule now takes a transient NotificationRule. Since it uses primitive booleans, defaults for omitted fields are applied in the resource.
Creating a notification rule via PUT /api/v1/notification/rule or PUT /api/v1/notification/rule/scheduled only accepted name, scope, level and publisher. All other fields, such as notifyOn and publisherConfig, were silently dropped, so clients had to issue a follow-up POST to get a usable rule. Both endpoints now accept the optional fields enabled, notifyChildren, logSuccessfulPublish, notifyOn, publisherConfig, filterExpression and tags, and the scheduled endpoint also accepts scheduleCron and scheduleSkipUnchanged. They are validated the same way as on update and applied in a single transaction. Invalid input yields 400 and no rule is persisted. Omitted fields keep their previous defaults, so existing clients are unaffected. Updating a rule without notifyOn previously failed with a NullPointerException. An omitted notifyOn is now treated as an empty set, consistent with rule creation. Projects and teams are still not accepted on creation and must be added via the existing endpoints. Fixes DependencyTrack#2940 Signed-off-by: Volodymyr Kucheriaviy <248452481+volodymyr-jdev@users.noreply.github.com>
7bc3b9a to
a23856d
Compare
|
Thanks for the review. Scheduled rules are now handled in this PR as well: While working on this, I found that updating a rule without Description updated. |
Description
Allow
PUT /api/v1/notification/ruleandPUT /api/v1/notification/rule/scheduledto accept all rule fields, so a usable notification rule can be created in a single request.Previously, both endpoints only accepted
name,scope,notificationLevelandpublisher. All other fields, such asnotifyOnandpublisherConfig, were silently dropped, so clients had to follow up with aPOST. Both endpoints now also acceptenabled,notifyChildren,logSuccessfulPublish,notifyOn,publisherConfig,filterExpressionandtags. The scheduled endpoint additionally acceptsscheduleCronandscheduleSkipUnchanged. All fields are validated the same way as on update and applied in the same transaction. Omitted fields keep their previous defaults, so existing clients are unaffected.Addressed Issue
Closes #2940
Additional Details
Implementation
CreateNotificationRuleRequestandCreateScheduledNotificationRuleRequestgain the optional fields above. Boolean fields use wrapper types, so an omitted field can be told apart fromfalse.NotificationQueryManager#createNotificationRule(NotificationRule)creates a rule from a transientNotificationRuleand handles both trigger types: the trigger type decides which notification groups are allowed and whether the schedule fields are applied. The existing four-argument create methods delegate to it.NotificationRuleuses primitive booleans, defaults for omitted fields are applied in the resource, separately for event and scheduled rules.notifyOnagainst the trigger type (validateNotifyOn) and of the publisher config (validatePublisherConfig) is shared between create and update.validateNotifyOntreats a missingnotifyOnas an empty set.publisherConfigis omitted on creation, the publisher's default config is used, as before. Providing one for a publisher that does not support it is rejected.Behavior change
filterExpression,publisherConfig,notifyOnorscheduleCronvalues to either create endpoint received201with those values discarded. They now receive400and no rule is created.POST /api/v1/notification/rulewithoutnotifyOnpreviously failed with500due to aNullPointerException. An omittednotifyOnis now treated as an empty set, consistent with rule creation, so the rule's subscriptions are cleared.Out of scope
Testing
NotificationRuleResourceTest. Existing tests pass unchanged.apiservertest suite locally.make apiserver-dev):POSTnotifyOnThe documentation checklist item is left unchecked, as it is unclear whether this change requires an update to the documentation repository. I can provide one if needed.
Checklist
This PR fixes a defect, and I have provided tests to verify that the fix is effectiveThis PR introduces changes to the database model, and I have updated the migration changelog accordinglyThis PR is a substantial change (per the ADR criteria), and I have added an ADR underdocs/adr/