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 Active and ProhibitLogin to API #15689

Merged
merged 7 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/convert/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func toUser(user *models.User, signed, authed bool) *api.User {
result.IsAdmin = user.IsAdmin
result.LastLogin = user.LastLoginUnix.AsTime()
result.Language = user.Language
result.IsActive = &user.IsActive
6543 marked this conversation as resolved.
Show resolved Hide resolved
result.ProhibitLogin = &user.ProhibitLogin
}
return result
}
4 changes: 4 additions & 0 deletions modules/structs/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type User struct {
Created time.Time `json:"created,omitempty"`
// Is user restricted
Restricted bool `json:"restricted"`
// Is user active
IsActive *bool `json:"active,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Why ref?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, just use bool if it will always have a value.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry! I take my words back. For non-admin users, hide the field is better. A nil bool means Don't know if it's active. @6543

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case all of these fields should be omitted:

// only site admin will get these information and possibly user himself
if authed {
result.IsAdmin = user.IsAdmin
result.LastLogin = user.LastLoginUnix.AsTime()
result.Language = user.Language
}

IsAdmin would be a pointer then and IsAdmin and Language would get the omitempty flag. LastLogin already has the flag.

Copy link
Member

Choose a reason for hiding this comment

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

well if it is always false it does not leak any info ... onto normal users

// Is user login prohibited
ProhibitLogin *bool `json:"prohibit_login,omitempty"`
}

// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
Expand Down
10 changes: 10 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16246,6 +16246,11 @@
"description": "User represents a user",
"type": "object",
"properties": {
"active": {
"description": "Is user active",
"type": "boolean",
"x-go-name": "IsActive"
},
"avatar_url": {
"description": "URL to the user's avatar",
"type": "string",
Expand Down Expand Up @@ -16292,6 +16297,11 @@
"type": "string",
"x-go-name": "UserName"
},
"prohibit_login": {
"description": "Is user login prohibited",
"type": "boolean",
"x-go-name": "ProhibitLogin"
},
"restricted": {
"description": "Is user restricted",
"type": "boolean",
Expand Down