Comments

subhojit777 created an issue. See original summary.

subhojit777’s picture

Assigned: Unassigned » subhojit777
subhojit777’s picture

Issue summary: View changes
Related issues: +#2644090: Page not found in profile listing page
StatusFileSize
new91.02 KB

Currently profile list is broken, see #2644090: Page not found in profile listing page.

After we fix #2644090: Page not found in profile listing page, I want to make sure - do we need to add a new operation "Default/Undefault" in the profile list, similar to what we have in here admin/commerce/config/currency

@bojanz can you please confirm.

subhojit777’s picture

Status: Active » Needs review
StatusFileSize
new4.09 KB

It's working. We need to write tests.

subhojit777’s picture

Status: Needs review » Needs work
naveenvalecha’s picture

Issue tags: +Needs tests
subhojit777’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new10.58 KB
new6.48 KB

Well $profile->isDefault() is returning false even if set to default, not sure.. Any idea?

Status: Needs review » Needs work

The last submitted patch, 7: mark_as_default_action-2639986-7.patch, failed testing.

The last submitted patch, 7: mark_as_default_action-2639986-7.patch, failed testing.

mglaman’s picture

  1. +++ b/src/Tests/ProfileCRUDTest.php
    @@ -248,9 +248,121 @@ class ProfileCRUDTest extends ProfileTestBase {
    +    $this->assertUrl($profile1->toUrl('collection')->toString());
    
    +++ b/src/Tests/ProfileTabTest.php
    @@ -95,7 +95,7 @@ class ProfileTabTest extends LocalTasksTest {
    +    $this->assertUrl($profile1->toUrl('collection')->toString());
    

    I know I said to fix these, but let's wait until later since they failed, too.

  2. +++ b/src/Tests/ProfileCRUDTest.php
    @@ -248,9 +248,121 @@ class ProfileCRUDTest extends ProfileTestBase {
    +  /**
    +   * Tests mark as default action.
    +   */
    +  public function testDefaultAction() {
    

    I made a ProfileDefaultTest, let's move this there.

  3. +++ b/src/Tests/ProfileCRUDTest.php
    @@ -248,9 +248,121 @@ class ProfileCRUDTest extends ProfileTestBase {
    +    $profile_profile_type_1_user1 = Profile::create($expected = [
    +      'type' => $types['profile_type_1']->id(),
    +      'uid' => $this->user1->id(),
    +      'status' => PROFILE_ACTIVE,
    +    ]);
    

    This wasn't working for me. I had to manually run ->setActive(TRUE) before save. See examples in ProfileDefaultTest.

subhojit777’s picture

Status: Needs work » Needs review
StatusFileSize
new10.39 KB
new12.41 KB
naveenvalecha’s picture

+++ b/profile.routing.yml
@@ -46,3 +46,14 @@ entity.profile.multiple_delete_confirm:
+    _permission: 'administer profiles'

Do we need a _csrf_token: 'TRUE' here to prevent CSRF ?
as in this function we are updating the profile entity.
Although this route is behind 'administer profiles' but with chain attack of XSS(with twig in core its no where by default) it can be exploitable.

mglaman’s picture

Status: Needs review » Needs work

Per #12: Yeah, let's do it. I was thinking "nah, it still needs a valid profile ID", but Core does it for comment approval.

comment.approve:
  path: '/comment/{comment}/approve'
  defaults:
    _title: 'Approve'
    _controller: '\Drupal\comment\Controller\CommentController::commentApprove'
    entity_type: 'comment'
  requirements:
    _entity_access: 'comment.approve'
    _csrf_token: 'TRUE'
    comment: \d+

It can't hurt.

subhojit777’s picture

Status: Needs work » Needs review
StatusFileSize
new10.41 KB
new295 bytes

makes sense :)

Status: Needs review » Needs work

The last submitted patch, 14: mark_as_default_action-2639986-14.patch, failed testing.

The last submitted patch, 14: mark_as_default_action-2639986-14.patch, failed testing.

mglaman’s picture

Shoot. Remove whatever is asserting the link

+++ b/src/Tests/ProfileDefaultTest.php
@@ -123,4 +123,129 @@ class ProfileDefaultTest extends ProfileTestBase {
+    // Check whether all have links "Mark as default".
+    $this->assertLinkByHref($profile_profile_type_0_user1_1->toUrl('set-default')->toString());
+    $this->assertLinkByHref($profile_profile_type_0_user1_2->toUrl('set-default')->toString());
+    $this->assertLinkByHref($profile_profile_type_1_user1->toUrl('set-default')->toString());
+    $this->assertLinkByHref($profile_profile_type_1_user2->toUrl('set-default')->toString());
+    $this->assertLinkByHref($profile_profile_type_1_user1_inactive->toUrl('set-default')->toString());
+    $this->assertLinkByHref($profile_profile_type_1_user1_active->toUrl('set-default')->toString());

:/ We can't do this on D.o test bot. I think it's just because paths are goofy. I wish we could assert text, maybe by the index?

I'd be fine skipping it.

subhojit777’s picture

But it was passing fine in #12

EDIT:
Sorry I got it. It's because of CSRF token.

subhojit777’s picture

Status: Needs work » Needs review
StatusFileSize
new9.64 KB
new2.51 KB
mglaman’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. I just want to get bojanz to take a peak and verify this is what we're going for, looks like it, though.

bojanz’s picture

+  requirements:
+    _permission: 'administer profiles'
+    _csrf_token: 'TRUE'

So it won't work for ordinary users?

mglaman’s picture

Status: Reviewed & tested by the community » Needs work

Oops. Good catch. Should be "edit own profiles"

subhojit777’s picture

Status: Needs work » Needs review
StatusFileSize
new9.77 KB
new2.25 KB
subhojit777’s picture

  1. +++ b/src/Tests/ProfileDefaultTest.php
    @@ -58,7 +58,6 @@ class ProfileDefaultTest extends ProfileTestBase {
    -    $this->user1->save();
    

    This was twice. I hope it makes sense to remove this in this issue.

  2. +++ b/src/Tests/ProfileDefaultTest.php
    @@ -145,17 +144,6 @@ class ProfileDefaultTest extends ProfileTestBase {
    -    $this->user1 = User::create([
    -      'name' => $this->randomMachineName(),
    -      'mail' => $this->randomMachineName() . '@example.com',
    -    ]);
    -    $this->user1->save();
    -    $this->user2 = User::create([
    -      'name' => $this->randomMachineName(),
    -      'mail' => $this->randomMachineName() . '@example.com',
    -    ]);
    -    $this->user2->save();
    -
    

    It's already there in the setUp()

Question: Do I need to show in the test that user having "edit own profiles" permission gets 403 error while marking profiles as default?

mglaman’s picture

Question: Do I need to show in the test that user having "edit own profiles" permission gets 403 error while marking profiles as default?

Wait, do you mean does not get 403? Or for other user profiles? Sorry I think I'm just reading comment wrong. We probably should show that "user1 cannot set user2's default profile without proper access"

subhojit777’s picture

Status: Needs review » Needs work

Yes that's what I meant, thanks for the clarification :)

subhojit777’s picture

Status: Needs work » Needs review
StatusFileSize
new10.72 KB
new2.16 KB

  • mglaman committed ec3d9ee on 8.x-1.x authored by subhojit777
    Issue #2639986 by subhojit777, mglaman, naveenvalecha: "Mark as default...
mglaman’s picture

Status: Needs review » Fixed
naveenvalecha’s picture

+++ b/src/Tests/ProfileDefaultTest.php
@@ -144,7 +144,25 @@ class ProfileDefaultTest extends ProfileTestBase {
+      'administer profiles',

Does $restricted_user really needs the administer profiles permission ? I did not find any other use of restricted user other than creating its own profile.
Did I miss something ?

mglaman’s picture

naveenvalecha, shoot. mind just opening a new issue to fix the test with the patch?

subhojit777’s picture

We are testing whether "default" functionality actually works, and also testing whether it works from the UI. The UI option is available only in profile listing page. To view the profile listing page you need "administer profiles" permission. That is why $restricted_user needs that permission.

The purpose of $restricted_user is to check whether he is able to set default his own profile, and is unable to set default others' profile. That is the only purpose of $restricted_user.

naveenvalecha’s picture

#32, cleared the usage of administer profiles.

Status: Fixed » Closed (fixed)

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