silverstripe-cms icon indicating copy to clipboard operation
silverstripe-cms copied to clipboard

CMS Reauthentication doesn't work with react components / sections

Open cansozeri opened this issue 7 years ago • 11 comments

Sometimes even the image is jpg format ( I am sure ). I don't know why, but I can't upload the image with the uploader.

But I can upload the image from files section :=)

ERROR [UNKNOWN TYPE, ERRNO 400]:

Trace

SilverStripe\Dev\CliDebugView->renderTrace() DetailedErrorFormatter.php:117

SilverStripe\Logging\DetailedErrorFormatter->output(400, , , , ) DetailedErrorFormatter.php:52

SilverStripe\Logging\DetailedErrorFormatter->format(Array) HTTPResponse.php:355

SilverStripe\Control\HTTPResponse->outputBody() HTTPResponse.php:283

SilverStripe\Control\HTTPResponse->output() index.php:18

cansozeri avatar Nov 29 '17 21:11 cansozeri

Would you mind please providing a bit more context, for example how you're uploading the image?

robbieaverill avatar Nov 29 '17 21:11 robbieaverill

@robbieaverill I usually can upload image but sometimes it gives me this error. I can upload the image from files section..

private static $has_one = [
      'Photo' => Image::class,
  ];

public function getCMSFields()
  {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab(
        'Root.Main', $uploader = UploadField::create('Photo', 'Profil Photo'),'Content'
    );
    $uploader->setFolderName('profile');
    $uploader->getValidator()->setAllowedExtensions(['png','gif','jpeg','jpg']);

    return $fields;
  }

cansozeri avatar Nov 29 '17 21:11 cansozeri

Does a file already exist with the same filename as the one you are trying to upload? If so, maybe related to an issue I raised - https://github.com/silverstripe/silverstripe-framework/issues/7541

christopherdarling avatar Nov 29 '17 21:11 christopherdarling

@christopherdarling No it is new .. The image that I have tried to upload is https://ibb.co/kpih5G

I think it is related with $uploader->getValidator()->setAllowedExtensions(['png','gif','jpeg','jpg']);

The image is jpg but it triggers an error -- ERROR [UNKNOWN TYPE, ERRNO 400]:

cansozeri avatar Nov 29 '17 21:11 cansozeri

@cansozeri can you find the exact file and line number this error appears on? The stack trace for errors is currently broken (it shows the stacktrace of the error reporting subsystem; Our fault not yours :) ).

E.g.

image

Can you please show me the entire Page.php file? It's possible the Image::class doesn't have a use namespace at the top; Could that cause an unknown type error?

tractorcow avatar Nov 30 '17 00:11 tractorcow

@tractorcow this is the entire class :=) As I told before, I usually can upload an image without error, but sometimes I get this error..

class Artist extends Page
{
  private static $db = [

  ];

  private static $has_many = array (
      'PortfolioAlbums' => PortfolioAlbum::class,
  );

  private static $has_one = [
      'Photo' => Image::class,
  ];

  private static $owns = [
      'PortfolioAlbums',
      'Photo'
  ];

  private static $versioned_gridfield_extensions = true;

  public function getCMSFields()
  {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab(
        'Root.Main', $uploader = UploadField::create('Photo'),'Content'
    );
    $uploader->setFolderName('profile');
    $uploader->getValidator()->setAllowedExtensions(['png','gif','jpeg','jpg']);

    $fields->addFieldsToTab('Root.Portfolio', array (
        GridField::create(
            'PortfolioAlbums',
            'Portfolyo',
            $this->PortfolioAlbums()->sort('SortID'),
            GridFieldConfig_RecordEditor::create(500)
                ->addComponent($sortable = new GridFieldSortableRows('SortID'))
        )
    ));

    $sortable->setUpdateVersionedStage('Live');

    return $fields;
  }
}

cansozeri avatar Nov 30 '17 17:11 cansozeri

@tractorcow Interesting, I can upload the same image now :=) If I faced again I am gonna write you the error line :=)

cansozeri avatar Nov 30 '17 17:11 cansozeri

@tractorcow I think I have found the problem. If you leave admin page after some period a pop up appears and ask you password to stay at the page, after that action I couldn't upload an image I get the error ERROR [UNKNOWN TYPE, ERRNO 400]:

But logout and login again - then I could upload my image...

But the interesting thing is - I can upload from files section - can not upload from page uploader ..

cansozeri avatar Nov 30 '17 20:11 cansozeri

Oh, so it's actually a permission issue; If your session times out the upload action will become a 400 error. :) Makes sense!

Perhaps we need to bake in the session-reauthentication logic into react components a bit more intelligently?

tractorcow avatar Dec 05 '17 21:12 tractorcow

Renaming to better reflect the issue at hand. :)

tractorcow avatar Dec 05 '17 21:12 tractorcow

Hi,

Now if you add photo from gridfield and after that delete it. For example delete the photo item and the gallery with delete button from cms. It deletes from gallery and gallery item tables but not delete from live tables. I do not know the issue is related with this but then if you try to add the same photo with the same name you got error {"message":{"type":"error","value":"Extension is not allowed"}} If you change the name of the photo, then you can upload it again :=)

cansozeri avatar Dec 23 '17 20:12 cansozeri