Skip to content
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
130 changes: 130 additions & 0 deletions app/Models/Common/Buckets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models\Common;

use App\Models\Common\BucketsRoles;
use App\Models\Core\Configs;
use App\Traits\ConnectRoleTrait;
use Database\Factories\Common\BucketsFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -14,6 +15,30 @@ class Buckets extends Model
use ConnectRoleTrait;
use HasFactory;

/**
* 新規バケツの投稿権限初期値に対応するConfig名
*/
private const DEFAULT_NEW_BUCKET_POST_ROLE_CONFIGS = [
'role_article' => 'new_bucket_role_article_post_flag',
'role_reporter' => 'new_bucket_role_reporter_post_flag',
];

/**
* 新規バケツの投稿権限初期値を適用する対象プラグイン
*/
private const DEFAULT_POST_ROLE_TARGET_PLUGINS = [
'bbses',
'blogs',
'cabinets',
'calendars',
'contents',
'databases',
'faqs',
'photoalbums',
'reservations',
'slideshows',
];

/**
* create()やupdate()で入力を受け付ける ホワイトリスト
*/
Expand All @@ -27,6 +52,13 @@ class Buckets extends Model
// Buckets のrole
private $buckets_roles = null;

protected static function booted()
{
static::deleting(function ($bucket) {
BucketsRoles::where('buckets_id', $bucket->id)->delete();
});
}

/**
* 投稿権限データをrole の配列で返却
*/
Expand Down Expand Up @@ -221,6 +253,104 @@ public function needApprovalUser($user, $frame = null)
return true;
}

/**
* 新規バケツ作成時の投稿権限初期値を適用する。
*/
public function initializeDefaultPostRoles(): void
{
$default_post_role_flags = self::getDefaultNewBucketPostRoleFlags();

foreach ($default_post_role_flags as $role => $post_flag) {
if ((int) $post_flag !== 1) {
continue;
}

BucketsRoles::firstOrCreate(
[
'buckets_id' => $this->id,
'role' => $role,
],
[
'post_flag' => 1,
'approval_flag' => 0,
]
);
}
}

/**
* 投稿権限設定を持つプラグインの新規バケツなら、投稿権限初期値を適用する。
*/
public function initializeDefaultPostRolesIfTargetPlugin(): void
{
if (!self::isDefaultPostRoleTargetPlugin($this->plugin_name)) {
return;
}

$this->initializeDefaultPostRoles();
}

/**
* 新規バケツを作成し、対象プラグインだけ投稿権限初期値を適用する。
*/
public static function createWithDefaultPostRoles(array $attributes): self
{
$bucket = self::create($attributes);
$bucket->initializeDefaultPostRolesIfTargetPlugin();

return $bucket;
}

/**
* バケツを作成または更新し、新規作成時だけ投稿権限初期値を適用する。
*/
public static function updateOrCreateWithDefaultPostRoles(array $attributes, array $values = []): self
{
$bucket = self::updateOrCreate($attributes, $values);

if ($bucket->wasRecentlyCreated) {
$bucket->initializeDefaultPostRolesIfTargetPlugin();
}

return $bucket;
}

/**
* 新規バケツの投稿権限初期値を適用する対象プラグインか判定する。
*/
public static function isDefaultPostRoleTargetPlugin(?string $plugin_name): bool
{
return in_array($plugin_name, self::DEFAULT_POST_ROLE_TARGET_PLUGINS, true);
}

/**
* 新規バケツ作成時の投稿権限初期値を取得する。
*/
public static function getDefaultNewBucketPostRoleFlags(): array
{
$config_names = array_values(self::DEFAULT_NEW_BUCKET_POST_ROLE_CONFIGS);
$configs = Configs::getSharedConfigs();

if ($configs->isEmpty()) {
$configs = Configs::whereIn('name', $config_names)->get();
}

return self::resolveDefaultNewBucketPostRoleFlags($configs);
}

/**
* Config群から新規バケツ作成時の投稿権限初期値を解決する。
*/
private static function resolveDefaultNewBucketPostRoleFlags($configs): array
{
$configs = collect($configs);

return [
'role_article' => (int) Configs::getConfigsValue($configs, self::DEFAULT_NEW_BUCKET_POST_ROLE_CONFIGS['role_article'], 0),
'role_reporter' => (int) Configs::getConfigsValue($configs, self::DEFAULT_NEW_BUCKET_POST_ROLE_CONFIGS['role_reporter'], 0),
];
}

protected static function newFactory()
{
return BucketsFactory::new();
Expand Down
14 changes: 14 additions & 0 deletions app/Plugins/Manage/SiteManage/SiteManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ public function update($request, $page_id = null)
'value' => $request->additional_theme]
);

// 新規バケツ作成時のモデレータ投稿権限
$configs = Configs::updateOrCreate(
['name' => 'new_bucket_role_article_post_flag'],
['category' => 'general',
'value' => (isset($request->new_bucket_role_article_post_flag) ? $request->new_bucket_role_article_post_flag : 0)]
);

// 新規バケツ作成時の編集者投稿権限
$configs = Configs::updateOrCreate(
['name' => 'new_bucket_role_reporter_post_flag'],
['category' => 'general',
'value' => (isset($request->new_bucket_role_reporter_post_flag) ? $request->new_bucket_role_reporter_post_flag : 0)]
);

// 画面の基本の背景色
$configs = Configs::updateOrCreate(
['name' => 'base_background_color'],
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/User/Bbses/BbsesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ public function saveBuckets($request, $page_id, $frame_id, $bucket_id = null)
}

// バケツの取得。なければ登録。
$bucket = Buckets::updateOrCreate(
$bucket = Buckets::updateOrCreateWithDefaultPostRoles(
['id' => $bucket_id],
['bucket_name' => $request->name, 'plugin_name' => 'bbses'],
);
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/User/Blogs/BlogsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ public function saveBuckets($request, $page_id, $frame_id, $blogs_id = null)
// 画面から渡ってくるblogs_id が空ならバケツとブログを新規登録
if (empty($request->blogs_id)) {
// バケツの登録
$bucket = Buckets::create([
$bucket = Buckets::createWithDefaultPostRoles([
'bucket_name' => $request->blog_name,
'plugin_name' => 'blogs'
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/User/Cabinets/CabinetsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ private function getMoveValidator($request)
private function saveCabinet($request, $frame_id, $bucket_id)
{
// バケツの取得。なければ登録。
$bucket = Buckets::updateOrCreate(
$bucket = Buckets::updateOrCreateWithDefaultPostRoles(
['id' => $bucket_id],
['bucket_name' => $request->name, 'plugin_name' => 'cabinets'],
);
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/User/Calendars/CalendarsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public function saveBuckets($request, $page_id, $frame_id, $bucket_id = null)
}

// バケツの取得。なければ登録。
$bucket = Buckets::updateOrCreate(
$bucket = Buckets::updateOrCreateWithDefaultPostRoles(
['id' => $bucket_id],
['bucket_name' => $request->name, 'plugin_name' => 'calendars'],
);
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/User/Contents/ContentsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public function store($request, $page_id = null, $frame_id = null, $id = null, $

// バケツがまだ登録されていなかったら登録する。
if (empty($this->buckets)) {
$bucket = Buckets::create([
$bucket = Buckets::createWithDefaultPostRoles([
'bucket_name' => $request->bucket_name ?? '無題',
'plugin_name' => 'contents'
]);
Expand Down
10 changes: 5 additions & 5 deletions app/Plugins/User/Databases/DatabasesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2136,10 +2136,10 @@ public function saveBuckets($request, $page_id, $frame_id, $databases_id = null)
// 画面から渡ってくるdatabases_id が空ならバケツとブログを新規登録
if (empty($databases_id)) {
// バケツの登録
$bucket = new Buckets();
$bucket->bucket_name = $request->databases_name;
$bucket->plugin_name = 'databases';
$bucket->save();
$bucket = Buckets::createWithDefaultPostRoles([
'bucket_name' => $request->databases_name,
'plugin_name' => 'databases',
]);

if (empty($request->copy_databases_id)) {
// 登録
Expand Down Expand Up @@ -2359,7 +2359,7 @@ public function destroyBuckets($request, $page_id, $frame_id, $databases_id)
BucketsRoles::where('buckets_id', $databases->bucket_id)->delete();

// backetsの削除
Buckets::where('id', $databases->bucket_id)->delete();
Buckets::destroy($databases->bucket_id);

// change: このバケツを表示している全ページのフレームのバケツIDを消す
// // バケツIDの取得のためにFrame を取得(Frame を更新する前に取得しておく)
Expand Down
5 changes: 3 additions & 2 deletions app/Plugins/User/Faqs/FaqsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,10 +961,11 @@ public function saveBuckets($request, $page_id, $frame_id, $faqs_id = null)
// 画面から渡ってくるfaqs_id が空ならバケツとFAQを新規登録
if (empty($request->faqs_id)) {
// バケツの登録
$bucket_id = DB::table('buckets')->insertGetId([
$bucket = Buckets::createWithDefaultPostRoles([
'bucket_name' => $request->faq_name,
'plugin_name' => 'faqs'
]);
$bucket_id = $bucket->id;

// FAQデータ新規オブジェクト
$faqs = new Faqs();
Expand Down Expand Up @@ -1043,7 +1044,7 @@ public function destroyBuckets($request, $page_id, $frame_id, $faqs_id)
Frame::where('id', $frame_id)->update(['bucket_id' => null]);

// backetsの削除
Buckets::where('id', $frame->bucket_id)->delete();
Buckets::destroy($frame->bucket_id);
}
// 削除処理はredirect 付のルートで呼ばれて、処理後はページの再表示が行われるため、ここでは何もしない。
}
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/User/Photoalbums/PhotoalbumsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ private function getContentsControlValidator($request)
private function savePhotoalbum($request, $frame_id, $bucket_id)
{
// バケツの取得。なければ登録。
$bucket = Buckets::updateOrCreate(
$bucket = Buckets::updateOrCreateWithDefaultPostRoles(
['id' => $bucket_id],
['bucket_name' => $request->name, 'plugin_name' => 'photoalbums'],
);
Expand Down
4 changes: 2 additions & 2 deletions app/Plugins/User/Reservations/ReservationsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ public function saveBuckets($request, $page_id, $frame_id, $reservations_id = nu
if (empty($request->reservations_id)) {
// 画面から渡ってくるid が空ならバケツと施設を新規登録
// バケツの登録
$bucket = Buckets::create([
$bucket = Buckets::createWithDefaultPostRoles([
'bucket_name' => $request->reservation_name,
'plugin_name' => 'reservations'
]);
Expand Down Expand Up @@ -1701,7 +1701,7 @@ public function destroyBuckets($request, $page_id, $frame_id, $reservations_id)
Frame::where('bucket_id', $reservation->bucket_id)->update(['bucket_id' => null]);

// backetsの削除
Buckets::where('id', $reservation->bucket_id)->delete();
Buckets::destroy($reservation->bucket_id);

// 施設予約を削除する。
$reservation->delete();
Expand Down
10 changes: 5 additions & 5 deletions app/Plugins/User/Slideshows/SlideshowsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ public function saveBuckets($request, $page_id, $frame_id, $slideshows_id = null
/**
* 新規登録用の処理
*/
$bucket = new Buckets();
$bucket->bucket_name = '無題';
$bucket->plugin_name = 'slideshows';
$bucket->save();
$bucket = Buckets::createWithDefaultPostRoles([
'bucket_name' => '無題',
'plugin_name' => 'slideshows',
]);

// スライドショーデータ新規オブジェクト
$slideshows = new Slideshows();
Expand Down Expand Up @@ -325,7 +325,7 @@ public function destroyBuckets($request, $page_id, $frame_id, $slideshows_id)
$slideshows = Slideshows::find($slideshows_id);

// backetsの削除
Buckets::where('id', $slideshows->bucket_id)->delete();
Buckets::destroy($slideshows->bucket_id);

// バケツIDの取得のためにFrame を取得(Frame を更新する前に取得しておく)
$frame = Frame::where('id', $frame_id)->first();
Expand Down
12 changes: 9 additions & 3 deletions app/Plugins/User/UserPluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ public function editBucketsRoles($request, $page_id, $frame_id, $id = null, $use
{
// Buckets の取得
$buckets = $this->getBuckets($frame_id);
$default_post_role_flags = [];

if ($this->frame->plugin_name == 'contents' || $buckets) {
// 固定記事プラグイン(=コンテンツプラグイン)はバケツありなし、どちらでも表示する。
Expand All @@ -624,10 +625,15 @@ public function editBucketsRoles($request, $page_id, $frame_id, $id = null, $use
return $this->commonView('empty_bucket_setting');
}

if ($this->frame->plugin_name == 'contents' && empty($buckets)) {
$default_post_role_flags = Buckets::getDefaultNewBucketPostRoleFlags();
}

return $this->commonView('frame_edit_roles', [
'buckets' => $buckets,
'plugin_name' => $this->frame->plugin_name,
'use_approval' => $use_approval,
'buckets' => $buckets,
'plugin_name' => $this->frame->plugin_name,
'use_approval' => $use_approval,
'default_post_role_flags' => $default_post_role_flags,
]);
}

Expand Down
10 changes: 8 additions & 2 deletions resources/views/plugins/common/frame_edit_roles.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
{{-- 登録後メッセージ表示 --}}
@include('plugins.common.flash_message_for_frame')

@php
$default_post_role_flags = $default_post_role_flags ?? [];
$role_article_post_checked = $buckets ? $buckets->canPost("role_article") : !empty($default_post_role_flags['role_article']);
$role_reporter_post_checked = $buckets ? $buckets->canPost("role_reporter") : !empty($default_post_role_flags['role_reporter']);
@endphp

<form action="{{ url("/redirect/plugin/$frame->plugin_name/saveBucketsRoles/$page->id/$frame_id#frame-$frame_id") }}" name="{{$frame->plugin_name}}_buckets_form" method="POST">
{{ csrf_field() }}
<input type="hidden" name="redirect_path" value="{{ url("/plugin/$frame->plugin_name/editBucketsRoles/$page->id/$frame_id#frame-$frame_id") }}">
Expand All @@ -38,7 +44,7 @@
<th>モデレータ</th>
<td>
<div class="custom-control custom-checkbox custom-control-inline">
@if($buckets && $buckets->canPost("role_article"))
@if($role_article_post_checked)
<input name="role_article[post]" value="1" type="checkbox" class="custom-control-input" id="role_article_post" checked="checked">
@else
<input name="role_article[post]" value="1" type="checkbox" class="custom-control-input" id="role_article_post">
Expand All @@ -64,7 +70,7 @@
<th>編集者</th>
<td>
<div class="custom-control custom-checkbox custom-control-inline">
@if($buckets && $buckets->canPost("role_reporter"))
@if($role_reporter_post_checked)
<input name="role_reporter[post]" value="1" type="checkbox" class="custom-control-input" id="role_reporter_post" checked="checked">
@else
<input name="role_reporter[post]" value="1" type="checkbox" class="custom-control-input" id="role_reporter_post">
Expand Down
8 changes: 8 additions & 0 deletions resources/views/plugins/manage/site/pdf/base_main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
<td>基本レイアウト</td>
<td>{{$base_layout_title}}</td>
</tr>
<tr nobr="true">
<td>プラグイン新規作成時のモデレータ投稿権限</td>
@if (Configs::getConfigsValue($configs, 'new_bucket_role_article_post_flag', 0) == '1') <td>許可する</td> @else <td>許可しない</td> @endif
</tr>
<tr nobr="true">
<td>プラグイン新規作成時の編集者投稿権限</td>
@if (Configs::getConfigsValue($configs, 'new_bucket_role_reporter_post_flag', 0) == '1') <td>許可する</td> @else <td>許可しない</td> @endif
</tr>
<tr nobr="true">
<td>背景色</td>
<td>{{Configs::getConfigsValue($configs, 'base_background_color', null)}}</td>
Expand Down
Loading
Loading