Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:humhub/humhub into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
luke- committed Apr 26, 2024
2 parents 87cd683 + ed40693 commit 17547f8
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 77 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG-DEV.md
Expand Up @@ -7,8 +7,13 @@ HumHub Changelog
- Fix #6909: Fix the marketplace searching when a module config file has missed fields
- Enh #6920: Enhancing of meta search for advanced search providers
- Enh #6952: Improve container title encoding in header
- Fix #6954: Search out of viewport on mobile
- Enh #6950: Ability to reset some notification settings to all users without resetting "Like" notifications by email
- Fix #6954: Search out of viewport on mobile

- Fix #6962: People filter - Hide follower options if Following is disabled in the User module
- Fix #6961: Fix people dropdown filter without defined keys
- Fix #6967: Use same order for meta searching that is used for content page searching by default
- Enh #6968: Meta search: open external links in new window

1.16.0-beta.2 (April 9, 2024)
-----------------------------
Expand Down
Expand Up @@ -77,6 +77,7 @@ public function getResults(int $maxResults): array
$resultSet = $module->getSearchDriver()->search(new SearchRequest([
'keyword' => $this->getKeyword(),
'pageSize' => $maxResults,
'orderBy' => SearchRequest::ORDER_BY_SCORE,
]));

$results = [];
Expand Down
2 changes: 1 addition & 1 deletion protected/humhub/modules/content/search/SearchRequest.php
Expand Up @@ -42,7 +42,7 @@ class SearchRequest extends Model

public $contentContainer = [];

public $orderBy = 'content.created_at';
public $orderBy = self::ORDER_BY_CREATION_DATE;

public ?SearchQuery $searchQuery = null;

Expand Down
Expand Up @@ -38,6 +38,11 @@ class NotificationManager
*/
public const EVENT_SEARCH_MODULE_NOTIFICATIONS = 'searchModuleNotifications';

/**
* User setting name to know if the user has modified default notification settings
*/
public const IS_TOUCHED_SETTINGS = 'is_touched_settings';

/**
*
* @var array Target configuration.
Expand Down Expand Up @@ -266,7 +271,7 @@ private function findNotExistingSettingSubQuery()
return ContentContainerSetting::find()
->where('contentcontainer_setting.contentcontainer_id=user.contentcontainer_id')
->andWhere(['contentcontainer_setting.module_id' => 'notification'])
->andWhere(['contentcontainer_setting.name' => 'notification.like_email']);
->andWhere(['contentcontainer_setting.name' => self::IS_TOUCHED_SETTINGS]);
}

/**
Expand All @@ -282,7 +287,7 @@ public function getSpaces(User $user)

$result = array_merge($memberSpaces, $followSpaces);

if ($this->isUntouchedSettings($user)) {
if (!static::isTouchedSettings($user)) {
$result = array_merge($result, Space::find()
->where(['guid' => Yii::$app->getModule('notification')->settings->getSerialized('sendNotificationSpaces')])
->visible($user)
Expand All @@ -293,9 +298,14 @@ public function getSpaces(User $user)
return $result;
}

private function isUntouchedSettings(User $user)
/**
* @throws \Throwable
*/
public static function isTouchedSettings(User $user): bool
{
return Yii::$app->getModule('notification')->settings->user($user)->get('notification.like_email') === null;
/** @var Module $module */
$module = Yii::$app->getModule('notification');
return (bool)$module->settings->user($user)?->get(self::IS_TOUCHED_SETTINGS);
}

/**
Expand Down Expand Up @@ -379,6 +389,7 @@ public function resetSpaces()
*/
public function setDesktopNoficationSettings($value = 0, User $user = null)
{
/** @var Module $module */
$module = Yii::$app->getModule('notification');
$settingManager = ($user) ? $module->settings->user($user) : $module->settings;
$settingManager->set('enable_html5_desktop_notifications', $value);
Expand Down
@@ -0,0 +1,55 @@
<?php

use humhub\modules\content\models\ContentContainerSetting;
use yii\db\Expression;
use yii\db\Migration;
use yii\db\Query;

/**
* Class m240422_162959_new_is_untouched_settings
*/
class m240422_162959_new_is_untouched_settings extends Migration
{
/**
* Inserts new rows into the `content_container_setting` table to add the "is_touched_settings"
* setting for the "notification" module where the "name" is "notification.like_email" which was
* previously used to know if the setting was modified by the user or not
*
* {@inheritdoc}
*/
public function safeUp()
{
$rows = (new Query())
->select([
"module_id",
"contentcontainer_id",
new Expression("'is_touched_settings' as name"),
new Expression("'1' as value"),
])
->from(ContentContainerSetting::tableName())
->where([
'name' => 'notification.like_email',
'module_id' => 'notification',
])
->all();

$query = Yii::$app->db->createCommand()
->batchInsert(
ContentContainerSetting::tableName(),
['module_id', 'contentcontainer_id', 'name', 'value'],
$rows,
);

$query->execute();
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m240422_162959_new_is_untouched_settings cannot be reverted.\n";

return false;
}
}
Expand Up @@ -8,15 +8,17 @@

namespace humhub\modules\notification\models\forms;

use humhub\components\Module;
use humhub\modules\admin\permissions\ManageSettings;
use humhub\modules\admin\permissions\ManageUsers;
use humhub\modules\content\models\ContentContainerSetting;
use humhub\modules\notification\components\NotificationCategory;
use humhub\modules\notification\components\NotificationManager;
use humhub\modules\notification\targets\BaseTarget;
use humhub\modules\user\models\User;
use Yii;
use yii\base\Model;
use yii\web\HttpException;
use humhub\modules\notification\targets\BaseTarget;
use humhub\modules\admin\permissions\ManageSettings;

/**
* Description of NotificationSettings
Expand Down Expand Up @@ -104,13 +106,12 @@ public function attributeLabels()

/**
* Checks if this form has already been saved before.
* @return bool
* @throws \Throwable
*/
public function isUserSettingLoaded()
public function isTouchedSettings(): bool
{
if ($this->user) {
return $this->getSettings()->get('enable_html5_desktop_notifications') !== null ||
$this->getSettings()->get('notification.like_email') !== null;
return NotificationManager::isTouchedSettings($this->user);
}

return false;
Expand Down Expand Up @@ -170,6 +171,10 @@ public function save()

$settings = $this->getSettings();

if ($this->user) {
$settings->set(NotificationManager::IS_TOUCHED_SETTINGS, true);
}

// Save all active settings
foreach ($this->settings as $settingKey => $value) {
$settings->set($settingKey, $value);
Expand Down Expand Up @@ -221,6 +226,7 @@ private function saveSpaceSettings()

public function getSettings()
{
/** @var Module $module */
$module = Yii::$app->getModule('notification');

return ($this->user) ? $module->settings->user($this->user) : $module->settings;
Expand All @@ -244,7 +250,8 @@ public function resetUserSettings()
}

$settings = $this->getSettings();
$settings->delete('enable_html5_desktop_notifications');
$settings?->delete(NotificationManager::IS_TOUCHED_SETTINGS);
$settings?->delete('enable_html5_desktop_notifications');
foreach ($this->targets() as $target) {
foreach ($this->categories() as $category) {
$settings->delete($target->getSettingKey($category));
Expand All @@ -265,10 +272,11 @@ public function canResetAllUsers()

/**
* Resets all settings stored for all current user
* @throws \Throwable
*/
public function resetAllUserSettings()
{
$notificationSettings = ['enable_html5_desktop_notifications'];
$notificationSettings = [NotificationManager::IS_TOUCHED_SETTINGS, 'enable_html5_desktop_notifications'];
foreach ($this->targets() as $target) {
foreach ($this->categories() as $category) {
$notificationSettings[] = $target->getSettingKey($category);
Expand All @@ -282,7 +290,9 @@ public function resetAllUserSettings()

Yii::$app->notification->resetSpaces();

$settingsManager = Yii::$app->getModule('notification')->settings->user();
$settingsManager->reload();
/** @var Module $module */
$module = Yii::$app->getModule('notification');
$settingsManager = $module->settings->user();
$settingsManager?->reload();
}
}
Expand Up @@ -31,7 +31,7 @@

<br/>
<button type="submit" class="btn btn-primary" data-ui-loader><?= Yii::t('base', 'Save'); ?></button>
<?php if ($model->isUserSettingLoaded()): ?>
<?php if ($model->isTouchedSettings()): ?>
<a href="#" class="btn btn-default pull-right" data-action-click="post"
data-action-url="<?= Url::to(['reset']) ?>"
data-ui-loader><?= Yii::t('ActivityModule.base', 'Reset to defaults') ?></a>
Expand Down
@@ -0,0 +1,72 @@
<?php

use humhub\modules\user\models\fieldtype\CheckboxList;
use humhub\modules\user\models\fieldtype\Select;
use humhub\modules\user\models\ProfileField;
use yii\db\Migration;
use yii\helpers\Json;

/**
* Class m240423_170311_profile_checkbox_list_field
*/
class m240423_170311_profile_checkbox_list_field extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$fields = ProfileField::find()
->where(['IN', 'field_type_class', [CheckboxList::class, Select::class]]);

foreach ($fields->all() as $field) {
/* @var ProfileField $field */
$fixedConfig = $this->getFixedProfileFieldConfig($field);
if ($fixedConfig !== null) {
$field->field_type_config = $fixedConfig;
$field->save();
}
}
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m240423_170311_profile_checkbox_list_field cannot be reverted.\n";
return false;
}

private function getFixedProfileFieldConfig(ProfileField $field): ?string
{
$config = Json::decode($field->field_type_config);

if (!isset($config['options']) || $config['options'] === '') {
return null;
}

$keyType = $field->field_type_class === Select::class ? 'index' : 'value';
$fixedOptions = [];
$index = 0;
$fixed = false;
foreach (preg_split('/[\r\n]+/', $config['options']) as $option) {
if (strpos($option, '=>') === false) {
// Fix an option without a Key
$fixed = true;
$fixedOptions[] = ($keyType === 'index' ? $index++ : trim($option)) . '=>' . $option;
} else {
// Leave a correct option as is
$fixedOptions[] = $option;
}
}

if ($fixed === false) {
return null;
}

$config['options'] = implode("\r\n", $fixedOptions);

return Json::encode($config);
}
}
45 changes: 45 additions & 0 deletions protected/humhub/modules/user/models/fieldtype/BaseType.php
Expand Up @@ -410,4 +410,49 @@ public function beforeProfileSave($value)
public function loadDefaults(Profile $profile)
{
}

/**
* Validate options which must be as associative array with format Key=>Value
*
* @param string $attribute
* @return void
*/
public function validateListOptions(string $attribute): void
{
if (!is_string($this->$attribute) || $this->$attribute === '') {
return;
}

foreach (preg_split('/[\r\n]+/', $this->$attribute) as $option) {
if (strpos($option, '=>') === false) {
$this->addError($attribute, Yii::t('UserModule.profile', 'Each line must be formatted as Key=>Value!'));
return;
}
}
}

/**
* Returns a list of possible options
*
* @return array
*/
public function getSelectItems(): array
{
$items = [];

if (!isset($this->options) || !is_string($this->options)) {
return $items;
}

foreach (preg_split('/[\r\n]+/', $this->options) as $option) {
if (strpos($option, '=>') !== false) {
list($key, $value) = explode('=>', $option, 2);
$items[trim($key)] = Yii::t($this->profileField->getTranslationCategory(), trim($value));
} else {
$items[trim($option)] = Yii::t($this->profileField->getTranslationCategory(), trim($option));
}
}

return $items;
}
}

0 comments on commit 17547f8

Please sign in to comment.