feat: allow to find users with access to a project more freely
Related to https://kolaente.dev/vikunja/frontend/issues/2196
This commit is contained in:
@ -503,6 +503,17 @@ func TestProjectUsers(t *testing.T) {
|
||||
"username": "user7",
|
||||
}, false)
|
||||
})
|
||||
t.Run("discoverable by partial username, email and name when matching fuzzily", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
all, err := ListUsers(s, "user", &ProjectUserOpts{
|
||||
MatchFuzzily: true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, all, 15)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUserPasswordReset(t *testing.T) {
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
type ProjectUserOpts struct {
|
||||
AdditionalCond builder.Cond
|
||||
ReturnAllIfNoSearchProvided bool
|
||||
MatchFuzzily bool
|
||||
}
|
||||
|
||||
// ListUsers returns a project with all users, filtered by an optional search string
|
||||
@ -48,6 +49,16 @@ func ListUsers(s *xorm.Session, search string, opts *ProjectUserOpts) (users []*
|
||||
|
||||
if search != "" {
|
||||
for _, queryPart := range strings.Split(search, ",") {
|
||||
|
||||
if opts.MatchFuzzily {
|
||||
conds = append(conds,
|
||||
db.ILIKE("name", queryPart),
|
||||
db.ILIKE("username", queryPart),
|
||||
db.ILIKE("email", queryPart),
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
var usernameCond builder.Cond = builder.Eq{"username": queryPart}
|
||||
if db.Type() == schemas.POSTGRES {
|
||||
usernameCond = builder.Expr("username ILIKE ?", queryPart)
|
||||
|
Reference in New Issue
Block a user