Skip to content
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

update readme, fix issues #5

Merged
merged 4 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion embargoes.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
arguments: ['embargoes']
embargoes.log:
class: Drupal\embargoes\EmbargoesLogService
arguments: []
arguments: ['@database']
embargoes.embargoes:
class: Drupal\embargoes\EmbargoesEmbargoesService
arguments: []
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/EmbargoesLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 12 additions & 4 deletions src/EmbargoesLogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
19 changes: 14 additions & 5 deletions src/Entity/EmbargoesEmbargoEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Form/EmbargoesEmbargoEntityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -119,7 +121,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';
Expand Down
1 change: 1 addition & 0 deletions src/Form/EmbargoesIpRangeEntityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = [
Expand Down
2 changes: 1 addition & 1 deletion src/Form/EmbargoesNodeEmbargoesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down