From 202aefd7a1f1c383476d1b8e5ba8b0a6f7c568fb Mon Sep 17 00:00:00 2001 From: qadan Date: Mon, 29 Jun 2020 15:22:06 -0300 Subject: [PATCH 1/4] update readme, fix issues --- README.md | 58 ++++++++++++++++++++++- src/Controller/EmbargoesLogController.php | 6 ++- src/Form/EmbargoesIpRangeEntityForm.php | 1 + 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e176ff..ef727bf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,62 @@ # Embargoes -Drupal 8 module for managing embargo policies with access restrictions on content + +# Introduction + +Adds the ability to manage embargo policies with access restrictions on content. ## Requirements -Embargoes requires no other Drupal modules to work. + +This module requires the following modules/libraries: + +* [Menu UI](https://www.drupal.org/docs/core-modules-and-themes/core-modules/menu-ui-module) + +## Installation + +Install as +[usual](https://www.drupal.org/docs/8/extending-drupal-8/installing-drupal-8-modules). + +## Configuration + +Configuration options can be set at `admin/config/content/embargoes/settings`, +including notification options and IP range settings that can apply to +embargoes. + +To add an IP range for use on embargoes, navigate to +`admin/config/content/embargoes/settings/ips` and click 'Add IP range'. Ranges +created via this method can then be used as IP address whitelists when creating +embargoes. + +## Usage + +### Applying an embargo + +An embargo can be applied to an existing node by navigating to +`node/{node_id/embargoes`. From here, an embargo can be applied if it doesn't +already exist, and existing embargoes can be modified or removed. + +### Logging + +Embargo logs are kept at `admin/config/content/embargoes/settings/log`, +including who created the embargo, or how it was changed. + +## Troubleshooting/Issues + +Having problems or solved one? Contact +[discoverygarden](http://support.discoverygarden.ca). + +## Maintainers/Sponsors + +Current maintainers: + +* [discoverygarden](http://www.discoverygarden.ca) + +## Development + +If you would like to contribute to this module, please check out the helpful +[Documentation](https://github.com/Islandora/islandora/wiki#wiki-documentation-for-developers), +[Developers](http://islandora.ca/developers) section on Islandora.ca and create +an issue, pull request and or contact +[discoverygarden](http://support.discoverygarden.ca). ## License [GPLv2](http://www.gnu.org/licenses/gpl-2.0.txt) diff --git a/src/Controller/EmbargoesLogController.php b/src/Controller/EmbargoesLogController.php index ff7ad05..0e7b90d 100644 --- a/src/Controller/EmbargoesLogController.php +++ b/src/Controller/EmbargoesLogController.php @@ -12,7 +12,11 @@ class EmbargoesLogController extends ControllerBase { public function showRenderedLog() { $database = \Drupal::database(); - $result = $database->query('SELECT * FROM {embargoes_log} ORDER BY time DESC;'); + $result = $database->getConnection() + ->select('embargoes_log', 'el') + ->fields('el') + ->orderBy('el.time', 'DESC') + ->execute(); $formatted_log = []; foreach ($result as $record) { diff --git a/src/Form/EmbargoesIpRangeEntityForm.php b/src/Form/EmbargoesIpRangeEntityForm.php index c53bd06..97e97a4 100644 --- a/src/Form/EmbargoesIpRangeEntityForm.php +++ b/src/Form/EmbargoesIpRangeEntityForm.php @@ -33,6 +33,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $range->label(), '#description' => $this->t("Label for the IP range."), '#required' => TRUE, + '#id' => 'ip-range-label', ]; $form['range'] = [ From 469f4d2e27c0e045c533fbf70b68f414654237aa Mon Sep 17 00:00:00 2001 From: qadan Date: Tue, 30 Jun 2020 10:58:45 -0300 Subject: [PATCH 2/4] fix logging --- embargoes.services.yml | 2 +- src/EmbargoesLogService.php | 16 ++++++++++++---- src/Form/EmbargoesEmbargoEntityForm.php | 2 +- src/Form/EmbargoesNodeEmbargoesForm.php | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/embargoes.services.yml b/embargoes.services.yml index 69b67f2..486675f 100644 --- a/embargoes.services.yml +++ b/embargoes.services.yml @@ -4,7 +4,7 @@ services: arguments: ['embargoes'] embargoes.log: class: Drupal\embargoes\EmbargoesLogService - arguments: [] + arguments: ['@database'] embargoes.embargoes: class: Drupal\embargoes\EmbargoesEmbargoesService arguments: [] diff --git a/src/EmbargoesLogService.php b/src/EmbargoesLogService.php index 7a3ac31..cef6286 100644 --- a/src/EmbargoesLogService.php +++ b/src/EmbargoesLogService.php @@ -2,22 +2,30 @@ namespace Drupal\embargoes; +use Drupal\Core\Database\Connection; + /** * Class EmbargoesLogService. */ class EmbargoesLogService implements EmbargoesLogServiceInterface { /** - * Constructs a new EmbargoesLogService object. + * @var \Drupal\Core\Database\Connection $database + * + * Database connection. */ - public function __construct() { + protected $database; + /** + * Constructs a new EmbargoesLogService object. + */ + public function __construct(Connection $connection) { + $this->database = $connection; } public function logEmbargoEvent($values) { - $conn = \Drupal::database()->getConnection(); $values['time'] = time(); - return $conn->insert('embargoes_log') + return $this->database->insert('embargoes_log') ->fields($values) ->execute(); } diff --git a/src/Form/EmbargoesEmbargoEntityForm.php b/src/Form/EmbargoesEmbargoEntityForm.php index 537ed78..82f2017 100644 --- a/src/Form/EmbargoesEmbargoEntityForm.php +++ b/src/Form/EmbargoesEmbargoEntityForm.php @@ -119,7 +119,7 @@ public function save(array $form, FormStateInterface $form_state) { $log_values['node'] = $embargo->getEmbargoedNode(); $log_values['uid'] = \Drupal::currentUser()->id(); - $log_values['embargo_id'] = $embargo->id(); + $log_values['embargo'] = $embargo->id(); if ($status == SAVED_NEW) { $log_values['action'] = 'created'; diff --git a/src/Form/EmbargoesNodeEmbargoesForm.php b/src/Form/EmbargoesNodeEmbargoesForm.php index 39139fc..3b6e817 100644 --- a/src/Form/EmbargoesNodeEmbargoesForm.php +++ b/src/Form/EmbargoesNodeEmbargoesForm.php @@ -157,7 +157,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $log_values['node'] = $embargo->getEmbargoedNode(); $log_values['uid'] = \Drupal::currentUser()->id(); - $log_values['embargo_id'] = $embargo->id(); + $log_values['embargo'] = $embargo->id(); if ($embargo_id == 'add') { $log_values['action'] = 'created'; From 5dca54271d35f8f072e8b025388a8dda629350a3 Mon Sep 17 00:00:00 2001 From: qadan Date: Tue, 30 Jun 2020 11:59:20 -0300 Subject: [PATCH 3/4] issue with the form not having a preselected node --- src/Entity/EmbargoesEmbargoEntity.php | 19 ++++++++++++++----- src/Form/EmbargoesEmbargoEntityForm.php | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Entity/EmbargoesEmbargoEntity.php b/src/Entity/EmbargoesEmbargoEntity.php index 6d2b906..175b816 100644 --- a/src/Entity/EmbargoesEmbargoEntity.php +++ b/src/Entity/EmbargoesEmbargoEntity.php @@ -119,7 +119,10 @@ public function getExemptIps() { return $this->get('exempt_ips'); } - public function setExemptIps($range){ + public function setExemptIps($range) { + if (!$range) { + $range = []; + } $this->set('exempt_ips', $range); return $this; } @@ -136,7 +139,10 @@ public function getExemptUsersEntities() { return $exempt_user_entities; } - public function setExemptUsers($users){ + public function setExemptUsers($users) { + if (!$users) { + $users = []; + } $this->set('exempt_users', $users); return $this; } @@ -145,7 +151,10 @@ public function getAdditionalEmails() { return $this->get('additional_emails'); } - public function setAdditionalEmails($emails){ + public function setAdditionalEmails($emails) { + if (!$emails) { + $emails = []; + } $this->set('additional_emails', $emails); return $this; } @@ -154,7 +163,7 @@ public function getEmbargoedNode() { return $this->get('embargoed_node'); } - public function setEmbargoedNode($node){ + public function setEmbargoedNode($node) { $this->set('embargoed_node', $node); return $this; } @@ -163,7 +172,7 @@ public function getNotificationStatus() { return $this->get('notification_status'); } - public function setNotificationStatus($status){ + public function setNotificationStatus($status) { $this->set('notification_status', $status); return $this; } diff --git a/src/Form/EmbargoesEmbargoEntityForm.php b/src/Form/EmbargoesEmbargoEntityForm.php index 82f2017..ff73101 100644 --- a/src/Form/EmbargoesEmbargoEntityForm.php +++ b/src/Form/EmbargoesEmbargoEntityForm.php @@ -78,11 +78,13 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $embargo->getAdditionalEmails(), ); + $embargoed_node = $embargo->getEmbargoedNode(); $form['embargoed_node'] = array( '#type' => 'entity_autocomplete', '#target_type' => 'node', '#title' => $this->t('Embargoed node'), - '#default_value' => node_load($embargo->getEmbargoedNode()), + '#maxlength' => 255, + '#default_value' => $embargoed_node ? $embargoed_node : '', '#required' => TRUE, ); From 1c61f42efce67817179e0148c47faeea23fe406e Mon Sep 17 00:00:00 2001 From: qadan Date: Thu, 2 Jul 2020 10:26:42 -0300 Subject: [PATCH 4/4] closing brace --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef727bf..6546b38 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ embargoes. ### Applying an embargo An embargo can be applied to an existing node by navigating to -`node/{node_id/embargoes`. From here, an embargo can be applied if it doesn't +`node/{node_id}/embargoes`. From here, an embargo can be applied if it doesn't already exist, and existing embargoes can be modified or removed. ### Logging