diff -uprN old/acl_workflow_ng.inc new/acl_workflow_ng.inc --- old/acl_workflow_ng.inc 1970-01-01 05:30:00.000000000 +0530 +++ new/acl_workflow_ng.inc 2008-03-15 10:52:37.437500000 +0530 @@ -0,0 +1,277 @@ + array( + '#label' => t('Add user to ACL'), + '#arguments' => array( + 'user' => array('#entity' => 'user', '#label' => t('User which will be added to the ACL.')), + ), + '#module' => 'ACL', + ), + 'acl_workflow_ng_remove_user_from_acl' => array( + '#label' => t('Remove user from ACL'), + '#arguments' => array( + 'user' => array('#entity' => 'user', '#label' => t('User which will be removed from the ACL.')), + ), + '#module' => 'ACL', + ), + 'acl_workflow_ng_add_node_to_acl' => array( + '#label' => t('Add content to ACL'), + '#arguments' => array( + 'node' => array('#entity' => 'node', '#label' => t('Content')), + ), + '#module' => 'ACL', + ), + 'acl_workflow_ng_remove_node_from_acl' => array( + '#label' => t('Remove content from ACL'), + '#arguments' => array( + 'node' => array('#entity' => 'node', '#label' => t('Content')), + ), + '#module' => 'ACL', + ), + 'acl_workflow_ng_delete_whole_acl' => array( + '#label' => t('Delete ACL(s) from content'), + '#arguments' => array( + 'node' => array('#entity' => 'node', '#label' => t('Content')), + ), + '#module' => 'ACL', + ), + 'acl_workflow_ng_delete_acl' => array( + '#label' => t('Delete ACL'), + '#module' => 'ACL', + ), + ); +} + + +/* + * Action: Add a user to ACL + */ +function acl_workflow_ng_add_user_to_acl($user, $settings, &$arguments, &$log) { + $token = workflow_ng_token_replace_all(array('acl'), $settings, $arguments, $log); + //Make sure ACL exists, or create a new one + $acl_id = acl_get_id_by_name('acl', $token['acl'], TRUE); + acl_add_user($acl_id, $user->uid); +} + +/* + * Add a user to ACL form + * + * @ingroup forms + * @see acl_workflow_ng_add_user_to_acl_submit + * + */ +function acl_workflow_ng_add_user_to_acl_form($settings = array(), $argument_info) { + $form = array(); + $form['acl'] = array( + '#type' => 'textfield', + '#title' => t('ACL name'), + '#description' => t('Enter the name of the ACL. You may have a single user/node assigned to several ACL lists.'), + '#default_value' => $settings['acl'], + '#required' => TRUE, + ); + workflow_ng_token_replacement_help($form, $argument_info); + return $form; +} + +function acl_workflow_ng_add_user_to_acl_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('acl'), $form_values); + $settings = array('acl' => $form_values['acl']); + return $token + $settings; +} + +/* + * Action: Remove a user from ACL + */ +function acl_workflow_ng_remove_user_from_acl($user, $settings, &$arguments, &$log) { + //Make sure ACL exists + $token = workflow_ng_token_replace_all(array('acl'), $settings, $arguments, $log); + $acl_id = acl_get_id_by_name('acl', $token['acl'], TRUE); + if ($acl_id) { + acl_remove_user($acl_id, $user->uid); + } +} + +/* + * Remove a user from ACL + * + * @ingroup forms + * @see acl_workflow_ng_remove_user_from_acl_submit + */ + +function acl_workflow_ng_remove_user_from_acl_form($settings = array(), $argument_info) { + $form = array(); + $form['acl'] = array( + '#type' => 'textfield', + '#title' => t('ACL name'), + '#description' => t('Enter the name of the ACL, which the user will be deleted from.'), + '#default_value' => $settings['acl'], + '#required' => TRUE, + ); + workflow_ng_token_replacement_help($form, $argument_info); + return $form; +} + +function acl_workflow_ng_remove_user_from_acl_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('acl'), $form_values); + $settings = array('acl' => $form_values['acl']); + return $token + $settings; +} + + +/* + * Action: Add a node to ACL + */ +function acl_workflow_ng_add_node_to_acl($node, $settings, &$arguments, &$log) { + //Make sure ACL exists, or create a new one + $token = workflow_ng_token_replace_all(array('acl'), $settings, $arguments, $log); + $acl_id = acl_get_id_by_name('acl', $token['acl'], TRUE); + acl_node_add_acl($node->nid, $acl_id, (boolean)$settings['access_permissions']['view'], (boolean)$settings['access_permissions']['edit'], (boolean)$settings['access_permissions']['delete']); + //Make sure new node access grants are written. + return array('node' => $node); +} + +/* + * Add a node to ACL + * + * @ingroup forms + * @see acl_workflow_ng_add_node_to_acl_submit + */ +function acl_workflow_ng_add_node_to_acl_form($settings = array(), $argument_info) { + $form = array(); + $form['acl'] = array( + '#type' => 'textfield', + '#title' => t('ACL name'), + '#description' => t('Enter the name of the ACL.'), + '#default_value' => $settings['acl'], + '#required' => TRUE, + ); + workflow_ng_token_replacement_help($form, $argument_info); + $form['access_permissions'] = array( + '#type' => 'checkboxes', + '#title' => t('Access permissions'), + '#description' => t('Select the operations that this ACL will control.'), + '#default_value' => $settings['access_permissions'], + '#options' => array( + 'view' => t('View'), + 'edit' => t('Edit'), + 'delete' => t('Delete'), + ), + ); + return $form; +} + +function acl_workflow_ng_add_node_to_acl_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('acl'), $form_values); + $settings = array('acl' => $form_values['acl'], 'access_permissions' => $form_values['access_permissions']); + return $token + $settings; +} + +/* + * Action: Remove a node from ACL + */ +function acl_workflow_ng_remove_node_from_acl($node, $settings, &$arguments, &$log) { + //Make sure ACL exists + $token = workflow_ng_token_replace_all(array('acl'), $settings, $arguments, $log); + $acl_id = acl_get_id_by_name('acl', $token['acl']); + if ($acl_id) { + $node_exists = acl_node_remove_acl($node->nid, $acl_id); + if ($node_exists) { + //Make sure new node access grants are written. + return array('node' => $node); + } + } +} + +/* + * Remove a node from ACL + * + * @ingroup forms + * @see acl_workflow_ng_remove_node_from_acl_submit + */ +function acl_workflow_ng_remove_node_from_acl_form($settings = array(), $argument_info) { + $form = array(); + $form['acl'] = array( + '#type' => 'textfield', + '#title' => t('ACL name'), + '#description' => t('Enter the name of the ACL which the content will be removed from.'), + '#default_value' => $settings['acl'], + '#required' => TRUE, + ); + workflow_ng_token_replacement_help($form, $argument_info); + return $form; +} + +function acl_workflow_ng_remove_node_from_acl_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('acl'), $form_values); + $settings = array('acl' => $form_values['acl']); + return $token + $settings; +} + +/* + * Action: Delete ACL from node + */ +function acl_workflow_ng_delete_whole_acl($node, $settings, &$arguments, &$log) { + //Make sure ACL exists + $node_exists = acl_node_clear_acls($node->nid, 'acl'); + if ($node_exists) { + //Make sure new node access grants are written. + return array('node' => $node); + } +} + + +/* + * Action: Delete ACL + */ +function acl_workflow_ng_delete_acl($settings, &$arguments, &$log) { + //Make sure ACL exists + $token = workflow_ng_token_replace_all(array('acl'), $settings, $arguments, $log); + $acl_id = acl_get_id_by_name('acl', $token['acl']); + if ($acl_id) { + //ACL will take care of writing the node grants to the database. + acl_delete_acl($acl_id, TRUE); + } +} + +/* + * Delete ACL + * + * @ingroup forms + * @see acl_workflow_ng_delete_acl_submit + */ +function acl_workflow_ng_delete_acl_form($settings = array(), $argument_info) { + $form = array(); + $form['acl'] = array( + '#type' => 'textfield', + '#title' => t('ACL name'), + '#description' => t('Enter the name of the ACL which will be deleted. Note that this action may load a large number of nodes, possibly more than + your web server can take without exhausting memory or timing out; this would leave the database in an inconsistent state!'), + '#default_value' => $settings['acl'], + '#required' => TRUE, + ); + workflow_ng_token_replacement_help($form, $argument_info); + return $form; +} + +function acl_workflow_ng_delete_acl_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('acl'), $form_values); + $settings = array('acl' => $form_values['acl']); + return $token + $settings; +} + + + +