add exemple of public post status permission

This commit is contained in:
Jean-Christian Denis 2025-01-10 17:20:32 +01:00
parent 68f754792f
commit 33b3035e11
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
3 changed files with 55 additions and 4 deletions

15
img/subscriber.svg Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<svg height="64px" width="64px" version="1.1" fill="none" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 235.517 235.517" xml:space="preserve">
<g>
<path fill="#b2b5ba" d="M118.1,235.517c7.898,0,14.31-6.032,14.31-13.483c0-7.441,0-13.473,0-13.473
c39.069-3.579,64.932-24.215,64.932-57.785v-0.549c0-34.119-22.012-49.8-65.758-59.977V58.334c6.298,1.539,12.82,3.72,19.194,6.549
c10.258,4.547,22.724,1.697,28.952-8.485c6.233-10.176,2.866-24.47-8.681-29.654c-11.498-5.156-24.117-8.708-38.095-10.236V8.251
c0-4.552-6.402-8.251-14.305-8.251c-7.903,0-14.31,3.514-14.31,7.832c0,4.335,0,7.843,0,7.843
c-42.104,3.03-65.764,25.591-65.764,58.057v0.555c0,34.114,22.561,49.256,66.862,59.427v33.021
c-10.628-1.713-21.033-5.243-31.623-10.65c-11.281-5.755-25.101-3.72-31.938,6.385c-6.842,10.1-4.079,24.449,7.294,30.029
c16.709,8.208,35.593,13.57,54.614,15.518v13.755C103.79,229.36,110.197,235.517,118.1,235.517z M131.301,138.12
c14.316,4.123,18.438,8.257,18.438,15.681v0.555c0,7.979-5.776,12.651-18.438,14.033V138.12z M86.999,70.153v-0.549
c0-7.152,5.232-12.657,18.71-13.755v29.719C90.856,81.439,86.999,77.305,86.999,70.153z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -21,7 +21,9 @@ use Dotclear\Module\MyPlugin;
*/
class My extends MyPlugin
{
public const POST_READY = -100;
public const POST_PROOFREAD = -110;
public const POST_DRAFT = -120;
public const PERMISSION_SUBSCRIBER = 'subscriber';
public const POST_SUBSCRIBED = -200;
public const POST_READY = -100;
public const POST_PROOFREAD = -110;
public const POST_DRAFT = -120;
}

View file

@ -3,6 +3,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\Proofreading;
use ArrayObject;
use Dotclear\App;
use Dotclear\Core\PostType;
use Dotclear\Core\Process;
@ -28,7 +29,11 @@ class Prepend extends Process
return false;
}
return
// subscirber permission
App::auth()->setPermissionType(My::PERMISSION_SUBSCRIBER, __('Posts subscriber'));
// posts status
$status =
App::status()->post()->set(
(new Status(My::POST_DRAFT , My::id() . 'draft', 'Draft', 'Draft (>1)', My::fileURL('img/draft.svg'))),
)
@ -37,7 +42,36 @@ class Prepend extends Process
)
&& App::status()->post()->set(
(new Status(My::POST_READY , My::id() . 'ready', 'Fulfilled', 'Fulfilled (>1)', My::fileURL('img/ready.svg'))),
)
&& App::status()->post()->set(
(new Status(My::POST_SUBSCRIBED , My::id() . 'subscriber', 'Subscription', 'Subscription (>1)', My::fileURL('img/subscriber.svg'))),
);
// tweak frontend
if ($status) {
App::behavior()->addBehaviors([
'coreBlogBeforeGetPostsAddingParameters' => self::getPosts(...),
]);
}
return $status;
}
/**
* @param array<string, mixed>|ArrayObject<string, mixed> $params Parameters
*/
public static function getPosts(ArrayObject $params, string|null $arg = null): void
{
if (App::task()->checkContext('FRONTEND') && App::auth()->check(My::PERMISSION_SUBSCRIBER, App::blog()->id()) === true) {
if (!isset($params['psot_status'])) {
$params['post_status'] = [];
}
if (!is_array($params['post_status'])) {
$params['post_status'] = [$params['post_status']];
}
//$params['post_status'][] = App::status()->post()::PUBLISHED;
$params['post_status'][] = My::POST_SUBSCRIBED;
}
}
}