Problem/Motivation

When adding a non-authenticated Twitter account, either in the Twitter admin page (/admin/config/services/twitter) or in the user profile page itself (user/%uid/edit/twitter), the code just adds the uid of the logged in user to the twitter_accounts.uid column.

function twitter_non_auth_account_form_submit($form, &$form_state) {
  $name = $form_state['values']['screen_name'];
  $twitter = twitter_connect();
  $twitter_account = $twitter->users_show($name, FALSE);
  if (!isset($twitter_account->id)) {
    form_set_error('screen_name', t('Could not add the Twitter account <em>@name</em>. ' .
      'Check the recent messages log.', array('@name' => $name)));
  }
  else {
    global $user;
    $twitter_account->uid = $user->uid;
    twitter_account_save($twitter_account, FALSE);
    drupal_set_message(t('Twitter account added successfully'));
  }
}

This causes a problem when you want to create a block of a user's tweets and display them on the user's profile page. Following the docs, you would clone the default Blocks display and add a contextual filter of the uid (the way the docs describe it is pretty inflexible in that it suggests adding a hardocded uid default value, when you can actually just use "User ID from URL"). The generated query joins the users table on the twitter_account table:

LEFT JOIN {users} users ON twitter_account.uid = users.uid

The problem is that since the form submit code just adds the logged in user id, if I'm an administrator adding Twitter account info for some users from their profile pages, my uid is written to twitter_user.uid, so even if I've run cron and there are records in the twitter table, any tweets from my account (if I have entered that one) will be returned for any account that I've entered Twitter accounts for at user/%uid/edit/twitter. In my case, once I manually edited the twitter_account.uid column, tweets started showing up just fine.

Proposed resolution

I see a patch that does the following three things solving the problem:

  1. In twitter_user_settings(), the $user object is available (as optional arg $account), since it has been passed to it from twitter_menu(), so pass it to twitter_non_auth_account_form:
        if (twitter_connect()) {
          $output['add_account']['non_auth'] = drupal_get_form('twitter_non_auth_account_form', $account);
        }
    
  2. Add it as a hidden field in twitter_non_auth_account_form()
  3. Look for the uid in twitter_non_auth_account_form_submit(), and set $twitter_account->uid = $account->uid. Otherwise use the global value.

This will write the correct value to twitter_account.uid.

Remaining tasks

  1. Determine if suggestion is acceptable
  2. Write patch
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonhines’s picture

I've implemented the close to the proposed suggestion and it appears to work fine for both the user specific and global non-auth account form.

jonhines’s picture

This second patch is the same as the first but I accidentally deleted some code that differed between 5.8 and 5.x in the first one, it has been fixed here.

DamienMcKenna’s picture

Version: 7.x-5.8 » 7.x-5.x-dev
Status: Active » Needs review
Parent issue: » #2402311: Plan for Twitter v6.x-5.2 release
Related issues: +#2402307: Plan for Twitter v7.x-5.9 release, +#2402309: Plan for Twitter v7.x-6.0 release
DamienMcKenna’s picture

I simplified it a little by passing the uid in as a hidden value on the non-auth form.

DamienMcKenna’s picture

Ported to the 7.x-6.x branch.

Status: Needs review » Needs work

The last submitted patch, 5: twitter-n2212407-5-7.x-6.x.patch, failed testing.

DamienMcKenna’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev

Forgot to change the branch when uploading the 7.x-6.x patch.

Status: Needs work » Needs review
DamienMcKenna’s picture

Version: 7.x-6.x-dev » 6.x-5.x-dev
FileSize
0 bytes

Backported to 6.x-5.x.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed.

  • DamienMcKenna committed dd6e814 on 6.x-5.x
    Issue #2212407 by DamienMcKenna, jonhines: Tie non-auth accounts to the...

  • DamienMcKenna committed 8854137 on
    Issue #2212407 by DamienMcKenna, jonhines: Tie non-auth accounts to the...

Status: Fixed » Closed (fixed)

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