-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[WEB-2615] fix: module date validation during chart distribution generation #5791
Conversation
WalkthroughThe changes in this pull request primarily focus on enhancing the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
apiserver/plane/utils/analytics_plot.py (2)
Line range hint
206-212
: Approved: Improved date range calculation for modulesThe changes to the date range calculation for modules are well-implemented and align with the module's structure. Using
target_date
instead ofend_date
is more appropriate for modules, and the simplifiedtimedelta
usage is more efficient.For consistency, consider updating the date comparison later in the function:
if date > timezone.now().date():to:
if date > timezone.now():This change would make the comparison consistent with the new
timedelta
objects and eliminate the need for the.date()
call.
Line range hint
206-212
: Overall improvement: Enhanced module support in burndown_plotThe changes successfully improve the
burndown_plot
function's handling of modules by using the appropriatetarget_date
and simplifying the date range calculation. This enhancement doesn't affect the existing cycle-related logic, maintaining the function's versatility.To further improve code clarity and maintainability, consider extracting the date range calculation into a separate helper function for both cycle and module cases. This would reduce code duplication and make future modifications easier. For example:
def calculate_date_range(start_date, end_date): return [ start_date + timedelta(days=x) for x in range((end_date - start_date).days + 1) ] # Usage in the function: if cycle_id: date_range = calculate_date_range(queryset.start_date, queryset.end_date) if queryset.end_date and queryset.start_date else [] elif module_id: date_range = calculate_date_range(queryset.start_date, queryset.target_date)This refactoring would make the code more DRY (Don't Repeat Yourself) and easier to maintain.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- apiserver/plane/app/views/module/base.py (2 hunks)
- apiserver/plane/utils/analytics_plot.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
apiserver/plane/app/views/module/base.py (5)
438-438
: LGTM: Permission decorator addedThe addition of the
@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
decorator is a good practice. It ensures that only users with admin or member roles can access this method, improving security and access control.
669-675
: Optimization: Conditional chart generationThe new condition
modules.total_issues > 0
is a good optimization. It prevents unnecessary chart generation when there are no issues in the module, potentially improving performance.
Line range hint
696-696
: LGTM: Consistent permission controlThe addition of the
@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
decorator is consistent with theretrieve
method. This ensures uniform access control across different operations on modules.
Line range hint
301-301
: LGTM: Consistent permission controlThe addition of the
@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
decorator to thecreate
method maintains consistency in access control across theModuleViewSet
class.
Line range hint
1-1000
: Summary: Improved security and performanceThe changes in this file focus on two main areas:
- Security: Consistent application of permission decorators (
@allow_permission
) across multiple methods in theModuleViewSet
class, ensuring proper access control.- Performance: Addition of a condition to prevent unnecessary chart generation when there are no issues in a module.
These changes enhance the overall security and efficiency of the module management system without introducing any apparent issues or inconsistencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Outside diff range and nitpick comments (3)
apiserver/plane/app/views/view/base.py (3)
Line range hint
471-479
: Use appropriate HTTP status code and error messageIn the
retrieve
method, when a guest user is not allowed to view the issue view, the response returns a status code of400 Bad Request
. It's more appropriate to return a403 Forbidden
status code to indicate that the server understood the request but refuses to authorize it. Additionally, update the error message to accurately reflect the resource.Proposed change:
return Response( - {"error": "You are not allowed to view this issue"}, - status=status.HTTP_400_BAD_REQUEST, + {"error": "You are not allowed to view this view"}, + status=status.HTTP_403_FORBIDDEN, )
Line range hint
509-513
: Return403 Forbidden
instead of400 Bad Request
for unauthorized accessWhen a user who is not the owner attempts to update the view, the response returns a
400 Bad Request
. It's more appropriate to return a403 Forbidden
status code in this case.Proposed change:
if issue_view.owned_by_id != request.user.id: return Response( { "error": "Only the owner of the view can update the view" }, - status=status.HTTP_400_BAD_REQUEST, + status=status.HTTP_403_FORBIDDEN, )
Line range hint
542-546
: Return403 Forbidden
instead of400 Bad Request
when deletion is unauthorizedIf a user who is neither an admin nor the owner attempts to delete a view, a
400 Bad Request
is returned. Update the status code to403 Forbidden
to correctly indicate the authorization error.Proposed change:
else: return Response( {"error": "Only admin or owner can delete the view"}, - status=status.HTTP_400_BAD_REQUEST, + status=status.HTTP_403_FORBIDDEN, )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- apiserver/plane/app/views/module/base.py (6 hunks)
- apiserver/plane/app/views/view/base.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- apiserver/plane/app/views/module/base.py
🧰 Additional context used
🔇 Additional comments (1)
apiserver/plane/app/views/view/base.py (1)
588-588
:⚠️ Potential issueCorrect the keyword argument when retrieving UserFavorite
In the
destroy
method, theUserFavorite.objects.get
usesproject=project_id
as a keyword argument. However, the correct field isproject_id
.Proposed change:
view_favorite = UserFavorite.objects.get( - project=project_id, + project_id=project_id, user=request.user, workspace__slug=slug, entity_type="view", entity_identifier=view_id, )Likely invalid or redundant comment.
Summary
In this PR date validation for modules when generating chart distributions.
Plane Issue:
[WEB-2615]
Summary by CodeRabbit
New Features
Bug Fixes
Refactor