예제 #1
0
파일: user.go 프로젝트: vmware/harbor
// Delete ...
func (ua *UserAPI) Delete() {
	if !ua.IsAdmin {
		log.Warningf("current user, id: %d does not have admin role, can not remove user", ua.currentUserID)
		ua.RenderError(http.StatusForbidden, "User does not have admin role")
		return
	}

	// TODO read from conifg
	authMode := os.Getenv("AUTH_MODE")
	if authMode == "ldap_auth" {
		ua.CustomAbort(http.StatusForbidden, "user can not be deleted in LDAP authentication mode")
	}

	if ua.currentUserID == ua.userID {
		ua.CustomAbort(http.StatusForbidden, "can not delete yourself")
	}

	var err error
	err = dao.DeleteUser(ua.userID)
	if err != nil {
		log.Errorf("Failed to delete data from database, error: %v", err)
		ua.RenderError(http.StatusInternalServerError, "Failed to delete User")
		return
	}
}
예제 #2
0
func CommonDelUser() {
	queryUser := &models.User{
		Username: TestUserName,
	}
	commonUser, _ := dao.GetUser(*queryUser)
	_ = dao.DeleteUser(commonUser.UserID)

}