--- Z:/Joonas/Drupal6/Modules/relativity/relativity.module	Tue Apr 21 00:07:09 2009
+++ Y:/public_html/drupal6/sites/dev.ee.tut.fi.~merilai2.drupal6.opintopiiri/modules/relativity/relativity.module	Fri May 22 11:07:50 2009
@@ -8,6 +8,13 @@
  * To store this extra information, we need an auxiliary database table.
  */
 
+ /**
+ * Implementation of hook_perm().
+ */
+function relativity_perm() {
+  return array('view link operations', 'add child relations', 'remove child relations of own nodes', 'remove any child relation');
+}
+ 
 /**
  * Generates an array of named nodes keyed by node type.
  * With no args, returns relativity node types
@@ -272,7 +279,7 @@
       'page callback' => 'relativity_list_possible_children',
       'page arguments' => array(2, 4),
       'access callback' => 'relativity_access_listnodes',
-      'access arguments' => array('update', 4, 'access content'),
+      'access arguments' => array('update', 4, 'add child relations'),
       'type' => MENU_CALLBACK,
     );
 
@@ -340,7 +347,7 @@
 }
 
 function relativity_access_listnodes($op, $node, $user_access) {
-  if (node_access('update', $node) && user_access($user_access)) {
+  if (user_access($user_access)) {
     return TRUE;
   }
   else{
@@ -958,11 +965,12 @@
  * If this node is required to connect a series of nodes together, return FALSE
  */
 function relativity_may_unchild($parent, $child) {
-
-  if (!node_access('update', $parent)) {
+  
+  //If user is the author of parent node AND has permission to "remove child relations" OR has permission to "remove any child relation", then user can remove child relation
+  if (!((user_access('remove child relations of own nodes') && node_access('update', $parent)) || user_access('remove any child relation'))) {
     return FALSE;
   }
-
+  
   // check all possible child types for this parent
   foreach (node_get_types('names') as $type => $name) {
     $conduit_types = variable_get('relativity_common_child_'. $parent->type .'_'. $type, array());
@@ -981,7 +989,7 @@
  * See if current user may create a *new* child of type $child_type to a parent of type $parent_type
  */
 function relativity_may_attach_new_child_type($parent_type, $child_type) {
-  if (node_access('create', $child_type)) {
+  if (node_access('create', $child_type) && user_access('add child relations')) {
     // make sure relationship is still valid
     if (in_array($child_type, variable_get('relativity_type_'. $parent_type, array()))) {
       // make sure relatinship doesn't require a common child
@@ -1140,7 +1148,7 @@
       }
 
       // output links to attach allowed children types and remove existing children
-      if ($w = variable_get('relativity_'. $node->type .'_operations_weight', 12)) {
+      if ($w = variable_get('relativity_'. $node->type .'_operations_weight', 12) && user_access('view link operations')) {
         $node->content['relativity_operations'] = array(
           '#value' => theme('relativity_show_link_operations', $node),
           '#weight' => $w,
@@ -1703,12 +1711,12 @@
       // only offer to let user create new child if user has 'create' access
 
       // and common child relationship isn't required
-      if ($may_create && node_access('update', $parent)) {
+      if ($may_create) {
         $items[] = l(t('Create new !type', array('!type' => $type_name)), "node/add/$type/parent/$parent_nid", array('class' => 'relativity_create_'. $type));
       }
 
       // only show link to attach existing node when the potential child doesn't require a parent.
-      if ((!relativity_requires_parent($type) || relativity_multi_parent($type)) && node_access('update', $parent)) {
+      if ((!relativity_requires_parent($type) || relativity_multi_parent($type)) && user_access('add child relations')) {
         $items[] = l(t('Attach existing !type', array('!type' => $type_name)), "relativity/listnodes/$type/parent/$parent_nid", array('class' => 'relativity_attach_'. $type));
       }
     }
