Skip to content

fix(licenses): enforce min one obligation requirement#191

Open
krishi-agrawal wants to merge 1 commit intofossology:mainfrom
krishi-agrawal:fix-136
Open

fix(licenses): enforce min one obligation requirement#191
krishi-agrawal wants to merge 1 commit intofossology:mainfrom
krishi-agrawal:fix-136

Conversation

@krishi-agrawal
Copy link
Copy Markdown
Contributor

Changes

  • Add validation to ensure licenses always have at least one obligation
    when creating, updating, or importing licenses.
  • Fixes License Creation #136

Submitter Checklist

  • Includes tests (if there is a feature changed/added)
  • Includes docs ( if changes are user facing)
  • I have tested my changes locally.

References

Signed-off-by: Krishi Agrawal <krishi.agrawal26@gmail.com>
Copy link
Copy Markdown
Member

@Kaushl2208 Kaushl2208 left a comment

Choose a reason for hiding this comment

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

Hey @krishi-agrawal ,

  1. The issue is just not about restrictions to the License creation, You will need to make some logic changes to the endpoints as well both (Create and Update).
  2. If you see the test cases are failing since the changes made. Please dont forget to update or write the test cases for your changes.
  3. If you need to discuss the logic change, We can discuss it over the issue.

c.JSON(http.StatusBadRequest, er)
return errors.New("license must have at least one obligation")
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This check here is kinda stale. Error message says: Cant create license with these field values. But it has already been created:

_ = db.DB.Transaction(func(tx *gorm.DB) error {
    result := tx.Create(&lic)

Also there are multiple checks after that too. So this looks like more of a defensive check. Can be removed.

Comment on lines +466 to +476
if len(newLicense.Obligations) == 0 {
er := models.LicenseError{
Status: http.StatusBadRequest,
Message: "can not update license with these field values",
Error: "license must have at least one obligation",
Path: c.Request.URL.Path,
Timestamp: time.Now().Format(time.RFC3339),
}
c.JSON(http.StatusBadRequest, er)
return errors.New("license must have at least one obligation")
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didnt see a step in UpdateLicense endpoint to updated or support obligation support too. Logically it should be there and when the user decides to update the License with Obligation we should put a check for that.

Also this check doesnt make sense bcause: Line 453, we are already preLoading the obligations for the license, can we update the logic and check somewhere there?

abhayrajjais01 added a commit to abhayrajjais01/LicenseDb that referenced this pull request Jan 22, 2026
…ossology#136)

- Add validation to CreateLicense endpoint to reject licenses without obligations
- Add validation to UpdateLicense endpoint to prevent removing all obligations
- Add validation to ImportLicenses flow for imported licenses
- Update existing tests to include obligations
- Add new test case for license creation without obligations
- Create getTestObligation() helper function for tests

Addresses all feedback from PR fossology#191:
- Validation occurs before database transactions (not after)
- UpdateLicense endpoint now validates obligations
- All test cases updated and passing
- Clear, user-friendly error messages

Fixes fossology#136
abhayrajjais01 added a commit to abhayrajjais01/LicenseDb that referenced this pull request Jan 22, 2026
…ossology#136)

- Add validation to CreateLicense endpoint to reject licenses without obligations
- Add validation to UpdateLicense endpoint to prevent removing all obligations
- Add validation to ImportLicenses flow for imported licenses
- Update existing tests to include obligations
- Add new test case for license creation without obligations
- Create getTestObligation() helper function for tests

Addresses all feedback from PR fossology#191:
- Validation occurs before database transactions (not after)
- UpdateLicense endpoint now validates obligations
- All test cases updated and passing
- Clear, user-friendly error messages

Fixes fossology#136

Signed-off-by: abhayrajjais01 <abhayraj916146@gmail.com>
abhayrajjais01 added a commit to abhayrajjais01/LicenseDb that referenced this pull request Jan 25, 2026
…ossology#136)

- Add validation to CreateLicense endpoint to reject licenses without obligations
- Add validation to UpdateLicense endpoint to prevent removing all obligations
- Add validation to ImportLicenses flow for imported licenses
- Update existing tests to include obligations
- Add new test case for license creation without obligations
- Create getTestObligation() helper function for tests

Addresses all feedback from PR fossology#191:
- Validation occurs before database transactions (not after)
- UpdateLicense endpoint now validates obligations
- All test cases updated and passing
- Clear, user-friendly error messages

Fixes fossology#136

Signed-off-by: abhayrajjais01 <abhayraj916146@gmail.com>
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.

License Creation

2 participants