Merge pull request #7145 from MrPetovan/task/7141-contact-block-reason

Add node-wide contact block reason
This commit is contained in:
Philipp 2019-05-16 15:39:11 +02:00 committed by GitHub
commit 9519ad2174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 27 deletions

View File

@ -34,7 +34,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1312); define('DB_UPDATE_VERSION', 1313);
} }
return [ return [
@ -241,7 +241,8 @@ return [
"term-date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""], "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"], "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" => ""], "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"], "readonly" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "posts of the contact are readonly"],
"writable" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "writable" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"forum" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a forum"], "forum" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "contact is a forum"],

View File

@ -25,10 +25,11 @@ class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
$help = <<<HELP $help = <<<HELP
console globalcommunityblock - Block remote profile from interacting with this node console globalcommunityblock - Block remote profile from interacting with this node
Usage Usage
bin/console globalcommunityblock <profile_url> [-h|--help|-?] [-v] bin/console globalcommunityblock <profile_url> [<reason>] [-h|--help|-?] [-v]
Description Description
Blocks an account in such a way that no postings or comments this account writes are accepted to this node. 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 Options
-h|--help|-? Show help information -h|--help|-? Show help information
@ -52,7 +53,7 @@ HELP;
return 0; return 0;
} }
if (count($this->args) > 1) { if (count($this->args) > 2) {
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
} }
@ -64,7 +65,9 @@ HELP;
if (!$contact_id) { if (!$contact_id) {
throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $this->getArgument(0))); 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_id, $block_reason)) {
$this->out(L10n::t('The contact has been blocked from the node')); $this->out(L10n::t('The contact has been blocked from the node'));
} else { } else {
throw new \RuntimeException('The contact block failed.'); throw new \RuntimeException('The contact block failed.');

View File

@ -1670,13 +1670,13 @@ class Contact extends BaseObject
/** /**
* @brief Blocks a contact * @brief Blocks a contact
* *
* @param int $uid * @param int $cid
* @return bool * @return bool
* @throws \Exception * @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; return $return;
} }
@ -1684,13 +1684,13 @@ class Contact extends BaseObject
/** /**
* @brief Unblocks a contact * @brief Unblocks a contact
* *
* @param int $uid * @param int $cid
* @return bool * @return bool
* @throws \Exception * @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; return $return;
} }

View File

@ -15,18 +15,19 @@ class Contact extends BaseAdminModule
{ {
parent::post(); parent::post();
$contact_url = defaults($_POST, 'contact_url', ''); $contact_url = defaults($_POST, 'contact_url', '');
$contacts = defaults($_POST, 'contacts', []); $block_reason = defaults($_POST, 'contact_block_reason', '');
$contacts = defaults($_POST, 'contacts', []);
parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock'); parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
if (!empty($_POST['page_contactblock_block'])) { if (!empty($_POST['page_contactblock_block'])) {
$contact_id = Model\Contact::getIdForURL($contact_url); $contact_id = Model\Contact::getIdForURL($contact_url);
if ($contact_id) { 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')); notice(L10n::t('The contact has been blocked from the node'));
} else { } 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) { foreach ($contacts as $uid) {
Model\Contact::unblock($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'); self::getApp()->internalRedirect('admin/blocklist/contact');
@ -69,9 +70,9 @@ class Contact extends BaseAdminModule
'$h_contacts' => L10n::t('Blocked Remote Contacts'), '$h_contacts' => L10n::t('Blocked Remote Contacts'),
'$h_newblock' => L10n::t('Block New Remote Contact'), '$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 // // values //
'$baseurl' => $a->getBaseURL(true), '$baseurl' => $a->getBaseURL(true),
@ -79,7 +80,8 @@ class Contact extends BaseAdminModule
'$contacts' => $contacts, '$contacts' => $contacts,
'$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total), '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total),
'$paginate' => $pager->renderFull($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; return $o;
} }

View File

@ -25,7 +25,6 @@
{{$th}} {{$th}}
</th> </th>
{{/foreach}} {{/foreach}}
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -33,9 +32,11 @@
<tr> <tr>
<td class="checkbox"><input type="checkbox" class="contacts_ckbx" id="id_contact_{{$contact.id}}" name="contacts[]" value="{{$contact.id}}"/></td> <td class="checkbox"><input type="checkbox" class="contacts_ckbx" id="id_contact_{{$contact.id}}" name="contacts[]" value="{{$contact.id}}"/></td>
<td><img class="icon" src="{{$contact.micro}}" alt="{{$contact.nickname}}" title="{{$contact.nickname}}"></td> <td><img class="icon" src="{{$contact.micro}}" alt="{{$contact.nickname}}" title="{{$contact.nickname}}"></td>
<td class="name">{{$contact.name}}</td> <td class="name">
<td class="addr">{{$contact.addr}}</td> {{$contact.name}}<br>
<td class="addr"><a href="{{$contact.url}}" title="{{$contact.nickname}}" >{{$contact.url}}</a></td> <a href="{{$contact.url}}" title="{{$contact.nickname}}">{{$contact.addr}}</a>
</td>
<td class="reason">{{if $contact.block_reason}}{{$contact.block_reason}}{{else}}N/A{{/if}}</td>
</tr> </tr>
{{/foreach}} {{/foreach}}
</tbody> </tbody>
@ -55,6 +56,7 @@
<tbody> <tbody>
<tr> <tr>
<td>{{include file="field_input.tpl" field=$contacturl}}</td> <td>{{include file="field_input.tpl" field=$contacturl}}</td>
<td>{{include file="field_textarea.tpl" field=$contact_block_reason}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -22,6 +22,7 @@
<input type="hidden" name="form_security_token" value="{{$form_security_token}}"> <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
{{include file="field_input.tpl" field=$contacturl}} {{include file="field_input.tpl" field=$contacturl}}
{{include file="field_textarea.tpl" field=$contact_block_reason}}
<div class="admin-settings-submit-wrapper form-group pull-right"> <div class="admin-settings-submit-wrapper form-group pull-right">
<button type="submit" class="btn btn-primary" name="page_contactblock_block" value="1">{{$submit}}</button> <button type="submit" class="btn btn-primary" name="page_contactblock_block" value="1">{{$submit}}</button>
@ -55,7 +56,6 @@
{{$th}} {{$th}}
</th> </th>
{{/foreach}} {{/foreach}}
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -68,8 +68,11 @@
</div> </div>
</td> </td>
<td><img class="icon" src="{{$contact.micro}}" alt="{{$contact.nickname}}" title="{{$contact.addr}}"></td> <td><img class="icon" src="{{$contact.micro}}" alt="{{$contact.nickname}}" title="{{$contact.addr}}"></td>
<td class="name">{{$contact.name}}</td> <td class="name">
<td class="addr" colspan="3"><a href="{{$contact.url}}" title="{{$contact.addr}}" >{{$contact.url}}</a></td> {{$contact.name}}<br>
<a href="{{$contact.url}}" title="{{$contact.nickname}}">{{$contact.addr}}</a>
</td>
<td class="reason">{{if $contact.block_reason}}{{$contact.block_reason}}{{else}}N/A{{/if}}</td>
</tr> </tr>
{{/foreach}} {{/foreach}}
</tbody> </tbody>
@ -82,7 +85,7 @@
<label for="contactblock-select"></label> <label for="contactblock-select"></label>
</div> </div>
</td> </td>
<td colspan="5"> <td colspan="3">
{{$total_contacts}} {{$total_contacts}}
<div class="admin-settings-submit-wrapper form-group pull-right"> <div class="admin-settings-submit-wrapper form-group pull-right">
<button type="submit" class="btn btn-small btn-default pull-right" name="page_contactblock_unblock" value="1">{{$unblock}}</button> <button type="submit" class="btn btn-small btn-default pull-right" name="page_contactblock_unblock" value="1">{{$unblock}}</button>