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

Add API for changing Avatars #25369

Merged
merged 9 commits into from
Jun 29, 2023
Merged

Add API for changing Avatars #25369

merged 9 commits into from
Jun 29, 2023

Conversation

JakobDev
Copy link
Contributor

This adds an API for uploading and Deleting Avatars for of Users, Repos and Organisations. I'm not sure, if this should also be added to the Admin API.

Resolves #25344

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 19, 2023
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jun 19, 2023
}

st := typesniffer.DetectContentType(content)
if !(st.IsImage() && !st.IsSvgImage()) {
Copy link
Member

@silverwind silverwind Jun 20, 2023

Choose a reason for hiding this comment

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

I don't think we actually support SVG avatars on UI avatar upload, so it should not accept them here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was just copied from the Web UI

if int64(len(content)) > setting.Avatar.MaxFileSize {
ctx.Error(http.StatusBadRequest, "AvatarTooBig", fmt.Errorf("The avatar is to big"))
return
}
Copy link
Member

Choose a reason for hiding this comment

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

There is also a height/width check (4000x4000 default). Can we maybe combine these checks so we don't have to duplicate them?

Copy link
Contributor

Choose a reason for hiding this comment

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

All "pre-check" code for uploaded avatar can be removed.

The UploadAvatar calls ProcessAvatarImage, which already handle type-check, size-limit, resizing, etc, correctly.

@6543 6543 added modifies/api This PR adds API routes or modifies them theme/avatar labels Jun 22, 2023
@6543 6543 added this to the 1.21.0 milestone Jun 22, 2023
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 27, 2023
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 29, 2023
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 29, 2023
@silverwind silverwind enabled auto-merge (squash) June 29, 2023 03:39
@silverwind silverwind removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 29, 2023
@silverwind
Copy link
Member

Swagger compilation failure:

The swagger spec at "./templates/swagger/v1_json.tmpl" is invalid against swagger specification 2.0.
See errors below:
- "paths./orgs/{org}/avatar.delete.parameters" must validate one and only one schema (oneOf). Found none valid
- paths./orgs/{org}/avatar.delete.parameters.in in body should be one of [header]
- paths./orgs/{org}/avatar.delete.parameters.type in body is required
- "paths./orgs/{org}/avatar.post.parameters" must validate one and only one schema (oneOf). Found none valid
- paths./orgs/{org}/avatar.post.parameters.in in body should be one of [header]
- paths./orgs/{org}/avatar.post.parameters.type in body is required
- invalid definition for parameter org in path in operation "orgDeleteAvatar"
- in operation "orgDeleteAvatar",path param "org" must be declared as required
- invalid definition for parameter org in path in operation "orgUpdateAvatar"
- in operation "orgUpdateAvatar",path param "org" must be declared as required

auto-merge was automatically disabled June 29, 2023 12:38

Head branch was pushed to by a user without write access

@JakobDev
Copy link
Contributor Author

Swagger compilation failure:

I don't really know what causes this. The swagger comments are the same as in other functions and I ran make generate-swagger.

@silverwind
Copy link
Member

silverwind commented Jun 29, 2023

Could try updating go-swagger to v0.30.5 in Makefile if you suspect a bug.

@JakobDev
Copy link
Contributor Author

I figured it out myself: make lint-swagger gave a more helpful error:

 1609:11  error  path-params  Path parameter "org" must have "required" property that is set to
"true".  paths./orgs/{org}/avatar.post.parameters[0]
 1638:11  error  path-params  Path parameter "org" must have "required" property that is set to
"true".  paths./orgs/{org}/avatar.delete.parameters[0]

That's one of the times were you look at the code and don't find the error.

@silverwind
Copy link
Member

Ah, indeed. lint-swagger has much better errors, yes.

@silverwind
Copy link
Member

This actually highlighed a bug in our action pipelines where lint-swagger did not run, will file a PR.

@silverwind
Copy link
Member

#25593 will fix it.

@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 29, 2023
@silverwind silverwind enabled auto-merge (squash) June 29, 2023 22:49
@silverwind silverwind merged commit 254a828 into go-gitea:main Jun 29, 2023
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 29, 2023
@JakobDev JakobDev deleted the avatarapi branch June 30, 2023 06:02
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jul 2, 2023
* giteaoffical/main: (89 commits)
  Move some files under repo/setting (go-gitea#25585)
  Following-up improvments for various PRs (go-gitea#25620)
  Set SSH_AUTHORIZED_KEYS_BACKUP to false (go-gitea#25412)
  Fix bug of branches API with tests (go-gitea#25578)
  [skip ci] Updated translations via Crowdin
  Application as a maintainer (go-gitea#25614)
  Adding  branch-name copy  to clipboard branches screen. (go-gitea#25596)
  Use AfterCommitId to get commit for Viewed functionality (go-gitea#25529)
  Fix branch commit message too long problem (go-gitea#25588)
  Restrict `[actions].DEFAULT_ACTIONS_URL` to only `github` or `self` (go-gitea#25581)
  Add API for changing Avatars (go-gitea#25369)
  read-only checkboxes don't appear and don't entirely act the way one might expect (go-gitea#25573)
  Redirect to package after version deletion (go-gitea#25594)
  Update emoji set to Unicode 15 (go-gitea#25595)
  Fix `lint-swagger` action (go-gitea#25593)
  Replace fomantic divider module with our own (go-gitea#25539)
  Add documentation about supported workflow trigger events (go-gitea#25582)
  Sync branches into databases (go-gitea#22743)
  Fix milestones deletion (go-gitea#25583)
  Reduce table padding globally (go-gitea#25568)
  ...

# Conflicts:
#	templates/repo/wiki/revision.tmpl
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set user avatar with CLI or API
6 participants