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

[API][Administrator] Implement managing avatar features #11255

Merged
merged 1 commit into from
Mar 19, 2020

Conversation

GSadee
Copy link
Member

@GSadee GSadee commented Mar 19, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets part of #11250
License MIT

@GSadee GSadee added Feature New feature proposals. API APIs related issues and PRs. labels Mar 19, 2020
@GSadee GSadee requested a review from a team as a code owner March 19, 2020 13:42
*/
public function iUploadTheImageAsMyAvatar(string $avatar, AdminUserInterface $administrator): void
{
$response = $this->client->upload(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also use avatarImageClient for the avatar uploading?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, there is no difference as I pass entire url here. Do you suggest to refactor upload method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an option, but for me, the main problem is confusion, that we upload an avatar with $client, but remove it with the avatarImageClient 🐎

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote for doing it the same way with the rest of our resources. Right now upload function is behaving differently than other client methods, so +1 for refactor

$response = $this->client->upload(
'/new-api/avatar-images',
['owner' => $this->iriConverter->getIriFromItem($administrator)],
['file' => new UploadedFile($this->minkParameters['files_path'] . $avatar, basename($avatar))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering, is it a proper approach 🤔 It's not resolving the issue like this one when one wants to just use the API (not call the endpoint in the code). Maybe we should just pass the URL to the image which is temporarily somewhere else? I don' know, just thinking out loud 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I don't understand you in 100%, the case is to upload an image, not to pass a URL to the image... I have no other idea how to approach this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, there is an ongoing problem in Sylius documentation on how to handle files upload through API since the Admin API. Problem is that what you have used here (and is used in the whole Sylius codebase) works because we are operating inside of a project. One could not simply use UploadedFile in js.

$response = $this->client->upload(
'/new-api/avatar-images',
['owner' => $this->iriConverter->getIriFromItem($administrator)],
['file' => new UploadedFile($this->minkParameters['files_path'] . $avatar, basename($avatar))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, there is an ongoing problem in Sylius documentation on how to handle files upload through API since the Admin API. Problem is that what you have used here (and is used in the whole Sylius codebase) works because we are operating inside of a project. One could not simply use UploadedFile in js.


$oldImage = $owner->getImage();
if ($oldImage !== null) {
$this->avatarImageRepository->remove($oldImage);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it will remove a file from disk as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, to be 100% sure, I've checked that and ImagesRemoveListener will remove the file

*/
public function iUploadTheImageAsMyAvatar(string $avatar, AdminUserInterface $administrator): void
{
$response = $this->client->upload(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote for doing it the same way with the rest of our resources. Right now upload function is behaving differently than other client methods, so +1 for refactor

@lchrusciel lchrusciel merged commit 0f8ab07 into Sylius:master Mar 19, 2020
@lchrusciel
Copy link
Member

Thank you, Grzegorz! 🎉

@GSadee GSadee deleted the api-administrator-avatar branch March 19, 2020 14:59
lchrusciel added a commit that referenced this pull request Mar 23, 2020
…ient + minor fixes (GSadee)

This PR was merged into the 1.8-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | after #11255
| License         | MIT


Commits
-------

27405f5 [API][Administrator] Refactor upload action in api client + minor fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API APIs related issues and PRs. Feature New feature proposals.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants