errMap := make(map[string]interface{})
json.Unmarshal(resp.Body.Bytes(), &errMap)
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)
}
return nil
}
result := &api.User{
- ID: user.ID,
- UserName: user.Name,
- FullName: markup.Sanitize(user.FullName),
- Email: user.GetEmail(),
- AvatarURL: user.AvatarLink(),
- Created: user.CreatedUnix.AsTime(),
+ ID: user.ID,
+ UserName: user.Name,
+ FullName: markup.Sanitize(user.FullName),
+ Email: user.GetEmail(),
+ AvatarURL: user.AvatarLink(),
+ Created: user.CreatedUnix.AsTime(),
+ Restricted: user.IsRestricted,
}
// hide primary email if API caller is anonymous or user keep email private
if signed && (!user.KeepEmailPrivate || authed) {
MaxRepoCreation *int `json:"max_repo_creation"`
ProhibitLogin *bool `json:"prohibit_login"`
AllowCreateOrganization *bool `json:"allow_create_organization"`
+ Restricted *bool `json:"restricted"`
}
LastLogin time.Time `json:"last_login,omitempty"`
// swagger:strfmt date-time
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
if form.ProhibitLogin != nil {
u.ProhibitLogin = *form.ProhibitLogin
}
+ if form.Restricted != nil {
+ u.IsRestricted = *form.Restricted
+ }
if err := models.UpdateUser(u); err != nil {
if models.IsErrEmailAlreadyUsed(err) || models.IsErrEmailInvalid(err) {
"type": "boolean",
"x-go-name": "ProhibitLogin"
},
+ "restricted": {
+ "type": "boolean",
+ "x-go-name": "Restricted"
+ },
"source_id": {
"type": "integer",
"format": "int64",
"description": "the user's username",
"type": "string",
"x-go-name": "UserName"
+ },
+ "restricted": {
+ "description": "Is user restricted",
+ "type": "boolean",
+ "x-go-name": "Restricted"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"