Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views field "Comment: Edit link" call to comment_access() always returns false #5883

Closed
alanmels opened this issue Dec 8, 2022 · 13 comments · Fixed by backdrop/backdrop#4270

Comments

@alanmels
Copy link

alanmels commented Dec 8, 2022

Description of the bug

If you use the same test view given in #5882 and just add Comment: Edit link (Edit link) link field as shown below:

Screenshot 2022-12-08 at 3 52 58 PM

then the website logs starts filled in with the reported comments in title.

Additional information

It's not an error or even a notice, but just a comment:

Screenshot 2022-12-08 at 3 55 02 PM

However, still (1) it is not pleasant at all that the log gets quickly flooded with the same comment if your website is actively using the corresponding views page/block. And then (2) this message is caused not by some kind of contributed module, but core itself. See https://github.com/backdrop/backdrop/blob/7cc9968d3c1f8885a9d126668b1a8c0766b8e3d6/core/modules/comment/comment.module#L1508 :

function comment_access($op, Comment $comment = NULL) {
  if ($op == 'edit') {
    // Normalize 'edit' operation to 'update'.
    $op = 'update';
    // Log to watchdog for DX. @todo add watchdog_deprecated_parameter().
    $message = 'The function comment_access() was called with the operation <em>edit</em>. This operation is now named <em>update</em>. The <em>edit</em> operation will be removed in the next major release of Backdrop.';
    $variables = array();
    watchdog('comment', $message, $variables, WATCHDOG_DEPRECATED);
  }

  if ($op == 'create') {
    return Comment::createAccess();
  }
  else {
    return $comment->access($op);
  }
}

I'm not sure how to tackle this issue as there is simply no such operation as Comment: Update link, but there is Comment: Edit link.

@argiepiano
Copy link

Hi @alanmels. Thanks much for reporting! I followed the steps:

  1. Import the view you posted in Notice: Undefined index: position in views_plugin_display_block->options_form() (line 296 of ../views_plugin_display_block.inc).  #5882
  2. Added the Comment: Edit link
  3. Saved the View

I don't see anything in the log. Is there a step missing? Do you have to place the block somewhere and then try to access it?

@argiepiano
Copy link

argiepiano commented Dec 9, 2022

OK, I found the issue. views_handler_field_comment_link_edit::render_link() makes a call to comment_access() using the $op edit instead of update. This a minor problem (which is the reason the log shows a notice instead of an error). The function comment_access() takes care of interpreting the $op edit as update. This notice is similar to a deprecation notice. The function still works. The $op edit was used in the past, and at some point it was changed to update.

However, it'd be good to fix this.

@argiepiano
Copy link

PR provided: backdrop/backdrop#4270

Please test!

@alanmels
Copy link
Author

alanmels commented Dec 9, 2022

@argiepiano, you'll see the log if everything is turned on /admin/config/development/logging Thanks for confirming my finding. I know it's just a comment, but since it's flooding the log page would be still nice to get this fixed.

@alanmels
Copy link
Author

alanmels commented Dec 9, 2022

Thanks for the quick fix. I've tested PR and it works as expected - the log page is no more flooded with the reported comments. It's ready to be committed from my perspective, however one could suggest that once this is being dealt to improve other related issues such as:

  • since op is changing should the respective file's name be changed from views_handler_field_comment_link_edit.inc to views_handler_field_comment_link_update.inc?
  • should couple more occurrences of edit in the same function be replaced with update?
function render_link($data, $values) {
    parent::render_link($data, $values);
    // ensure user has access to edit this comment.
    $comment = $this->get_value($values);
    if (!comment_access('update', $comment)) {
      return;
    }

    $text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
    unset($this->options['alter']['fragment']);

    if (!empty($this->options['destination'])) {
      $this->options['alter']['query'] = backdrop_get_destination();
    }

    $this->options['alter']['path'] = "comment/" . $comment->cid . "/edit";

    return $text;
  }

@argiepiano
Copy link

argiepiano commented Dec 9, 2022

@alanmels, I believe you are misunderstanding the way comment_access() works. The text shown to the user is edit because that's easiest to understand from the UI point of view, since that's what the link does (it sends you to the edit page for the comment). But the function comment_access() uses the "machine name" update as a blanket operation for anything that's related to saving an already existing entity. In this case, update is the "internal name" for the operation of saving an existing comment after being edited.

So, in my view, it's best not to change the user-facing text, nor the name of the handler. This last one would require many changes in the code in several places.

If this works for you, please mark it so with the "works for me" label.

@alanmels
Copy link
Author

alanmels commented Dec 9, 2022

Thanks for the explanation. I agree with your arguments. I've just approved backdrop/backdrop#4270 (review), but I don't think I have enough privileges to mark this issue with "works for me" label. At least I don't see such option anywhere on my end.

@argiepiano
Copy link

The "works for me" label should be applied here - not in the PR. It's on top of this screen, under "Labels". Marking the PR as "approved" doesn't mean anything in the Backdrop community

@alanmels
Copy link
Author

alanmels commented Dec 9, 2022

@argiepiano, once again, I do not I have enough privileges to use labels here. Per https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels

Anyone with write access to a repository can create a label.

I do not have write access.

@argiepiano
Copy link

argiepiano commented Dec 9, 2022

@argiepiano, once again, I do not I have enough privileges to use labels here

My apologies

@alanmels
Copy link
Author

alanmels commented Dec 9, 2022

To quote from https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels#applying-a-label

Anyone with triage access to a repository can apply and dismiss labels.

So I believe I do not have triage access to the repository either. I'm not sure if I should apply for it or if Backdrop gods will just magically give it to me. I'm totally ok without such access, though.

@bugfolder
Copy link

bugfolder commented Sep 18, 2023

Code reviewed. The one-word change looks good to me. Removed the "needs testing" label based on @kiamlaluno's WFM label and previous comments.

@quicksketch
Copy link
Member

Thanks folks! A nice easy fix. Sorry this took so long to pull in. I've merged backdrop/backdrop#4270 into 1.x and 1.26.x. Thanks @argiepiano, @alanmels, @bugfolder, and @kiamlaluno!

@quicksketch quicksketch changed the title The function comment_access() was called with the operation edit. Views field "Comment: Edit link" call to comment_access() always returns false Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants