Problem/Motivation

Follow-up to #3330887: GUI install multiple modules at once.,

    const div = document.createElement('div');
    if (err.unlock_url && err.unlock_url !== '') {
      div.innerHTML += `<p>${errorMessage} <a href="${
        err.unlock_url
      }&destination=admin/modules/browse">${Drupal.t(

@phenaproxima suggested

This assumes that the unlock URL has a query string. IMHO we would benefit here from more robust parsing of the actual URL, but that can be done in a follow-up.

Steps to reproduce

Proposed resolution

Instead of adding hard coded destination=admin/modules/browse", parse and use actual page url.

CommentFileSizeAuthor
#3 Use-actual-page-URL-3476818-3.patch862 bytesanjali rathod
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

narendrar created an issue. See original summary.

anjali rathod’s picture

Assigned: Unassigned » anjali rathod
Issue tags: +Barcelona2024
anjali rathod’s picture

Assigned: anjali rathod » Unassigned
Status: Active » Needs review
StatusFileSize
new862 bytes

chrisfromredfin made their first commit to this issue’s fork.

narendrar’s picture

Title: [PP-1] Use actual page URL instead of hardcoding the query string in unlock URL » Use actual page URL instead of hardcoding the query string in unlock URL
narendrar’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Changes looks good to me, but it needs to be done in different file due to #3330887: GUI install multiple modules at once.. Also instead of patch, it will be good if we use MR.

anish.a’s picture

Issue tags: +dcp2024

We are taking up this issue in DrupalCampPune2024

sudhanshu0542’s picture

Assigned: Unassigned » sudhanshu0542
sudhanshu0542’s picture

Assigned: sudhanshu0542 » Unassigned

utkarsh_33 made their first commit to this issue’s fork.

utkarsh_33’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

Rebased to latest 2.0.x and It's ready for review.

narendrar’s picture

Status: Needs review » Reviewed & tested by the community
phenaproxima’s picture

Status: Reviewed & tested by the community » Needs work

I don't think this actually solves the problem. Here's why.

If the err.unlock_url property looks like this: /admin/modules/browse/unlock, then the current code will generate this: /admin/modules/browse/unlock&destination=my+current+url. That's an invalid URL which will lead to a 404 or worse.

What we need here is:

  • If the unlock URL looks something like /admin/modules/browse/unlock?some_param=foo, then the generated URL has to look like: /admin/modules/browse/unlock?some_param=foo&destination=my+current+url. This, to be fair, is what the code in HEAD already does.
  • But if the unlock URL doesn't have a query string, then we need to append it, prefixed by a question mark.
utkarsh_33’s picture

Status: Needs work » Needs review
phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine to me!

chrisfromredfin’s picture

Status: Reviewed & tested by the community » Needs work

We have native JS API's for this now, so we don't need to do our own string concat. I think something like this would make the code more readable. (Bear in mind this is GPT-generated and untested, but point being we should use URL - https://developer.mozilla.org/en-US/docs/Web/API/URL )

// Get the current page URL as a URL object for easier manipulation
const currentUrl = new URL(window.location.href);

if (err.unlock_url) {
  const unlockUrl = new URL(err.unlock_url);

  // Append the 'destination' parameter to unlockUrl
  unlockUrl.searchParams.set('destination', currentUrl.toString());

  // Update the HTML content
  div.innerHTML += `<p>${errorMessage} <a href="${unlockUrl.toString()}">${Drupal.t(
    'Unlock Install Stage'
  )}</a></p>`;
} else {
  div.innerHTML += `<p>${errorMessage}</p>`;
}
utkarsh_33’s picture

Status: Needs work » Needs review

It is ready for a review.

narendrar’s picture

Status: Needs review » Needs work

Changes not implemented as suggested in #17

chrisfromredfin’s picture

Issue tags: +core-mvp, +beta blocker
utkarsh_33’s picture

Status: Needs work » Needs review
phenaproxima’s picture

Status: Needs review » Needs work

Found something that is suspicious at best, wrong at worst, and probably needs test coverage. But I may be wrong. If I am, great - let's just add a comment to clarify and it's full steam ahead.

utkarsh_33’s picture

Status: Needs work » Needs review
phenaproxima’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Reviewed. I'm still not sure we are doing this correctly, which is why I think adding some functional JS test coverage is a good idea.

utkarsh_33’s picture

Status: Needs work » Needs review

@phenaproxima I added functional js tests as you suggested and i think those are taking care of sub directory issue that you were mentioning in this as tests were initially failing here because of the sub directory path was appended correctly in the code but we were not taking that into account for tests.
Marking it NR again.

narendrar’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs reroll
utkarsh_33’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

Resolved all the open threads and addressed feedbacks as well.Marking it NR again.

narendrar’s picture

Looks good to me, except some minor suggestions.

narendrar’s picture

Status: Needs review » Reviewed & tested by the community

Changes looks good to me.

chrisfromredfin’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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