Remove interface ReadableInterface (#6671)

* Remove interface `ReadableInterface`

* Update CHANGELOG-DEV.md

* Update MIGRATE-DEV.md

---------

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Yuriy Bakhtin 2023-11-22 16:01:55 +01:00 committed by GitHub
parent e5e46018cc
commit 8782149262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 41 deletions

View File

@ -22,3 +22,4 @@ HumHub Changelog
- Enh #6650: Add assets GZIP compression with Apache
- Fix #6662: Change the start_url of the PWA from home to base URL
- Enh #6667: Allow view file when owner object provides this
- Enh #6671: Remove interface `ReadableInterface`

View File

@ -9,14 +9,17 @@ Version 1.16 (Unreleased)
### Deprecations
- `\humhub\modules\content\components\ContentAddonActiveRecord::canWrite()`
- `\humhub\modules\file\models\File::canRead()` use `canView()` instead
- `\humhub\modules\content\components\ContentAddonActiveRecord::canRead()` use `canView()` instead
### Type restrictions
- `\humhub\modules\comment\models\Comment` on `canDelete()`
- `\humhub\modules\content\components\ContentAddonActiveRecord` on `canDelete()`, `canRead()`, `canWrite()`, `canEdit()`
- `\humhub\modules\content\components\ContentAddonActiveRecord` on `canDelete()`, `canWrite()`, `canEdit()`
- `\humhub\modules\content\models\Content` on `canEdit()`, `canView()`
- `\humhub\modules\file\models\File` on `canRead()`, `canDelete()`
Version 1.15
-------------------------

View File

@ -1,25 +0,0 @@
<?php
/*
* @link https://www.humhub.org/
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\interfaces;
use humhub\modules\user\models\User;
/**
* Readable Interface
* @since 1.16
*/
interface ReadableInterface
{
/**
* Checks if given element can be read.
*
* @param User|integer|string|null $user User instance or user id, null - current user
* @return bool
*/
public function canRead($user = null): bool;
}

View File

@ -199,7 +199,7 @@ class CommentController extends Controller
{
$comment = $this->getComment($id);
if (!$comment->canRead()) {
if (!$comment->canView()) {
throw new ForbiddenHttpException();
}

View File

@ -31,7 +31,7 @@ class PermaController extends Controller
{
$comment = Comment::findOne(['id' => $id]);
if (!$comment || !$comment->content || !$comment->canRead()) {
if (!$comment || !$comment->content || !$comment->canView()) {
throw new NotFoundHttpException();
}

View File

@ -11,7 +11,7 @@ namespace humhub\modules\content\components;
use humhub\components\ActiveRecord;
use humhub\interfaces\DeletableInterface;
use humhub\interfaces\EditableInterface;
use humhub\interfaces\ReadableInterface;
use humhub\interfaces\ViewableInterface;
use humhub\modules\content\interfaces\ContentOwner;
use humhub\modules\content\models\Content;
use humhub\modules\content\Module;
@ -39,7 +39,7 @@ use yii\base\Exception;
* @package humhub.components
* @since 0.5
*/
class ContentAddonActiveRecord extends ActiveRecord implements ContentOwner, ReadableInterface, EditableInterface, DeletableInterface
class ContentAddonActiveRecord extends ActiveRecord implements ContentOwner, ViewableInterface, EditableInterface, DeletableInterface
{
/**
* @var boolean also update underlying contents last update stream sorting
@ -150,9 +150,17 @@ class ContentAddonActiveRecord extends ActiveRecord implements ContentOwner, Rea
}
/**
* @inheritdoc
* @deprecated Use canView() instead. It will be deleted since v1.17
*/
public function canRead($user = null): bool
{
return $this->canView($user);
}
/**
* @inheritdoc
*/
public function canView($user = null): bool
{
return $this->content->canView($user);
}

View File

@ -143,7 +143,7 @@ class DownloadAction extends Action
throw new HttpException(401, Yii::t('FileModule.base', 'Insufficient permissions!'));
}
if (!$file->canRead($user)) {
if (!$file->canView($user)) {
throw new HttpException(401, Yii::t('FileModule.base', 'Insufficient permissions!'));
}

View File

@ -281,9 +281,17 @@ class File extends FileCompat implements ViewableInterface
}
/**
* @inheritdoc
* @deprecated Use canView() instead. It will be deleted since v1.17
*/
public function canRead($user = null): bool
{
return $this->canView($user);
}
/**
* @inheritdoc
*/
public function canView($user = null): bool
{
$object = $this->getPolymorphicRelation();
if ($object instanceof ContentActiveRecord || $object instanceof ContentAddonActiveRecord) {
@ -296,14 +304,6 @@ class File extends FileCompat implements ViewableInterface
return true;
}
/**
* @inheritdoc
*/
public function canView($user = null): bool
{
return $this->canRead($user);
}
/**
* Checks if given file can be deleted.
*