-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Reject star-related requests if stars are disabled #33208
base: main
Are you sure you want to change the base?
Conversation
- add APIGone response type - re-generate Swagger spec if stars are disabled: - render 404 page on /repo/stars - return 410 error on star-related API endpoints and actions - return empty value on star model functions (StarRepo, IsStaring, GetStargazers)
If there is a simple and clear solution to "disable" some requests, I could vote my approval. But this change doesn't look good to me: too many "if" tricks and unnecessary new error type. I prefer to be "restraint" to avoid making the code more complex than it should be. IMO it's not feasible to keep adding more options and "if" code to make every feature "disable-able". |
a middleware maybe?
it's not 400: nothing wrong with the request, the resource is just disabled 410 Gone is the status that best fits a resource that was intentionally made unavailable, likely permanently, and it did not exist already so I had to create it for Swagger.
I get that, but having a piece of software that is highly customizable without having to hack it yourself is a very good thing. I personally want to completely disable the repo watching feature, which is not currently doable via config, so I'm having to implement it myself, and will contribute my changes in case someone else needs to disable it as well. isn't that what OSS is about? |
Gitea already uses 403/404 for disabled features, see other code. |
That's a trade-off. Just like Linux doesn't accept all patches into the kernel, it depends on many facts: the public interests, the maintainability cost, the benefits to end users, etc. My opinions are:
Disclaimer: that's just my opinion (to explain "look good to 'me' or not"), other maintainers could still approve if it looks good to them. |
I think this is a reasonable pattern to establish, as even though "stars" may not do much if someone gets around the block by using the API, in the case of watchers that has an impact due to emails being sent out. As for status, 403 is acceptable as it's "you are forbidden from doing this", and while gone does make sense, it's for things that don't come back, but in theory stars could be re-enabled |
and it makes total sense for stars to be consistent with watching being fully disabled. |
That's a different problem and not in this PR's scope (unrelated) If you would like to fix that problem, it also needs tests to make sure the logic is right and won't break. |
if you're willing to explain how to set config options during testing I'll definitely write them, but as of right now I have no idea of how to do that or if it's even possible. |
|
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/410
As |
IMO it has a higher chance of being permanent, i.e. an undesired feature than temporary, i.e. "someone is abusing it so I'll turn if off for now" or something. Can't say the same for all config options though. Plus they also state: That being said, for consistency with existing code we should either go with 403 or 404, and I personally prefer the latter. |
I've been busy this week but I'll try to get more progress done in this tonight. |
also return 403 Forbidden instead of 410 Gone
…ually_disable_stars
also undo disabled stars check before sending StarUnstar template in Action() as the action already checks for it.
now I think I need to tackle tests, which I'm not looking forward to. |
This PR fixes #33205.
If stars are disabled:
.../repo/stars
page now shows a 404 errorStars are disabled.