30

I want to let users unpublish and publish their own content. By default, you have to give "administer nodes" permission for users to be able to unpublish or publish content. That is way to broad though. I want to let users unpublish or publish a node if and only if they created it. This also means they should be able to view unpublished nodes if and only if they created it.

20

A UI approach which I have used on some sites is the Override Node Options module, adds permissions similar to those that my other answer provides, plus a bunch extra.

  • This seems to be the simplest approach... and it is currently working for me. Thanks! – Chaulky Mar 9 '11 at 15:00
  • This is the best as you can allow publish & sticky without administer nodes :) – Alex Weber Mar 13 '11 at 22:37
  • Looks like a great module to deal with this issue. – zilverdistel Apr 29 '11 at 11:03
20

We always use the Publish Content module for that. It adds a number of fine-grained permissions and a publish/unpublish tab on nodes.

This module

  • enables granular publish and unpublish permissions:
    • global (un/publish any content)
    • per "node type" (un/publish any [nodetype] content)
    • per user (un/publish own [nodetype] content
  • adds a "Publish/Unpublish" tab to the node page for one-click un/publishing.
  • exposes publish/unpublish links to your views, making it easy to streamline workflows for reviewers, editors and publishers.
  • is lightweight and always will be.
9

I'd recommend using the Revisioning Module which gives you a few benefits over the above methods. One of course is that it is a fully maintained module and thus there will be a lot of eyes on the code and plenty of bug fixes. Two, you will get more features to fit this into your overall workflow.

For your use case, gives your users both the "creator" permissions and the "moderator" permissions, so they can basically moderate their own content, but as says in the module description, they are not given god-like powers such as giving 'administer nodes' would give.

  • This is a very interesting option, but there's way more in there than I need. Thought I'm glad I know about it know, I can think of some other sites it would come in handy. – Chaulky Mar 9 '11 at 14:59
6

There is a module that does this, but I can't quite remember the name. I actually felt that the approach the module took was too cumbersome, it had a lot of code when the actual important code was only really one line wrapped with some permission logic.

This is my version of the code:

function MYMODULE_perm() {
  $perms[] = 'administer status of any content';

  foreach (node_get_types() as $type) {
    if (isset($type->type)) {
      $perms[] = 'administer status of any '. check_plain($type->type) .' content';
      $perms[] = 'administer status of own '. check_plain($type->type) .' content';
    }
  }

  return $perms;
}

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#id'] == 'node-form' && $form_id == "{$form['#node']->type}_node_form" && _MYMODULE_access($form['#node']->type)) {
    if ($form['options']['#access'] == FALSE) {
      $form['options']['#access'] = TRUE;
    }
  }
}

function _MYMODULE_access($type) {
  return user_access('administer status of any content')
      || user_access('administer status of any ' . check_plain($type) . ' content')
      || user_access('administer status of own ' . check_plain($type) . ' content');
}

That adds a few extra permissions that allow you to allow users to publish/unpublish their own or all of a content type, and all content types, set how you wish.

  • Thanks, that looks pretty good, makes sense. What about being able to view their unpublished content though? If they can't view it, how will the publish it? – Chaulky Mar 3 '11 at 5:32
  • Shouldn't affect that, IIRC a user can see their un-published content whether or not that have 'administer nodes'. – Decipher Mar 3 '11 at 5:33
3

I just want to update Decipher answer, witch seams to me the best approach if you do not want to add another module, to fit for Drupal 7 :

/**
 * Implements hook_permission().
 */
function MYMODULE_permission() {  
  $perms = array(
    'administer status of any content' => array(
      'title' => t('Administer status for all content type'),
      'description' => t(''),
      'restrict access' => true
    ),
  );

  foreach (node_type_get_types() as $type) {
    if (isset($type->type)) {
      $perm_types = array(
        'administer status of any '. check_plain($type->type) .' content' => array(
          'title' => t('Administer status of any '. check_plain($type->type) .' content'),
          'description' => t(''),
        ),

        'administer status of own '. check_plain($type->type) .' content' => array(
          'title' => t('Administer status of own '. check_plain($type->type) .' content'),
          'description' => t(''),
        ),
      );
      $perms = array_merge($perms,$perm_types);
    }
  }

  return $perms;
}


function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if (preg_match('/_node_form$/', $form_id) && _MYMODULE_access($form['#node']->type)) {
    if ($form['options']['#access'] == FALSE) {
      $form['options']['#access'] = TRUE;
    }
  }
}

function _MYMODULE_access($type) {
  return user_access('administer status of any content')
      || user_access('administer status of any ' . check_plain($type) . ' content')
      || user_access('administer status of own ' . check_plain($type) . ' content');
}
  • there is a typo. change $perms_type to $perm_types - plus the any/own status is not checked .. – rémy Jul 10 '13 at 6:36
0

You can achieve this by combining the power of the Flag and Rules modules.

  1. Create a new Flag Publish and give users permission to only flag their own content.
  2. Next, add a new Rule that triggers when a node is flagged and that publishes the flagged node. Similarly, create a second Rule that unpublishes nodes which are unflagged under Publish.
  3. Finally, give users permission to see their own unpublished nodes and add a Publish link to the node's pages.
-1

The content access module should cover what you want.

This module allows you to manage permissions for content types by role and author. It allows you to specifiy custom view, edit and delete permissions for each content type. Optionally you can enable per content access settings, so you can customize the access for each content node.

  • 1
    Bit of a vague answer. If this is preferable to Decipher's answer, maybe you could elaborate on the benefits of this approach? – Chris Cohen Mar 3 '11 at 15:35
  • The Content Access module doesn't actually solve the problem, it adds the ability to set View, Edit and Delete by role but not Publish. – Decipher Mar 4 '11 at 0:14

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.