This commit is contained in:
Wenkai Yin 2017-06-16 16:41:48 +08:00
parent ae77753bf2
commit df56010739
4 changed files with 11 additions and 4 deletions

View File

@ -411,7 +411,7 @@ func TestListUsers(t *testing.T) {
if err != nil {
t.Errorf("Error occurred in ListUsers: %v", err)
}
if len(users) != 2 {
if len(users) != 1 {
t.Errorf("Expect one user in list, but the acutal length is %d, the list: %+v", len(users), users)
}
users2, err := ListUsers(&models.UserQuery{Username: username})

View File

@ -109,7 +109,9 @@ func ListUsers(query *models.UserQuery) ([]models.User, error) {
}
func userQueryConditions(query *models.UserQuery) orm.QuerySeter {
qs := GetOrmer().QueryTable(&models.User{}).Filter("deleted", 0)
qs := GetOrmer().QueryTable(&models.User{}).
Filter("deleted", 0).
Filter("user_id__gt", 1)
if query == nil {
return qs

View File

@ -272,6 +272,11 @@ func (ua *UserAPI) Delete() {
ua.CustomAbort(http.StatusForbidden, "can not delete yourself")
}
if ua.userID == 1 {
ua.HandleForbidden(ua.SecurityCtx.GetUsername())
return
}
var err error
err = dao.DeleteUser(ua.userID)
if err != nil {

View File

@ -68,8 +68,8 @@ func initRouters() {
beego.Router("/api/projects/:id([0-9]+)/publicity", &api.ProjectAPI{}, "put:ToggleProjectPublic")
beego.Router("/api/projects/:id([0-9]+)/logs", &api.ProjectAPI{}, "get:Logs")
beego.Router("/api/statistics", &api.StatisticAPI{})
beego.Router("/api/users/:id", &api.UserAPI{}, "get:Get")
beego.Router("/api/users", &api.UserAPI{}, "get:List;post:Post;delete:Delete;put:Put")
beego.Router("/api/users/:id", &api.UserAPI{}, "get:Get;delete:Delete;put:Put")
beego.Router("/api/users", &api.UserAPI{}, "get:List;post:Post")
beego.Router("/api/users/:id([0-9]+)/password", &api.UserAPI{}, "put:ChangePassword")
beego.Router("/api/internal/syncregistry", &api.InternalAPI{}, "post:SyncRegistry")
beego.Router("/api/repositories", &api.RepositoryAPI{}, "get:Get")