-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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: UserID is missing sometimes #12846
Comments
It's not a bug :) gitea/modules/convert/convert.go Lines 347 to 354 in 08a905f
|
other endpoint's return it and it is needed for migration - inconsistency is a bug |
I already know where the issue is - we have 2 differend function to convert a user into an api-user -> bad thing!!! but didn't had time to refactor all of it |
@a1012112796 just use |
Hmm, Maybe the id of user is not an secret message. |
found it :) Lines 241 to 257 in 08a905f
|
So the main problem is whether the id of user should be protected? |
Chage Idea: diff --git a/models/user.go b/models/user.go
index c7b3f0981..08237b2cb 100644
--- a/models/user.go
+++ b/models/user.go
@@ -239,21 +239,34 @@ func (u *User) GetEmail() string {
}
// APIFormat converts a User to api.User
-func (u *User) APIFormat() *api.User {
+func (u *User) APIFormat(doer *User) *api.User {
if u == nil {
return nil
}
- return &api.User{
- ID: u.ID,
+
+ result := &api.User{
UserName: u.Name,
FullName: u.FullName,
- Email: u.GetEmail(),
AvatarURL: u.AvatarLink(),
Language: u.Language,
- IsAdmin: u.IsAdmin,
- LastLogin: u.LastLoginUnix.AsTime(),
Created: u.CreatedUnix.AsTime(),
}
+
+ signed := doer != nil
+ authed := doer != nil && (doer.IsAdmin || u.ID == doer.ID)
+
+ // hide primary email if API caller is anonymous or user keep email private
+ if signed && (!u.KeepEmailPrivate || authed) {
+ result.Email = u.Email
+ }
+ // only site admin will get these information and possibly user himself
+ if authed {
+ result.ID = u.ID
+ result.IsAdmin = u.IsAdmin
+ result.LastLogin = u.LastLoginUnix.AsTime()
+ result.Language = u.Language
+ }
+ return result
}
// IsLocal returns true if user login type is LoginPlain.
|
This comment has been minimized.
This comment has been minimized.
@a1012112796 I have created #12855 to fix this issue and #12856 witch wont get into v1.13 who will remove APIFormat ... |
@a1012112796 the refactor for User -> API-User convert refactor is ready :) -> #12856 |
sometimes UserID is missing!!
https://gitea.com/api/swagger#/repository/repoListPullReviews
example:
GET
https://gitea.com/api/v1/repos/gitea/test_repo/pulls/7/reviews
-> techknowlogick has ID 0 !!The text was updated successfully, but these errors were encountered: