Skip to content

Commit

Permalink
Started moving access callbacks to services, removed view inc and upd…
Browse files Browse the repository at this point in the history
…ated README.
  • Loading branch information
mccrodp committed Dec 23, 2015
1 parent b8d61a4 commit fbe5944
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 355 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,37 @@ INSTALLATION
CONFIGURATION
-------------
Enabling Permissions:
"View a new message instance for Private Message" &
"Create a new message instance for Private Message" for users needing to create
and view private messages.
To hide private messages from this view,
you must override view provided by Message module:
admin/structure/views/view/message/edit
* "View a new message instance for Private Message" &
"Create a new message instance for Private Message" for users needing to create
and view private messages.
* To hide private messages from this view, you must override view provided by
Message module: admin/structure/views/view/message/edit

When enabled, the module will provide a new message type "Private Message" and a
Message Private View.

Message Create Limits:
Message creation limits can be managed per role on the module settings form. A
message create limit can be set per interval per role. Users with more than one
role get the maximum limit by calculating the lowest time per message over each
role. Users with the 'bypass private message access control' permission bypass
these limitations.
* Message creation limits can be managed per role on the module settings form.
A message create limit can be set per interval per role. Users with more than
one role get the maximum limit by calculating the lowest time per message over
each role. Users with the 'bypass private message access control' permission
bypass these limitations.


HOW TO USE
----------
To Create messages:
Visit /admin/content/message/create/private-message and Save the message to send
or
Visit the "Messages" tab detailed below and find the "Create a new message"
* Visit /admin/content/message/create/private-message and Save the message to
send, or
* Visit the "Messages" tab detailed below and find the "Create a new message"
local action.

To View inbox and sent messages:
Visit your user page at /user and find the "Messages" tab which displays
* Visit your user page at /user and find the "Messages" tab which displays
received messages (Inbox local task), the "Sent" local task under that tab which
displays sent messages and the "Group" local task which displays group messages.
/user/USER_ID/messages/inbox
/user/USER_ID/messages/sent
* /user/USER_ID/messages/inbox
* /user/USER_ID/messages/sent


SECURITY
Expand All @@ -81,8 +80,8 @@ This module does not come with any security features out-of-the-box, but you can
easily configure your own, using methods and modules of your choice.

E.G:
Honeypot and timestamp methods: https://www.drupal.org/project/honeypot
CAPTCHA method: https://www.drupal.org/project/recaptcha
* Honeypot and timestamp methods: https://www.drupal.org/project/honeypot
* CAPTCHA method: https://www.drupal.org/project/recaptcha


DEVELOPMENT AND TEST
Expand Down
62 changes: 14 additions & 48 deletions message_private.module
Original file line number Diff line number Diff line change
@@ -1,98 +1,63 @@
<?php
/**
* @file
* Message Private with access permissions based on message fields.
*/

/**
* The string name for email notifications variable.
*/
define('MESSAGE_PRIVATE_EMAIL_NOTIFICATIONS', 'message_private_email_notifications');
use Drupal\Core\Routing\RouteMatchInterface;

/**
* The string name for message limit variable.
*/
define('MESSAGE_PRIVATE_MESSAGE_LIMIT', 'message_private_message_limit');
const MESSAGE_PRIVATE_MESSAGE_LIMIT = 'message_private_message_limit';

/**
* The assoc index to be used when fetching default limit variable.
*/
define('MESSAGE_PRIVATE_DEFAULT_LIMIT', 'message_private_default_limit');
const MESSAGE_PRIVATE_DEFAULT_LIMIT = 'message_private_default_limit';

/**
* The assoc index to be used when fetching default interval variable.
*/
define('MESSAGE_PRIVATE_DEFAULT_INTERVAL', 'message_private_default_interval');
const MESSAGE_PRIVATE_DEFAULT_INTERVAL = 'message_private_default_interval';

/**
* The default index for settings such as role.
*/
define('MESSAGE_PRIVATE_DEFAULT_INDEX', 0);
const MESSAGE_PRIVATE_DEFAULT_INDEX = 0;

/**
* The maximum message limit.
*/
define('MESSAGE_PRIVATE_MESSAGE_LIMIT_MAX', 1000);
const MESSAGE_PRIVATE_MESSAGE_LIMIT_MAX = 1000;

/**
* The minimum message limit.
*/
define('MESSAGE_PRIVATE_MESSAGE_LIMIT_MIN', 1);
const MESSAGE_PRIVATE_MESSAGE_LIMIT_MIN = 1;

/**
* The maximum message interval in minutes.
*/
define('MESSAGE_PRIVATE_MESSAGE_INTERVAL_MAX', 1440);
const MESSAGE_PRIVATE_MESSAGE_INTERVAL_MAX = 1440;

/**
* The minimum message interval in minutes.
*/
define('MESSAGE_PRIVATE_MESSAGE_INTERVAL_MIN', 1);
const MESSAGE_PRIVATE_MESSAGE_INTERVAL_MIN = 1;


/**
* Implements hook_help().
*/
function message_private_help($path, $arg) {
switch ($path) {
case 'admin/help#message_private':
function message_private_help($route_name, RouteMatchInterface $arg) {
switch ($route_name) {
case 'help.page.message_private':
$output = file_get_contents(drupal_get_path('module', 'message_private') . '/README.md');
return \Drupal::moduleHandler()->moduleExists('markdown') ? \Drupal\Component\Utility\Xss::filterAdmin(\Drupal::moduleHandler()->invoke('markdown', 'filter', ['process', 0, -1, $output])) : '<h3>Message Private README</h3><pre>' . \Drupal\Component\Utility\Html::escape($output) . '</pre>';
}
}

/**
* Implements hook_views_api().
*/
function message_private_views_api() {
list($module, $api) = func_get_args();
if ($module == 'views' && $api == 'views_default') {
return array('version' => '3.0');
}
return array();
}

/**
* Implements hook_permission().
*/
function message_private_permission() {

// Build the permissions.
$permissions = array();

$permissions['bypass private message access control'] = array(
'title' => t('Bypass message access control'),
'description' => t('Grant to the user the permission to apply CRUD option on any private messages.'),
'restrict access' => TRUE,
);

$permissions['administer message private'] = array(
'title' => t('Administer message private'),
'description' => t('Access the message private administration pages.'),
);

return $permissions;
}

/**
* Access callback for Messages tab.
*
Expand All @@ -119,6 +84,7 @@ function message_private_access_callback($message) {
function message_private_menu_alter(&$items) {

// Override access callbacks.
// @todo: add appropriate callbacks to services refering to node.services.yml.
$items['message/%message']['access callback'] = 'message_private_access_control';
$items['message/%message/view']['access callback'] = 'message_private_access_control';
$items['message/%message/edit']['access callback'] = 'message_private_access_control';
Expand Down
7 changes: 4 additions & 3 deletions message_private.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ message_private.create_message:
title: 'Create Private Message'
description: 'Create a new message Private Message instance'
options:
parameters:
message_type: 'private-message'
#'access callback' => 'message_private_access_control'
parameters:
message_type: 'private-message'
requirements:
_message_private_add_access: 'message:private_message'
6 changes: 6 additions & 0 deletions message_private.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
access_check.message_private.add:
class: Drupal\message_private\Access\MessagePrivateAddAccessCheck
arguments: ['@entity.manager']
tags:
- { name: access_check, applies_to: _message_private_add_access }
Loading

0 comments on commit fbe5944

Please sign in to comment.