Skip to content

Remove the urban ops monetary contribution tab for admin#485

Merged
tarunnjoshi merged 4 commits intodevelopfrom
remove-contribution-tab-for-admin
Nov 22, 2024
Merged

Remove the urban ops monetary contribution tab for admin#485
tarunnjoshi merged 4 commits intodevelopfrom
remove-contribution-tab-for-admin

Conversation

@tarunnjoshi
Copy link
Copy Markdown
Member

@tarunnjoshi tarunnjoshi commented Nov 22, 2024

Remove the urban ops monetary contribution for admin

Summary by CodeRabbit

  • New Features

    • Enhanced tab visibility based on user permissions, specifically for admin users.
  • Bug Fixes

    • Improved control flow for tab configuration, ensuring appropriate tabs are displayed based on user roles.
  • Chores

    • Minor formatting adjustments and added comments for clarity.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 22, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce a new dependency on CRM_Core_Permission in the CollectionCampService.php file. The collectionCampTabset method is modified to include a permission check that prevents the "monetaryContributionForUrbanOps" tab from being added if the user has admin permissions. This adjustment alters the control flow regarding tab visibility based on user roles, while minor formatting changes and comments are also included without affecting the overall functionality.

Changes

File Path Change Summary
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php Added import for CRM_Core_Permission and modified collectionCampTabset method to check for admin permissions, skipping a specific tab for admins. Minor formatting adjustments included.
wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php Modified droppingCenterTabset method to include a check for admin permissions, skipping the "monetaryContributionForUrbanOps" tab for admins. No changes to method signatures.

Possibly related PRs

  • add check for poster presence before trying to attach it #308: The DroppingCenterService.php file also modifies a method to include an admin permission check, similar to the changes made in the main PR.
  • bug fixes and refactor #329: The CollectionCampService.php file is updated with new methods that enhance functionality related to collection camps, which aligns with the changes made in the main PR regarding user permissions.
  • Collection Camp Authorisation Status #362: The CollectionCampService.php file is updated to include permission checks and status updates, which relates to the permission checks introduced in the main PR.
  • Add Monetary Contribution Tabs #441: The addition of a new tab configuration in the CollectionCampService.php file for monetary contributions is relevant as it expands the functionality of the collectionCampTabset method, which is also modified in the main PR.
  • Add ACL Monetory Contribution #470: The changes in the CollectionCampService.php file regarding role-based visibility for tabs directly relate to the permission checks added in the main PR.

Suggested reviewers

  • belwalshubham
  • nishant22029

🎉 In code we trust, with logic so bright,
A tab's fate now hinges on admin's insight.
Permissions now guide what users can see,
A cleaner control flow, as smooth as can be!
So here's to the changes, both subtle and grand,
In the world of Civi, we take a bold stand! 🎊


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@tarunnjoshi tarunnjoshi requested a review from pokhiii November 22, 2024 10:21
@tarunnjoshi tarunnjoshi self-assigned this Nov 22, 2024
@tarunnjoshi tarunnjoshi changed the title Remove the urban ops monetary contribution for admin Remove the urban ops monetary contribution tab for admin Nov 22, 2024
Copy link
Copy Markdown

@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: 1

🧹 Outside diff range and nitpick comments (1)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)

Line range hint 27-27: Consider splitting this class into smaller, focused service classes.

The CollectionCampService class has grown to handle multiple responsibilities, which violates the Single Responsibility Principle. Consider extracting the following functionalities into separate service classes:

  1. CollectionCampEmailService - For email notification logic
  2. CollectionCampQRService - For QR code generation
  3. CollectionCampFormService - For form processing
  4. CollectionCampStatusService - For status management
  5. CollectionCampLogisticsService - For logistics handling
  6. CollectionCampMonetaryService - For monetary contribution management

This refactoring would:

  • Improve code maintainability
  • Make the codebase easier to test
  • Reduce the risk of merge conflicts
  • Make the code more modular

Would you like me to provide a detailed refactoring plan?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed8479 and e52d578.

📒 Files selected for processing (1)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2 hunks)
🔇 Additional comments (1)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)

23-23: LGTM: Import statement is correctly placed.

The addition of CRM_Core_Permission import is necessary for the new permission check functionality.

Comment on lines +161 to +167
// Check if the user is an admin.
$isAdmin = CRM_Core_Permission::check('administer CiviCRM');

// Skip the "monetaryContributionForUrbanOps" tab for admins.
if ($key == 'monetaryContributionForUrbanOps' && $isAdmin) {
continue;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codebase verification

Potential inconsistency in admin permission handling

The monetaryContributionForUrbanOps tab appears in both CollectionCampService.php and DroppingCenterService.php, but the admin visibility restriction is only implemented in CollectionCampService.php. This inconsistency could lead to confusion where admins see the tab in one context but not in another.

  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php: Missing admin permission check for monetaryContributionForUrbanOps tab
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php: Has admin permission check

Consider applying the same visibility rules consistently across both services to maintain a uniform user experience.

🔗 Analysis chain

LGTM: Permission check is correctly implemented.

The implementation effectively prevents admin users from seeing the "monetaryContributionForUrbanOps" tab, which aligns with the PR objective.

Let's verify that this is the only place where monetary contribution for urban ops is referenced:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other references to monetaryContributionForUrbanOps
rg -i "monetaryContributionForUrbanOps"

Length of output: 810


Script:

#!/bin/bash
# Check if similar admin permission check exists in DroppingCenterService.php
ast-grep --pattern 'if ($_ == "monetaryContributionForUrbanOps" && $_) {' wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php

Length of output: 145

Copy link
Copy Markdown

@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: 1

🧹 Outside diff range and nitpick comments (2)
wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php (2)

556-562: Fix indentation and remove redundant comment

The indentation of the added code block doesn't match the surrounding code style, and the comment is redundant as the code is self-explanatory.

-      // Check if the user is an admin.
-      $isAdmin = \CRM_Core_Permission::check('admin');
-
-      // Skip the "monetaryContributionForUrbanOps" tab for admins.
-      if ($key == 'monetaryContributionForUrbanOps' && $isAdmin) {
-        continue;
-      }
+    $isAdmin = \CRM_Core_Permission::check('admin');
+    if ($key == 'monetaryContributionForUrbanOps' && $isAdmin) {
+      continue;
+    }

556-562: Consider refactoring permission checks

The current implementation performs multiple permission checks in the loop (admin check and permission check). Consider refactoring to improve efficiency and maintainability.

 public static function droppingCenterTabset($tabsetName, &$tabs, $context) {
+    $isAdmin = \CRM_Core_Permission::check('admin');
     foreach ($tabConfigs as $key => $config) {
-      $isAdmin = \CRM_Core_Permission::check('admin');
-
-      if ($key == 'monetaryContributionForUrbanOps' && $isAdmin) {
+      if ($isAdmin && $key == 'monetaryContributionForUrbanOps') {
         continue;
       }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e52d578 and 326ce97.

📒 Files selected for processing (2)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php

Comment on lines +556 to +562
// Check if the user is an admin.
$isAdmin = \CRM_Core_Permission::check('admin');

// Skip the "monetaryContributionForUrbanOps" tab for admins.
if ($key == 'monetaryContributionForUrbanOps' && $isAdmin) {
continue;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codebase verification

🛠️ Refactor suggestion

Extract permission check and tab skipping logic to a shared trait

The permission check and tab skipping logic for admin users is indeed duplicated between DroppingCenterService and CollectionCampService. However, since both services already use shared traits (QrCodeable and CollectionSource), the best approach would be to extract this common functionality into a new trait rather than a utility method.

  • Create a new trait AdminTabManagement to handle the shared logic for managing admin tabs
  • Both services can then use this trait to avoid code duplication
  • The trait should contain the common logic for checking admin permissions and skipping specific tabs

Example implementation:

trait AdminTabManagement {
    private static function shouldSkipTabForAdmin($tabKey) {
        return $tabKey == 'monetaryContributionForUrbanOps' && \CRM_Core_Permission::check('admin');
    }
}
🔗 Analysis chain

Extract permission logic to a separate method

The permission check logic appears to be duplicated between DroppingCenterService and CollectionCampService. Consider extracting this into a shared utility method.

Suggested refactor:

+ private static function shouldSkipTabForAdmin($tabKey) {
+   return $tabKey == 'monetaryContributionForUrbanOps' && \CRM_Core_Permission::check('admin');
+ }

  public static function droppingCenterTabset($tabsetName, &$tabs, $context) {
    foreach ($tabConfigs as $key => $config) {
-      $isAdmin = \CRM_Core_Permission::check('admin');
-      if ($key == 'monetaryContributionForUrbanOps' && $isAdmin) {
+      if (self::shouldSkipTabForAdmin($key)) {
         continue;
       }

Confirmed: Permission check logic is duplicated

The code for checking admin permissions and skipping the "monetaryContributionForUrbanOps" tab is indeed duplicated between DroppingCenterService and CollectionCampService. Let's verify if these are part of the same inheritance hierarchy or if they share a common interface.


Let me try a different approach to check the class definitions and their relationships.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the duplication of permission check logic
rg -A 5 "CRM_Core_Permission::check\('admin'\)" --type php

Length of output: 1342


Script:

#!/bin/bash
# Check if these services share a common parent or interface
ast-grep --pattern 'class DroppingCenterService extends $_'
ast-grep --pattern 'class CollectionCampService extends $_'
ast-grep --pattern 'class DroppingCenterService implements $_'
ast-grep --pattern 'class CollectionCampService implements $_'

Length of output: 37341


Script:

#!/bin/bash
# Get the content of both service files to analyze their structure
cat wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php
cat wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php

Length of output: 66727

];

foreach ($tabConfigs as $key => $config) {
// Check if the user is an admin.
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.

We don't need comments for this

// Check if the user is an admin.
$isAdmin = CRM_Core_Permission::check('admin');

// Skip the "monetaryContributionForUrbanOps" tab for admins.
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.

for this as well

];

foreach ($tabConfigs as $key => $config) {
// Check if the user is an admin.
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.

remove

// Check if the user is an admin.
$isAdmin = \CRM_Core_Permission::check('admin');

// Skip the "monetaryContributionForUrbanOps" tab for admins.
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.

remove

@tarunnjoshi tarunnjoshi merged commit a8f0300 into develop Nov 22, 2024
@tarunnjoshi tarunnjoshi deleted the remove-contribution-tab-for-admin branch November 22, 2024 10:56
@tarunnjoshi tarunnjoshi restored the remove-contribution-tab-for-admin branch November 22, 2024 11:04
@pokhiii pokhiii deleted the remove-contribution-tab-for-admin branch April 19, 2025 11:29
@coderabbitai coderabbitai bot mentioned this pull request Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants