Skip to content

Commit

Permalink
- Implemented "Allow access rights to specific wiki pages or books": h…
Browse files Browse the repository at this point in the history
  • Loading branch information
jrosgiralt committed Mar 5, 2017
1 parent c2ce44e commit 3909101
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 6 deletions.
46 changes: 46 additions & 0 deletions modules/custom/lbd_wiki/lbd_wiki.module
Expand Up @@ -499,3 +499,49 @@ function lbd_wiki_node_view($node, $view_mode, $langcode) {
return;
}


/**
* Returns the list of book predecessors
*
* @param array $node
* The book page from which to return the predecessors
*
* @return array
* The list of node IDs corresponding to the predecessors
*
*/
function _get_predecessors($node) {
$predecessors = array();
$iterNode = $node;

while($iterNode->book['plid'] != 0) {
$mlid = menu_link_load($iterNode->book['plid']);
$parentNid = explode('node/', $mlid['link_path'])[1];
$predecessors[] = $parentNid;
$iterNode = node_load($parentNid);
}
return $predecessors;
}


/**
* Implements hook_node_access
*
*/
function lbd_wiki_node_access($node, $op, $account) {
global $user;

if($op == "update" && $node->type == "book") {
$predecessorsList = _get_predecessors($node);
foreach($predecessorsList as $predecessor) {
$nodeLoaded = node_load($predecessor);
$editors = labdoo_lib_get_field_all($nodeLoaded, 'field_grant_edit_rights_wiki', 'node', 'target_id');
if(in_array($user->uid, $editors))
return NODE_ACCESS_ALLOW;
}
return NODE_ACCESS_IGNORE;
}

return;
}

153 changes: 150 additions & 3 deletions modules/features/lbd_layout/lbd_layout.features.field.inc
Expand Up @@ -457,7 +457,7 @@ function lbd_layout_field_default_fields() {
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => '3',
'weight' => '4',
),
'node_gallery_node_thumbnail' => array(
'label' => 'above',
Expand Down Expand Up @@ -489,6 +489,151 @@ function lbd_layout_field_default_fields() {
),
);

// Exported field: 'node-book-field_grant_edit_rights_wiki'.
$fields['node-book-field_grant_edit_rights_wiki'] = array(
'field_config' => array(
'active' => '1',
'cardinality' => '-1',
'deleted' => '0',
'entity_types' => array(),
'field_name' => 'field_grant_edit_rights_wiki',
'foreign keys' => array(
'users' => array(
'columns' => array(
'target_id' => 'uid',
),
'table' => 'users',
),
),
'indexes' => array(
'target_id' => array(
0 => 'target_id',
),
),
'locked' => '0',
'module' => 'entityreference',
'settings' => array(
'handler' => 'base',
'handler_settings' => array(
'behaviors' => array(
'views-select-list' => array(
'status' => 0,
),
),
'sort' => array(
'type' => 'none',
),
'target_bundles' => array(),
),
'target_type' => 'user',
),
'translatable' => '0',
'type' => 'entityreference',
),
'field_instance' => array(
'bundle' => 'book',
'default_value' => NULL,
'default_value_function' => '',
'deleted' => '0',
'description' => 'Add users who need to have permission to edit this wiki page and all the wiki pages that are children to this page.',
'display' => array(
'default' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => '2',
),
'node_gallery_node_thumbnail' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
'teaser' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
'entity_type' => 'node',
'field_name' => 'field_grant_edit_rights_wiki',
'label' => 'Grant edit rights',
'required' => 0,
'settings' => array(
'behaviors' => array(
'prepopulate' => array(
'status' => 0,
),
),
'nodeaccess_userreference' => array(
'all' => array(
'view' => 'view',
),
'all_published' => '0',
'author' => array(
'delete' => 0,
'update' => 'update',
'view' => 'view',
),
'author_published' => '0',
'create' => array(
'action' => 0,
'article' => 0,
'blog' => 0,
'book' => 0,
'dootrip' => 0,
'drupal_wall' => 0,
'edoovillage' => 0,
'event' => 0,
'gic' => 0,
'hub' => 0,
'labdoo_slide' => 0,
'labdoo_story' => 0,
'laptop' => 0,
'node_gallery_gallery' => 0,
'node_gallery_item' => 0,
'page' => 0,
'private_page' => 0,
'simplenews' => 0,
'slider_page' => 0,
'superhub_page' => 0,
'team' => 0,
'team_page' => 0,
'team_task' => 0,
),
'priority' => '0',
'referenced' => array(
'delete' => 0,
'deny_delete' => 0,
'deny_update' => 0,
'deny_view' => 0,
'update' => 'update',
'view' => 'view',
),
'referenced_published' => '0',
'unused' => '0',
'views' => array(
'view' => '',
'view_args' => '',
),
),
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'entityreference',
'settings' => array(
'match_operator' => 'CONTAINS',
'path' => '',
'size' => 60,
),
'type' => 'entityreference_autocomplete',
'weight' => '8',
),
),
);

// Exported field: 'node-book-field_is_first_page'.
$fields['node-book-field_is_first_page'] = array(
'field_config' => array(
Expand Down Expand Up @@ -529,7 +674,7 @@ function lbd_layout_field_default_fields() {
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => '4',
'weight' => '5',
),
'node_gallery_node_thumbnail' => array(
'label' => 'above',
Expand Down Expand Up @@ -614,7 +759,7 @@ function lbd_layout_field_default_fields() {
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => '5',
'weight' => '6',
),
'node_gallery_node_thumbnail' => array(
'label' => 'above',
Expand Down Expand Up @@ -813,10 +958,12 @@ function lbd_layout_field_default_fields() {

// Translatables
// Included for use with string extractors like potx.
t('Add users who need to have permission to edit this wiki page and all the wiki pages that are children to this page.');
t('Body');
t('Comment');
t('Enter a comma separated list of words that describe this content. The auto-completion text will also allow you to select tagged words that already exist.');
t('Enter a comma-separated list of words to describe your content.');
t('Grant edit rights');
t('Image');
t('Is this wiki page a translation of another wiki page or is this the original?');
t('Language');
Expand Down
3 changes: 2 additions & 1 deletion modules/features/lbd_layout/lbd_layout.info
Expand Up @@ -54,6 +54,7 @@ features[field][] = node-article-field_image
features[field][] = node-article-field_tags
features[field][] = node-book-body
features[field][] = node-book-field_book_language
features[field][] = node-book-field_grant_edit_rights_wiki
features[field][] = node-book-field_is_first_page
features[field][] = node-book-field_reference_book
features[field][] = node-book-field_wiki_tags
Expand Down Expand Up @@ -230,4 +231,4 @@ features[variable][] = theme_default
features[variable][] = transliteration_search
features[views_view][] = front_page
features[wysiwyg][] = full_html
mtime = 1486460347
mtime = 1486460435
4 changes: 2 additions & 2 deletions modules/features/lbd_layout/lbd_layout.strongarm.inc
Expand Up @@ -730,8 +730,8 @@ a2a_config.linkurl = \'www.labdoo.org/hubs\';';
'display' => array(
'sharethis' => array(
'default' => array(
'weight' => '2',
'visible' => TRUE,
'weight' => '3',
'visible' => FALSE,
),
),
),
Expand Down

0 comments on commit 3909101

Please sign in to comment.