-
Notifications
You must be signed in to change notification settings - Fork 7
Handle plugin settings with up to date patterns #15
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
Open
jardakotesovec
wants to merge
4
commits into
ajnyga:master
Choose a base branch
from
jardakotesovec:plugin_config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+160
−168
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6a5a432
Handle plugin settings with up to date patterns
jardakotesovec 016dd45
Refine authorisation logic (site vs contex plugins), adjust the api e…
jardakotesovec c9875ff
Showcase how it would look like with PluginSettingsController
jardakotesovec be687b4
Fix order, to avoid calling controller if plugin is not enabled, beca…
jardakotesovec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @file plugins/generic/allowedUploads/AllowedUploadsForm.php | ||
| * | ||
| * | ||
| * @brief Form component for AllowedUploads plugin settings | ||
| */ | ||
|
|
||
| namespace APP\plugins\generic\allowedUploads; | ||
|
|
||
| use PKP\components\forms\FieldText; | ||
| use PKP\components\forms\FormComponent; | ||
|
|
||
| class AllowedUploadsForm extends FormComponent | ||
| { | ||
| public $id = 'allowedUploadsSettings'; | ||
| public $method = 'PUT'; | ||
|
|
||
| public function __construct(string $action) | ||
| { | ||
| $this->action = $action; | ||
|
|
||
| $this->addField(new FieldText('allowedExtensions', [ | ||
| 'label' => __('plugins.generic.allowedUploads.manager.settings.allowedExtensions'), | ||
| 'description' => __('plugins.generic.allowedUploads.manager.settings.description'), | ||
| 'value' => '', | ||
| ])); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @file plugins/generic/allowedUploads/AllowedUploadsSettingsController.php | ||
| * | ||
| * @class AllowedUploadsSettingsController | ||
| * | ||
| * @brief API controller for AllowedUploads plugin settings | ||
| */ | ||
|
|
||
| namespace APP\plugins\generic\allowedUploads; | ||
|
|
||
| use APP\plugins\generic\allowedUploads\formRequests\EditAllowedUploadsSettings; | ||
| use Illuminate\Http\JsonResponse; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Http\Response; | ||
| use PKP\plugins\PluginSettingsController; | ||
|
|
||
| class AllowedUploadsSettingsController extends PluginSettingsController | ||
| { | ||
|
|
||
| public function get(Request $illuminateRequest): JsonResponse | ||
| { | ||
| $contextId = $this->getRequest()->getContext()->getId(); | ||
|
|
||
| return response()->json( | ||
| ['allowedExtensions' => $this->plugin->getSetting($contextId, 'allowedExtensions') ?? ''], | ||
| Response::HTTP_OK | ||
| ); | ||
| } | ||
|
|
||
| public function edit(EditAllowedUploadsSettings $illuminateRequest): JsonResponse | ||
| { | ||
| $contextId = $this->getRequest()->getContext()->getId(); | ||
| $allowedExtensions = $illuminateRequest->validated()['allowedExtensions']; | ||
|
|
||
| $this->plugin->updateSetting($contextId, 'allowedExtensions', $allowedExtensions); | ||
|
|
||
| return response()->json( | ||
| ['allowedExtensions' => $allowedExtensions], | ||
| Response::HTTP_OK | ||
| ); | ||
| } | ||
|
|
||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @file plugins/generic/allowedUploads/formRequests/EditAllowedUploadsSettings.php | ||
| * | ||
| * Copyright (c) 2014-2026 Simon Fraser University | ||
| * Copyright (c) 2003-2026 John Willinsky | ||
| * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
| * | ||
| * @class EditAllowedUploadsSettings | ||
| * | ||
| * @ingroup plugins_generic_allowedUploads | ||
| * | ||
| * @brief Handle validation for updating AllowedUploads plugin settings | ||
| */ | ||
|
|
||
| namespace APP\plugins\generic\allowedUploads\formRequests; | ||
|
|
||
| use Illuminate\Foundation\Http\FormRequest; | ||
|
|
||
| class EditAllowedUploadsSettings extends FormRequest | ||
| { | ||
| public function rules(): array | ||
| { | ||
| return [ | ||
| 'allowedExtensions' => [ | ||
| 'required', | ||
| 'string', | ||
| 'regex:/^\s*[a-zA-Z0-9]+(\s*;\s*[a-zA-Z0-9]+)*\s*$/', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| public function messages(): array | ||
| { | ||
| return [ | ||
| 'allowedExtensions.regex' => __('plugins.generic.allowedUploads.manager.settings.validationError'), | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this changes anything based on the updates here, but how does the plugin handle an empty string for this value? Is an empty string distinct from the idea of a
nullvalue? (Not necessarily in the form field, but for the setting value in general?)