On the function anonymizer_form_submit, the code for anonymize and unanonymize nodes must work only when the node is being anonymized or were anonymized previously in order to unanonymize.

I think this is critical.

Comments

dannymontalvo’s picture

Title: The code for anonymize and unanonymize is working incorrectly » When a user submit a node_form configured for anonymize nodes, change options for anonymize a node is working incorrectly

Hello,

I am assuming that you're familiar with the module, and configured correctly to work with some content types.
I tested the module to anonymize a node, and unanonymize nodes(revert back to original author), changing the checkbox option on the node_form for anonymizing and saving, what i am looking is a wrong functionality, something is bad on the function anonymizer_form_submit.

I hope that explain in a more detail the problem.
Cheers

dannymontalvo’s picture

Take a look to the code for the function anonymizer_form_submit

/**
 * Submit handler for node form.
 */
function anonymizer_form_submit($form, &$form_state) {
  // Get context
  $set_anon = $form_state['values']['anonymous'] == '1';

  $author = anonymizer_get_form_author($form, $form_state);

  if (isset($form_state['values']['anonymous'])) {
    form_set_value($author['item'], $form_state['values']['anonymizer']['name'], $form_state);
    form_set_value($form['uid'], $form_state['values']['anonymizer']['uid'], $form_state);
  }
  // Anonymize post
  if ($set_anon && !$author['real_uid']) {
    // Change user ID
    $anon_user = user_load(array('uid' => variable_get('anonymizer_author', 0)));
    form_set_value($author['item'], $anon_user->name, $form_state);
    form_set_value($form['uid'], $anon_user->uid, $form_state);
  }
  // Revert to original author
  elseif (!$set_anon && $author['real_uid'] > 0) {
    $anon_user = user_load(array('uid' => $author['real_uid']));
    form_set_value($author['item'], $anon_user->name, $form_state);
  }
}

I can't understand what is done on the first condition on the function, I think that is equivalent to the code of the section for "Anonymize post". maybe that can be the source of the bug.

Cheers

dannymontalvo’s picture

StatusFileSize
new2.14 KB

Anyway, I have a patch that seems to correct the bug, and were tested. I think that could be better but for now seems to be ok.

gaele’s picture

StatusFileSize
new1.93 KB

Updated patch

gaele’s picture

Status: Active » Reviewed & tested by the community
develcuy’s picture

Status: Reviewed & tested by the community » Needs work

@gaele thanks for the patch but you should not RTBC your own code ;)

develcuy’s picture

Status: Needs work » Reviewed & tested by the community

@dannymontalvo solid patch

develcuy’s picture

Status: Reviewed & tested by the community » Fixed

@gaele, just seen that you fixed a typo, next time please comment your changes. Thanks for your contribution to you both!

Status: Fixed » Closed (fixed)
Issue tags: -anonymizer, -hidden author

Automatically closed -- issue fixed for 2 weeks with no activity.