1
0

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:
kolaente
2023-04-03 18:49:04 +02:00
parent 327bb3bed9
commit a7231e197e
5 changed files with 34 additions and 2 deletions

View File

@ -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) {

View File

@ -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)