From 408834e92badc1ee926c02c839525c5d2a9176d8 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Tue, 27 Aug 2019 18:01:18 +0200 Subject: [PATCH] spec cleanup, add find-by-handle for users --- api/system/spec.json | 12 +++++++++--- api/system/spec/user.json | 6 ++++++ docs/system/README.md | 1 + system/internal/repository/mocks/user.go | 13 +++++++++++++ system/internal/repository/user.go | 4 ++++ system/rest/request/user.go | 5 +++++ system/rest/user.go | 1 + system/types/user.go | 1 + 8 files changed, 40 insertions(+), 3 deletions(-) diff --git a/api/system/spec.json b/api/system/spec.json index d0ca75158..e5522c3b3 100644 --- a/api/system/spec.json +++ b/api/system/spec.json @@ -309,7 +309,8 @@ } } ] - },{ + }, + { "title": "Organisations", "description": "Organisations represent a top-level grouping entity. There may be many organisations defined in a single deployment.", "path": "/organisations", @@ -702,6 +703,12 @@ "required": false, "title": "Search email to match against users" }, + { + "type": "string", + "name": "handle", + "required": false, + "title": "Search handle to match against users" + }, { "name": "kind", "type": "types.UserKind", @@ -1096,8 +1103,7 @@ } } ] - }, - { + }, { "title": "Permissions", "parameters": {}, "entrypoint": "permissions", diff --git a/api/system/spec/user.json b/api/system/spec/user.json index b8b604628..e96cdec36 100644 --- a/api/system/spec/user.json +++ b/api/system/spec/user.json @@ -41,6 +41,12 @@ "title": "Search email to match against users", "type": "string" }, + { + "name": "handle", + "required": false, + "title": "Search handle to match against users", + "type": "string" + }, { "name": "kind", "required": false, diff --git a/docs/system/README.md b/docs/system/README.md index 210b4d59a..7f7814d02 100644 --- a/docs/system/README.md +++ b/docs/system/README.md @@ -754,6 +754,7 @@ An organisation may have many roles. Roles may have many channels available. Acc | query | string | GET | Search query to match against users | N/A | NO | | username | string | GET | Search username to match against users | N/A | NO | | email | string | GET | Search email to match against users | N/A | NO | +| handle | string | GET | Search handle to match against users | N/A | NO | | kind | types.UserKind | GET | Kind (normal, bot) | N/A | NO | | incDeleted | bool | GET | Include deleted users (requires 'access' permission) | N/A | NO | | incSuspended | bool | GET | Include suspended users (requires 'access' permission) | N/A | NO | diff --git a/system/internal/repository/mocks/user.go b/system/internal/repository/mocks/user.go index 994c434d1..6503184cf 100644 --- a/system/internal/repository/mocks/user.go +++ b/system/internal/repository/mocks/user.go @@ -75,6 +75,19 @@ func (mr *MockUserRepositoryMockRecorder) FindByUsername(username interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindByUsername", reflect.TypeOf((*MockUserRepository)(nil).FindByUsername), username) } +// FindByHandle mocks base method +func (m *MockUserRepository) FindByHandle(handle string) (*types.User, error) { + ret := m.ctrl.Call(m, "FindByHandle", handle) + ret0, _ := ret[0].(*types.User) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FindByHandle indicates an expected call of FindByHandle +func (mr *MockUserRepositoryMockRecorder) FindByHandle(handle interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindByHandle", reflect.TypeOf((*MockUserRepository)(nil).FindByHandle), handle) +} + // FindByID mocks base method func (m *MockUserRepository) FindByID(id uint64) (*types.User, error) { ret := m.ctrl.Call(m, "FindByID", id) diff --git a/system/internal/repository/user.go b/system/internal/repository/user.go index 7691d968d..d803dc47d 100644 --- a/system/internal/repository/user.go +++ b/system/internal/repository/user.go @@ -148,6 +148,10 @@ func (r user) Find(filter types.UserFilter) (set types.UserSet, f types.UserFilt q = q.Where("u.username = ?", f.Username) } + if f.Handle != "" { + q = q.Where("u.handle = ?", f.Handle) + } + if f.Kind != "" { q = q.Where("u.kind = ?", f.Kind) } diff --git a/system/rest/request/user.go b/system/rest/request/user.go index da2fe0c7e..09976c6f4 100644 --- a/system/rest/request/user.go +++ b/system/rest/request/user.go @@ -37,6 +37,7 @@ type UserList struct { Query string Username string Email string + Handle string Kind types.UserKind IncDeleted bool IncSuspended bool @@ -55,6 +56,7 @@ func (r UserList) Auditable() map[string]interface{} { out["query"] = r.Query out["username"] = r.Username out["email"] = r.Email + out["handle"] = r.Handle out["kind"] = r.Kind out["incDeleted"] = r.IncDeleted out["incSuspended"] = r.IncSuspended @@ -101,6 +103,9 @@ func (r *UserList) Fill(req *http.Request) (err error) { if val, ok := get["email"]; ok { r.Email = val } + if val, ok := get["handle"]; ok { + r.Handle = val + } if val, ok := get["kind"]; ok { r.Kind = types.UserKind(val) } diff --git a/system/rest/user.go b/system/rest/user.go index 36624abd9..035a81de3 100644 --- a/system/rest/user.go +++ b/system/rest/user.go @@ -38,6 +38,7 @@ func (ctrl User) List(ctx context.Context, r *request.UserList) (interface{}, er Query: r.Query, Email: r.Email, Username: r.Username, + Handle: r.Handle, Kind: r.Kind, IncSuspended: r.IncSuspended, IncDeleted: r.IncDeleted, diff --git a/system/types/user.go b/system/types/user.go index 732c29d86..e92c67893 100644 --- a/system/types/user.go +++ b/system/types/user.go @@ -46,6 +46,7 @@ type ( Query string `json:"query"` Email string `json:"email"` Username string `json:"username"` + Handle string `json:"handle"` Kind UserKind `json:"kind"` IncDeleted bool `json:"incDeleted"` IncSuspended bool `json:"incSuspended"`