Loading content_access.admin.inc +13 −5 Changes for content_access.admin.inc: 13 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -34,11 +34,7 @@ function content_access_page(&$form_state, $node) { '#tree' => TRUE, ); foreach (array('view', 'update', 'delete') as $op) { $acl_id = acl_get_id_by_name('content_access', $op .'_'. $node->nid); if (!$acl_id) { // Create one: $acl_id = acl_create_new_acl('content_access', $op .'_'. $node->nid); } $acl_id = content_access_get_acl_id($node, $op); acl_node_add_acl($node->nid, $acl_id, $op == 'view', $op == 'update', $op == 'delete', content_access_get_settings('priority', $node->type)); $form['acl'][$op] = acl_edit_form($acl_id, t('Grant !op access', array('!op' => $op))); $form['acl'][$op]['#collapsed'] = !isset($_POST['acl_'. $acl_id]) && !unserialize($form['acl'][$op]['user_list']['#default_value']); Loading Loading @@ -395,6 +391,18 @@ function _content_access_get_node_permissions($type) { return array_filter(array_map('content_access_get_permission_by_op', _content_access_get_operations(), array_fill(0, 6, $type))); } /** * Gets the content access acl id of the node. */ function content_access_get_acl_id($node, $op) { $acl_id = acl_get_id_by_name('content_access', $op .'_'. $node->nid); if (!$acl_id) { // Create one: $acl_id = acl_create_new_acl('content_access', $op .'_'. $node->nid); } return $acl_id; } /** * Detaches all our ACLs for the nodes of the given type. */ Loading content_access.module +1 −1 Changes for content_access.module: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -380,7 +380,7 @@ function content_access_save_per_node_settings($node, $settings) { } /** * Delets custom per node settings, so that content type defaults are used again. * Deletes custom per node settings, so that content type defaults are used again. */ function content_access_delete_per_node_settings($node) { db_query("DELETE FROM {content_access} WHERE nid = %d", $node->nid); Loading content_access.rules.inc +92 −1 Changes for content_access.rules.inc: 92 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ function _content_access_rules_check_setting($node) { * Implementation of hook_action_info(). */ function content_access_rules_action_info() { return array( $items = array( 'content_access_action_grant_node_permissions' => array( 'label' => t('Grant content permissions by role'), 'arguments' => array( Loading @@ -63,6 +63,27 @@ function content_access_rules_action_info() { 'module' => 'Content access', ), ); if (module_exists('acl')) { $items += array( 'content_access_action_acl_grant_access' => array( 'label' => t('Grant access for a user'), 'arguments' => array( 'node' => array('type' => 'node', 'label' => t('Content')), 'user' => array('type' => 'user', 'label' => t('User')), ), 'module' => 'Content access', ), 'content_access_action_acl_revoke_access' => array( 'label' => t('Revoke access for a user'), 'arguments' => array( 'node' => array('type' => 'node', 'label' => t('Content')), 'user' => array('type' => 'user', 'label' => t('User')), ), 'module' => 'Content access', ), ); } return $items; } /** Loading Loading @@ -112,6 +133,76 @@ function content_access_action_revoke_node_permissions_submit(&$settings, $form, } /** * Action implementation: Grant access for a user. */ function content_access_action_acl_grant_access($node, $user, $settings) { if (_content_access_rules_check_setting($node)) { module_load_include('inc', 'content_access', 'content_access.admin'); foreach ($settings['ops'] as $op) { $acl_id = content_access_get_acl_id($node, $op); acl_add_user($acl_id, $user->uid); } // A following node_save() updates the grants for us. return array('node' => $node); } } function content_access_action_acl_grant_access_form($settings, &$form) { $settings += array('ops' => array('view', 'update', 'delete')); $form['settings']['ops'] = array( '#type' => 'checkboxes', '#options' => drupal_map_assoc(array('view', 'update', 'delete')), '#title' => t('Operations to grant access for'), '#default_value' => $settings['ops'], ); } function content_access_action_acl_grant_access_submit(&$settings, $form, $form_state) { $settings['ops'] = array_filter($settings['ops']); } function content_access_action_acl_grant_access_help() { return t("Note that this action is not going to revoke access for not chosen operations."); } function content_access_action_acl_grant_access_label($settings, $argument_labels) { return t('Grant access for @user.', $argument_labels); } /** * Action implementation: Revoke access for a user. */ function content_access_action_acl_revoke_access($node, $user, $settings) { if (_content_access_rules_check_setting($node)) { module_load_include('inc', 'content_access', 'content_access.admin'); foreach ($settings['ops'] as $op) { $acl_id = content_access_get_acl_id($node, $op); acl_remove_user($acl_id, $user->uid); } // A following node_save() updates the grants for us. return array('node' => $node); } } function content_access_action_acl_revoke_access_form($settings, &$form) { $settings += array('ops' => array('view', 'update', 'delete')); $form['settings']['ops'] = array( '#type' => 'checkboxes', '#options' => drupal_map_assoc(array('view', 'update', 'delete')), '#title' => t('Operations to revoke access for'), '#default_value' => $settings['ops'], ); } function content_access_action_acl_revoke_access_submit(&$settings, $form, $form_state) { $settings['ops'] = array_filter($settings['ops']); } function content_access_action_acl_revoke_access_help() { return t("Note that this action is only able to revoke access that has been previously granted with the help of the content access module."); } function content_access_action_acl_revoke_access_label($settings, $argument_labels) { return t('Revoke access for @user.', $argument_labels); } /** * Action implementation: Reset permissions for a node. */ Loading Loading
content_access.admin.inc +13 −5 Changes for content_access.admin.inc: 13 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -34,11 +34,7 @@ function content_access_page(&$form_state, $node) { '#tree' => TRUE, ); foreach (array('view', 'update', 'delete') as $op) { $acl_id = acl_get_id_by_name('content_access', $op .'_'. $node->nid); if (!$acl_id) { // Create one: $acl_id = acl_create_new_acl('content_access', $op .'_'. $node->nid); } $acl_id = content_access_get_acl_id($node, $op); acl_node_add_acl($node->nid, $acl_id, $op == 'view', $op == 'update', $op == 'delete', content_access_get_settings('priority', $node->type)); $form['acl'][$op] = acl_edit_form($acl_id, t('Grant !op access', array('!op' => $op))); $form['acl'][$op]['#collapsed'] = !isset($_POST['acl_'. $acl_id]) && !unserialize($form['acl'][$op]['user_list']['#default_value']); Loading Loading @@ -395,6 +391,18 @@ function _content_access_get_node_permissions($type) { return array_filter(array_map('content_access_get_permission_by_op', _content_access_get_operations(), array_fill(0, 6, $type))); } /** * Gets the content access acl id of the node. */ function content_access_get_acl_id($node, $op) { $acl_id = acl_get_id_by_name('content_access', $op .'_'. $node->nid); if (!$acl_id) { // Create one: $acl_id = acl_create_new_acl('content_access', $op .'_'. $node->nid); } return $acl_id; } /** * Detaches all our ACLs for the nodes of the given type. */ Loading
content_access.module +1 −1 Changes for content_access.module: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -380,7 +380,7 @@ function content_access_save_per_node_settings($node, $settings) { } /** * Delets custom per node settings, so that content type defaults are used again. * Deletes custom per node settings, so that content type defaults are used again. */ function content_access_delete_per_node_settings($node) { db_query("DELETE FROM {content_access} WHERE nid = %d", $node->nid); Loading
content_access.rules.inc +92 −1 Changes for content_access.rules.inc: 92 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ function _content_access_rules_check_setting($node) { * Implementation of hook_action_info(). */ function content_access_rules_action_info() { return array( $items = array( 'content_access_action_grant_node_permissions' => array( 'label' => t('Grant content permissions by role'), 'arguments' => array( Loading @@ -63,6 +63,27 @@ function content_access_rules_action_info() { 'module' => 'Content access', ), ); if (module_exists('acl')) { $items += array( 'content_access_action_acl_grant_access' => array( 'label' => t('Grant access for a user'), 'arguments' => array( 'node' => array('type' => 'node', 'label' => t('Content')), 'user' => array('type' => 'user', 'label' => t('User')), ), 'module' => 'Content access', ), 'content_access_action_acl_revoke_access' => array( 'label' => t('Revoke access for a user'), 'arguments' => array( 'node' => array('type' => 'node', 'label' => t('Content')), 'user' => array('type' => 'user', 'label' => t('User')), ), 'module' => 'Content access', ), ); } return $items; } /** Loading Loading @@ -112,6 +133,76 @@ function content_access_action_revoke_node_permissions_submit(&$settings, $form, } /** * Action implementation: Grant access for a user. */ function content_access_action_acl_grant_access($node, $user, $settings) { if (_content_access_rules_check_setting($node)) { module_load_include('inc', 'content_access', 'content_access.admin'); foreach ($settings['ops'] as $op) { $acl_id = content_access_get_acl_id($node, $op); acl_add_user($acl_id, $user->uid); } // A following node_save() updates the grants for us. return array('node' => $node); } } function content_access_action_acl_grant_access_form($settings, &$form) { $settings += array('ops' => array('view', 'update', 'delete')); $form['settings']['ops'] = array( '#type' => 'checkboxes', '#options' => drupal_map_assoc(array('view', 'update', 'delete')), '#title' => t('Operations to grant access for'), '#default_value' => $settings['ops'], ); } function content_access_action_acl_grant_access_submit(&$settings, $form, $form_state) { $settings['ops'] = array_filter($settings['ops']); } function content_access_action_acl_grant_access_help() { return t("Note that this action is not going to revoke access for not chosen operations."); } function content_access_action_acl_grant_access_label($settings, $argument_labels) { return t('Grant access for @user.', $argument_labels); } /** * Action implementation: Revoke access for a user. */ function content_access_action_acl_revoke_access($node, $user, $settings) { if (_content_access_rules_check_setting($node)) { module_load_include('inc', 'content_access', 'content_access.admin'); foreach ($settings['ops'] as $op) { $acl_id = content_access_get_acl_id($node, $op); acl_remove_user($acl_id, $user->uid); } // A following node_save() updates the grants for us. return array('node' => $node); } } function content_access_action_acl_revoke_access_form($settings, &$form) { $settings += array('ops' => array('view', 'update', 'delete')); $form['settings']['ops'] = array( '#type' => 'checkboxes', '#options' => drupal_map_assoc(array('view', 'update', 'delete')), '#title' => t('Operations to revoke access for'), '#default_value' => $settings['ops'], ); } function content_access_action_acl_revoke_access_submit(&$settings, $form, $form_state) { $settings['ops'] = array_filter($settings['ops']); } function content_access_action_acl_revoke_access_help() { return t("Note that this action is only able to revoke access that has been previously granted with the help of the content access module."); } function content_access_action_acl_revoke_access_label($settings, $argument_labels) { return t('Revoke access for @user.', $argument_labels); } /** * Action implementation: Reset permissions for a node. */ Loading