3

I'd like to be able to have nodes of a certain type "lock" after fifteen minutes, so that for the first fifteen minutes after a node of that type has been created its creator can edit that node, but after that fifteen minutes has passed only users with a specific permission can edit that node.

What's the best way to achieve this result?

  • Have you already looked at the [Rules module] (drupal.org/project/rules)? It has a scheduling functionality so you can invoke a rule restricting access after some time elapsed – longboardnode Jun 22 '13 at 23:59
  • Thanks, @longboardnode! I've ended up going for the custom-coded solution below, as I was struggling to see how I could achieve the result I was after with Rules. Would be interested to hear more details on how I could do that, though! – Jim Jul 4 '13 at 12:06
9

You could do something like this:

/**
 * Implements hook_menu_alter
 */
function MY_MODULE_menu_alter(&$items){
  $items['node/%node/edit']['access callback'] = 'MY_MODULE_check_node_access';
}

/**
 * Custom menu access callback for node/%node/edit
 */
function MY_MODULE_check_node_access($op, $node){
  global $user;
  // Note $op and $node are passed in default node_menu access arguments
  // Allow bypass by users with administer nodes permission
  if (($op == 'update') && (!user_access('administer nodes'))) {
    // Allow edit access to node author if within time limit
    if ($user->uid == $node->uid) {
      $limit = variable_get('node_edit_limit', (15 * 60));
      if ((REQUEST_TIME - $node->created) > $limit) {
        drupal_set_message(t('Edit time limit exceeded'));
        return FALSE;
      } else {
        return TRUE;
      }
    }
  }
  // Fallback to regular node_access checks
  return node_access($op, $node);
}
1

Module edit_limit available for drupal 7 version since 2013-May-28 , just few days before David's answer. May be he was not aware of it that time.
Just few lines from modules page which is specific for OP's requirement.

Node edit time limit

Nodes can be limited to a given time frame. When this is used, nodes can only be edited within the time limit set by the site administrator, starting when the node is initially saved. This can be limited to a subset of content types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.