Even with workflow (settings -> content types -> story -> configure -> workflow) enabling "Access restricted for non-premium users," new content created by non-administrators does not respect this option. For admins, the premium access is checked, but for non-admins -- regardless of the workflow setting for any content type -- premium access for content is not enabled. Admins or users with publishing options control must manually enabled "Access restricted for non-premium users" on the new content.

Comments

simon rawson’s picture

I would have thought that this is not a bug, rather this was how the module was written to work. (That is not to say that is correct!)

The "premium" option is tagged onto the "Publishing Option" in the node form, the rest of which is only available to users who have the "administer nodes" permission.

Maybe "make nodes premium" should be a separate permission and there shoud be a separate fieldset on the node form?

vph’s picture

I too have this problem. I think it's an oversight. The reason admin sees the checkbox is that he has the option to UNCHECK it (i.e. making the node non-premium even thought it is set premium). If, however, a node is supposed to be premium, then it should be premium by default and a non-admin user can not make it non-premium.

vph’s picture

Status: Active » Needs review

Here is a patch.

--- premium.module~     2006-07-19 13:01:46.000000000 -0400
+++ premium.module      2006-09-09 15:43:04.000000000 -0400
@@ -81,13 +81,15 @@
 function premium_nodeapi(&$node, $op, $teaser) {
   switch ($op) {

-    case 'delete':
     case 'insert':
+       $node->premium = in_array('premium', variable_get("node_options_$node->type",array()));
+    case 'delete':
     case 'update':
       if ($node->nid) {
         db_query('DELETE FROM {premium} WHERE nid = %d', $node->nid);
         if ($op == 'delete') return;
       }
+
       if ($node->premium) {
         _premium_offset($node, $start_ts = 0, $end_ts = 0);
         db_query('INSERT INTO {premium} (nid, start_ts, end_ts) VALUES ( %d, %d, %d )'

Or if you want, replace the premium_nodeapi with this new one

function premium_nodeapi(&$node, $op, $teaser) {
  switch ($op) {
    
    case 'insert':
       $node->premium = in_array('premium', variable_get("node_options_$node->type",array()));
    case 'delete':
    case 'update':
      if ($node->nid) {
        db_query('DELETE FROM {premium} WHERE nid = %d', $node->nid);
        if ($op == 'delete') return;
      }
      if ($node->premium) {
        _premium_offset($node, $start_ts = 0, $end_ts = 0);
        db_query('INSERT INTO {premium} (nid, start_ts, end_ts) VALUES ( %d, %d, %d )'
          , $node->nid, $start_ts, $end_ts);
      }
      return;
      
    case 'load':
      return array('premium' => (int) db_result(db_query(
      		'SELECT 1 FROM {premium}  WHERE nid = %d 
    			AND ( start_ts = 0 OR start_ts > NOW()) AND end_ts < NOW()', $node->nid)));
      
    case 'view':
      $node->premium_access = true;

      global $user;
      if (!$node->premium || user_access('access premium content')) {
        return;                  // not premium content or user has privileges
      }
      if ($teaser) {
        return;                  // not viewing the body
      }
      foreach (module_implements('premium_access') as $name) {
        $function = $name.'_premium_access';
        if ($function($user, $node)) {
          return;                // access granted explicitly
        }
      }
  
      $node->premium_access = false;
      $node->body = theme('premium_body', $node);
  }
  return;
} 
allie micka’s picture

Status: Needs review » Fixed

Fixed in HEAD. Thanks a lot y'all!

Anonymous’s picture

Status: Fixed » Closed (fixed)