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

Add constrain to check if plugin can be published. #13696

Open
wants to merge 23 commits into
base: 5.x
Choose a base branch
from

Conversation

rohitpavaskar
Copy link
Contributor

@rohitpavaskar rohitpavaskar commented Apr 26, 2024

Q A
Bug fix? (use the a.b branch) [N ]
New feature/enhancement? (use the a.x branch) [Y]
Deprecations? [N]
BC breaks? (use the c.x branch) [N]
Automated tests included? [Y]
Related user documentation PR URL mautic/mautic-documentation#...
Related developer documentation PR URL mautic/developer-documentation#...
Issue(s) addressed Fixes #...

Description:

When authorizing the plugin, if my user doesn't have particular access, I should receive an error and fail to authorize the plugin. This i new constrain which we need to add in any plugin which will not allow user to publish the plugin if user don't have sufficient access.
Also clear the access and refresh token whenever credentials are changed.

Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs here)
  2. Not testable without adding constrain in plugin.

rohitp19 and others added 23 commits April 26, 2024 11:54
…need to do some verification before publishing plugin
…the form validation fails so that it will not publish plugin with errors. If already in publish state do not unpublish as it may cause other things to fail
Co-authored-by: Miroslav Fedeleš <miroslav.fedeles@gmail.com>
Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 86.36364% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 61.52%. Comparing base (3e95053) to head (cc7787b).
Report is 24 commits behind head on 5.x.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                5.x   #13696      +/-   ##
============================================
+ Coverage     61.42%   61.52%   +0.09%     
- Complexity    34050    34091      +41     
============================================
  Files          2240     2245       +5     
  Lines        101773   101909     +136     
============================================
+ Hits          62519    62703     +184     
+ Misses        39254    39206      -48     
Files Coverage Δ
...dles/PluginBundle/Event/PluginIsPublishedEvent.php 100.00% <100.00%> (ø)
...ndles/PluginBundle/Exception/ApiErrorException.php 41.17% <100.00%> (+24.50%) ⬆️
...undles/PluginBundle/Form/Constraint/CanPublish.php 100.00% <100.00%> (ø)
...uginBundle/Form/Constraint/CanPublishValidator.php 100.00% <100.00%> (ø)
app/bundles/PluginBundle/Form/Type/DetailsType.php 93.33% <100.00%> (+0.11%) ⬆️
...les/PluginBundle/Form/Type/FeatureSettingsType.php 74.07% <100.00%> (ø)
app/bundles/PluginBundle/MauticPluginBundle.php 100.00% <100.00%> (ø)
...ndles/PluginBundle/Controller/PluginController.php 46.31% <83.33%> (+3.21%) ⬆️
...s/PluginBundle/Integration/AbstractIntegration.php 34.00% <33.33%> (+0.33%) ⬆️

... and 9 files with indirect coverage changes

@escopecz escopecz added ready-to-test PR's that are ready to test enhancement Any improvement to an existing feature or functionality plugin Anything related to plugins unforking Used for PRs in the Acquia's unforking initiative labels Apr 30, 2024
Copy link
Sponsor Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

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

Thanks Rohit! I found a few places that could improve. Please go through the suggestions and apply them if they make sense.

*
* @return array <string,mixed>
*
* @phpstan-ignore-next-line
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Can you please add a comment at the end of this line why this needs to be ignored?

Comment on lines +81 to +87
'mautic.plugin.validator.can_publish_validator' => [
'class' => Mautic\PluginBundle\Form\Constraint\CanPublishValidator::class,
'arguments' => [
'event_dispatcher',
],
'tag' => 'validator.constraint_validator',
],
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This shouldn't be necessary for M5. Is it? The tag can be added in services.php if the service isn't autoconfigured.

Comment on lines +9 to +16
private string $message;
private bool $canPublish;

public function __construct(private int $value, private string $integrationName)
{
$this->canPublish = true;
$this->message = '';
}
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Suggested change
private string $message;
private bool $canPublish;
public function __construct(private int $value, private string $integrationName)
{
$this->canPublish = true;
$this->message = '';
}
private string $message = true;
private bool $canPublish = '';
public function __construct(private int $value, private string $integrationName)
{
}

@@ -133,4 +133,13 @@ final class PluginEvents
* @var string
*/
public const ON_PLUGIN_INSTALL = 'mautic.plugin.on_plugin_install';

/**
* The mautic.plugin.is_published_state_changing event is dispatched when a user tries to changes plugin is published state.
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Suggested change
* The mautic.plugin.is_published_state_changing event is dispatched when a user tries to changes plugin is published state.
* The mautic.plugin.is_published_state_changing event is dispatched when a user tries to change the published state of a plugin.

foreach ($container->getDefinitions() as $definition) {
$class = (string) $definition->getClass();

/** @phpstan-ignore-next-line */
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Please add a reason why the next line is ignored if it cannot be fixed.

@@ -0,0 +1,92 @@
<?php

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Suggested change
declare(strict_types=1);

Comment on lines +18 to +19
private MockObject $dispatcher;
private MockObject $event;
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

These should have a & the real type like MockObject&EventDispatcherInterface as it needs the methods from both. PHP 8 doesn't allow the & operator just yet so you'll have to add the real type to the comment along as the MockObject type you have there.

mautic.plugin.field.required_mapping_missing="At least one required field is not mapped."
mautic.lead_list.not_allowed_plugin_publish="You are not allowed to publish plugin due to insufficient configurations."
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

It doesn't sound right. Should there be the or this?

Suggested change
mautic.lead_list.not_allowed_plugin_publish="You are not allowed to publish plugin due to insufficient configurations."
mautic.lead_list.not_allowed_plugin_publish="You are not allowed to publish this plugin due to insufficient configurations."

@escopecz escopecz added the pending-feedback PR's and issues that are awaiting feedback from the author label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any improvement to an existing feature or functionality pending-feedback PR's and issues that are awaiting feedback from the author plugin Anything related to plugins ready-to-test PR's that are ready to test unforking Used for PRs in the Acquia's unforking initiative
Projects
Status: 🚨 Developer revision needed
Development

Successfully merging this pull request may close these issues.

None yet

4 participants