fix(licenses): enforce min one obligation requirement#191
fix(licenses): enforce min one obligation requirement#191krishi-agrawal wants to merge 1 commit intofossology:mainfrom
Conversation
Signed-off-by: Krishi Agrawal <krishi.agrawal26@gmail.com>
Kaushl2208
left a comment
There was a problem hiding this comment.
Hey @krishi-agrawal ,
- 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).
- 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.
- 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") | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
| 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") | ||
| } |
There was a problem hiding this comment.
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?
…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
…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>
…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>
Changes
when creating, updating, or importing licenses.
Submitter Checklist
References