Add V1 API deprecation middleware (configurable with settings) #506
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
This PR introduces a new Django middleware to handle the deprecation of the v1 API endpoints. When enabled, this middleware will return a
410 Gonestatus code for any requests targeting/v1paths, along with a message guiding users to migrate to v2.Approach
A new Django middleware,
V1DeprecationMiddleware, has been created. This middleware is added to theMIDDLEWAREsetting and checks the request path. If theV1_DEPRECATEDsetting is enabled (controlled by an environment variable) and the request path starts with/v1/or is exactly/v1, the middleware intercepts the request and returns aJsonResponsewith a410 Gonestatus. Otherwise, it allows the request to proceed to the next middleware or view.Key Modifications
rorapi/middleware/deprecation.pycontainingV1DeprecationMiddleware.rorapi/settings.pyincludesV1_DEPRECATEDsetting, which can be configured via theV1_DEPRECATEDenvironment variable.rorapi/settings.pyaddsrorapi.middleware.deprecation.V1DeprecationMiddlewareto theMIDDLEWARElist.rorapi/tests/tests_unit/tests_deprecation_middleware.pywith comprehensive unit tests for the new middleware.Important Technical Details
V1_DEPRECATEDsetting defaults toFalseif the environment variable is not set./v1/(e.g.,/v1/organizations) and exact/v1paths./v1(e.g.,/v2/,/heartbeat,/) are not affected by this middleware.Types of changes
New feature (non-breaking change which adds functionality)
Bug fix (non-breaking change which fixes an issue)
Breaking change (fix or feature that would cause existing functionality to change)
Reviewer, please remember our guidelines: