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

move key and permission checks inside the event #74

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed a bug where Craft user’s email address was not synced to Stripe even if `syncChangedUserEmailsToStripe` was set to `true`. ([#69](https://github.com/craftcms/stripe/issues/69))
- Fixed an error where the plugin could attempt to check User permissions before Craft was fully initialized. ([#71](https://github.com/craftcms/stripe/issues/71))
- Fixed a bug where the plugin was attempting to create missing users when `createUserIfMissing` was `true` but the Craft edition didn’t allow for multiple users. ([#72](https://github.com/craftcms/stripe/pull/72))

## 1.3.2 - 2024-12-11
Expand Down
20 changes: 10 additions & 10 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,14 @@ function(RegisterConditionRulesEvent $event) {

private function registerUserActions(): void
{
if (
!empty(Plugin::getInstance()->getApi()->getApiKey()) &&
Craft::$app->getUser()->checkPermission('accessPlugin-stripe')
) {
Event::on(
User::class,
Element::EVENT_DEFINE_ACTION_MENU_ITEMS,
function(DefineMenuItemsEvent $event) {
Event::on(
User::class,
Element::EVENT_DEFINE_ACTION_MENU_ITEMS,
function(DefineMenuItemsEvent $event) {
if (
!empty(Plugin::getInstance()->getApi()->getApiKey()) &&
Craft::$app->getUser()->checkPermission('accessPlugin-stripe')
) {
$sender = $event->sender;
if ($email = $sender->email) {
$customers = Plugin::getInstance()->getApi()->fetchAllCustomers(['email' => $email]);
Expand All @@ -598,8 +598,8 @@ function(DefineMenuItemsEvent $event) {
}
}
}
);
}
}
);
}

/**
Expand Down
Loading