The tabs on notification settings show wrong number of content.
Seems that status and node_access is ignored.

(active tab shows a count of 1, but no content)
follow

Responsible seems to be:

function commons_follow_ui_tab_title($account, $flag_name = NULL) {
  global $user;

  if (!$flag_name) {
    // We are inside /message-subscribe so get the first flag.
    $flag_name = key(message_subscribe_flag_get_flags());
  }

  $flag = flag_get_flag($flag_name);
  $flaggings = flag_get_user_flags($flag->content_type, NULL, $account->uid);

  $count = !empty($flaggings[$flag_name]) ? count($flaggings[$flag_name]) : 0;
  $params = array(
    '@flag' => $flag->get_title(),
    '@count' => $count,
    '@name' => format_username($account),
  );
  return $account->uid == $user->uid ? t('@flag you follow <span class="user-follow-count">@count</span>', $params) : t('@flag @name follows <span class="user-follow-count">@count</span>', $params);
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

WebSinPat’s picture

I too have been getting this same behavior (have posted an issue about it somewhere a while back). Problem seems to be that it's still counting unpublished nodes in the count, iirc. As noted by the OP.

japerry’s picture

Assigned: Unassigned » japerry
slowflyer’s picture

FileSize
1.35 KB

The attached patch is a quick solution to the fix the issue.

ezra-g’s picture

Status: Active » Needs review

Thanks for the patch, slowflyer! Marking as, "Needs review."

japerry’s picture

Status: Needs review » Needs work

So the crux of the issue is flag_get_user_flags call doesn't do any checks for whether content is published or not.

While the patch does work, it performs another node_load. I'm hoping we can make it a bit more efficient than that, and it probably needs to be a patch to flag.

japerry’s picture

Status: Needs work » Needs review
FileSize
1.33 KB

I realized something this morning -- we're only doing the call once, therefore its not as bad that we're doing a node (entity) load.

Unfortunately flag 2 has limitations on its architecture for us to add reliable access checks, so it does need to happen within commons_follow_ui for now.

However, we are trying to make sure we make this entity generic. The patch below should allow for that.

WebSinPat’s picture

Version: 7.x-3.8 » 7.x-3.9
Status: Needs review » Needs work
FileSize
22.94 KB
5.4 KB

The patch in #6 still doesn't seem to account for all cases.

1) For one of my users it works great for "groups" and nodes/"other content" count and as expected does not affect "topics" count, but has done something weird for "people" count.
Though I follow 3 people and all of whose status is active, the count is only 1. (Prior to the patch that count was correct at 3)
screenshot mismatch in people count

2) for another of my users, I'm still getting a mismatch between the count and the number of groups shown. (the patch is making some adjustment: before the patch the count is 10; after the patch the count is 9; the number of groups shown in the list is: 8). I'm not sure yet what else is accounting for the mismatch after the patch, now that it's checking for unpublished nodes. If other folks don't have ideas, I can try to dig in and do some more debugging.
screenshot group count mismatch

japerry’s picture

There is something possibly wrong with the views as well. I'm really thinking we need to figure out a way to get a count of the results instead of trying to re-generate the results on our own.

PS. I haven't been able to re-produce the errors in count after the patch with authenticate or admins. =/

WebSinPat’s picture

I agree it's a bit odd and error-prone to calculate the count different than how the view is generated...
That said, here is a patch that takes care of the final mis-matches I am seeing.

1. if the entity is a user, do not run it through $access_func = user_access. Not sure if there's a need to check that the logged in user has permissions to follow the users they are following? But as the code is written, user_access syntax is different than node_access, so that part of the code is buggy and always returns FALSE unless the user being followed is user1.

2. For some reason, I have in my $flagging array an invalid node. Not sure if it's a node that was deleted and the flag was not deleted properly or what. Adding an else in the case the entity_load fails takes care of it.

japerry’s picture

Status: Needs work » Needs review
FileSize
2.28 KB

Okay time to make this super simple...

#2206157: Add an API function to grab the view object of a message subscribe page, fix page count

With that and this patch, we shouldn't see the counts be inconsistent again.

japerry’s picture

japerry’s picture

Project: Drupal Commons » Message Subscribe
Version: 7.x-3.9 » 7.x-1.x-dev

Ugh. This is a problem with message subscribe.

I mean it is -also- a commons issue, but thats because we copied the code from message subscribe because the API is hardcoded to output text in its title.

However, the underlying code is the same, and the bug exists there.

  $flaggings = flag_get_user_flags($entity_type, NULL, $account->uid);
  $count = !empty($flaggings[$flag_name]) ? count($flaggings[$flag_name]) : 0;

Therefore, we should make two changes here.
1) Fix the count in message subscribe to grab the view output
2) Create APIs inside message subscribe so users (not just commons) who implement message subscribe ui don't have to copy code.

This issue will take care of #1, while #2206157: Add an API function to grab the view object of a message subscribe page, fix page count takes care of #2.

japerry’s picture

Project: Message Subscribe » Drupal Commons
Version: 7.x-1.x-dev » 7.x-3.x-dev
FileSize
2.96 KB

Bringing back to the commons queue, because commons will have to do its own fix for this (because we're in a quicktab and not a page title).

The patch for fixing the count in Message subscribe is in #2206157: Add an API function to grab the view object of a message subscribe page, fix page count -- its fairly annoying to split these patches apart.

And here is a patch for follow_ui, requires the patch in 2206157 to work.

japerry’s picture

Status: Needs review » Fixed

Message subscribe is fixed, and I've changed the make file to point to that specific commit.

http://drupalcode.org/project/commons.git/commit/780d64d2c9cdcbb80c05c08...

Status: Fixed » Closed (fixed)

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