I have an issue the same as

http://drupal.org/node/235956

But instead of using the bio module I'm using Content Profile.

Basically I need an administrator to approve registrations, but as I have profile fields in the registration, the user is created as 'blocked' and their profile node is set as 'published'. The profile then appears in the user directory before they are verified.

What is the best approach to get around this?

Comments

mattfielding’s picture

I decided to write a module to handle this. This will be my first attempt at writing one!

It will add a trigger and an action.

eliza411’s picture

This would be incredibly useful . . . I'd love to use it when you're done. :)

mattfielding’s picture

I made a start and almost got there before getting sidetracked. Will return to this next week hopefully.

eliza411’s picture

If you want to share your start, I have someone who would finish and share it back. If not, we can start on our own solution and we'll post when we get there.

vivianspencer’s picture

subscribing

vivianspencer’s picture

Why not just use the Rules module for now? Below is the export of a rule I created to perform this needed functionality

array (
  'rules' => 
  array (
    'rules_1' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_update',
      '#label' => 'publish profile upon confirmation',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#info' => 
          array (
            'label' => 'Execute custom PHP code',
            'module' => 'PHP',
            'eval input' => 
            array (
              0 => 'code',
            ),
          ),
          '#name' => 'rules_condition_custom_php',
          '#settings' => 
          array (
            'code' => 'return  (!empty($account->login)) ? true : false;',
            'vars' => 
            array (
              0 => 'account',
            ),
          ),
          '#type' => 'condition',
          '#weight' => 0,
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#type' => 'action',
          '#settings' => 
          array (
            'type' => 'profile',
            '#argument map' => 
            array (
              'user' => 'account',
              'profile_node' => 'profile_node',
            ),
          ),
          '#name' => 'content_profile_action_load',
          '#info' => 
          array (
            'label' => 'Load updated user\'s Profile',
            'arguments' => 
            array (
              'user' => 
              array (
                'type' => 'user',
                'label' => 'User, whose profile should be loaded',
              ),
            ),
            'new variables' => 
            array (
              'profile_node' => 
              array (
                'type' => 'node',
                'label' => 'Content Profile',
              ),
            ),
            'module' => 'Content Profile',
          ),
          '#weight' => 0,
        ),
        1 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'label' => 'Publish Content Profile',
            'module' => 'Node',
            'arguments' => 
            array (
              'node' => 
              array (
                'label' => 'Content',
                'type' => 'node',
              ),
            ),
            'base' => 'rules_core_action_execute',
            'action_name' => 'node_publish_action',
            'configurable' => false,
            'label callback' => 'rules_core_node_label_callback',
          ),
          '#name' => 'rules_core_node_publish_action',
          '#settings' => 
          array (
            'auto_save' => 1,
            '#argument map' => 
            array (
              'node' => 'profile_node',
            ),
          ),
          '#type' => 'action',
        ),
      ),
    ),
  ),
  'rule_sets' => 
  array (
  ),
)
eliza411’s picture

I'd never used the Rules module before. I installed it and adjusted the rule above to meet my specific needs, which were to publish and unpublish the profile when a user was made active or blocked. Thank you.

fago’s picture

Perhaps you could export your rules too and add a short tutorial in the handbooks? -> A good place to post it would be http://drupal.org/node/298483.

joostvdl’s picture

#7: Is there an export of your ruleset available somewhere?

nedjo’s picture

Here's some custom code that will synchronize the user status to content node status:


/**
 * Implementation of hook_nodeapi().
 *
 * @todo: delete this function when upgrading to D7. It is replaced by hook_node_[op].
 */
function example_nodeapi(&$node, $op) {
  switch ($op) {
    case 'update':
      example_node_update($node);
      break;
  }
}

/**
 * Implement hook_node_update().
 */
function example_node_update(&$node) {
  _example_sync_user($node);
}

/**
 * Synchronize a user's status to that of its corresponding content profile.
 */
function _example_sync_user($node) {
  if (is_content_profile($node)) {
    $user = user_load($node->uid);
    if ($user && ($user->status != $node->status)) {
      $user->status = $node->status;
      user_save($user);
      $status = array(t('blocked'), t('active'));
      drupal_set_message(t('Status for user %name set to !status.', array('%name' => $user->name, '!status' => $status[$user->status])));
    }
  }
}

nedjo’s picture

And the converse for synchronizing content profile status when a user is blocked/unblocked (thought not that this is not compatible with the code in #10, due to the way one calls the other):


/**
 * Implement hook_user().
 *
 * @todo: delete this function when upgrading to D7. It is replaced by hook_user_[op].
 */
function example_user($op, &$edit, &$user) {
  switch ($op) {
    case 'after_update':
      example_user_after_update($edit, $user);
      break;
  }
}

/**
 * Implement hook_user_update().
 */
function example_user_after_update(&$edit, &$user) {
  _example_sync_nodes($user);
}

/**
 * Synchronize the status of all content profile nodes to the status of their corresponding
 * user.
 */
function _example_sync_nodes($user) {
  foreach (content_profile_get_types('names') as $type => $type_name) {
    $node = node_load(array('type' => $type, 'uid' => $user->uid));
    if ($node && ($user->status != $node->status)) {
      $node->status = $user->status;
      node_save($node);
      $status = array(t('unpublished'), t('published'));
      drupal_set_message(t('Status for content profile %title set to !status.', array('%title' => $node->title, '!status' => $status[$node->status])));
    }
  }
}

laroccadahouse’s picture

I would like to have any content that a blocked user is the author of to be unpublished and set to a specific workflow state (i.e., in draft). I wanted to use a rule to do this, but I couldn't figure out how to trigger the rule when a user's status is changed.

I am using the Inactive User module to set the users status automatically after a certain amount of time of inactivity.

fago’s picture

Try you using rules, you could configure it with it. -> http://drupal.org/project/rules
Use the "user has been updated" event and compare the user status using the token.

neclimdul’s picture

Version: 6.x-1.0-beta3 » 6.x-1.0

This would be handy. I couldn't find anyway to do this with rules because status wasn't an exposed token. Nedjo's psuedo module seems to be working great.