diff --git a/components/ILIAS/Container/News/class.ilContainerNewsSettingsGUI.php b/components/ILIAS/Container/News/class.ilContainerNewsSettingsGUI.php index 62518cf5095a..aa0a7eefc49c 100755 --- a/components/ILIAS/Container/News/class.ilContainerNewsSettingsGUI.php +++ b/components/ILIAS/Container/News/class.ilContainerNewsSettingsGUI.php @@ -216,7 +216,6 @@ public function save(): void //save contextblock settings $context_block_settings = [ "public_feed" => $form->getInput("notifications_public_feed") ?? "", - "default_visibility" => $form->getInput("default_visibility"), "hide_news_per_date" => $form->getInput("hide_news_per_date"), "hide_news_date" => $form->getInput("hide_news_date") ]; diff --git a/components/ILIAS/Container/classes/class.ilContainerGUI.php b/components/ILIAS/Container/classes/class.ilContainerGUI.php index c586c22e00dd..5545f6d27ee7 100755 --- a/components/ILIAS/Container/classes/class.ilContainerGUI.php +++ b/components/ILIAS/Container/classes/class.ilContainerGUI.php @@ -1903,7 +1903,6 @@ public function setColumnSettings(ilColumnGUI $column_gui): void if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) { $column_gui->setBlockProperty("news", "settings", '1'); //$column_gui->setBlockProperty("news", "public_notifications_option", true); - $column_gui->setBlockProperty("news", "default_visibility_option", '1'); $column_gui->setBlockProperty("news", "hide_news_block_option", '1'); } diff --git a/components/ILIAS/Export/xml/il_news_5_4.xsd b/components/ILIAS/Export/xml/il_news_5_4.xsd index 6d2bfae6e1ad..78309b9d6cdc 100755 --- a/components/ILIAS/Export/xml/il_news_5_4.xsd +++ b/components/ILIAS/Export/xml/il_news_5_4.xsd @@ -52,7 +52,7 @@ - + diff --git a/components/ILIAS/File/classes/trait.ilObjFileMetadata.php b/components/ILIAS/File/classes/trait.ilObjFileMetadata.php index 0006a0c6a42a..61a5dc0836cd 100755 --- a/components/ILIAS/File/classes/trait.ilObjFileMetadata.php +++ b/components/ILIAS/File/classes/trait.ilObjFileMetadata.php @@ -60,7 +60,7 @@ public function createProperties(bool $a_upload = false): void // New Item if (isset($this->ref_id)) { - $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($this->ref_id); + $default_visibility = ilNewsItem::getDefaultVisibility(); if ($default_visibility === "public") { ilBlockSetting::_write("news", "public_notifications", 1, 0, $this->getId()); } diff --git a/components/ILIAS/Forum/classes/class.ilObjForum.php b/components/ILIAS/Forum/classes/class.ilObjForum.php index e9232c0adf54..71c12a0b9a27 100755 --- a/components/ILIAS/Forum/classes/class.ilObjForum.php +++ b/components/ILIAS/Forum/classes/class.ilObjForum.php @@ -645,18 +645,8 @@ public static function _lookupModeratorRole(int $a_ref_id): int public function createSettings(): void { - global $DIC; - - $ref_id = 0; - if ($DIC->http()->wrapper()->query()->has('ref_id')) { - $ref_id = $DIC->http()->wrapper()->query()->retrieve( - 'ref_id', - $DIC->refinery()->kindlyTo()->int() - ); - } - // news settings (public notifications yes/no) - $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($ref_id); + $default_visibility = ilNewsItem::getDefaultVisibility(); if ($default_visibility === 'public') { ilBlockSetting::_write('news', 'public_notifications', '1', 0, $this->getId()); } diff --git a/components/ILIAS/News/News.php b/components/ILIAS/News/News.php index 0550ab950bc2..d44068c7580d 100644 --- a/components/ILIAS/News/News.php +++ b/components/ILIAS/News/News.php @@ -20,6 +20,8 @@ namespace ILIAS; +use ILIAS\Setup\Agent as SetupAgent; + class News implements Component\Component { public function init( @@ -32,6 +34,7 @@ public function init( array | \ArrayAccess &$pull, array | \ArrayAccess &$internal, ): void { + $contribute[SetupAgent::class] = static fn() => new \ilNewsSetupAgent($pull[\ILIAS\Refinery\Factory::class]); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "Timeline.js"); $contribute[Component\Resource\PublicAsset::class] = fn() => diff --git a/components/ILIAS/News/PRIVACY.md b/components/ILIAS/News/PRIVACY.md index 9da47a15465d..3ae40f9e138f 100755 --- a/components/ILIAS/News/PRIVACY.md +++ b/components/ILIAS/News/PRIVACY.md @@ -16,7 +16,6 @@ or contribute a fix via [Pull Request](../../docs/development/contributing.md#pu **Repository Objects** - The News service can be **activated** on the level of repository objects using the service, e.g. courses. -- The **default access** of single news entries, authenticated users or public via RSS, can be set on the repository object level. This overwrites the global setting. **Single New Entries** diff --git a/components/ILIAS/News/classes/Setup/class.ilNewsDefaultVisibilityMigration.php b/components/ILIAS/News/classes/Setup/class.ilNewsDefaultVisibilityMigration.php new file mode 100644 index 000000000000..ab2537d2aa66 --- /dev/null +++ b/components/ILIAS/News/classes/Setup/class.ilNewsDefaultVisibilityMigration.php @@ -0,0 +1,69 @@ +db = $environment->getResource(Environment::RESOURCE_DATABASE); + } + + public function step(Environment $environment): void + { + $this->db->manipulateF( + 'DELETE FROM il_block_setting WHERE type = %s AND setting = %s', + [ilDBConstants::T_TEXT, ilDBConstants::T_TEXT], + ['news', 'default_visibility'] + ); + } + + public function getRemainingAmountOfSteps(): int + { + return (int) ($this->db->fetchAssoc( + $this->db->queryF( + 'SELECT COUNT(*) AS count FROM il_block_setting WHERE type = %s AND setting = %s', + [ilDBConstants::T_TEXT, ilDBConstants::T_TEXT], + ['news', 'default_visibility'] + ) + )['count'] ?? 0); + } +} diff --git a/components/ILIAS/News/classes/Setup/class.ilNewsSetupAgent.php b/components/ILIAS/News/classes/Setup/class.ilNewsSetupAgent.php index c4ecb53d7547..749d84905a3e 100644 --- a/components/ILIAS/News/classes/Setup/class.ilNewsSetupAgent.php +++ b/components/ILIAS/News/classes/Setup/class.ilNewsSetupAgent.php @@ -20,6 +20,7 @@ use ILIAS\Setup\Agent\HasNoNamedObjective; use ILIAS\Setup\Agent\NullAgent; +use ILIAS\Setup\Config; use ILIAS\Setup\Objective; class ilNewsSetupAgent extends NullAgent @@ -30,4 +31,11 @@ public function getUpdateObjective(?ILIAS\Setup\Config $config = null): Objectiv { return new ilDatabaseUpdateStepsExecutedObjective(new ilNewsDBUpdateSteps()); } + + public function getMigrations(?Config $config = null): array + { + return [ + new ilNewsDefaultVisibilityMigration(), + ]; + } } diff --git a/components/ILIAS/News/classes/class.ilNewsDataSet.php b/components/ILIAS/News/classes/class.ilNewsDataSet.php index ce59c8f09a88..890b0d2e275a 100755 --- a/components/ILIAS/News/classes/class.ilNewsDataSet.php +++ b/components/ILIAS/News/classes/class.ilNewsDataSet.php @@ -62,7 +62,6 @@ protected function getTypes(string $a_entity, string $a_version): array return [ "ObjId" => "integer", "PublicFeed" => "integer", - "DefaultVisibility" => "text", "KeepRssMin" => "integer", "HideNewsPerDate" => "integer", "HideNewsDate" => "text", @@ -102,7 +101,6 @@ public function readData(string $a_entity, string $a_version, array $a_ids): voi $this->data[$obj_id]["ObjId"] = $obj_id; $this->data[$obj_id]["PublicFeed"] = ilBlockSetting::_lookup("news", "public_feed", 0, $obj_id); $this->data[$obj_id]["KeepRssMin"] = (int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $obj_id); - $this->data[$obj_id]["DefaultVisibility"] = ilBlockSetting::_lookup("news", "default_visibility", 0, $obj_id); $this->data[$obj_id]["HideNewsPerDate"] = (int) ilBlockSetting::_lookup("news", "hide_news_per_date", 0, $obj_id); $this->data[$obj_id]["HideNewsDate"] = ilBlockSetting::_lookup("news", "hide_news_date", 0, $obj_id); $this->data[$obj_id]["PublicNotifications"] = (int) ilBlockSetting::_lookup("news", "public_notifications", 0, $obj_id); @@ -153,7 +151,6 @@ public function importRecord(string $a_entity, array $a_types, array $a_rec, ilI foreach ([ "public_feed" => "PublicFeed", "keep_rss_min" => "KeepRssMin", - "default_visibility" => "DefaultVisibility", "hide_news_per_date" => "HideNewsPerDate", "hide_news_date" => "HideNewsDate", "public_notifications" => "PublicNotifications" diff --git a/components/ILIAS/News/classes/class.ilNewsForContextBlockGUI.php b/components/ILIAS/News/classes/class.ilNewsForContextBlockGUI.php index da2d994301f9..07fa172dedfc 100755 --- a/components/ILIAS/News/classes/class.ilNewsForContextBlockGUI.php +++ b/components/ILIAS/News/classes/class.ilNewsForContextBlockGUI.php @@ -831,31 +831,6 @@ public function initSettingsForm(): void $this->settings_form->addItem($hnpd); } - // default visibility - if ($enable_internal_rss && $this->getProperty("default_visibility_option")) { - $default_visibility = ilBlockSetting::_lookup( - $this->getBlockType(), - "default_visibility", - 0, - (int) $this->block_id - ); - if ($default_visibility == "") { - $default_visibility = - ilNewsItem::_getDefaultVisibilityForRefId($this->std_request->getRefId()); - } - - // Default Visibility - $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility"); - $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users"); - $radio_group->addOption($radio_option); - $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public"); - $radio_group->addOption($radio_option); - $radio_group->setInfo($lng->txt("news_news_item_visibility_info")); - $radio_group->setRequired(false); - $radio_group->setValue($default_visibility); - $this->settings_form->addItem($radio_group); - } - // public notifications if ($enable_internal_rss && $this->getProperty("public_notifications_option")) { $ch = new ilCheckboxInputGUI( @@ -890,11 +865,6 @@ public static function addToSettingsForm(ilFormPropertyGUI $a_input): void { global $DIC; - $std_request = $DIC->news() - ->internal() - ->gui() - ->standardRequest(); - $lng = $DIC->language(); $block_id = $DIC->ctrl()->getContextObjId(); @@ -907,20 +877,6 @@ public static function addToSettingsForm(ilFormPropertyGUI $a_input): void 0, $block_id ); - $default_visibility = ilBlockSetting::_lookup(self::$block_type, "default_visibility", 0, $block_id); - if ($default_visibility == "") { - $default_visibility = - ilNewsItem::_getDefaultVisibilityForRefId($std_request->getRefId()); - } - $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility"); - $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users"); - $radio_group->addOption($radio_option); - $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public"); - $radio_group->addOption($radio_option); - $radio_group->setInfo($lng->txt("news_news_item_visibility_info")); - $radio_group->setRequired(false); - $radio_group->setValue($default_visibility); - $a_input->addSubItem($radio_group); // extra rss feed if ($enable_internal_rss) { @@ -976,13 +932,6 @@ public function saveSettings(): string 0, (int) $this->block_id ); - ilBlockSetting::_write( - $this->getBlockType(), - "default_visibility", - $form->getInput("default_visibility"), - 0, - (int) $this->block_id - ); } if ($this->getProperty("hide_news_block_option")) { diff --git a/components/ILIAS/News/classes/class.ilNewsItem.php b/components/ILIAS/News/classes/class.ilNewsItem.php index 717e7d657eb1..0a43cb5adee1 100755 --- a/components/ILIAS/News/classes/class.ilNewsItem.php +++ b/components/ILIAS/News/classes/class.ilNewsItem.php @@ -1280,42 +1280,11 @@ public static function mergeNews( } /** - * Get default visibility for reference id - * @deprecated will move to ilNewsData + * Get global default visibility for news items. */ - public static function _getDefaultVisibilityForRefId(int $a_ref_id): string + public static function getDefaultVisibility(): string { - global $DIC; - - $tree = $DIC->repositoryTree(); - - $news_set = new ilSetting("news"); - $default_visibility = ($news_set->get("default_visibility") != "") - ? $news_set->get("default_visibility") - : "users"; - - if ($tree->isInTree($a_ref_id)) { - $path = $tree->getPathFull($a_ref_id); - - foreach ($path as $key => $row) { - if (!in_array($row["type"], ["root", "cat", "crs", "fold", "grp"], true)) { - continue; - } - - $visibility = ilBlockSetting::_lookup( - "news", - "default_visibility", - 0, - (int) $row["obj_id"] - ); - - if ($visibility != "") { - $default_visibility = $visibility; - } - } - } - - return $default_visibility; + return (new ilSetting('news'))->get('default_visibility', NEWS_USERS); } diff --git a/components/ILIAS/News/classes/class.ilNewsItemGUI.php b/components/ILIAS/News/classes/class.ilNewsItemGUI.php index 6b4be0b5dc1b..3cbf39ee8bc4 100755 --- a/components/ILIAS/News/classes/class.ilNewsItemGUI.php +++ b/components/ILIAS/News/classes/class.ilNewsItemGUI.php @@ -233,7 +233,7 @@ public static function getEditForm( $radio_group->addOption($radio_option); $radio_group->setInfo($lng->txt("news_news_item_visibility_info")); $radio_group->setRequired(false); - $radio_group->setValue("users"); + $radio_group->setValue(ilNewsItem::getDefaultVisibility()); $form->addItem($radio_group); // media @@ -261,7 +261,7 @@ public static function getEditForm( } else { $nv = $form->getItemByPostVar("news_visibility"); if (is_object($nv)) { - $nv->setValue(ilNewsItem::_getDefaultVisibilityForRefId($a_ref_id)); + $nv->setValue(ilNewsItem::getDefaultVisibility()); } }