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

[4.x] Prevent calling notifications method on User model #9936

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Data/AbstractAugmented.php
Expand Up @@ -2,6 +2,7 @@

namespace Statamic\Data;

use Statamic\Contracts\Auth\User;
use Statamic\Contracts\Data\Augmented;
use Statamic\Fields\Value;
use Statamic\Statamic;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function get($handle): Value
: new Value($value, $method, null, $this->data);
}

if (method_exists($this->data, $method) && collect($this->keys())->contains(Str::snake($handle))) {
if ($this->methodExistsOnData($method, $handle)) {
return $this->wrapValue($this->data->$method(), $handle);
}

Expand All @@ -80,6 +81,15 @@ private function methodExistsOnThisClass($method)
return method_exists($this, $method) && ! in_array($method, ['select', 'except']);
}

private function methodExistsOnData(string $method, string $handle): bool
{
if ($this->data instanceof User && $handle === 'notifications') {
return false;
}

return method_exists($this->data, $method) && collect($this->keys())->contains(Str::snake($handle));
}

protected function getFromData($handle)
{
$value = method_exists($this->data, 'value') ? $this->data->value($handle) : $this->data->get($handle);
Expand Down