Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resources/templates/_components/fieldtypes/Matrix/block.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
]) %}
{% endif %}

{% if entry.id or (Auth.user.admin and config('craft.general.allowAdminChanges')) %}
{% if entry.id or (currentUser.admin and config('craft.general.allowAdminChanges')) %}
{% set actionMenuItems = actionMenuItems|push({hr: true}) %}

{% if entry.id and not static %}
Expand All @@ -84,7 +84,7 @@
}) %}
{% endif %}

{% if Auth.user.admin and config('craft.general.allowAdminChanges') %}
{% if currentUser.admin and config('craft.general.allowAdminChanges') %}
{% set actionMenuItems = actionMenuItems|push({
icon: 'gear',
label: 'Entry type settings'|t('app'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
{{ hiddenInput('widgetId', widget.id) }}
{{ hiddenInput('message', '', {class: 'cs-support-message'}) }}

{% set email = Auth.user.email %}
{% set email = currentUser.email %}
{% if email in ['support@pixelandtonic.com', 'support@craftcms.com'] %}
{% set email = '' %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/_includes/forms/autosuggest.twig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ new Vue({
name: (name ?? '')|namespaceInputName,
size: size ?? '',
maxlength: maxlength ?? '',
autofocus: (autofocus ?? false) and Auth.user and Auth.user.getAutofocusPreferred() and not Request.isMobileBrowser(true),
autofocus: (autofocus ?? false) and currentUser and currentUser.getAutofocusPreferred() and not Request.isMobileBrowser(true),
disabled: disabled ?? false,
title: title ?? '',
placeholder: placeholder ?? '',
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/_includes/forms/text.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
name: name ?? false,
value: value ?? false,
maxlength: maxlength ?? false,
autofocus: (autofocus ?? false) and Auth.user and Auth.user.getAutofocusPreferred() and not Request.isMobileBrowser(true),
autofocus: (autofocus ?? false) and currentUser and currentUser.getAutofocusPreferred() and not Request.isMobileBrowser(true),
autocomplete: autocomplete is boolean ? (autocomplete ? 'on' : 'off') : autocomplete,
autocorrect: (autocorrect ?? true) ? false : 'off',
autocapitalize: (autocapitalize ?? true) ? false : 'none',
Expand Down
6 changes: 3 additions & 3 deletions resources/templates/_layouts/base.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

{% set bodyClass = (bodyClass ?? [])|explodeClass|merge([
orientation,
(Auth.user.getPreference('useShapes') ?? a11yDefaults['useShapes'] ?? false) ? 'use-shapes',
(Auth.user.getPreference('underlineLinks') ?? a11yDefaults['underlineLinks'] ?? false) ? 'underline-links',
"notifications--#{Auth.user.getPreference('notificationPosition') ?? a11yDefaults['notificationPosition'] ?? 'end-start'}",
(currentUser.getPreference('useShapes') ?? a11yDefaults['useShapes'] ?? false) ? 'use-shapes',
(currentUser.getPreference('underlineLinks') ?? a11yDefaults['underlineLinks'] ?? false) ? 'underline-links',
"notifications--#{currentUser.getPreference('notificationPosition') ?? a11yDefaults['notificationPosition'] ?? 'end-start'}",
requestedSite ? "site--#{requestedSite.handle}",
'cp-legacy-reset',
'cp-legacy'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
} %}
</div>

{% if Auth.user.admin and devMode %}
{% if currentUser.admin and devMode %}
{% set devModeText = 'Craft CMS is running in Dev Mode.'|t('app') %}
<div id="devmode">
{% tag 'span' with {
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/_layouts/components/header-photo.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="header-photo">
{{ Auth.user.getThumbHtml(30)|raw }}
{{ currentUser.getThumbHtml(30)|raw }}
</div>
8 changes: 4 additions & 4 deletions resources/templates/_layouts/cp.twig
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ history.replaceState(undefined, undefined, window.location.href.match(/^[^#]*/)[
<ul>
<li>
<a href="{{ url('myaccount') }}" class="flex flex-nowrap">
{% if Auth.user.photoId %}
{% if currentUser.photoId %}
{{ userPhoto|raw }}
{% endif %}
<div class="flex-grow">
<div>{{ Auth.user.username }}</div>
<div>{{ currentUser.username }}</div>
{% if not config('craft.general.useEmailAsUsername') %}
<div class="smalltext">{{ Auth.user.email }}</div>
<div class="smalltext">{{ currentUser.email }}</div>
{% endif %}
</div>
</a>
Expand Down Expand Up @@ -393,7 +393,7 @@ history.replaceState(undefined, undefined, window.location.href.match(/^[^#]*/)[
{% endblock %}


{% if Auth.user.can('performUpdates') and not Updates.isUpdateInfoCached() %}
{% if currentUser.can('performUpdates') and not Updates.isUpdateInfoCached() %}
{% js %}
Craft.cp.checkForUpdates();
{% endjs %}
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/users/_index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% set canHaveDrafts = craft.users().drafts().draftOf(false).savedDraftsOnly().exists() %}

{% block actionButton %}
{% if Auth.user.canRegisterUsers() %}
{% if canRegisterUsers %}
<a class="btn submit add icon" href="{{ url('users/new') }}">
{{ buttonLabel }}
</a>
Expand Down
7 changes: 2 additions & 5 deletions resources/templates/users/_permissions.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{% import '_includes/forms.twig' as forms %}
{{ hiddenInput('userId', user.id) }}

{% set showUserGroups = Auth.user.canAssignUserGroups() %}
{% set showPermissions = Auth.user.can('assignUserPermissions') %}

{% if showUserGroups %}
<fieldset class="first">
<h2>{{ 'User Groups'|t('app') }}</h2>
Expand All @@ -21,7 +18,7 @@
values: user.getGroups(),
showDescription: true,
sortable: false,
createAction: Auth.user.admin and config('craft.general.allowAdminChanges') ? 'user-settings/edit-group' : null,
createAction: currentUserIsAdmin and config('craft.general.allowAdminChanges') ? 'user-settings/edit-group' : null,
} %}
{% endblock %}
{% endembed %}
Expand All @@ -36,7 +33,7 @@
<div>
<h2>{{ 'Permissions'|t('app') }}</h2>

{% if Auth.user.admin %}
{% if currentUserIsAdmin %}
{{ forms.lightswitchField({
label: 'Admin'|t('app'),
name: 'admin',
Expand Down
22 changes: 11 additions & 11 deletions resources/templates/users/_preferences.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
id: 'weekStartDay',
name: 'weekStartDay',
options: I18N.getLocale().getWeekDayNames(),
value: Auth.user.getPreference('weekStartDay', config('craft.general.defaultWeekStartDay'))
value: currentUser.getPreference('weekStartDay', config('craft.general.defaultWeekStartDay'))
}) }}

{{ forms.timeZoneField({
Expand Down Expand Up @@ -59,13 +59,13 @@
label: 'Use shapes to represent statuses'|t('app'),
name: 'useShapes',
id: 'useShapes',
checked: Auth.user.getPreference('useShapes') ?? a11yDefaults['useShapes'] ?? false,
checked: currentUser.getPreference('useShapes') ?? a11yDefaults['useShapes'] ?? false,
},
{
label: 'Underline links'|t('app'),
name: 'underlineLinks',
id: 'underlineLinks',
checked: Auth.user.getPreference('underlineLinks') ?? a11yDefaults['underlineLinks'] ?? false,
checked: currentUser.getPreference('underlineLinks') ?? a11yDefaults['underlineLinks'] ?? false,
},
],
}) }}
Expand All @@ -77,7 +77,7 @@
label: 'Disable autofocus'|t('app'),
name: 'disableAutofocus',
id: 'disableAutofocus',
checked: Auth.user.getPreference('disableAutofocus') ?? a11yDefaults['disableAutofocus'] ?? false,
checked: currentUser.getPreference('disableAutofocus') ?? a11yDefaults['disableAutofocus'] ?? false,
},
],
}) }}
Expand All @@ -93,7 +93,7 @@
{value: 10000, label: '{num, number} {num, plural, =1{second} other{seconds}}'|t('app', {num: 10})},
{value: 0, label: 'Show them indefinitely'|t('app')},
],
value: Auth.user.getPreference('notificationDuration') ?? a11yDefaults['notificationDuration'] ?? 5000,
value: currentUser.getPreference('notificationDuration') ?? a11yDefaults['notificationDuration'] ?? 5000,
}) }}

{{ forms.buttonGroupField({
Expand Down Expand Up @@ -142,7 +142,7 @@
},
},
],
value: Auth.user.getPreference('notificationPosition') ?? a11yDefaults['notificationPosition'] ?? 'end-start',
value: currentUser.getPreference('notificationPosition') ?? a11yDefaults['notificationPosition'] ?? 'end-start',
}) }}

{{ forms.buttonGroupField({
Expand Down Expand Up @@ -171,12 +171,12 @@
},
},
],
value: Auth.user.getPreference('slideoutPosition') ?? a11yDefaults['slideoutPosition'] ?? 'end',
value: currentUser.getPreference('slideoutPosition') ?? a11yDefaults['slideoutPosition'] ?? 'end',
}) }}

</div>

{% if Auth.user.admin %}
{% if currentUser.admin %}
<hr>

<div>
Expand All @@ -189,19 +189,19 @@
label: 'Show field handles in edit forms'|t('app'),
name: 'showFieldHandles',
id: 'showFieldHandles',
checked: Auth.user.getPreference('showFieldHandles')
checked: currentUser.getPreference('showFieldHandles')
},
{
label: 'Profile Twig templates when Dev Mode is disabled'|t('app'),
name: 'profileTemplates',
id: 'profileTemplates',
checked: Auth.user.getPreference('profileTemplates')
checked: currentUser.getPreference('profileTemplates')
},
{
label: 'Show full exception views when Dev Mode is disabled'|t('app'),
name: 'showExceptionView',
id: 'showExceptionView',
checked: Auth.user.getPreference('showExceptionView')
checked: currentUser.getPreference('showExceptionView')
},
],
}) }}
Expand Down
2 changes: 1 addition & 1 deletion src/Address/Elements/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ protected function safeActionMenuItems(): array

if (
app(ElementRequest::class)->element === $this &&
Auth::user()->isAdmin() &&
Auth::craftUser()->isAdmin() &&
Cms::config()->allowAdminChanges &&
! empty($this->fieldId)
) {
Expand Down
14 changes: 7 additions & 7 deletions src/Address/Policies/AddressPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use CraftCms\Cms\Address\Elements\Address;
use CraftCms\Cms\Element\Contracts\ElementInterface;
use CraftCms\Cms\Element\Policies\ElementPolicy;
use CraftCms\Cms\User\Elements\User;
use CraftCms\Cms\User\Contracts\CraftUser;

class AddressPolicy extends ElementPolicy
{
public function view(User $user, Address $address): bool
public function view(CraftUser $user, Address $address): bool
{
if (! $owner = $this->getOwner($address)) {
return false;
Expand All @@ -20,7 +20,7 @@ public function view(User $user, Address $address): bool
return $user->can('view', $owner);
}

public function save(User $user, Address $address): bool
public function save(CraftUser $user, Address $address): bool
{
if (! $owner = $this->getOwner($address)) {
return false;
Expand All @@ -29,7 +29,7 @@ public function save(User $user, Address $address): bool
return $user->can('save', $owner);
}

public function delete(User $user, Address $address): bool
public function delete(CraftUser $user, Address $address): bool
{
if (! $owner = $this->getOwner($address)) {
return false;
Expand All @@ -38,7 +38,7 @@ public function delete(User $user, Address $address): bool
return $user->can('save', $owner);
}

public function duplicate(User $user, Address $address): bool
public function duplicate(CraftUser $user, Address $address): bool
{
if (! $owner = $this->getOwner($address)) {
return false;
Expand All @@ -47,12 +47,12 @@ public function duplicate(User $user, Address $address): bool
return $user->can('save', $owner);
}

public function copy(User $user, Address $address): bool
public function copy(CraftUser $user, Address $address): bool
{
return $user->can('duplicate', $address);
}

public function createDrafts(User $user, Address $address): bool
public function createDrafts(CraftUser $user, Address $address): bool
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Announcement/Announcements.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function push(string $heading, string $body, ?string $pluginHandle = null
*/
public function get(): array
{
$userId = Auth::user()?->getKey();
$userId = Auth::craftUser()?->getCraftUserId();

if (! $userId) {
return [];
Expand Down Expand Up @@ -111,7 +111,7 @@ public function markAsRead(array $ids): void
return;
}

$userId = Auth::user()?->getKey();
$userId = Auth::craftUser()?->getCraftUserId();

if (! $userId) {
return;
Expand Down
5 changes: 3 additions & 2 deletions src/Asset/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use Throwable;
use Tpetry\QueryExpressions\Language\Alias;

use function CraftCms\Cms\currentUserElement;
use function CraftCms\Cms\t;

#[Singleton]
Expand Down Expand Up @@ -94,7 +95,7 @@ public function replaceAssetFile(Asset $asset, string $pathOnServer, string $fil
$asset->tempFilePath = $pathOnServer;
$asset->newFilename = $filename;
$asset->setMimeType(File::getMimeType($pathOnServer, checkExtension: false) ?? $mimeType);
$asset->uploaderId = Auth::user()?->id;
$asset->uploaderId = Auth::craftUser()?->getCraftUserId();
$asset->avoidFilenameConflicts = true;
$asset->ruleset->useScenario(AssetRules::SCENARIO_REPLACE);
$this->elements->saveElement($asset);
Expand Down Expand Up @@ -346,7 +347,7 @@ public function createTempAssetQuery(): AssetQuery
*/
public function getUserTemporaryUploadFolder(?User $user = null): VolumeFolder
{
$user ??= Auth::user();
$user ??= currentUserElement();
$cacheKey = $user->id ?? '__GUEST__';

if (isset($this->userTempFolders[$cacheKey])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/Data/Volume.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public function getUiLabel(): string

public function getCpEditUrl(): ?string
{
if (! $this->id || ! Auth::user()?->isAdmin()) {
if (! $this->id || ! Auth::craftUser()?->isAdmin()) {
return null;
}

Expand Down
Loading
Loading