summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Stevenson2008-04-25 02:03:14 (GMT)
committer Karen Stevenson2008-04-25 02:03:14 (GMT)
commitd0cb2dbe00265b962a2a0f99753230641fae439a (patch)
treed18124d993f382966466aa8c9b8b6cd9eb65e4de
parent833886f8ba55295c91545ca2a5d2c4dc093d3a69 (diff)
#63240 Implement new views access callback feature and add install file with warning that permissions need to be set, patch by Moshe Weitzman.
-rw-r--r--includes/content.views.inc18
-rw-r--r--modules/content_permissions/content_permissions.install8
-rw-r--r--modules/content_permissions/content_permissions.module21
3 files changed, 19 insertions, 28 deletions
diff --git a/includes/content.views.inc b/includes/content.views.inc
index 55dae8f..f5c246f 100644
--- a/includes/content.views.inc
+++ b/includes/content.views.inc
@@ -102,6 +102,9 @@ function content_views_field_views_data($field) {
'additional fields' => $columns,
'content_field_name' => $field['field_name'],
'allow_empty' => TRUE,
+ // Access control modules should implement content_views_access_callback().
+ 'access callback' => 'content_views_access_callback',
+ 'access arguments' => array($field),
),
'argument' => array(
'field' => $columns[0],
@@ -260,21 +263,6 @@ class views_handler_field_content extends views_handler_field_node {
$this->content_field = content_fields($this->definition['content_field_name']);
}
- /**
- * This provides a method of controlling field-level access in Views.
- */
- function access() {
- // Avoid FALSE returns for non-existant hooks by using module_implements()
- // to check only modules that implement the hook.
- $modules = module_implements('content_views_access');
- foreach ($modules as $module) {
- if (module_invoke($module, 'content_views_access', $this->definition['content_field_name']) === FALSE) {
- return FALSE;
- }
- }
- return parent::access();
- }
-
function options(&$options) {
parent::options($options);
$field = $this->content_field;
diff --git a/modules/content_permissions/content_permissions.install b/modules/content_permissions/content_permissions.install
new file mode 100644
index 0000000..74c95fa
--- /dev/null
+++ b/modules/content_permissions/content_permissions.install
@@ -0,0 +1,8 @@
+<?php
+// $Id$
+/**
+ * Implementation of hook_install().
+ */
+function content_permissions_install() {
+ drupal_set_message(t('Please <a href="!url">configure your field permissions</a> immediately. All fields are inaccessible by default.', array('!url' => url('admin/user/access', array('fragment' => 'content_permissions')))));
+} \ No newline at end of file
diff --git a/modules/content_permissions/content_permissions.module b/modules/content_permissions/content_permissions.module
index 997800f..5104144 100644
--- a/modules/content_permissions/content_permissions.module
+++ b/modules/content_permissions/content_permissions.module
@@ -1,12 +1,5 @@
<?php
-
-/**
- * TODO:
- * Views access implementation
- * Fieldgroups
- */
-
-
+// $Id$
/**
* Implementation of hook_perm().
*/
@@ -19,7 +12,7 @@ function content_permissions_perm() {
}
/**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_alter(). Remove inaccessible fields from node display.
*/
function content_permissions_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
@@ -33,7 +26,7 @@ function content_permissions_form_alter(&$form, $form_state, $form_id) {
}
/**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_nodeapi(). Remove inaccessible fields from node display.
*/
function content_permissions_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'view') {
@@ -47,8 +40,10 @@ function content_permissions_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
}
/**
- * Implementation of hook_content_views_access().
+ * The default field access callback. Remove inaccessible fields from Views.
+ *
+ * @see content_views_field_views_data().
*/
-function content_permissions_content_views_access($field_name) {
- return user_access('view '. $field_name);
+function content_views_access_callback($field) {
+ return user_access('view '. $field['field_name']);
} \ No newline at end of file