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

Bypass checking for currentUser in getCpEditUrl() method #6275

Closed
ryanmwc opened this issue Jun 26, 2020 · 2 comments
Closed

Bypass checking for currentUser in getCpEditUrl() method #6275

ryanmwc opened this issue Jun 26, 2020 · 2 comments

Comments

@ryanmwc
Copy link

ryanmwc commented Jun 26, 2020

Description

When calling the getCpEditUrl() method on a User element, it would be helpful to be able to bypass the $this->getIsCurrent() check that forces the URL to point to myaccount if you're the current user. I want something like this:

public function getCpEditUrl(bool $forceUrl = false)
{
    if ($this->getIsCurrent() && ! $forceUrl) {
        return UrlHelper::cpUrl('myaccount');
    }

    if (Craft::$app->getEdition() === Craft::Pro) {
        return UrlHelper::cpUrl('users/' . $this->id);
    }

    return null;
}

instead of

public function getCpEditUrl()
{
    if ($this->getIsCurrent()) {
        return UrlHelper::cpUrl('myaccount');
    }

    if (Craft::$app->getEdition() === Craft::Pro) {
        return UrlHelper::cpUrl('users/' . $this->id);
    }

    return null;
}

A good use case would be a form that gets submitted on the front end somewhere and a notification email that gets sent to some site admin email address. Let's say the email template provides some data on the registered User who submitted the form. I like to conveniently provide a link to the user's CP account easily for the admins who receive the email, but if you're logged in when you submit the form, the email template code detects this and makes the cpEditUrl point to myaccount, so if one of those admins clicks that link, it ends up taking them to their account and not mine.

Bypassing that check could then be as simple as {{ user.getCpEditUrl(true) }} to make all links go to the url with the user ID in it.

Additional info

  • Craft version: 3.4.25
@brandonkelly
Copy link
Member

getCpUrl() is part of the element interface, so not something user elements can modify like that, but I’ve changed its behavior so /myaccount is only returned if the method is called within the control panel, for the next release.

@brandonkelly
Copy link
Member

Craft 3.4.26 is out now with that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants