snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
11.14k stars 3.19k forks source link

Edit profile not showing avatar #15239

Open reiserfs opened 3 months ago

reiserfs commented 3 months ago

Debug mode

Describe the bug

In the view -> resources/views/partials/forms/edit/image-upload.blade.php

the code do not handle the avatar if is a url from workspace with http or https on it.


<!-- Image stuff - kept in /resources/views/partials/forms/edit/image-upload.blade.php -->
<!-- Image Delete -->
@if (isset($item) && ($item->{($fieldname ?? 'image')}))
    <div class="form-group{{ $errors->has('image_delete') ? ' has-error' : '' }}">
        <div class="col-md-9 col-md-offset-3">
            <label class="form-control">
                {{ Form::checkbox('image_delete', '1', old('image_delete'), ['aria-label'=>'image_delete']) }}
                {{ trans('general.image_delete') }}
                {!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
            </label>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-9 col-md-offset-3">
            <img src="{{ Storage::disk('public')->url($image_path.e($item->{($fieldname ?? 'image')})) }}" class="img-responsive">
            {!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
        </div>
    </div>
@endif

i made some changes to work with google workspace avatar, also disable delete form in case is an url.

<!-- Image stuff - kept in /resources/views/partials/forms/edit/image-upload.blade.php -->
<!-- Image Delete -->
@php
    use Illuminate\Support\Str;
@endphp
@if (isset($item) && ($item->{($fieldname ?? 'image')}))
    @php
        $imageUrl = $item->{($fieldname ?? 'image')};
        $isExternal = false;

        if (Str::startsWith($imageUrl, ['http://', 'https://'])) {
            $isExternal = true;
        } else {
            try {
                $imageUrl = Storage::disk('public')->url($image_path . e($imageUrl));
            } catch (Exception $e) {
                $imageUrl = null;
            }
        }
    @endphp

    @if ($imageUrl)
        <div class="form-group">
            <div class="col-md-9 col-md-offset-3">
                <img src="{{ $imageUrl }}" class="img-responsive">
                {!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
            </div>
        </div>

        @if (!$isExternal)
            <div class="form-group{{ $errors->has('image_delete') ? ' has-error' : '' }}">
                <div class="col-md-9 col-md-offset-3">
                    <label class="form-control">
                        {{ Form::checkbox('image_delete', '1', old('image_delete'), ['aria-label'=>'image_delete']) }}
                        {{ trans('general.image_delete') }}
                        {!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
                    </label>
                </div>
            </div>
        @endif
    @endif
@endif  

Reproduction steps

  1. Login with google workspace account
  2. Go to edit user profile
  3. Avatar do not show because url is malformed https://snipeit.url.com/uploads/avatars/https://lh3.googleusercontent.com/a/data ...

Expected behavior

Show avatar

Screenshots

No response

Snipe-IT Version

v7.0.10

Operating System

docker

Web Server

snipe/snipe-it:v7.0.10

PHP Version

8.1.2-1ubuntu2.18

Operating System

No response

Browser

No response

Version

No response

Device

No response

Operating System

No response

Browser

No response

Version

No response

Error messages

No response

Additional context

No response

snipe commented 3 months ago

We do handle avatars from http or https tho.

https://github.com/snipe/snipe-it/blob/28abb8d8cc269af554f562bac639124e3cf5bc3d/app/Presenters/UserPresenter.php#L433-L473

reiserfs commented 3 months ago

yes i saw that, but this do not work in users edit profile.

reiserfs commented 3 months ago

Also in account/profile [snipe-it/app/Presenters/UserPresenter.php] is not used.

snipe commented 3 months ago

That's not really going to work though, because it would prevent admins from overwriting asset, etc images that were populated with URLs but need to be updated with something locally or with no image at all.

snipe commented 3 months ago

(Also, it's generally better to keep PHP logic and variable setting out of the blades)

iungoron commented 2 months ago

Same issue for me. When I login with Google Workspace the avatar image is broken. If I replace the image with my own it appears till the next login, because the image "link" fall back to the Google image. My image is not retained in the DB configurazione of the user.