forked from vikunja/vikunja
fix: rename incorrectly named ProjectUsers method
This commit is contained in:
parent
8f4abd2fe8
commit
7e53a21407
@ -26,12 +26,12 @@ import (
|
||||
|
||||
func TestUserProject(t *testing.T) {
|
||||
t.Run("Normal test", func(t *testing.T) {
|
||||
rec, err := newTestRequestWithUser(t, http.MethodPost, apiv1.UserProject, &testuser1, "", nil, nil)
|
||||
rec, err := newTestRequestWithUser(t, http.MethodPost, apiv1.UserList, &testuser1, "", nil, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "null\n", rec.Body.String())
|
||||
})
|
||||
t.Run("Search for user3", func(t *testing.T) {
|
||||
rec, err := newTestRequestWithUser(t, http.MethodPost, apiv1.UserProject, &testuser1, "", map[string][]string{"s": {"user3"}}, nil)
|
||||
rec, err := newTestRequestWithUser(t, http.MethodPost, apiv1.UserList, &testuser1, "", map[string][]string{"s": {"user3"}}, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, rec.Body.String(), `user3`)
|
||||
assert.NotContains(t, rec.Body.String(), `user1`)
|
||||
|
@ -32,8 +32,8 @@ type ProjectUIDs struct {
|
||||
TeamProjectUserID int64 `xorm:"tlUID"`
|
||||
}
|
||||
|
||||
// ProjectUsersFromProject returns a project with all users who have access to a project, regardless of the method which gave them access
|
||||
func ProjectUsersFromProject(s *xorm.Session, l *Project, search string) (users []*user.User, err error) {
|
||||
// ListUsersFromProject returns a list with all users who have access to a project, regardless of the method which gave them access
|
||||
func ListUsersFromProject(s *xorm.Session, l *Project, search string) (users []*user.User, err error) {
|
||||
|
||||
userids := []*ProjectUIDs{}
|
||||
|
||||
@ -102,7 +102,7 @@ func ProjectUsersFromProject(s *xorm.Session, l *Project, search string) (users
|
||||
cond = builder.In("id", uids)
|
||||
}
|
||||
|
||||
users, err = user.ProjectUsers(s, search, &user.ProjectUserOpts{
|
||||
users, err = user.ListUsers(s, search, &user.ProjectUserOpts{
|
||||
AdditionalCond: cond,
|
||||
ReturnAllIfNoSearchProvided: true,
|
||||
})
|
||||
|
@ -228,9 +228,9 @@ func TestProjectUsersFromProject(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
gotUsers, err := ProjectUsersFromProject(s, tt.args.l, tt.args.search)
|
||||
gotUsers, err := ListUsersFromProject(s, tt.args.l, tt.args.search)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ProjectUsersFromProject() error = %v, wantErr %v", err, tt.wantErr)
|
||||
t.Errorf("ListUsersFromProject() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if diff, equal := messagediff.PrettyDiff(tt.wantUsers, gotUsers); !equal {
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// UserProject gets all information about a user
|
||||
// UserList gets all information about a list of users
|
||||
// @Summary Get users
|
||||
// @Description Search for a user by its username, name or full email. Name (not username) or email require that the user has enabled this in their settings.
|
||||
// @tags user
|
||||
@ -41,13 +41,13 @@ import (
|
||||
// @Failure 400 {object} web.HTTPError "Something's invalid."
|
||||
// @Failure 500 {object} models.Message "Internal server error."
|
||||
// @Router /users [get]
|
||||
func UserProject(c echo.Context) error {
|
||||
func UserList(c echo.Context) error {
|
||||
search := c.QueryParam("s")
|
||||
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
users, err := user.ProjectUsers(s, search, nil)
|
||||
users, err := user.ListUsers(s, search, nil)
|
||||
if err != nil {
|
||||
_ = s.Rollback()
|
||||
return handler.HandleHTTPError(err, c)
|
||||
@ -66,9 +66,9 @@ func UserProject(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
||||
// ProjectUsersForProject returns a project with all users who have access to a project, regardless of the method the project was shared with them.
|
||||
// ListUsersForProject returns a list with all users who have access to a project, regardless of the method the project was shared with them.
|
||||
// @Summary Get users
|
||||
// @Description Projects all users (without emailadresses). Also possible to search for a specific user.
|
||||
// @Description Lists all users (without emailadresses). Also possible to search for a specific user.
|
||||
// @tags project
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@ -80,7 +80,7 @@ func UserProject(c echo.Context) error {
|
||||
// @Failure 401 {object} web.HTTPError "The user does not have the right to see the project."
|
||||
// @Failure 500 {object} models.Message "Internal server error."
|
||||
// @Router /projects/{id}/projectusers [get]
|
||||
func ProjectUsersForProject(c echo.Context) error {
|
||||
func ListUsersForProject(c echo.Context) error {
|
||||
projectID, err := strconv.ParseInt(c.Param("project"), 10, 64)
|
||||
if err != nil {
|
||||
return handler.HandleHTTPError(err, c)
|
||||
@ -105,7 +105,7 @@ func ProjectUsersForProject(c echo.Context) error {
|
||||
}
|
||||
|
||||
search := c.QueryParam("s")
|
||||
users, err := models.ProjectUsersFromProject(s, &project, search)
|
||||
users, err := models.ListUsersFromProject(s, &project, search)
|
||||
if err != nil {
|
||||
_ = s.Rollback()
|
||||
return handler.HandleHTTPError(err, c)
|
||||
|
@ -288,7 +288,7 @@ func registerAPIRoutes(a *echo.Group) {
|
||||
|
||||
u.GET("", apiv1.UserShow)
|
||||
u.POST("/password", apiv1.UserChangePassword)
|
||||
u.GET("s", apiv1.UserProject)
|
||||
u.GET("s", apiv1.UserList)
|
||||
u.POST("/token", apiv1.RenewToken)
|
||||
u.POST("/settings/email", apiv1.UpdateUserEmail)
|
||||
u.GET("/settings/avatar", apiv1.GetUserAvatarProvider)
|
||||
@ -327,7 +327,7 @@ func registerAPIRoutes(a *echo.Group) {
|
||||
a.POST("/projects/:project", projectHandler.UpdateWeb)
|
||||
a.DELETE("/projects/:project", projectHandler.DeleteWeb)
|
||||
a.PUT("/namespaces/:namespace/projects", projectHandler.CreateWeb)
|
||||
a.GET("/projects/:project/projectusers", apiv1.ProjectUsersForProject)
|
||||
a.GET("/projects/:project/projectusers", apiv1.ListUsersForProject)
|
||||
|
||||
if config.ServiceEnableLinkSharing.GetBool() {
|
||||
projectSharingHandler := &handler.WebHandler{
|
||||
|
@ -377,7 +377,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "user1", nil)
|
||||
all, err := ListUsers(s, "user1", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, len(all) > 0)
|
||||
assert.Equal(t, all[0].Username, "user1")
|
||||
@ -387,7 +387,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "uSEr1", nil)
|
||||
all, err := ListUsers(s, "uSEr1", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, len(all) > 0)
|
||||
assert.Equal(t, all[0].Username, "user1")
|
||||
@ -406,7 +406,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "", nil)
|
||||
all, err := ListUsers(s, "", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 0)
|
||||
})
|
||||
@ -415,7 +415,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "user1@example.com", nil)
|
||||
all, err := ListUsers(s, "user1@example.com", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 0)
|
||||
db.AssertExists(t, "users", map[string]interface{}{
|
||||
@ -428,7 +428,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "one else", nil)
|
||||
all, err := ListUsers(s, "one else", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 0)
|
||||
db.AssertExists(t, "users", map[string]interface{}{
|
||||
@ -441,7 +441,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "user7@example.com", nil)
|
||||
all, err := ListUsers(s, "user7@example.com", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 1)
|
||||
assert.Equal(t, int64(7), all[0].ID)
|
||||
@ -455,7 +455,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "with space", nil)
|
||||
all, err := ListUsers(s, "with space", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 1)
|
||||
assert.Equal(t, int64(12), all[0].ID)
|
||||
@ -469,7 +469,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "user7@example.com", &ProjectUserOpts{AdditionalCond: builder.In("id", 7)})
|
||||
all, err := ListUsers(s, "user7@example.com", &ProjectUserOpts{AdditionalCond: builder.In("id", 7)})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 1)
|
||||
assert.Equal(t, int64(7), all[0].ID)
|
||||
@ -483,7 +483,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "user7", nil)
|
||||
all, err := ListUsers(s, "user7", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 1)
|
||||
assert.Equal(t, int64(7), all[0].ID)
|
||||
@ -496,7 +496,7 @@ func TestProjectUsers(t *testing.T) {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ProjectUsers(s, "user", nil)
|
||||
all, err := ListUsers(s, "user", nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 0)
|
||||
db.AssertExists(t, "users", map[string]interface{}{
|
||||
|
@ -31,8 +31,8 @@ type ProjectUserOpts struct {
|
||||
ReturnAllIfNoSearchProvided bool
|
||||
}
|
||||
|
||||
// ProjectUsers returns a project with all users, filtered by an optional search string
|
||||
func ProjectUsers(s *xorm.Session, search string, opts *ProjectUserOpts) (users []*User, err error) {
|
||||
// ListUsers returns a project with all users, filtered by an optional search string
|
||||
func ListUsers(s *xorm.Session, search string, opts *ProjectUserOpts) (users []*User, err error) {
|
||||
if opts == nil {
|
||||
opts = &ProjectUserOpts{}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user