Skip to content
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

clean(ZMS-2872): added scope and department to delete message #711

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

msfb3
Copy link
Contributor

@msfb3 msfb3 commented Nov 28, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced success messages for department and scope deletions to include specific entity names for improved clarity.
  • Bug Fixes

    • Adjusted the response handling in deletion processes to ensure the correct names are included in success messages.
  • Tests

    • Improved test coverage for department and scope deletion processes with additional API calls and refined assertions for redirect responses.

Copy link

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes involve updates to success messages in the messages.twig template for department and scope deletions, enhancing clarity by including the names of the respective entities. Additionally, modifications were made to the readResponse methods in the DepartmentDelete, ScopeDelete, and OwnerOverview classes to retrieve and include these names in the redirect responses. The overall structure of the templates and classes remains intact, with no alterations to error handling or public entity declarations.

Changes

File Path Change Summary
zmsadmin/custom_templates/block/element/helper/messages.twig
zmsadmin/custom_templates/element/helper/messages.twig
Updated success messages for department and scope deletions to include departmentName and scopeName.
zmsadmin/src/Zmsadmin/DepartmentDelete.php Modified readResponse method to include departmentName in the redirect response.
zmsadmin/src/Zmsadmin/OwnerOverview.php Updated readResponse method to include scopeName and departmentName in the response array.
zmsadmin/src/Zmsadmin/ScopeDelete.php Modified readResponse method to include scopeName in the redirect response.
zmsadmin/tests/Zmsadmin/DepartmentDeleteTest.php Enhanced test by adding an API call and refining redirect assertion in testRendering method.
zmsadmin/tests/Zmsadmin/ScopeDeleteTest.php Enhanced test by adding an API call and refining redirect assertion in testRendering method.

Poem

🐇
In the land of code where changes bloom,
Success messages now brighten the room.
Departments and scopes, their names now clear,
A hop of joy, for all to hear!
With every delete, a name to show,
Clarity reigns, let the good times flow!
🌼


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 428a765 and 1781bd3.

📒 Files selected for processing (2)
  • zmsadmin/src/Zmsadmin/DepartmentDelete.php (1 hunks)
  • zmsadmin/src/Zmsadmin/OwnerOverview.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • zmsadmin/src/Zmsadmin/DepartmentDelete.php
  • zmsadmin/src/Zmsadmin/OwnerOverview.php

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 (5)
zmsadmin/src/Zmsadmin/ScopeDelete.php (1)

31-42: Consider optimizing the data fetching pattern

The current implementation makes an additional API call to fetch the scope name. Consider these alternatives:

  1. Pass the scope name from the UI/previous page as a query parameter
  2. Fetch this data earlier in the flow and cache it
  3. Batch the data fetching with other required operations

This would reduce API calls and improve performance, especially if this pattern is replicated across other delete controllers.

zmsadmin/src/Zmsadmin/DepartmentDelete.php (1)

32-34: Remove debug code and commented out lines

Debug statements and commented out code should not be committed to the codebase.

Apply this diff to clean up the code:

-       // xdebug_var_dump($entity);
-        
-        // $departmentName = $entity->offsetGet('contact')->offsetGet('name'); 
zmsadmin/src/Zmsadmin/OwnerOverview.php (1)

Line range hint 1-39: Consider separating deletion feedback handling

The OwnerOverview class is now handling both the overview display and deletion feedback responsibilities. Consider extracting the deletion feedback handling into a separate trait or service class to improve separation of concerns and maintainability.

This would:

  1. Make the code more modular and reusable
  2. Simplify testing
  3. Make it easier to modify the feedback mechanism in the future

Would you like assistance in designing this separation?

zmsadmin/custom_templates/element/helper/messages.twig (2)

107-107: LGTM! Consider extending the pattern to related messages.

The addition of departmentName improves user feedback. For consistency, consider adding the department name to the related messages in department_created and department_saved blocks as well.

{% block department_created %}
{{ block('success_start') }}
-    Die Behörde wurde {{ timeString }} erfolgreich angelegt.
+    Die Behörde {{ departmentName }} wurde {{ timeString }} erfolgreich angelegt.
{{ block('success_end') }}
{% endblock %}

{% block department_saved %}
{{ block('success_start') }}
-    Die Behörde wurde {{ timeString }} erfolgreich aktualisiert.
+    Die Behörde {{ departmentName }} wurde {{ timeString }} erfolgreich aktualisiert.
{{ block('success_end') }}
{% endblock %}

170-170: LGTM! Consider extending the pattern to related messages.

The addition of scopeName improves user feedback. For consistency, consider adding the scope name to the related messages in scope_created and scope_saved blocks as well.

{% block scope_created %}
{% set successTitle = "Anlegen erfolgreich" %}
{{ block('success_start') }}
-    Der Standort wurde {{ timeString }} erfolgreich angelegt.
+    Der Standort {{ scopeName }} wurde {{ timeString }} erfolgreich angelegt.
{{ block('success_end') }}
{% endblock %}

{% block scope_saved %}
{% set successTitle = "Speichern erfolgreich" %}
{{ block('success_start') }}
-    Der Standort wurde {{ timeString }} erfolgreich aktualisiert.
+    Der Standort {{ scopeName }} wurde {{ timeString }} erfolgreich aktualisiert.
{{ block('success_end') }}
{% endblock %}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bd65587 and a4bf6a0.

📒 Files selected for processing (5)
  • zmsadmin/custom_templates/block/element/helper/messages.twig (2 hunks)
  • zmsadmin/custom_templates/element/helper/messages.twig (2 hunks)
  • zmsadmin/src/Zmsadmin/DepartmentDelete.php (1 hunks)
  • zmsadmin/src/Zmsadmin/OwnerOverview.php (2 hunks)
  • zmsadmin/src/Zmsadmin/ScopeDelete.php (1 hunks)
🔇 Additional comments (4)
zmsadmin/src/Zmsadmin/ScopeDelete.php (1)

41-42: Verify template usage and controller consistency

The redirect parameters look correct, but let's ensure:

  1. The template uses these parameters correctly
  2. Similar changes exist in other delete controllers for consistency
✅ Verification successful

The verification results show that:

  1. The template usage is confirmed:

    • The scope_deleted block exists in multiple message template files
    • The custom templates (zmsadmin/custom_templates/*/messages.twig) use the scopeName parameter in the message: Der Standort {{ scopeName }} wurde {{ timeString }} erfolgreich entfernt.
    • The default templates also have the scope_deleted block but without using the scopeName parameter
  2. The controller consistency check shows multiple delete controllers exist, so let's verify if they follow similar patterns for success messages.


Redirect parameters are consistent with similar delete controllers

The verification shows that:

  1. The template correctly uses the scope_deleted message block and scopeName parameter in custom templates
  2. Other delete controllers follow a similar pattern:
    • All use a *_deleted success message key
    • Some controllers (like DepartmentDelete.php) also pass entity names as parameters (departmentName)

The changes are consistent with the codebase patterns and the templates are properly configured to handle these parameters.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the template uses these parameters and verify consistency across controllers

# Check template usage
echo "Checking template usage..."
rg -A 5 "scope_deleted|scopeName" --type=twig

# Check other delete controllers for consistency
echo "Checking other delete controllers..."
fd -e php . | xargs rg -l "class \w+Delete extends BaseController"

Length of output: 10259


Script:

#!/bin/bash
# Check the redirect parameters in other delete controllers
echo "Checking redirect parameters in delete controllers..."
rg -B 2 -A 2 "'success' =>" zmsadmin/src/Zmsadmin/*Delete.php

Length of output: 2924

zmsadmin/src/Zmsadmin/DepartmentDelete.php (1)

42-43: LGTM! The success message now includes the department name

The modification improves user feedback by including the department name in the success message, which aligns with the PR objectives.

zmsadmin/custom_templates/block/element/helper/messages.twig (2)

107-107: LGTM! Enhanced feedback by including department name

The message now provides more specific feedback by including the department name, which improves user experience.


170-170: LGTM! Enhanced feedback by including scope name

The message now provides more specific feedback by including the scope name, which improves user experience.

Let's verify that both variables are properly passed from the controllers:

✅ Verification successful

Variables are properly passed and handled in the codebase

The verification shows that both variables are correctly handled:

  • In ScopeDelete.php, the scopeName is properly extracted from the entity's contact name and passed to the redirect
  • In OwnerOverview.php, the scopeName is correctly received as a request parameter and passed to the template
  • The variable usage in the template matches the data flow in the controllers
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that departmentName and scopeName variables are properly set in the controllers

# Check for departmentName in DepartmentDelete controller
rg -A 5 "departmentName.*=.*" --type php

# Check for scopeName in ScopeDelete controller
rg -A 5 "scopeName.*=.*" --type php

Length of output: 4616

zmsadmin/src/Zmsadmin/ScopeDelete.php Show resolved Hide resolved
zmsadmin/src/Zmsadmin/DepartmentDelete.php Show resolved Hide resolved
zmsadmin/src/Zmsadmin/OwnerOverview.php Outdated Show resolved Hide resolved
zmsadmin/src/Zmsadmin/OwnerOverview.php Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a 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 (3)
zmsadmin/tests/Zmsadmin/ScopeDeleteTest.php (2)

23-27: Consider using a dedicated fixture for the GET request.

While using the same fixture works functionally, it would be more accurate to use a separate fixture that specifically represents the GET response format. This would better reflect the real-world scenario where DELETE and GET endpoints might return different response structures.


Line range hint 14-34: Consider adding test cases for error scenarios.

The current test only covers the successful deletion path. Consider adding test cases for:

  • Invalid scope ID
  • Permission denied scenarios
  • API error responses

Example structure:

public function testInvalidScopeId()
{
    // Test with non-existent scope ID
}

public function testApiError()
{
    // Test handling of API error response
}
zmsadmin/tests/Zmsadmin/DepartmentDeleteTest.php (1)

33-33: Consider using a more specific assertion.

While assertStringContainsString works, consider using a more robust assertion that specifically checks the success parameter.

-$this->assertStringContainsString('/owner/?success=department_deleted', $response->getHeaderLine('Location'));
+$locationHeader = $response->getHeaderLine('Location');
+$this->assertMatchesRegularExpression('/^\/owner\/\?success=department_deleted$/', $locationHeader);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a4bf6a0 and 428a765.

📒 Files selected for processing (2)
  • zmsadmin/tests/Zmsadmin/DepartmentDeleteTest.php (1 hunks)
  • zmsadmin/tests/Zmsadmin/ScopeDeleteTest.php (1 hunks)
🔇 Additional comments (2)
zmsadmin/tests/Zmsadmin/ScopeDeleteTest.php (1)

32-32: Verify success message format consistency across delete operations.

The success message format should be consistent across all delete operations (scope, department, etc.).

Let's verify the consistency:

✅ Verification successful

Success message format is consistent across delete operations

The success message format follows a consistent pattern across all delete operations:

  • Scope: /owner/?success=scope_deleted
  • Department: /owner/?success=department_deleted
  • Organisation: /owner/?success=organisation_deleted
  • Cluster: /owner/?success=cluster_deleted

All operations redirect to the owner page with a success parameter following the pattern {entity}_deleted. The change from assertRedirect to assertStringContainsString is an implementation detail that doesn't affect the consistency of the success message format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check success message format consistency across delete operation tests

# Search for similar assertions in other delete operation tests
rg -A 1 "success=" "tests/" | grep -E "assertString|assertRedirect"

# Check for all success message definitions in templates
rg "success=" "templates/"

Length of output: 188


Script:

#!/bin/bash
# Let's first find the test files and template files in the repository
fd -t f "Test\.php$"

# Then search for success message patterns in all PHP files
rg -A 1 "success=" ".*\.php$"

# Also check for any redirect assertions
rg -A 1 "assert.*Redirect|assertString.*Contains" ".*\.php$"

Length of output: 21664


Script:

#!/bin/bash
# Let's check the specific test files for delete operations and their assertions
rg -A 1 "success=" "zmsadmin/tests/Zmsadmin/ScopeDeleteTest.php" "zmsadmin/tests/Zmsadmin/DepartmentDeleteTest.php" "zmsadmin/tests/Zmsadmin/OrganisationDeleteTest.php" "zmsadmin/tests/Zmsadmin/ClusterDeleteTest.php"

# Also check for similar assertion patterns in these files
rg -A 1 "assert.*Redirect|assertString.*Contains" "zmsadmin/tests/Zmsadmin/ScopeDeleteTest.php" "zmsadmin/tests/Zmsadmin/DepartmentDeleteTest.php" "zmsadmin/tests/Zmsadmin/OrganisationDeleteTest.php" "zmsadmin/tests/Zmsadmin/ClusterDeleteTest.php"

Length of output: 2508

zmsadmin/tests/Zmsadmin/DepartmentDeleteTest.php (1)

23-28: LGTM! Verify if the additional API call is necessary.

The additional readGetResult API call is added to support retrieving the department name for the success message. The implementation looks correct.

Let's verify if this additional API call is actually needed by checking the implementation:

✅ Verification successful

Let me gather more information to verify if the department name is actually used in the implementation.


The additional API call is necessary and correctly implemented

The verification confirms that the additional API call is required because:

  1. The custom message template uses {{ departmentName }} to display the department's name in the deletion success message
  2. The DepartmentDelete class extracts the department name ($departmentName = $entity->name) from the GET response before deletion
  3. This name is then passed to the success message parameters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if DepartmentDelete.php uses the department name from an additional API call

# Search for the readResponse method implementation in DepartmentDelete
ast-grep --pattern 'function readResponse($_) {
  $$$
}'

# Search for any department name usage in success messages
rg -A 3 'department_deleted'

Length of output: 2800


Script:

#!/bin/bash
# Check the DepartmentDelete class implementation
ast-grep --pattern 'class DepartmentDelete {
  $$$
}'

# Find where departmentName is used in the class
rg -A 3 '\$departmentName' zmsadmin/src/Zmsadmin/DepartmentDelete.php

Length of output: 486

@msfb3 msfb3 requested a review from manjencic November 29, 2024 10:18
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.

2 participants