Skip to content

Commit

Permalink
Merge branch 'release/1.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 6, 2021
2 parents 3b776f5 + fc38bac commit 26e1087
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 14 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# v1.0.7
## 04/06/2021

1. [](#new)
* Added deny option support to `filepicker` field [#119](https://github.com/trilbymedia/grav-plugin-flex-objects/pull/119)
1. [](#bugfix)
* Prevent expert editing mode from anyone else than super users [grav-plugin-admin#2094](https://github.com/getgrav/grav-plugin-admin/issues/2094)
* Fixed not being able to add new folder [grav#3293](https://github.com/getgrav/grav/issues/3293)
* Fixed Flex directories defined only in theme not showing up [grav#3292](https://github.com/getgrav/grav/issues/3292)

# v1.0.6
## 03/30/2021

1. [](#bugfix)
* Fixed automatic git-sync in admin save and delete [#120](https://github.com/trilbymedia/grav-plugin-flex-objects/issues/120)
* Prevent Add Page / Add Module modals from closing if clicking on the outside overlay [getgrav/grav-plugin-admin#2089](https://github.com/getgrav/grav-plugin-admin/issues/2089)
* Prevent Add Page / Add Module modals from closing if clicking on the outside overlay [grav-plugin-admin#2089](https://github.com/getgrav/grav-plugin-admin/issues/2089)

# v1.0.5
## 03/19/2021
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{% endblock %}

{% block topbar %}
{% if user.authorize('admin.super') %}
<form id="admin-mode-toggle">
{% set normalText = 'PLUGIN_ADMIN.NORMAL'|tu %}
{% set expertText = 'PLUGIN_ADMIN.EXPERT'|tu %}
Expand All @@ -54,6 +55,7 @@
<a></a>
</div>
</form>
{% endif %}
{% endblock topbar %}

{% block content %}
Expand Down
4 changes: 3 additions & 1 deletion admin/templates/flex-objects/types/pages/edit.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'flex-objects/types/default/edit.html.twig' %}

{% set form = form ?? object.form(admin.session.expert != '0' ? 'raw') %}
{% set form = form ?? object.form(user.authorize('admin.super') and admin.session.expert != '0' ? 'raw') %}

{% set title = title ?? form.getValue('header.title') ?? object.title ?? key %}
{% set parent = object.parent %}
Expand Down Expand Up @@ -153,6 +153,7 @@
</div>
{% endif %}

{% if user.authorize('admin.super') %}
<form id="admin-mode-toggle">
{% set normalText = 'PLUGIN_ADMIN.NORMAL'|tu %}
{% set expertText = 'PLUGIN_ADMIN.EXPERT'|tu %}
Expand All @@ -168,6 +169,7 @@
<a></a>
</div>
</form>
{% endif %}
{% endblock topbar %}

{% block edit %}
Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Flex Objects
slug: flex-objects
type: plugin
version: 1.0.6
version: 1.0.7
description: Flex Objects plugin allows you to manage Flex Objects in Grav Admin.
icon: list-alt
author:
Expand All @@ -14,7 +14,7 @@ docs: https://github.com/trilbymedia/grav-plugin-flex-objects/blob/develop/READM
license: MIT

dependencies:
- { name: grav, version: '>=1.7.9' }
- { name: grav, version: '>=1.7.10' }
- { name: form, version: '>=5.0.1' }

form:
Expand Down
13 changes: 11 additions & 2 deletions classes/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,13 @@ public function taskSaveNewFolder(): void

/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
if ($locator->isStream($new_path)) {
$new_path = $locator->findResource($new_path, true, true);
} else {
$new_path = GRAV_ROOT . '/' . $new_path;
}

Folder::create($locator->findResource($new_path, true, true));
Folder::create($new_path);
Cache::clearCache('invalidate');

$this->grav->fireEvent('onAdminAfterSaveAs', new Event(['path' => $new_path]));
Expand Down Expand Up @@ -733,14 +738,18 @@ public function taskSave(): bool
/** @var FlexForm $form */
$form = $this->getForm($object);

$callable = static function (array $data, array $files, FlexObject $object) use ($form) {
$callable = function (array $data, array $files, FlexObject $object) use ($form) {
if (method_exists($object, 'storeOriginal')) {
$object->storeOriginal();
}
$object->update($data, $files);

// Support for expert mode.
if (str_ends_with($form->getId(), '-raw') && isset($data['frontmatter']) && is_callable([$object, 'frontmatter'])) {
if (!$this->user->authorize('admin.super')) {
throw new RuntimeException($this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' save raw.',
403);
}
$object->frontmatter($data['frontmatter']);
unset($data['frontmatter']);
}
Expand Down
27 changes: 27 additions & 0 deletions classes/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,16 @@ protected function actionMediaPicker(): ResponseInterface
});
}

if (isset($settings['deny'])) {
$available_files = array_filter($available_files, function ($file) use ($settings) {
return $this->filterDeniedFiles($file, $settings);
});

$pending_files = array_filter($pending_files, function ($file) use ($settings) {
return $this->filterDeniedFiles($file, $settings);
});
}

// Generate thumbs if needed
if (isset($settings['preview_images']) && $settings['preview_images'] === true) {
foreach ($available_files as $filename) {
Expand Down Expand Up @@ -432,6 +442,23 @@ protected function filterAcceptedFiles(string $file, array $settings)
return $valid;
}

/**
* @param string $file
* @param array $settings
* @return false|int
*/
protected function filterDeniedFiles(string $file, array $settings)
{
$valid = true;

foreach ((array)$settings['deny'] as $type) {
$find = str_replace('*', '.*', $type);
$valid = !preg_match('#' . $find . '$#i', $file);
}

return $valid;
}

/**
* @param string $action
* @return void
Expand Down
52 changes: 44 additions & 8 deletions flex-objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function initializeFlex(): void
*/
public function onPluginsInitialized(): void
{
if ($this->isAdmin() && method_exists(Admin::class, 'getChangelog')) {
if ($this->isAdmin()) {
/** @var UserInterface|null $user */
$user = $this->grav['user'] ?? null;

Expand All @@ -153,6 +153,9 @@ public function onPluginsInitialized(): void
'onAdminControllerInit' => [
['onAdminControllerInit', 0]
],
'onThemeInitialized' => [
['onThemeInitialized', 0]
],
'onPageInitialized' => [
['onAdminPageInitialized', 0]
],
Expand All @@ -163,8 +166,6 @@ public function onPluginsInitialized(): void
['onGetPageTemplates', 0]

]);
/** @var AdminController controller */
$this->controller = new AdminController();

} else {
$this->enable([
Expand All @@ -181,25 +182,60 @@ public function onPluginsInitialized(): void
*/
public function onRegisterFlex(FlexRegisterEvent $event): void
{
/** @var \Grav\Framework\Flex\Flex $flex */
$flex = $event->flex;
$map = Flex::getLegacyBlueprintMap(false);
$types = (array)$this->config->get('plugins.flex-objects.directories', []);
$this->registerDirectories($flex, $types);
}

/**
* @return void
*/
public function onThemeInitialized(): void
{
// Register directories defined in the theme.
/** @var \Grav\Framework\Flex\Flex $flex */
$flex = $this->grav['flex'];
$types = (array)$this->config->get('plugins.flex-objects.directories', []);
$this->registerDirectories($flex, $types, true);

/** @var AdminController controller */
$this->controller = new AdminController();

/** @var Debugger $debugger */
$debugger = Grav::instance()['debugger'];
$names = implode(', ', array_keys($flex->getDirectories()));
$debugger->addMessage(sprintf('Registered flex types: %s', $names), 'debug');
}

/**
* @param \Grav\Framework\Flex\Flex $flex
* @param array $types
* @param bool $report
*/
protected function registerDirectories(\Grav\Framework\Flex\Flex $flex, array $types, bool $report = false): void
{
$map = Flex::getLegacyBlueprintMap(false);
foreach ($types as $blueprint) {
// Backwards compatibility to v1.0.0-rc.3
$blueprint = $map[$blueprint] ?? $blueprint;
$type = basename((string)$blueprint, '.yaml');
if (!$type) {
continue;
}

if (!file_exists($blueprint)) {
/** @var Debugger $debugger */
$debugger = Grav::instance()['debugger'];
$debugger->addMessage(sprintf('Flex: blueprint for flex type %s is missing', $type), 'error');
if ($report) {
/** @var Debugger $debugger */
$debugger = Grav::instance()['debugger'];
$debugger->addMessage(sprintf('Flex: blueprint for flex type %s is missing', $type), 'error');
}

continue;
}

$directory = $flex->getDirectory($type);
if ($type && (!$directory || !$directory->isEnabled())) {
if (!$directory || !$directory->isEnabled()) {
$flex->addDirectoryType($type, $blueprint);
}
}
Expand Down

0 comments on commit 26e1087

Please sign in to comment.