Skip to content

[3.0] Look for a gallery avatar where the gallery is - #9588

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/avatar-configured-directory
Open

[3.0] Look for a gallery avatar where the gallery is#9588
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/avatar-configured-directory

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Note

This change was produced by an LLM. The fix, the tests, the commit message and
this description were all written by Claude (Anthropic), driven by @albertlast. It
has not yet had human code review.

Description

Config::$modSettings['avatar_directory'] is where the avatar gallery lives. It is
a setting the admin owns:

  • Actions/Admin/Attachments.php offers the field, defaults it to
    Config::$boarddir . '/avatars' when it is submitted empty, and shows
    avatar_directory_wrong when the directory it names is not a directory.
  • Profile::getAvatars() lists the gallery out of it.
  • Profile refuses to save a chosen avatar whose realpath() does not start with
    it.

So a stored gallery avatar is a path into that directory, and the forum has already
said so twice by the time Avatar sees it.

Avatar looked under Config::$boarddir . '/avatars', hard-coded, in the three
places that find the file — while building the address from
Config::$modSettings['avatar_url'], which is the URL of the configured
directory. The path and the address only name the same place while the admin leaves
the setting alone.

When they do not, every member's chosen avatar is looked for somewhere it has never
been: not found at the gallery step, not found in custom_avatar, and answered with
default.png. A forum that moved its avatars directory shows the default image for
everybody, with nothing in the error log to say why.

The fix reads the setting in one place, getGalleryDir(), and keeps the admin
panel's own default as the fallback for a forum that never wrote the setting.

These are regression tests

tests/Unit/AvatarGalleryDirectoryTest.php points avatar_directory at
Themes/default/images, which stands in for a moved gallery: full of images, not
the directory SMF ships the gallery in, and nothing has to be written to disk to
use it.

Against the unfixed constructor, two of the three fail, and the failure is the
symptom rather than an abstraction of it:

-'https://example.com/gallery/cake.png'
+'https://example.com/gallery/default.png'

The third passes either side, which is the point of it: a forum whose admin never
touched the setting keeps the gallery SMF ships.

Notes for review

Issues References (Fixes|Related|Closes)

Related to #9586, #9587.

Config::$modSettings['avatar_directory'] is where the avatar gallery lives.
The admin nominates it, and Attachments warns when the directory it names is
not there. Profile lists the gallery out of it, and refuses to save a choice
that resolves outside it, so a stored gallery avatar is a path into that
directory and nowhere else.

Avatar looked for the file under Config::$boarddir . '/avatars' instead, while
building the address from Config::$modSettings['avatar_url']. The two agree
until an admin moves the gallery, and then every member's chosen avatar is
looked for in a directory it was never in: not found at the gallery step, not
found at the custom_avatar step, and answered with default.png. A forum that
moved its avatars directory shows the default image for everybody.

Reading the setting in one place keeps the file and its address naming the same
directory, and keeps the value the admin panel writes when the field is left
empty as the fallback.

Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant