-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 ContextUser
#18798
Add ContextUser
#18798
Conversation
// Show SSH keys. | ||
if isShowKeys { | ||
ShowSSHKeys(ctx, ctxUser.ID) | ||
return | ||
} | ||
|
||
// Show GPG keys. | ||
if isShowGPG { | ||
ShowGPGKeys(ctx, ctxUser.ID) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just removed or is it moved elsewhere? I can't find it but maybe I missed it. If it is removed, could please explain why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to other reviewers: there was a hint in the description.
While most changes are straight forward, have a look at routers/web/user/profile.go where I had to change the Profile method with additional routes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clean refactor, congrats. Easy to read too.
@KN4CK3R did you verify all the lines where |
I would say 50:50. The following methods are not tested, the rest is covered:
|
@@ -67,7 +63,7 @@ func CreateOrg(ctx *context.APIContext) { | |||
Visibility: visibility, | |||
} | |||
|
|||
if err := models.CreateOrganization(org, u); err != nil { | |||
if err := models.CreateOrganization(org, ctx.ContextUser); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may should be login user but not contextUser? It's not this PR but before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says
username of the user that will own the created organization
so ContextUser
is the correct user.
@singuliere I added the missing integration tests in #18872. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could rename ctx.User
together with this refactor, see my other comment.
Otherwise lgtm!
…r-context-user
#19161 is merged. How should the |
I still have a feeling that Since the user comes from |
But
That is only a short path so I don't have to query the database again (similar short path is in repo assignment). But that code is not run if there is no org involved in the path. |
I was thinking that If there is no better names, So I vote for |
…r-context-user
Is TargetUser a better name? Although actually ContextUser is not actually that bad really. What is the ContextUser? Its the user that is referred to by the path in the URL - i.e. the URL Context. |
I don't really like that
All three should be named similar. |
…r-context-user
Personally, I have a strong preference for Reasons:
And i think it's easier (and more clear) to rename And |
Yup this would be the only consistent way of doing it. The one slight flaw with sticking with context user is that it stutters somewhat in the go code. |
Then .... if no objection, could we merge and use |
* giteaofficial/main: Check go and nodejs version by go.mod and package.json (go-gitea#19197) Add `ContextUser` to http request context (go-gitea#18798) Set OpenGraph title to DisplayName in profile pages (go-gitea#19206)
This PR adds a middleware which sets a ContextUser (like GetUserByParams before) in a single place which can be used by other methods. For routes which represent a repo or org the respective middlewares set the field too. Also fix a bug in modules/context/org.go during refactoring.
This PR is a part of my package PR but I think it is better to have it standalone.
We have lots of places (mostly the API) where we call
GetUserByParams
to request the user for the current context. The method name is a bit misleading because it does not just gets the user but performs a redirect if the username was changed and so on.This PR adds a middleware which sets a
ContextUser
in a single place which can be used by other methods. For routes which represent a repo or org the respective middlewares set the field too.The change in modules/context/org.go is a bug I found while testing.
While most changes are straight forward, have a look at routers/web/user/profile.go where I had to change the
Profile
method with additional routes.