Skip to content

Organizations: allow uploading avatar #12254

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Jun 17, 2025

  • The file size is set to 750kb as max
  • The image dimensions should be equal or less to 500px
  • Only jpg and png formats are allowed (this is a soft check anyway), we are not checking for the content, but django does check if the file is an image using pillow at least.
  • Images are publicly accessible and can be enumerated, I think this is fine, avatar images aren't sensible information.
  • pillow is a required dependency when using ImageField

This requires creating a new bucket and the corresponding settings in ops.

Closes https://github.com/readthedocs/readthedocs-corporate/issues/1471

@stsewd stsewd requested a review from a team as a code owner June 17, 2025 19:18
@stsewd stsewd requested a review from humitos June 17, 2025 19:18
@stsewd
Copy link
Member Author

stsewd commented Jun 17, 2025

Not sure about the migrations check, I don't see any changes locally :/

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Looks good to me. I left some small comments.

@@ -26,6 +29,21 @@
log = structlog.get_logger(__name__)


def _upload_organization_avatar_to(instance, filename):
extension = filename.split(".")[-1].lower()
return f"avatars/organizations/{instance.pk}.{extension}"
Copy link
Member

Choose a reason for hiding this comment

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

We use the slug of the object in other buckets to generate the path. It will be easier to find the file when debugging as well.

Suggested change
return f"avatars/organizations/{instance.pk}.{extension}"
return f"avatars/organizations/{instance.slug}.{extension}"

Copy link
Member Author

Choose a reason for hiding this comment

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

Organization slugs can be renamed, we don't want to have broken/orphan avatars when that happens.

Copy link
Member

Choose a reason for hiding this comment

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

Nope, organization slugs cannot be changed. We use them on the media bucket to store the documentation. We should keep consistency here 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.

Slugs are changed via support, the slug from the media bucket is the project slug, not the organization slug.

Copy link
Member

Choose a reason for hiding this comment

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

We don't change slug via support on purpose. We always tell people to re-create the object. The project slug in .com is the combination of "organization slug + project slug"

Copy link
Member

Choose a reason for hiding this comment

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

If it feels like much more work, the rest of us are all okay with just using the org slug.

👍🏼

Copy link
Member Author

Choose a reason for hiding this comment

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

Using a UUID is safer (we don't need a hash) and just avoids having edge cases with slug renames. Slug renames can lead to collisions, allowing another organization to control the avatar from another organization. Why take that risk when a UUID is much safer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah UUID does avoid all that.

But we're all saying the slug is fine because the risk here doesn't seem significant. The cost of this discussion and spending more time engineering a solution for an edge case will overshadow the cost of spending a few extra minutes each year telling a couple users they need to update their avatar.

Copy link
Member Author

Choose a reason for hiding this comment

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

The cost of having to deal the avatars randomly changing when there is a slug change is greater than implementing a good solution from the start that only requires a couple of lines of code. And as mentioned, this edge case allows for random users changing the avatar from another organization, so the problems caused are not insignificant.

Copy link
Member

Choose a reason for hiding this comment

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

So implement a UUID and move forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants