Skip to content

Set Institution POC address#686

Merged
belwalshubham merged 3 commits intodevelopfrom
set-institution-poc-address
Dec 24, 2024
Merged

Set Institution POC address#686
belwalshubham merged 3 commits intodevelopfrom
set-institution-poc-address

Conversation

@belwalshubham
Copy link
Copy Markdown
Collaborator

@belwalshubham belwalshubham commented Dec 24, 2024

  1. set Institute address
  2. set Institution Poc Address

Summary by CodeRabbit

  • New Features

    • Enhanced logging capabilities in the CollectionCampService for better data traceability.
    • Added new event handling methods in the InstitutionService for managing institution addresses during form submissions.
    • Introduced new constants and static variables for improved address management.
  • Bug Fixes

    • Improved monitoring of address updates to ensure accuracy in the InstitutionService.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 24, 2024

Warning

Rate limit exceeded

@belwalshubham has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 27 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 9477573 and a8b9ec4.

📒 Files selected for processing (2)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (0 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionService.php (3 hunks)

Walkthrough

This pull request introduces logging enhancements to the CollectionCampService class and significant modifications to the InstitutionService class. The changes focus on improving debugging capabilities and adding new event handling methods for address management. The modifications include adding error logging statements and implementing new event-driven methods to process form submissions related to institutions and addresses.

Changes

File Change Summary
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php Added error logging statements in setCollectionCampAddress and setEventVolunteersAddress methods to improve traceability
wp-content/civi-extensions/goonjcustom/Civi/InstitutionService.php - Added new constants and static variables
- Implemented setInstituteAddress and setInstitutionPocAddress methods
- Updated getSubscribedEvents with new event handlers

Sequence Diagram

sequenceDiagram
    participant Form as Afform Submit
    participant Service as InstitutionService
    participant Address as Address Utility

    Form->>Service: Submit Event
    Service->>Service: Check Form Name
    Service->>Service: Validate Entity Type
    Service->>Address: Update Address
    Address-->>Service: Return Update Result
Loading

Possibly related PRs

Suggested labels

status : ready for review, status : reviewed

Suggested reviewers

  • nishant22029

Poem

🌟 Logging's dance, a digital art,
Tracing paths where data starts,
Debugging whispers, code's sweet song,
Revealing secrets where they belong!
🕵️‍♀️ Refactoring magic, line by line! 🔍


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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: 2

🧹 Nitpick comments (3)
wp-content/civi-extensions/goonjcustom/Civi/InstitutionService.php (2)

24-26: Consider adjusting naming and static usage
Defining const Institution_INTENT_FB_NAME with a capitalized prefix is good, but for consistency across constants, you might rename it INSTITUTION_INTENT_FB_NAME. Also, relying on a static property ($goonjActivitiesAddress) can lead to concurrency conflicts when multiple requests run concurrently; consider storing the address in a request-scoped variable or passing it explicitly.


47-81: Check for multiple address entries and handle potential missing data
The setInstituteAddress function currently assigns only the first address record [0], which might be limiting if there are multiple addresses. Consider supporting all addresses or clearly documenting that only the first address is processed.

wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)

230-247: Be cautious about sensitive data in logs
These newly added error_log statements may inadvertently expose personally identifiable information (PII) or sensitive data if $fields contain user information. Ensure that logging is sanitized or strictly limited to non-sensitive data.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7cf33d and 9477573.

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

5-13: All required imports appear consistent and complete
These added use statements correctly reference the classes used in the new methods.


33-36: Validate event priority ordering
The subscription to civi.afform.submit is prioritizing setInstituteAddress (9) above setInstitutionPocAddress (8). Ensure this priority ordering is intended. If not, switch them so that POC address logic executes first if needed.

Comment on lines +86 to +117
public static function setInstitutionPocAddress(AfformSubmitEvent $event) {
$afform = $event->getAfform();
$formName = $afform['name'];

if ($formName !== self::Institution_INTENT_FB_NAME) {
return;
}

$entityType = $event->getEntityType();

if (!CoreUtil::isContact($entityType)) {
return;
}

foreach ($event->records as $index => $contact) {
if (empty($contact['fields'])) {
continue;
}

$contactId = $contact['fields']['id'];

$stateProvinceId = self::$goonjActivitiesAddress['state_province_id'];

$updateResults = Address::update(FALSE)
->addValue('state_province_id', $stateProvinceId)
->addWhere('contact_id', '=', $test)
->execute();
}

\Civi::log()->info('Address update results', $updateResults);

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical bug: Missing variable $test reference
Line 111 uses ->addWhere('contact_id', '=', $test), but $test is not defined anywhere. This is likely a typo and should be replaced with $contactId or the appropriate variable.

You can fix this issue by changing $test to $contactId:

-  ->addWhere('contact_id', '=', $test)
+  ->addWhere('contact_id', '=', $contactId)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static function setInstitutionPocAddress(AfformSubmitEvent $event) {
$afform = $event->getAfform();
$formName = $afform['name'];
if ($formName !== self::Institution_INTENT_FB_NAME) {
return;
}
$entityType = $event->getEntityType();
if (!CoreUtil::isContact($entityType)) {
return;
}
foreach ($event->records as $index => $contact) {
if (empty($contact['fields'])) {
continue;
}
$contactId = $contact['fields']['id'];
$stateProvinceId = self::$goonjActivitiesAddress['state_province_id'];
$updateResults = Address::update(FALSE)
->addValue('state_province_id', $stateProvinceId)
->addWhere('contact_id', '=', $test)
->execute();
}
\Civi::log()->info('Address update results', $updateResults);
}
public static function setInstitutionPocAddress(AfformSubmitEvent $event) {
$afform = $event->getAfform();
$formName = $afform['name'];
if ($formName !== self::Institution_INTENT_FB_NAME) {
return;
}
$entityType = $event->getEntityType();
if (!CoreUtil::isContact($entityType)) {
return;
}
foreach ($event->records as $index => $contact) {
if (empty($contact['fields'])) {
continue;
}
$contactId = $contact['fields']['id'];
$stateProvinceId = self::$goonjActivitiesAddress['state_province_id'];
$updateResults = Address::update(FALSE)
->addValue('state_province_id', $stateProvinceId)
->addWhere('contact_id', '=', $contactId)
->execute();
}
\Civi::log()->info('Address update results', $updateResults);
}

Comment on lines +274 to +286
error_log("entityType.." . print_r($entityType, TRUE));


if (!CoreUtil::isContact($entityType)) {
return;
}

foreach ($event->records as $index => $contact) {
error_log("contact.." . print_r($contact['fields'], TRUE));
if (empty($contact['fields'])) {
continue;
}

error_log("nitu.." . print_r($event->records, TRUE));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Prevent logging entire contact objects
Using print_r($contact['fields'], TRUE) and printing $event->records in logs might include private data. Consider logging only necessary fields or masking sensitive details.

@belwalshubham belwalshubham merged commit ddf9465 into develop Dec 24, 2024
@belwalshubham belwalshubham deleted the set-institution-poc-address branch December 24, 2024 12:27
@coderabbitai coderabbitai bot mentioned this pull request Mar 1, 2025
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.

1 participant