Skip to content

Commit

Permalink
Make Image Upload and Display re-usable
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-rueegg committed Jul 14, 2023
1 parent 24741d1 commit a73a17e
Show file tree
Hide file tree
Showing 59 changed files with 4,942 additions and 765 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG-DEV.md
@@ -1,6 +1,20 @@
HumHub Changelog
================

## Advantages
- Re-use of components (image upload/preview/cropping/deletion)
- Image options from file module settings are respected on all uploads and preview generateions
- De-duplication of redundant code sections/functionality
- Allows access restriction/control
- Cannot read image, if user-guid is known
- Cannot guess user-guid from image-guid
-

## Questions
- Difference between canRead() and canView()
- \humhub\libs\Helpers::CheckClassType(): Cleaning the class name but not returning it


1.15.0 (Unreleased)
-------------------
- Fix #6423: log.fata in frontend logging is redirected to log.fatal, which did not work
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -1143,7 +1143,7 @@ This release also brings a [security update](https://github.com/yiisoft/yii2/sec
------------------
- Fix #3945: Default object-src policy prevents loading pdf on safari
- Fix #3963: Richtext/Markdown links not highlighted by default
- Fix #3986: Cannot use yii\helpers\Html as Html because the name is already in use in `humhub\libs\ProfileBannerImage`
- Fix #3986: Cannot use yii\helpers\Html as Html because the name is already in use in `humhub\modules\content\libs\ProfileBannerImage`


1.4.4 (March 24, 2020)
Expand Down
19 changes: 19 additions & 0 deletions protected/humhub/exceptions/InvalidConfigException.php
@@ -0,0 +1,19 @@
<?php

/*
* @link https://www.humhub.org/
* @copyright Copyright (c) 2023 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/

namespace humhub\exceptions;

class InvalidConfigException extends \yii\base\InvalidConfigException
{
use InvalidArgumentExceptionTrait;

protected function formatPrologue(array $constructArguments): string
{
return "Parameter $this->parameter of configuration";
}
}
10 changes: 0 additions & 10 deletions protected/humhub/exceptions/InvalidConfigTypeException.php
Expand Up @@ -8,17 +8,7 @@

namespace humhub\exceptions;

use yii\base\InvalidConfigException;

/**
* @since 1.15
*/
class InvalidConfigTypeException extends InvalidConfigException
{
use InvalidTypeExceptionTrait;

protected function formatPrologue(array $constructArguments): string
{
return "Parameter $this->parameter of configuration";
}
}
51 changes: 17 additions & 34 deletions protected/humhub/exceptions/InvalidTypeExceptionTrait.php
Expand Up @@ -8,61 +8,44 @@

namespace humhub\exceptions;

/**
* @since 1.15
*/
trait InvalidTypeExceptionTrait
{
// public properties

public string $methodName;
public $parameter;
public array $validType = [];

/**
* @var mixed|null
*/
public $givenValue;

/**
* @param string $method
* @param int|array $parameter = [
* int => string, // position, or [ position => name ] of the argument
* ]
* @param array|string|null $validType
* @param null $givenValue
* @param array|string|null $valid
* @param null $given
*/
public function __construct(
$method = '',
$parameter = null,
$validType = [],
$givenValue = null,
$valid = [],
$given = null,
$nullable = false,
$suffix = null,
$code = 0,
$previous = null
) {
$valid = (array)($valid ?? ['mixed']);

$this->methodName = $method;
$this->parameter = $parameter;
$this->validType = (array)($validType ?? ['mixed']);
$this->givenValue = $givenValue;

if ($nullable && !in_array('null', $this->validType, true)) {
$this->validType[] = 'null';
if ($nullable && !in_array('null', $this->valid, true)) {
$valid[] = 'null';
}

$message = sprintf(
'%s passed to %s must be of type %s, %s given.',
$this->formatPrologue(func_get_args()),
$this->methodName,
implode(', ', $this->validType),
get_debug_type($this->givenValue)
);
$givenType = get_debug_type($given);
if (is_scalar($given)) {
$givenType .= " ($given)";
}

parent::__construct($message, $code, $previous);
parent::__construct($method, $parameter, $valid, $givenType, $suffix, $code, $previous);
}

abstract protected function formatPrologue(array $constructArguments): string;
protected function formatValid(): string
{
return 'of type ' . implode(', ', $this->valid);
}

public function getName(): string
{
Expand Down
86 changes: 86 additions & 0 deletions protected/humhub/interfaces/ActiveRecordInterface.php
@@ -0,0 +1,86 @@
<?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\file\components\FileManager;
use humhub\modules\user\models\User;

/**
* Description of ActiveRecord
*
* @property FileManager $fileManager
* @property User $createdBy
* @property User $updatedBy
* @author luke
*/
interface ActiveRecordInterface
extends \yii\db\ActiveRecordInterface, BaseActiveRecord
{
/**
* @inheritdoc
*/
public function getAttributeLabel($attribute);

/**
* Relation to User defined in created_by attribute
*
* @return User|null
*/
public function getCreatedBy();

/**
* Returns the errors as string for all attribute or a single attribute.
*
* @param string $attribute attribute name. Use null to retrieve errors for all attributes.
*
* @return string the error message
* @since 1.2
*/
public function getErrorMessage($attribute = null);

/**
* Returns the file manager for this record
*
* @return FileManager the file manager instance
*/
public function getFileManager();

/**
* Returns a unique id for this record/model
*
* @return String Unique Id of this record
*/
public function getUniqueId();

/**
* Relation to User defined in updated_by attribute
*
* @return User|null
*/
public function getUpdatedBy();

/**
* @inheritdoc
*/
public function afterSave(
$insert,
$changedAttributes
);

/**
* @inheritdoc
*/
public function beforeSave($insert);

/**
* @inheritdoc
*/
public function createValidators();

}

0 comments on commit a73a17e

Please sign in to comment.