FIX: fix content dependency on categories
This commit is contained in:
@@ -17,8 +17,7 @@ class History implements HistoryHandler
|
||||
switch ($changeset->column) {
|
||||
case 'pageContent':
|
||||
$route = route('history.diff', [
|
||||
'revision' => $changeset->edit_batch,
|
||||
'id' => $changeset->id
|
||||
'revision' => $changeset->id
|
||||
]);
|
||||
|
||||
return "(<a href='" . $route . "'>" . trans('admin/history.diff') . "</a>)";
|
||||
@@ -48,8 +47,8 @@ class History implements HistoryHandler
|
||||
break;
|
||||
default:
|
||||
return trans('admin/history.changedFromTo', [
|
||||
'from' => is_null($changeset->old_value) ? trans('admin/history.emptyValue') : $changeset->old_value,
|
||||
'to' => is_null($changeset->new_value) ? trans('admin/history.emptyValue') : $changeset->new_value,
|
||||
'from' => empty($changeset->old_value) ? trans('admin/history.emptyValue') : $changeset->old_value,
|
||||
'to' => empty($changeset->new_value) ? trans('admin/history.emptyValue') : $changeset->new_value,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,11 @@ class InstallModule extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:install {name} {parentModuleId?}';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Custom installation of CMS module. Name given as directory name in /modules.';
|
||||
@@ -31,7 +29,6 @@ class InstallModule extends Command
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -56,8 +53,9 @@ class InstallModule extends Command
|
||||
// get config
|
||||
$config = $this->loadConfig();
|
||||
|
||||
if (empty($config))
|
||||
if (empty($config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check if it is valid
|
||||
$this->checkMandatoryFields($config);
|
||||
@@ -69,14 +67,15 @@ class InstallModule extends Command
|
||||
Cache::forget('enabled-modules');
|
||||
Cache::forget('module-handler-to-id-enumeration');
|
||||
|
||||
exec('composer dump-autoload');
|
||||
|
||||
// inform user
|
||||
$this->line('Module ' . $name . ' successfuly installed');
|
||||
$this->line('Module ' . $name . ' successfuly installed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load config from Config/config.php in module files. We cannot use config() because the file have not published
|
||||
* yet.
|
||||
*
|
||||
* @return array
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
@@ -85,8 +84,9 @@ class InstallModule extends Command
|
||||
$basePath = $this->modulesPath . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR;
|
||||
$path = $basePath . 'Config' . DIRECTORY_SEPARATOR . 'config.php';
|
||||
|
||||
if (basename($basePath) == 'Database')
|
||||
if (basename($basePath) == 'Database') {
|
||||
return [];
|
||||
}
|
||||
|
||||
// check if module has Config/config.php file
|
||||
if (!file_exists($path)) {
|
||||
@@ -121,7 +121,6 @@ class InstallModule extends Command
|
||||
|
||||
/**
|
||||
* Installs module into database.
|
||||
*
|
||||
* This method calls Module::install, which handles specific installation of module. In this way we should be able
|
||||
* to install any module even with some other database structures.
|
||||
*
|
||||
@@ -155,9 +154,9 @@ class InstallModule extends Command
|
||||
if (is_null($module)) {
|
||||
// insert module into database
|
||||
$settings = [
|
||||
'providers' => $providers,
|
||||
'order' => isset($config['order']) ? $config['order'] : 0,
|
||||
'files' => isset($config['files']) ? $config['files'] : []
|
||||
'providers' => $providers,
|
||||
'order' => isset($config['order']) ? $config['order'] : 0,
|
||||
'files' => isset($config['files']) ? $config['files'] : []
|
||||
];
|
||||
|
||||
$module = Installer::install($name, $alias, $this->moduleName, $description, $handler, $this->parentModuleId, $settings);
|
||||
|
||||
@@ -59,7 +59,7 @@ class SetTemplate extends Command
|
||||
}
|
||||
|
||||
try {
|
||||
Installer::install($config['name'], $config['alias'], $current->static_name, $config['description'], $config['handler'], false, $config);
|
||||
Installer::install($config['name'], $config['alias'], $config['staticName'], $config['description'], $config['handler'], false, $config);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
|
||||
return;
|
||||
|
||||
@@ -46,10 +46,13 @@ class ContentOverview extends Controller
|
||||
// get homepage - for checking if homepage is set and available
|
||||
$homepage = $this->content->getHomepage();
|
||||
|
||||
$contentModules = app(\App\CMS\Repositories\Module::class)->getContentModules();
|
||||
|
||||
return view('admin.content.overview', [
|
||||
'pages' => $pages,
|
||||
'homepage' => $homepage,
|
||||
'pageHeading' => $pageHeading,
|
||||
'contentModules' => $contentModules,
|
||||
'statuses' => ContentStatuses::getWithTranslations(),
|
||||
'module' => isset($module) ? $module : null
|
||||
]);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Contents;
|
||||
|
||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
||||
@@ -11,13 +12,12 @@ use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\CreateNewContentRequest;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Module;
|
||||
use Illuminate\Support\Collection;
|
||||
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
||||
|
||||
/**
|
||||
* Class CreateNewContent
|
||||
*
|
||||
* Controller for creating new content page.
|
||||
*
|
||||
* @package App\Http\Controllers\Admin\Contents
|
||||
*/
|
||||
class CreateNewContent extends Controller
|
||||
@@ -30,10 +30,6 @@ class CreateNewContent extends Controller
|
||||
* @var IModuleRepository
|
||||
*/
|
||||
private $module;
|
||||
/**
|
||||
* @var ICategory
|
||||
*/
|
||||
private $category;
|
||||
/**
|
||||
* @var ITemplate
|
||||
*/
|
||||
@@ -41,23 +37,20 @@ class CreateNewContent extends Controller
|
||||
|
||||
/**
|
||||
* CreateNewContent constructor.
|
||||
*
|
||||
* Sets File and Content models into class variables
|
||||
*
|
||||
* @param IContent|Content $content
|
||||
* @param IModuleRepository $module
|
||||
* @param ICategory $category
|
||||
*
|
||||
* @param ITemplate $template
|
||||
*
|
||||
* @internal param File $file
|
||||
*/
|
||||
public function __construct(IContent $content, IModuleRepository $module, ICategory $category, ITemplate $template)
|
||||
public function __construct(IContent $content, IModuleRepository $module, ITemplate $template)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->content = $content;
|
||||
$this->module = $module;
|
||||
$this->category = $category;
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
@@ -73,7 +66,11 @@ class CreateNewContent extends Controller
|
||||
$statuses = ContentStatuses::getWithTranslations();
|
||||
$pageHeading = $this->module->getCreateContentTitle($module);
|
||||
$templates = $this->template->getForModule($module);
|
||||
$categories = $this->category->getForModule($module);
|
||||
|
||||
$categories = new Collection();
|
||||
if (class_exists(ICategory::class)) {
|
||||
$categories = app(ICategory::class)->getForModule($module);
|
||||
}
|
||||
|
||||
$page = $this->content->getOne();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Contents;
|
||||
|
||||
use App\CMS\Contracts\Repositories\Content as IContent;
|
||||
@@ -6,20 +7,15 @@ use App\CMS\Contracts\Repositories\Module as IModuleRepository;
|
||||
use App\CMS\Contracts\Repositories\Template as ITemplate;
|
||||
use App\CMS\Enumerations\ContentStatuses;
|
||||
use App\Cms\Handlers\Interactions\Interaction;
|
||||
use App\CMS\Helpers\CurrentTemplate;
|
||||
use App\Cms\Interactions\Admin\Content\EditContent as EditContentInteraction;
|
||||
use App\Events\AttemptToEditInvalidContent;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\EditContentRequest;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content\Content;
|
||||
use App\Models\Content\ContentHistory;
|
||||
use App\Models\FileManager\File;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Collection;
|
||||
use Modules\Categories\Contracts\Repositories\Category as ICategory;
|
||||
use Modules\Categories\Repositories\Category;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class EditContent extends Controller
|
||||
{
|
||||
@@ -39,10 +35,6 @@ class EditContent extends Controller
|
||||
* @var IModuleRepository
|
||||
*/
|
||||
private $module;
|
||||
/**
|
||||
* @var ICategory
|
||||
*/
|
||||
private $category;
|
||||
/**
|
||||
* @var ITemplate
|
||||
*/
|
||||
@@ -50,7 +42,6 @@ class EditContent extends Controller
|
||||
|
||||
/**
|
||||
* EditContent constructor.
|
||||
*
|
||||
* Load ContentHistory and File into this controller
|
||||
*
|
||||
* @param ContentHistory $history
|
||||
@@ -60,13 +51,12 @@ class EditContent extends Controller
|
||||
* @param ICategory $category
|
||||
* @param ITemplate $template
|
||||
*/
|
||||
public function __construct(ContentHistory $history, File $file, IContent $content, IModuleRepository $module, Category $category, ITemplate $template)
|
||||
public function __construct(ContentHistory $history, File $file, IContent $content, IModuleRepository $module, ITemplate $template)
|
||||
{
|
||||
$this->history = $history;
|
||||
$this->file = $file;
|
||||
$this->content = $content;
|
||||
$this->module = $module;
|
||||
$this->category = $category;
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
@@ -85,9 +75,13 @@ class EditContent extends Controller
|
||||
$module = $this->module->getByHandler($page->moduleHandler);
|
||||
$pageHeading = $this->module->getUpdateContentTitle($module, $page);
|
||||
$templates = $this->template->getForModule($module);
|
||||
$categories = $this->category->getForModule($module);
|
||||
$history = $this->history->getStructuredHistoryOf($page);
|
||||
|
||||
$categories = new Collection();
|
||||
if (class_exists(ICategory::class)) {
|
||||
$categories = app(ICategory::class)->getForModule($module);
|
||||
}
|
||||
|
||||
// render view
|
||||
return view('admin.content.edit', [
|
||||
'pageHeading' => $pageHeading,
|
||||
@@ -95,7 +89,8 @@ class EditContent extends Controller
|
||||
'page' => $page,
|
||||
'module' => $module,
|
||||
'categories' => $categories,
|
||||
'rootPages' => $this->content->getOverview()->get(),
|
||||
'rootPages' => $this->content->getOverview()
|
||||
->get(),
|
||||
'templates' => $templates,
|
||||
'formSectionNames' => $this->module->call($module, 'getExtendedFormSections'),
|
||||
'formSections' => $this->module->call($module, 'getExtendedFormInputsEdit'),
|
||||
|
||||
@@ -22,8 +22,12 @@ class ContentHistory extends Model
|
||||
'new_value',
|
||||
'old_value'
|
||||
];
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* Author of the change
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
|
||||
@@ -20,12 +20,11 @@ abstract class BasicPolicy
|
||||
*/
|
||||
public function before(User $user, $ability)
|
||||
{
|
||||
|
||||
// check if user can operate on given entity
|
||||
if (!$this->manage($user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,10 +21,6 @@ class ContentPolicy extends BasicPolicy
|
||||
*/
|
||||
public function update(User $user, Content $content)
|
||||
{
|
||||
// if (!$user->hasAbility('update-contents-' . $content->module->alias)) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
if ($user->id != $content->user_id) {
|
||||
return $user->hasAbility('update-contents') && $user->hasAbility('update-all-contents');
|
||||
};
|
||||
@@ -32,21 +28,28 @@ class ContentPolicy extends BasicPolicy
|
||||
return $user->hasAbility('update-contents');
|
||||
}
|
||||
|
||||
public function create(User $user, Content $content) {
|
||||
/**
|
||||
* Does given user has permissions to create new content page?
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function create(User $user) {
|
||||
return $user->hasAbility('create-contents');
|
||||
}
|
||||
|
||||
public function publish(User $user, Content $content)
|
||||
public function publish(User $user)
|
||||
{
|
||||
return $user->hasAbility('publish-contents');
|
||||
}
|
||||
|
||||
public function setHomepage(User $user, Content $content)
|
||||
public function setHomepage(User $user)
|
||||
{
|
||||
return $user->hasAbility('set-homepage-contents');
|
||||
}
|
||||
|
||||
public function viewHistory(User $user, Content $content) {
|
||||
public function viewHistory(User $user) {
|
||||
return $user->hasAbility('view-history-contents');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user