Merge pull request #10882 from MrPetovan/task/10865-contact-purge
Add new purge contact content option to admin contact blocklist
This commit is contained in:
commit
5d0b7fd87b
9 changed files with 133 additions and 83 deletions
|
@ -1199,10 +1199,8 @@ class Worker
|
|||
* array $arr
|
||||
*
|
||||
*/
|
||||
public static function add($cmd)
|
||||
public static function add(...$args)
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
if (!count($args)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -1241,6 +1239,8 @@ class Worker
|
|||
if (isset($run_parameter['force_priority'])) {
|
||||
$force_priority = $run_parameter['force_priority'];
|
||||
}
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Priority number or task parameter array expected as first argument');
|
||||
}
|
||||
|
||||
$command = array_shift($args);
|
||||
|
|
|
@ -823,7 +823,7 @@ class Contact
|
|||
self::update(['archive' => true, 'network' => Protocol::PHANTOM, 'deleted' => true], ['id' => $id]);
|
||||
|
||||
// Delete it in the background
|
||||
Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $id);
|
||||
Worker::add(PRIORITY_MEDIUM, 'Contact\Remove', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2562,48 +2562,6 @@ class Contact
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated contact's SSL policy
|
||||
*
|
||||
* @param array $contact Contact array
|
||||
* @param string $new_policy New policy, valid: self,full
|
||||
*
|
||||
* @return array Contact array with updated values
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updateSslPolicy(array $contact, $new_policy)
|
||||
{
|
||||
$ssl_changed = false;
|
||||
if ((intval($new_policy) == BaseURL::SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) {
|
||||
$ssl_changed = true;
|
||||
$contact['url'] = str_replace('https:', 'http:', $contact['url']);
|
||||
$contact['request'] = str_replace('https:', 'http:', $contact['request']);
|
||||
$contact['notify'] = str_replace('https:', 'http:', $contact['notify']);
|
||||
$contact['poll'] = str_replace('https:', 'http:', $contact['poll']);
|
||||
$contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']);
|
||||
$contact['poco'] = str_replace('https:', 'http:', $contact['poco']);
|
||||
}
|
||||
|
||||
if ((intval($new_policy) == BaseURL::SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) {
|
||||
$ssl_changed = true;
|
||||
$contact['url'] = str_replace('http:', 'https:', $contact['url']);
|
||||
$contact['request'] = str_replace('http:', 'https:', $contact['request']);
|
||||
$contact['notify'] = str_replace('http:', 'https:', $contact['notify']);
|
||||
$contact['poll'] = str_replace('http:', 'https:', $contact['poll']);
|
||||
$contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']);
|
||||
$contact['poco'] = str_replace('http:', 'https:', $contact['poco']);
|
||||
}
|
||||
|
||||
if ($ssl_changed) {
|
||||
$fields = ['url' => $contact['url'], 'request' => $contact['request'],
|
||||
'notify' => $contact['notify'], 'poll' => $contact['poll'],
|
||||
'confirm' => $contact['confirm'], 'poco' => $contact['poco']];
|
||||
self::update($fields, ['id' => $contact['id']]);
|
||||
}
|
||||
|
||||
return $contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow a contact
|
||||
*
|
||||
|
|
|
@ -23,10 +23,12 @@ namespace Friendica\Module\Admin\Blocklist;
|
|||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseAdmin;
|
||||
use Friendica\Model;
|
||||
use Friendica\Module\BaseAdmin;
|
||||
use Friendica\Util\Network;
|
||||
|
||||
class Contact extends BaseAdmin
|
||||
{
|
||||
|
@ -38,16 +40,30 @@ class Contact extends BaseAdmin
|
|||
|
||||
$contact_url = $_POST['contact_url'] ?? '';
|
||||
$block_reason = $_POST['contact_block_reason'] ?? '';
|
||||
$block_purge = $_POST['contact_block_purge'] ?? false;
|
||||
$contacts = $_POST['contacts'] ?? [];
|
||||
|
||||
if (!empty($_POST['page_contactblock_block'])) {
|
||||
$contact_id = Model\Contact::getIdForURL($contact_url);
|
||||
if ($contact_id) {
|
||||
Model\Contact::block($contact_id, $block_reason);
|
||||
info(DI::l10n()->t('The contact has been blocked from the node'));
|
||||
} else {
|
||||
$contact = Model\Contact::getByURL($contact_url, null, ['id', 'nurl']);
|
||||
if (empty($contact)) {
|
||||
notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
|
||||
DI::baseUrl()->redirect('admin/blocklist/contact');
|
||||
}
|
||||
|
||||
if (Network::isLocalLink($contact['nurl'])) {
|
||||
notice(DI::l10n()->t('You can\'t block a local contact, please block the user instead'));
|
||||
DI::baseUrl()->redirect('admin/blocklist/contact');
|
||||
}
|
||||
|
||||
Model\Contact::block($contact['id'], $block_reason);
|
||||
|
||||
if ($block_purge) {
|
||||
foreach (Model\Contact::selectToArray(['id'], ['nurl' => $contact['nurl']]) as $contact) {
|
||||
Worker::add(PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']);
|
||||
}
|
||||
}
|
||||
|
||||
info(DI::l10n()->t('The contact has been blocked from the node'));
|
||||
}
|
||||
|
||||
if (!empty($_POST['page_contactblock_unblock'])) {
|
||||
|
@ -98,6 +114,7 @@ class Contact extends BaseAdmin
|
|||
'$total_contacts' => DI::l10n()->tt('%s total blocked contact', '%s total blocked contacts', $total),
|
||||
'$paginate' => $pager->renderFull($total),
|
||||
'$contacturl' => ['contact_url', DI::l10n()->t('Profile URL'), '', DI::l10n()->t('URL of the remote contact to block.')],
|
||||
'$contact_block_purge' => ['contact_block_purge', DI::l10n()->t('Also purge contact'), false, DI::l10n()->t('Removes all content related to this contact from the node. Keeps the contact record. This action canoot be undone.')],
|
||||
'$contact_block_reason' => ['contact_block_reason', DI::l10n()->t('Block Reason')],
|
||||
]);
|
||||
return $o;
|
||||
|
|
|
@ -34,7 +34,7 @@ class CheckDeletedContacts
|
|||
{
|
||||
$contacts = DBA::select('contact', ['id'], ['deleted' => true]);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $contact['id']);
|
||||
Worker::add(PRIORITY_MEDIUM, 'Contact\Remove', $contact['id']);
|
||||
}
|
||||
DBA::close($contacts);
|
||||
}
|
||||
|
|
47
src/Worker/Contact/Remove.php
Normal file
47
src/Worker/Contact/Remove.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Worker\Contact;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
|
||||
/**
|
||||
* Removes a contact and all its related content
|
||||
*/
|
||||
class Remove extends RemoveContent
|
||||
{
|
||||
public static function execute(int $id): array
|
||||
{
|
||||
$contact = parent::execute($id);
|
||||
|
||||
if (!empty($contact)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ret = DBA::delete('contact', ['id' => $id]);
|
||||
Logger::info('Deleted contact', ['id' => $id, 'result' => $ret]);
|
||||
|
||||
$contact['id'] = null;
|
||||
|
||||
return $contact;
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Worker;
|
||||
namespace Friendica\Worker\Contact;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
|
@ -28,21 +28,23 @@ use Friendica\Model\Photo;
|
|||
use Friendica\Model\Post;
|
||||
|
||||
/**
|
||||
* Removes orphaned data from deleted contacts
|
||||
* Removes all content related to the given contact id, doesn't remove the contact itself
|
||||
*/
|
||||
class RemoveContact {
|
||||
public static function execute($id) {
|
||||
class RemoveContent
|
||||
{
|
||||
public static function execute(int $id): array
|
||||
{
|
||||
if (empty($id)) {
|
||||
return;
|
||||
return [];
|
||||
}
|
||||
|
||||
// Only delete if the contact is to be deleted
|
||||
$contact = DBA::selectFirst('contact', ['id', 'uid', 'url', 'nick', 'name'], ['deleted' => true, 'id' => $id]);
|
||||
if (!DBA::isResult($contact)) {
|
||||
return;
|
||||
return [];
|
||||
}
|
||||
|
||||
Logger::info('Start deleting contact', ['contact' => $contact]);
|
||||
Logger::info('Start deleting contact content', ['contact' => $contact]);
|
||||
|
||||
// Now we delete the contact and all depending tables
|
||||
DBA::delete('post-tag', ['cid' => $id]);
|
||||
|
@ -73,7 +75,16 @@ class RemoveContact {
|
|||
Post::delete(['causer-id' => $id]);
|
||||
|
||||
Photo::delete(['contact-id' => $id]);
|
||||
$ret = DBA::delete('contact', ['id' => $id]);
|
||||
Logger::info('Deleted contact', ['id' => $id, 'result' => $ret]);
|
||||
|
||||
DBA::delete('contact-relation', ['contact-id = ? OR cid = ?', $id, $id]);
|
||||
DBA::delete('event', ['cid' => $id]);
|
||||
DBA::delete('fsuggest', ['cid' => $id]);
|
||||
DBA::delete('post-tag', ['cid' => $id]);
|
||||
DBA::delete('user-contact', ['cid' => $id]);
|
||||
|
||||
DBA::delete('group_member', ['contact-id' => $id]);
|
||||
DBA::delete('intro', ['contact-id' => $id]);
|
||||
|
||||
return $contact;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 2021.12-dev\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-10-14 06:20+0000\n"
|
||||
"POT-Creation-Date: 2021-10-16 19:31-0400\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -715,7 +715,7 @@ msgid "Your Identity Address:"
|
|||
msgstr ""
|
||||
|
||||
#: mod/follow.php:141 mod/unfollow.php:100
|
||||
#: src/Module/Admin/Blocklist/Contact.php:100 src/Module/Contact.php:561
|
||||
#: src/Module/Admin/Blocklist/Contact.php:116 src/Module/Contact.php:561
|
||||
#: src/Module/Notifications/Introductions.php:107
|
||||
#: src/Module/Notifications/Introductions.php:176
|
||||
msgid "Profile URL"
|
||||
|
@ -1476,7 +1476,7 @@ msgstr ""
|
|||
msgid "Connected Apps"
|
||||
msgstr ""
|
||||
|
||||
#: mod/settings.php:429 src/Module/Admin/Blocklist/Contact.php:90
|
||||
#: mod/settings.php:429 src/Module/Admin/Blocklist/Contact.php:106
|
||||
#: src/Module/Admin/Users/Active.php:129 src/Module/Admin/Users/Blocked.php:130
|
||||
#: src/Module/Admin/Users/Create.php:71 src/Module/Admin/Users/Deleted.php:88
|
||||
#: src/Module/Admin/Users/Index.php:142 src/Module/Admin/Users/Index.php:162
|
||||
|
@ -2420,7 +2420,7 @@ msgid "Could not find any contact entry for this URL (%s)"
|
|||
msgstr ""
|
||||
|
||||
#: src/Console/GlobalCommunityBlock.php:101
|
||||
#: src/Module/Admin/Blocklist/Contact.php:47
|
||||
#: src/Module/Admin/Blocklist/Contact.php:66
|
||||
msgid "The contact has been blocked from the node"
|
||||
msgstr ""
|
||||
|
||||
|
@ -3010,7 +3010,7 @@ msgstr ""
|
|||
msgid "Send PM"
|
||||
msgstr ""
|
||||
|
||||
#: src/Content/Item.php:449 src/Module/Admin/Blocklist/Contact.php:84
|
||||
#: src/Content/Item.php:449 src/Module/Admin/Blocklist/Contact.php:100
|
||||
#: src/Module/Admin/Users/Active.php:140 src/Module/Admin/Users/Index.php:154
|
||||
#: src/Module/Contact.php:544 src/Module/Contact.php:787
|
||||
#: src/Module/Contact.php:1064
|
||||
|
@ -4868,7 +4868,7 @@ msgid "Enable"
|
|||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Addons/Details.php:111 src/Module/Admin/Addons/Index.php:67
|
||||
#: src/Module/Admin/Blocklist/Contact.php:78
|
||||
#: src/Module/Admin/Blocklist/Contact.php:94
|
||||
#: src/Module/Admin/Blocklist/Server.php:88 src/Module/Admin/Federation.php:159
|
||||
#: src/Module/Admin/Item/Delete.php:65 src/Module/Admin/Logs/Settings.php:80
|
||||
#: src/Module/Admin/Logs/View.php:83 src/Module/Admin/Queue.php:72
|
||||
|
@ -4968,76 +4968,90 @@ msgstr ""
|
|||
msgid "Relay"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:57
|
||||
#: src/Module/Admin/Blocklist/Contact.php:54
|
||||
msgid "You can't block a local contact, please block the user instead"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:73
|
||||
#, php-format
|
||||
msgid "%s contact unblocked"
|
||||
msgid_plural "%s contacts unblocked"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:79
|
||||
#: src/Module/Admin/Blocklist/Contact.php:95
|
||||
msgid "Remote Contact Blocklist"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:80
|
||||
#: src/Module/Admin/Blocklist/Contact.php:96
|
||||
msgid ""
|
||||
"This page allows you to prevent any message from a remote contact to reach "
|
||||
"your node."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:81
|
||||
#: src/Module/Admin/Blocklist/Contact.php:97
|
||||
msgid "Block Remote Contact"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:82
|
||||
#: src/Module/Admin/Blocklist/Contact.php:98
|
||||
#: src/Module/Admin/Users/Active.php:138 src/Module/Admin/Users/Blocked.php:139
|
||||
#: src/Module/Admin/Users/Index.php:151 src/Module/Admin/Users/Pending.php:103
|
||||
msgid "select all"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:83
|
||||
#: src/Module/Admin/Blocklist/Contact.php:99
|
||||
msgid "select none"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:85
|
||||
#: src/Module/Admin/Blocklist/Contact.php:101
|
||||
#: src/Module/Admin/Users/Blocked.php:142 src/Module/Admin/Users/Index.php:156
|
||||
#: src/Module/Contact.php:544 src/Module/Contact.php:787
|
||||
#: src/Module/Contact.php:1064
|
||||
msgid "Unblock"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:86
|
||||
#: src/Module/Admin/Blocklist/Contact.php:102
|
||||
msgid "No remote contact is blocked from this node."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:88
|
||||
#: src/Module/Admin/Blocklist/Contact.php:104
|
||||
msgid "Blocked Remote Contacts"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:89
|
||||
#: src/Module/Admin/Blocklist/Contact.php:105
|
||||
msgid "Block New Remote Contact"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:90
|
||||
#: src/Module/Admin/Blocklist/Contact.php:106
|
||||
msgid "Photo"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:90
|
||||
#: src/Module/Admin/Blocklist/Contact.php:106
|
||||
msgid "Reason"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:98
|
||||
#: src/Module/Admin/Blocklist/Contact.php:114
|
||||
#, php-format
|
||||
msgid "%s total blocked contact"
|
||||
msgid_plural "%s total blocked contacts"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:100
|
||||
#: src/Module/Admin/Blocklist/Contact.php:116
|
||||
msgid "URL of the remote contact to block."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:101
|
||||
#: src/Module/Admin/Blocklist/Contact.php:117
|
||||
msgid "Also purge contact"
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:117
|
||||
msgid ""
|
||||
"Removes all content related to this contact from the node. Keeps the contact "
|
||||
"record. This action canoot be undone."
|
||||
msgstr ""
|
||||
|
||||
#: src/Module/Admin/Blocklist/Contact.php:118
|
||||
msgid "Block Reason"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
<tbody>
|
||||
<tr>
|
||||
<td>{{include file="field_input.tpl" field=$contacturl}}</td>
|
||||
<td>{{include file="field_checkbox.tpl" field=$contact_block_purge}}</td>
|
||||
<td>{{include file="field_textarea.tpl" field=$contact_block_reason}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -63,3 +64,4 @@
|
|||
<div class="submit"><input type="submit" name="page_contactblock_block" value="{{$submit}}" /></div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
|
||||
|
||||
{{include file="field_input.tpl" field=$contacturl}}
|
||||
{{include file="field_checkbox.tpl" field=$contact_block_purge}}
|
||||
{{include file="field_textarea.tpl" field=$contact_block_reason}}
|
||||
|
||||
<div class="admin-settings-submit-wrapper form-group pull-right">
|
||||
|
|
Loading…
Reference in a new issue