Allow user to change author if they have the edit access

Created on 18 December 2019, almost 5 years ago
Updated 28 August 2024, 3 months ago

Problem/Motivation

The "Change the author of content" action cannot be run on content owned by the Anonymous user.

Steps to reproduce

  • Install a standard site
  • Create an article with the UID set to Anonymous
  • Enable Actions UI
  • Create an "Change the author of content" action
  • Try to run the action on the content owned by Anonymous
  • Observe you get the error message and the owner has not changed.

Proposed resolution

Add an additional check to the AssignOwnerNode action that the user has the access to update the node the action is being run against.

Remaining tasks

Code review
Commit

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None - I don't think one is needed for this.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Node system 

Last updated about 3 hours ago

No maintainer
Created by

🇧🇴Bolivia vacho Cochabamba

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to RTBC almost 2 years ago
  • 🇺🇸United States msbtterswrth

    Tested patch in #18 on 9.5.3 with VBO 4.2.3 and this fixed the issue for me! Thank you.

  • Status changed to Needs work almost 2 years ago
  • 🇳🇿New Zealand quietone

    @msbtterswrth, thanks for reporting that the patch works. Setting an issue to RTBC requires other checks as well.

    There have been changes to the patch and I don't see a code review. I too a very brief look at the patch and I saw commented out code and at least one todo. Those need to be addressed. This also needs an issue summary update, adding tag. Should the title be 'Allow non-administrator to change node author'?

  • 🇳🇿New Zealand danielveza Brisbane, AU

    I've rolled this against 10.1 and cleaned up the test + added a test for a node authored by an anon user. No interdiff since the last patch was rolled against the wrong directory. Only tests changed from that patch

    I'm out of time today but can come back for the IS update.

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Issue summary update still needs to happen

  • 🇳🇿New Zealand danielveza Brisbane, AU
  • Status changed to Needs review over 1 year ago
  • 🇳🇿New Zealand danielveza Brisbane, AU

    Updated the IS

  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    Thanks @DanielVeza!

    Just to make sure the test fail ran locally without the fix and got
    Behat\Mink\Exception\ResponseTextException : The text "uh4anwa5 was applied to 1 item." was not found anywhere in the text of the current page.

  • Status changed to Needs work over 1 year ago
  • 🇳🇿New Zealand danielveza Brisbane, AU

    Tests were green, but now the custom commands are failing. Setting back to NW.

  • Status changed to RTBC over 1 year ago
  • 🇳🇿New Zealand danielveza Brisbane, AU

    Fixing the CS issues, restoring RTBC status pending the test run

  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
    +++ b/core/modules/node/src/Plugin/Action/AssignOwnerNode.php
    @@ -134,10 +134,10 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
    -      ->andIf($object->getOwner()->access('edit', $account, TRUE));
    -
    +      ->andIf($object->access('update', $newUser, TRUE));
    

    Playing devil's advocate do we even need this at all?

    The user's ability to edit the node has nothing to do with their ability to be the owner of the node.

    You may want to change the author of a node for presentation purposes, even if the new author can not edit the node.

    Isn't the only salient check is that the person running the action has access to edit the node?

    Thoughts?

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    I would agree with that last statement

    Isn't the only salient check is that the person running the action has access to edit the node?

    Think that's all we care about

    You may want to change the author of a node for presentation purposes, even if the new author can not edit the node.

    I guess that's an option but sounds like a terrible approach haha. I'm assigning this to you but you can't do anything with it.

  • Status changed to Needs review over 1 year ago
  • 🇳🇿New Zealand danielveza Brisbane, AU

    I think @larowlan makes a good point, adjusted the patch to remove the check if the new owner can update the content.

  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    Thanks for the quick turnaround @DanielVeza!

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,203 pass
  • 🇳🇿New Zealand danielveza Brisbane, AU

    Closed 🐛 Unable to change the author of content using views/action Closed: duplicate as a duplicate.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Crediting @lobodacyril from the duplicate

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,284 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,301 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,303 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,305 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,360 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,367 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,367 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,372 pass
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,372 pass
  • 🇳🇿New Zealand quietone

    Thanks everyone for getting this to RTBC!

    Nice to see and complete Issue Summary, it make it much easier to review. I changed the IS to use the action id, node_assign_owner_action, instead of the class name.

    I skimmed through the comments and didn't find any comments that were not addressed. However, I do not see a full code review and no mention that the test has been reviewed.

    I then looked at the patch. The fix has been discussed so I spent my time on the test. I am finding it difficult to follow what is happening in the test and why. I was thinking that the names of the users could be more descriptive. After a few reads I figured out what was going on, sort of. Let's make this easier for devs in the future and add comments.

    I reworked the test so that all the setup is at the start and there blank lines between the test cases. There are also variable names changes and new comments.

  • 🇳🇿New Zealand quietone

    Better title, I hope.

  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    Made sure #49 still fails.

    Behat\Mink\Exception\ResponseTextException : The text "h2peia6h was applied to 1 item." was not found anywhere in the text of the current page.

    So test still tests so think the changes are good.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,379 pass
  • Status changed to Needs work over 1 year ago
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
    1. +++ b/core/modules/node/tests/src/Functional/NodeActionsConfigurationTest.php
      @@ -138,4 +138,126 @@ public function testAssignOwnerNodeActionAutocomplete() {
      +    // Create two actions. One to assign authorship to the page editor and the
      +    // other to assign authorship to the article editor.
      +    $this->drupalLogin($action_admin);
      +
      +    // Create action to assign ownership to $page_editor.
      +    $page_action_label = strtolower($this->randomMachineName());
      +    $edit = [
      +      'label' => $page_action_label,
      +      'id' => $page_action_label,
      +      'owner_uid' => $page_editor->id(),
      +    ];
      +    $this->drupalGet('admin/config/system/actions/add/node_assign_owner_action');
      +    $this->submitForm($edit, 'Save');
      +    $this->assertSession()->pageTextContains("The action has been successfully saved.");
      +
      +    $article_action_label = strtolower($this->randomMachineName());
      +    $edit = [
      +      'label' => $article_action_label,
      +      'id' => $article_action_label,
      +      'owner_uid' => $article_editor->id(),
      +    ];
      +    $this->drupalGet('admin/config/system/actions/add/node_assign_owner_action');
      +    $this->submitForm($edit, 'Save');
      +    $this->assertSession()->pageTextContains("The action has been successfully saved.");
      

      Sorry for not picking this up earlier.

      This test is about testing the action, not testing the action UI - so I think we can create this action using the API (i.e using Action::create()->save()) and make the test a bit more performant.

      It also means we don't need to create the admin user

    2. +++ b/core/modules/node/tests/src/Functional/NodeActionsConfigurationTest.php
      @@ -138,4 +138,126 @@ public function testAssignOwnerNodeActionAutocomplete() {
      +    // Confirm the action work for a node with an anonymous author.
      

      work -> works

  • None of these patches will apply cleanly on 10.3.1.

  • 🇩🇪Germany stefan.korn Jossgrund

    The action plugin has been moved to Action module in Drupal 10.3, see https://www.drupal.org/node/3424506

    this patch should apply to 10.3

    that said, for Drupal 11 the patch needs to be ported to the then separated action module: https://www.drupal.org/project/action

Production build 0.71.5 2024