mirror of https://github.com/go-gitea/gitea.git
[API] Add Restricted Field to User (#14630)
* Expose Restricted field for User * Add Option to Change Restricted on User via adminEditUser API * Add test who change restricted & test if it changed it ... * make generate-swagger Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
ce0346448f
commit
8d5c795cc4
|
@ -192,4 +192,18 @@ func TestAPIEditUser(t *testing.T) {
|
||||||
errMap := make(map[string]interface{})
|
errMap := make(map[string]interface{})
|
||||||
json.Unmarshal(resp.Body.Bytes(), &errMap)
|
json.Unmarshal(resp.Body.Bytes(), &errMap)
|
||||||
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
|
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
|
||||||
|
|
||||||
|
user2 := models.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
|
||||||
|
assert.Equal(t, false, user2.IsRestricted)
|
||||||
|
bTrue := true
|
||||||
|
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
|
||||||
|
// required
|
||||||
|
LoginName: "user2",
|
||||||
|
SourceID: 0,
|
||||||
|
// to change
|
||||||
|
Restricted: &bTrue,
|
||||||
|
})
|
||||||
|
session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
user2 = models.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
|
||||||
|
assert.Equal(t, true, user2.IsRestricted)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ func ToUser(user *models.User, signed, authed bool) *api.User {
|
||||||
Email: user.GetEmail(),
|
Email: user.GetEmail(),
|
||||||
AvatarURL: user.AvatarLink(),
|
AvatarURL: user.AvatarLink(),
|
||||||
Created: user.CreatedUnix.AsTime(),
|
Created: user.CreatedUnix.AsTime(),
|
||||||
|
Restricted: user.IsRestricted,
|
||||||
}
|
}
|
||||||
// hide primary email if API caller is anonymous or user keep email private
|
// hide primary email if API caller is anonymous or user keep email private
|
||||||
if signed && (!user.KeepEmailPrivate || authed) {
|
if signed && (!user.KeepEmailPrivate || authed) {
|
||||||
|
|
|
@ -41,4 +41,5 @@ type EditUserOption struct {
|
||||||
MaxRepoCreation *int `json:"max_repo_creation"`
|
MaxRepoCreation *int `json:"max_repo_creation"`
|
||||||
ProhibitLogin *bool `json:"prohibit_login"`
|
ProhibitLogin *bool `json:"prohibit_login"`
|
||||||
AllowCreateOrganization *bool `json:"allow_create_organization"`
|
AllowCreateOrganization *bool `json:"allow_create_organization"`
|
||||||
|
Restricted *bool `json:"restricted"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ type User struct {
|
||||||
LastLogin time.Time `json:"last_login,omitempty"`
|
LastLogin time.Time `json:"last_login,omitempty"`
|
||||||
// swagger:strfmt date-time
|
// swagger:strfmt date-time
|
||||||
Created time.Time `json:"created,omitempty"`
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
// Is user restricted
|
||||||
|
Restricted bool `json:"restricted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
|
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
|
||||||
|
|
|
@ -224,6 +224,9 @@ func EditUser(ctx *context.APIContext) {
|
||||||
if form.ProhibitLogin != nil {
|
if form.ProhibitLogin != nil {
|
||||||
u.ProhibitLogin = *form.ProhibitLogin
|
u.ProhibitLogin = *form.ProhibitLogin
|
||||||
}
|
}
|
||||||
|
if form.Restricted != nil {
|
||||||
|
u.IsRestricted = *form.Restricted
|
||||||
|
}
|
||||||
|
|
||||||
if err := models.UpdateUser(u); err != nil {
|
if err := models.UpdateUser(u); err != nil {
|
||||||
if models.IsErrEmailAlreadyUsed(err) || models.IsErrEmailInvalid(err) {
|
if models.IsErrEmailAlreadyUsed(err) || models.IsErrEmailInvalid(err) {
|
||||||
|
|
|
@ -13796,6 +13796,10 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "ProhibitLogin"
|
"x-go-name": "ProhibitLogin"
|
||||||
},
|
},
|
||||||
|
"restricted": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "Restricted"
|
||||||
|
},
|
||||||
"source_id": {
|
"source_id": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64",
|
"format": "int64",
|
||||||
|
@ -16209,6 +16213,11 @@
|
||||||
"description": "the user's username",
|
"description": "the user's username",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "UserName"
|
"x-go-name": "UserName"
|
||||||
|
},
|
||||||
|
"restricted": {
|
||||||
|
"description": "Is user restricted",
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "Restricted"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||||
|
|
Loading…
Reference in New Issue