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] Subscribing user to issue produces nil in API reponse #18090

Closed
realaravinth opened this issue Dec 24, 2021 · 2 comments · Fixed by #18091
Closed

[API] Subscribing user to issue produces nil in API reponse #18090

realaravinth opened this issue Dec 24, 2021 · 2 comments · Fixed by #18091

Comments

@realaravinth
Copy link
Contributor

Gitea Version

743-g7cc44491f

Git Version

No response

Operating System

No response

How are you running Gitea?

Tested on https://try.gitea.io

Database

No response

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Description

When subscribing a user through the API to an issue, it returns the following error when the operation is forbidden:

{
  "message": "%!s(<nil>)",
  "url": "https://try.gitea.io/api/swagger"
}

This is probably harmless but can be fixed to return an appropriate error message like so:

{
 "message": "Only admin and user for itself can change subscription",
"url": "https://try.gitea.io/api/swagger"
}

The problem seems to be in this line:

ctx.Error(http.StatusForbidden, "User", nil)

I'll be happy to submit a patch to this effect!

Screenshots

image

@zeripath
Copy link
Contributor

This can only occur if you're trying to subscribe a user that isn't the logged in user or you're not the admin.

It will be coming from

	//only admin and user for itself can change subscription
	if user.ID != ctx.User.ID && !ctx.User.IsAdmin {
		ctx.Error(http.StatusForbidden, "User", nil)
		return
	}

@realaravinth
Copy link
Contributor Author

The error(403 forbidden) is alright and is working according to spec but I was referring to the message. It's a minor thing but a descriptive error message might come in handy while debugging

zeripath added a commit to zeripath/gitea that referenced this issue Dec 24, 2021
…nied

Fix go-gitea#18090

Signed-off-by: Andrew Thornton <art27@cantab.net>
wxiaoguang added a commit that referenced this issue Dec 24, 2021
…nied (#18091)

Fix #18090

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
…nied (go-gitea#18091)

Fix go-gitea#18090

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants