Enable searching users by full email or name
This commit is contained in:
@ -31,11 +31,11 @@ import (
|
||||
|
||||
// UserList gets all information about a user
|
||||
// @Summary Get users
|
||||
// @Description Lists all users (without emailadresses). Also possible to search for a specific user.
|
||||
// @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
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param s query string false "Search for a user by its name."
|
||||
// @Param s query string false "The search criteria."
|
||||
// @Security JWTKeyAuth
|
||||
// @Success 200 {array} user.User "All (found) users."
|
||||
// @Failure 400 {object} web.HTTPError "Something's invalid."
|
||||
|
@ -38,7 +38,11 @@ type UserSettings struct {
|
||||
// The new name of the current user.
|
||||
Name string `json:"name"`
|
||||
// If enabled, sends email reminders of tasks to the user.
|
||||
EmailRemindersEnabled bool `xorm:"bool default false" json:"email_reminders_enabled"`
|
||||
EmailRemindersEnabled bool `json:"email_reminders_enabled"`
|
||||
// If true, this user can be found by their name or parts of it when searching for it.
|
||||
DiscoverableByName bool `json:"discoverable_by_name"`
|
||||
// If true, the user can be found when searching for their exact email.
|
||||
DiscoverableByEmail bool `json:"discoverable_by_email"`
|
||||
}
|
||||
|
||||
// GetUserAvatarProvider returns the currently set user avatar
|
||||
@ -161,6 +165,8 @@ func UpdateGeneralUserSettings(c echo.Context) error {
|
||||
|
||||
user.Name = us.Name
|
||||
user.EmailRemindersEnabled = us.EmailRemindersEnabled
|
||||
user.DiscoverableByEmail = us.DiscoverableByEmail
|
||||
user.DiscoverableByName = us.DiscoverableByName
|
||||
|
||||
_, err = user2.UpdateUser(s, user)
|
||||
if err != nil {
|
||||
|
@ -19,6 +19,8 @@ package v1
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
|
||||
"code.vikunja.io/api/pkg/models"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
@ -28,6 +30,11 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type userWithSettings struct {
|
||||
user.User
|
||||
Settings *UserSettings `json:"settings"`
|
||||
}
|
||||
|
||||
// UserShow gets all informations about the current user
|
||||
// @Summary Get user information
|
||||
// @Description Returns the current user object.
|
||||
@ -48,10 +55,20 @@ func UserShow(c echo.Context) error {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
user, err := models.GetUserOrLinkShareUser(s, a)
|
||||
u, err := models.GetUserOrLinkShareUser(s, a)
|
||||
if err != nil {
|
||||
return handler.HandleHTTPError(err, c)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, user)
|
||||
us := &userWithSettings{
|
||||
User: *u,
|
||||
Settings: &UserSettings{
|
||||
Name: u.Name,
|
||||
EmailRemindersEnabled: u.EmailRemindersEnabled,
|
||||
DiscoverableByName: u.DiscoverableByName,
|
||||
DiscoverableByEmail: u.DiscoverableByEmail,
|
||||
},
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, us)
|
||||
}
|
||||
|
Reference in New Issue
Block a user