From dd90fa97893818fff46a1150220c3d6f3c2cde51 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 15 May 2019 19:27:36 -0400 Subject: [PATCH 1/5] Database Structure Version 1313 --- config/dbstructure.config.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/dbstructure.config.php b/config/dbstructure.config.php index 38723ddc17..baca2bec63 100755 --- a/config/dbstructure.config.php +++ b/config/dbstructure.config.php @@ -34,7 +34,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1312); + define('DB_UPDATE_VERSION', 1313); } return [ @@ -241,7 +241,8 @@ return [ "term-date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""], "last-item" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "date of the last post"], "priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], - "blocked" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""], + "blocked" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "Node-wide block status"], + "block_reason" => ["type" => "text", "comment" => "Node-wide block reason"], "readonly" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "posts of the contact are readonly"], "writable" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "forum" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a forum"], From 79cb5b1bae59ffde96b7749f84e45f235d9db99d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 15 May 2019 19:28:00 -0400 Subject: [PATCH 2/5] Add block reason editing in Model\Contact --- src/Model/Contact.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 00a303a8b9..ce3aeac560 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1670,13 +1670,13 @@ class Contact extends BaseObject /** * @brief Blocks a contact * - * @param int $uid + * @param int $cid * @return bool * @throws \Exception */ - public static function block($uid) + public static function block($cid, $reason = null) { - $return = DBA::update('contact', ['blocked' => true], ['id' => $uid]); + $return = DBA::update('contact', ['blocked' => true, 'block_reason' => $reason], ['id' => $cid]); return $return; } @@ -1684,13 +1684,13 @@ class Contact extends BaseObject /** * @brief Unblocks a contact * - * @param int $uid + * @param int $cid * @return bool * @throws \Exception */ - public static function unblock($uid) + public static function unblock($cid) { - $return = DBA::update('contact', ['blocked' => false], ['id' => $uid]); + $return = DBA::update('contact', ['blocked' => false, 'block_reason' => null], ['id' => $cid]); return $return; } From 0c63f8aa42d03a793291f3ac55eb883441de6b42 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 15 May 2019 19:30:13 -0400 Subject: [PATCH 3/5] Add contact block reason form and display in admin page --- src/Module/Admin/Blocklist/Contact.php | 18 ++++++++++-------- view/templates/admin/blocklist/contact.tpl | 10 ++++++---- .../frio/templates/admin/blocklist/contact.tpl | 11 +++++++---- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php index 1ec6e00df0..60fe04bf7a 100644 --- a/src/Module/Admin/Blocklist/Contact.php +++ b/src/Module/Admin/Blocklist/Contact.php @@ -15,18 +15,19 @@ class Contact extends BaseAdminModule { parent::post(); - $contact_url = defaults($_POST, 'contact_url', ''); - $contacts = defaults($_POST, 'contacts', []); + $contact_url = defaults($_POST, 'contact_url', ''); + $block_reason = defaults($_POST, 'contact_block_reason', ''); + $contacts = defaults($_POST, 'contacts', []); parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock'); if (!empty($_POST['page_contactblock_block'])) { $contact_id = Model\Contact::getIdForURL($contact_url); if ($contact_id) { - Model\Contact::block($contact_id); + Model\Contact::block($contact_id, $block_reason); notice(L10n::t('The contact has been blocked from the node')); } else { - notice(L10n::t("Could not find any contact entry for this URL \x28%s\x29", $contact_url)); + notice(L10n::t('Could not find any contact entry for this URL (%s)', $contact_url)); } } @@ -34,7 +35,7 @@ class Contact extends BaseAdminModule foreach ($contacts as $uid) { Model\Contact::unblock($uid); } - notice(L10n::tt("%s contact unblocked", "%s contacts unblocked", count($contacts))); + notice(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts))); } self::getApp()->internalRedirect('admin/blocklist/contact'); @@ -69,9 +70,9 @@ class Contact extends BaseAdminModule '$h_contacts' => L10n::t('Blocked Remote Contacts'), '$h_newblock' => L10n::t('Block New Remote Contact'), - '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Address'), L10n::t('Profile URL')], + '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Reason')], - '$form_security_token' => parent::getFormSecurityToken("admin_contactblock"), + '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'), // values // '$baseurl' => $a->getBaseURL(true), @@ -79,7 +80,8 @@ class Contact extends BaseAdminModule '$contacts' => $contacts, '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total), '$paginate' => $pager->renderFull($total), - '$contacturl' => ['contact_url', L10n::t("Profile URL"), '', L10n::t("URL of the remote contact to block.")], + '$contacturl' => ['contact_url', L10n::t('Profile URL'), '', L10n::t('URL of the remote contact to block.')], + '$contact_block_reason' => ['contact_block_reason', L10n::t('Block Reason')], ]); return $o; } diff --git a/view/templates/admin/blocklist/contact.tpl b/view/templates/admin/blocklist/contact.tpl index 228ad6903f..78b4cd78fe 100644 --- a/view/templates/admin/blocklist/contact.tpl +++ b/view/templates/admin/blocklist/contact.tpl @@ -25,7 +25,6 @@ {{$th}} {{/foreach}} - @@ -33,9 +32,11 @@ {{$contact.nickname}} - {{$contact.name}} - {{$contact.addr}} - {{$contact.url}} + + {{$contact.name}}
+ {{$contact.addr}} + + {{if $contact.block_reason}}{{$contact.block_reason}}{{else}}N/A{{/if}} {{/foreach}} @@ -55,6 +56,7 @@ {{include file="field_input.tpl" field=$contacturl}} + {{include file="field_textarea.tpl" field=$contact_block_reason}} diff --git a/view/theme/frio/templates/admin/blocklist/contact.tpl b/view/theme/frio/templates/admin/blocklist/contact.tpl index 53fde9aefb..1f43b412b7 100644 --- a/view/theme/frio/templates/admin/blocklist/contact.tpl +++ b/view/theme/frio/templates/admin/blocklist/contact.tpl @@ -22,6 +22,7 @@ {{include file="field_input.tpl" field=$contacturl}} + {{include file="field_textarea.tpl" field=$contact_block_reason}}
@@ -55,7 +56,6 @@ {{$th}} {{/foreach}} - @@ -68,8 +68,11 @@
{{$contact.nickname}} - {{$contact.name}} - {{$contact.url}} + + {{$contact.name}}
+ {{$contact.addr}} + + {{if $contact.block_reason}}{{$contact.block_reason}}{{else}}N/A{{/if}} {{/foreach}} @@ -82,7 +85,7 @@ - + {{$total_contacts}}
From dbedcdbf692f696d33eb56517a447408185dff33 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 15 May 2019 19:30:48 -0400 Subject: [PATCH 4/5] Add reason editing to console globalcommunityblock command --- src/Console/GlobalCommunityBlock.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Console/GlobalCommunityBlock.php b/src/Console/GlobalCommunityBlock.php index bc067dada6..2eef427dba 100644 --- a/src/Console/GlobalCommunityBlock.php +++ b/src/Console/GlobalCommunityBlock.php @@ -25,10 +25,11 @@ class GlobalCommunityBlock extends \Asika\SimpleConsole\Console $help = << [-h|--help|-?] [-v] + bin/console globalcommunityblock [] [-h|--help|-?] [-v] Description Blocks an account in such a way that no postings or comments this account writes are accepted to this node. + You can provide a optional reason for the block. Options -h|--help|-? Show help information @@ -52,7 +53,7 @@ HELP; return 0; } - if (count($this->args) > 1) { + if (count($this->args) > 2) { throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } @@ -60,11 +61,13 @@ HELP; throw new \RuntimeException('Database isn\'t ready or populated yet'); } - $contact_id = Contact::getIdForURL($this->getArgument(0)); - if (!$contact_id) { + $contact_url = Contact::getIdForURL($this->getArgument(0)); + if (!$contact_url) { throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $this->getArgument(0))); } - if(Contact::block($contact_id)) { + + $block_reason = $this->getArgument(1); + if(Contact::block($contact_url, $block_reason)) { $this->out(L10n::t('The contact has been blocked from the node')); } else { throw new \RuntimeException('The contact block failed.'); From 8b3592b08c18f7027a7a1105962102ca353007bf Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 16 May 2019 08:42:07 -0400 Subject: [PATCH 5/5] Revert renaming variable in Console\GlobalCommunityBlock --- src/Console/GlobalCommunityBlock.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Console/GlobalCommunityBlock.php b/src/Console/GlobalCommunityBlock.php index 2eef427dba..12ea63e5d7 100644 --- a/src/Console/GlobalCommunityBlock.php +++ b/src/Console/GlobalCommunityBlock.php @@ -61,13 +61,13 @@ HELP; throw new \RuntimeException('Database isn\'t ready or populated yet'); } - $contact_url = Contact::getIdForURL($this->getArgument(0)); - if (!$contact_url) { + $contact_id = Contact::getIdForURL($this->getArgument(0)); + if (!$contact_id) { throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $this->getArgument(0))); } $block_reason = $this->getArgument(1); - if(Contact::block($contact_url, $block_reason)) { + if(Contact::block($contact_id, $block_reason)) { $this->out(L10n::t('The contact has been blocked from the node')); } else { throw new \RuntimeException('The contact block failed.');