aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/settings/general.php1
-rw-r--r--app/views/settings/general.php9
-rw-r--r--db/migrations/6.2.6.1_add_disable_mail_on_new_request_config.php36
-rw-r--r--lib/models/resources/ResourceRequest.php78
4 files changed, 94 insertions, 30 deletions
diff --git a/app/controllers/settings/general.php b/app/controllers/settings/general.php
index 0d1daa3..82754b2 100644
--- a/app/controllers/settings/general.php
+++ b/app/controllers/settings/general.php
@@ -68,6 +68,7 @@ class Settings_GeneralController extends Settings_SettingsController
$this->config->store('TOUR_AUTOSTART_DISABLE', Request::int('tour_autostart_disable'));
if ($this->show_room_management_autor_config) {
$this->config->store('RESOURCES_CONFIRM_PLAN_DRAG_AND_DROP', Request::int('resources_confirm_plan_drag_and_drop'));
+ $this->config->store('RESOURCES_DISABLE_MAIL_ON_NEW_REQUEST', Request::int('resources_disable_mail_on_new_request'));
}
if (Request::int('personal_notifications_activated')) {
diff --git a/app/views/settings/general.php b/app/views/settings/general.php
index 14e47be..f01a254 100644
--- a/app/views/settings/general.php
+++ b/app/views/settings/general.php
@@ -111,6 +111,15 @@ $start_pages = [
_('Wenn diese Einstellung aktiviert ist, wird die Buchung erst dann verschoben, wenn die Sicherheitsabfrage mit „Ja“ beantwortet wurde.')
) ?>
</label>
+ <label>
+ <input type="checkbox" name="resources_disable_mail_on_new_request"
+ value="1"
+ <?= $config->RESOURCES_DISABLE_MAIL_ON_NEW_REQUEST ? 'checked' : '' ?>>
+ <?= _('Benachrichtigungen über neue Raumanfragen ausschalten') ?>
+ <?= tooltipIcon(
+ _('Wenn diese Einstellung aktiviert ist, erhalten Sie keine Nachrichten mehr über neue Raumanfragen.')
+ ) ?>
+ </label>
</fieldset>
<? endif ?>
diff --git a/db/migrations/6.2.6.1_add_disable_mail_on_new_request_config.php b/db/migrations/6.2.6.1_add_disable_mail_on_new_request_config.php
new file mode 100644
index 0000000..1fa322e
--- /dev/null
+++ b/db/migrations/6.2.6.1_add_disable_mail_on_new_request_config.php
@@ -0,0 +1,36 @@
+<?php
+
+
+class AddDisableMailOnNewRequestConfig extends Migration
+{
+ public function description()
+ {
+ return 'Adds the personal configuration RESOURCES_DISABLE_MAIL_ON_NEW_REQUEST.';
+ }
+
+ protected function up()
+ {
+ $db = DBManager::get();
+ $db->exec(
+ "INSERT INTO `config`
+ (`field`, `value`, `type`, `range`, `section`, `mkdate`, `chdate`, `description`)
+ VALUES
+ ('RESOURCES_DISABLE_MAIL_ON_NEW_REQUEST', '0', 'boolean', 'user', 'resources',
+ UNIX_TIMESTAMP(), UNIX_TIMESTAMP(),
+ 'Schaltet den Versand von Mails bei neuen Raumanfragen aus.')"
+ );
+ }
+
+ protected function down()
+ {
+ $db = DBManager::get();
+ $db->exec(
+ "DELETE FROM `config_values`
+ WHERE `field` = 'RESOURCES_DISABLE_MAIL_ON_NEW_REQUEST'"
+ );
+ $db->exec(
+ "DELETE FROM `config`
+ WHERE `field` = 'RESOURCES_DISABLE_MAIL_ON_NEW_REQUEST'"
+ );
+ }
+}
diff --git a/lib/models/resources/ResourceRequest.php b/lib/models/resources/ResourceRequest.php
index 12a1e41..1b07280 100644
--- a/lib/models/resources/ResourceRequest.php
+++ b/lib/models/resources/ResourceRequest.php
@@ -2011,54 +2011,72 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
public function sendNewRequestMail()
{
//First we must get all users who have admin permissions in the
- //resource management system. Depending wheter a resource_id is set
- //for this resource request either all admins of a resource or
+ //resource management system. Depending on whether a resource_id is set
+ //for this resource request, either all authors, tutors and admins of a resource or
//all admins of the resource management system must be informed.
+ //Those users that do not wish to receive mails about new requests
+ //from the resource management are filtered out.
- $now = time();
+ $db = DBManager::get();
+ $no_mail_user_ids = $db->query(
+ "SELECT DISTINCT `range_id` FROM `config_values`
+ WHERE `field` = 'RESOURCES_DISABLE_MAIL_ON_NEW_REQUEST'
+ AND value = '1'"
+ )->fetchAll(PDO::FETCH_COLUMN, 0);
+
+ $now = time();
if ($this->resource_id) {
//The resource-ID is set for this request:
- //Get all admins of the resource and the resource management system.
- $admin_users = User::findBySql(
- "user_id IN (
- SELECT user_id FROM resource_permissions
- WHERE (
- resource_id = :resource_id
- OR resource_id = 'global'
+ //Get all authors, tutors and admins of the resource
+ //and all admins of the resource management system.
+ $users = User::findBySql(
+ "`user_id` IN (
+ SELECT `user_id` FROM `resource_permissions`
+ WHERE
+ `user_id` NOT IN ( :no_mail_user_ids )
+ AND (
+ `resource_id` = :resource_id AND `perms` IN ('autor', 'tutor', 'admin')
+ OR (`resource_id` = 'global' AND `perms` = 'admin')
)
- AND perms = 'admin'
UNION
- SELECT user_id FROM resource_temporary_permissions
- WHERE resource_id = :resource_id
- AND perms = 'admin'
- AND begin <= :now AND end >= :now
+ SELECT `user_id` FROM `resource_temporary_permissions`
+ WHERE
+ `user_id` NOT IN ( :no_mail_user_ids )
+ AND (`resource_id` = :resource_id AND `perms` IN ('autor', 'tutor', 'admin'))
+ AND `begin` <= :now AND `end` >= :now
)",
[
- 'resource_id' => $this->resource_id,
- 'now' => $now
+ 'resource_id' => $this->resource_id,
+ 'now' => $now,
+ 'no_mail_user_ids' => $no_mail_user_ids ?? []
]
);
} else {
//Get all admins of the resource management system.
- $admin_users = User::findBySql(
- "user_id IN (
- SELECT user_id FROM resource_permissions
- WHERE resource_id = 'global'
- AND perms = 'admin'
+ $users = User::findBySql(
+ "`user_id` IN (
+ SELECT `user_id` FROM resource_permissions
+ WHERE
+ `user_id` NOT IN ( :no_mail_user_ids )
+ AND `resource_id` = 'global'
+ AND `perms` = 'admin'
UNION
- SELECT user_id FROM resource_temporary_permissions
- WHERE resource_id = 'global'
- AND perms = 'admin'
- AND begin <= :now AND end >= :now
- GROUP BY user_id
+ SELECT `user_id` FROM `resource_temporary_permissions`
+ WHERE
+ `user_id` NOT IN ( :no_mail_user_ids )
+ AND `resource_id` = 'global'
+ AND `perms` = 'admin'
+ AND `begin` <= :now AND `end` >= :now
+ GROUP BY `user_id`
)",
[
- 'now' => $now
+ 'now' => $now,
+ 'no_mail_user_ids' => $no_mail_user_ids ?? []
]
);
}
- if (!$admin_users) {
+ if (!$users) {
return;
}
@@ -2066,7 +2084,7 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
$GLOBALS['STUDIP_BASE_PATH'] . '/locale/'
);
- foreach ($admin_users as $user) {
+ foreach ($users as $user) {
$user_lang_path = getUserLanguagePath($user->id);
$template = $factory->open(