-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(contactsinteraction): allow users to disable contacts interaction addressbook #39372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…n addressbook This allows simple users to opt-out of the contacts interaction addressbook even if admins have the app installed. Similar to how the birthday calendar works, the functionnality can be toggled in the user's settings or by doing a DELETE on the addressbook. A new contacts personal section has been added to contain this new setting. Signed-off-by: Thomas Citharel <[email protected]>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2023 Thomas Citharel <[email protected]> | ||
| * | ||
| * @author Thomas Citharel <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| return [ | ||
| 'ocs' => [ | ||
| ['name' => 'config#disable', 'url' => '/config/user/disable', 'verb' => 'POST'], | ||
| ], | ||
| ]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| <?php | ||
| /** | ||
| * @copyright 2023, Thomas Citharel <[email protected]> | ||
| * | ||
| * @author Thomas Citharel <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| namespace OCA\ContactsInteraction\DAV; | ||
|
|
||
| use OCA\ContactsInteraction\AddressBook; | ||
| use OCA\ContactsInteraction\AppInfo\Application; | ||
| use OCA\ContactsInteraction\Db\RecentContactMapper; | ||
| use OCP\IConfig; | ||
| use Sabre\DAV\Server; | ||
| use Sabre\DAV\ServerPlugin; | ||
| use Sabre\HTTP\RequestInterface; | ||
| use Sabre\HTTP\ResponseInterface; | ||
|
|
||
| /** | ||
| * Allows users to disable the feature by deleting the addressbook | ||
| * | ||
| * @package OCA\DAV\CalDAV\BirthdayCalendar | ||
| */ | ||
| class Plugin extends ServerPlugin { | ||
|
|
||
| protected Server $server; | ||
Check noticeCode scanning / Psalm PropertyNotSetInConstructor
Property OCA\ContactsInteraction\DAV\Plugin::$server is not defined in constructor of OCA\ContactsInteraction\DAV\Plugin or in any methods called in the constructor
|
||
|
|
||
| public function __construct(protected IConfig $config, protected RecentContactMapper $recentContactMapper) { | ||
| } | ||
|
|
||
| /** | ||
| * This method should return a list of server-features. | ||
| * | ||
| * This is for example 'versioning' and is added to the DAV: header | ||
| * in an OPTIONS response. | ||
| * | ||
| * @return string[] | ||
| */ | ||
| public function getFeatures() { | ||
| return ['nc-disable-recently-contacted']; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a plugin name. | ||
| * | ||
| * Using this name other plugins will be able to access other plugins | ||
| * using Sabre\DAV\Server::getPlugin | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getPluginName() { | ||
| return 'nc-disable-recently-contacted'; | ||
| } | ||
|
|
||
| /** | ||
| * This initializes the plugin. | ||
| * | ||
| * This function is called by Sabre\DAV\Server, after | ||
| * addPlugin is called. | ||
| * | ||
| * This method should set up the required event subscriptions. | ||
| * | ||
| * @param Server $server | ||
| */ | ||
| public function initialize(Server $server) { | ||
Check noticeCode scanning / Psalm MissingReturnType
Method OCA\ContactsInteraction\DAV\Plugin::initialize does not have a return type, expecting void
|
||
| $this->server = $server; | ||
|
|
||
| $this->server->on('method:DELETE', [$this, 'httpDelete']); | ||
| } | ||
|
|
||
| /** | ||
| * We intercept this to handle POST requests on contacts homes. | ||
| * | ||
| * @param RequestInterface $request | ||
| * @param ResponseInterface $response | ||
| * | ||
| * @return bool|void | ||
| */ | ||
| public function httpDelete(RequestInterface $request, ResponseInterface $response) { | ||
| $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); | ||
| if (!($node instanceof AddressBook)) { | ||
| return; | ||
| } | ||
|
|
||
| $principalUri = $node->getOwner(); | ||
| $userId = substr($principalUri, 17); | ||
|
|
||
| $this->config->setUserValue($userId, Application::APP_ID, 'disableContactsInteractionAddressBook', 'yes'); | ||
| $this->recentContactMapper->cleanForUser($userId); | ||
|
|
||
| $this->server->httpResponse->setStatus(204); | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OCA\ContactsInteraction\Listeners; | ||
|
|
||
| use OCA\ContactsInteraction\AppInfo\Application; | ||
| use OCA\ContactsInteraction\Db\RecentContactMapper; | ||
| use OCP\BackgroundJob\IJobList; | ||
| use OCP\Config\BeforePreferenceDeletedEvent; | ||
| use OCP\Config\BeforePreferenceSetEvent; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
|
|
||
| /** @template-implements IEventListener<BeforePreferenceSetEvent|BeforePreferenceDeletedEvent> */ | ||
| class UserPreferenceListener implements IEventListener { | ||
|
|
||
| public function __construct(protected IJobList $jobList, private RecentContactMapper $recentContactMapper) { } | ||
|
|
||
| public function handle(Event $event): void { | ||
| if (!$event instanceof BeforePreferenceSetEvent && !$event instanceof BeforePreferenceDeletedEvent) { | ||
| return; | ||
| } | ||
|
|
||
| if ($event->getAppId() !== Application::APP_ID || $event->getConfigKey() !== 'disableContactsInteractionAddressBook') { | ||
| return; | ||
| } | ||
|
|
||
| $enabled = $event->getConfigValue() === 'yes'; | ||
Check noticeCode scanning / Psalm PossiblyUndefinedMethod
Method OCP\Config\BeforePreferenceDeletedEvent::getConfigValue does not exist
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed 🙈 |
||
| $event->setValid($enabled); | ||
| if (!$enabled) { | ||
| $this->recentContactMapper->cleanForUser($event->getUserId()); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.