diff --git a/common/pages.go b/common/pages.go index d05b5777..26baa87a 100644 --- a/common/pages.go +++ b/common/pages.go @@ -612,13 +612,17 @@ type PanelMenuItemPage struct { } type PanelUserPageSearch struct { - Name string + Name string Email string + Group int + + Any bool } type PanelUserPage struct { *BasePanelPage ItemList []*User - Search PanelUserPageSearch + Groups []*Group + Search PanelUserPageSearch PaginatorMod } diff --git a/common/user_store.go b/common/user_store.go index 1e696865..78b3fa67 100644 --- a/common/user_store.go +++ b/common/user_store.go @@ -21,7 +21,7 @@ type UserStore interface { Getn(id int) *User GetByName(name string) (*User, error) Exists(id int) bool - SearchOffset(name, email string, offset, perPage int) (users []*User, err error) + SearchOffset(name, email string, gid, offset, perPage int) (users []*User, err error) GetOffset(offset, perPage int) ([]*User, error) Each(f func(*User) error) error //BulkGet(ids []int) ([]*User, error) @@ -30,7 +30,7 @@ type UserStore interface { Create(name, password, email string, group int, active bool) (int, error) Reload(id int) error Count() int - CountSearch(name, email string) int + CountSearch(name, email string, gid int) int SetCache(cache UserCache) GetCache() UserCache @@ -66,7 +66,7 @@ func NewDefaultUserStore(cache UserCache) (*DefaultUserStore, error) { get: acc.Select(u).Columns("name,group,active,is_super_admin,session,email,avatar,message,level,score,posts,liked,last_ip,temp_group,createdAt,enable_embeds,profile_comments,who_can_convo").Where("uid=?").Prepare(), getByName: acc.Select(u).Columns(allCols).Where("name=?").Prepare(), - searchOffset: acc.Select(u).Columns(allCols).Where("(name=? OR ?='') AND (email=? OR ?='')").Orderby("uid ASC").Limit("?,?").Prepare(), + searchOffset: acc.Select(u).Columns(allCols).Where("(name=? OR ?='') AND (email=? OR ?='') AND (group=? OR ?='')").Orderby("uid ASC").Limit("?,?").Prepare(), getOffset: acc.Select(u).Columns(allCols).Orderby("uid ASC").Limit("?,?").Prepare(), getAll: acc.Select(u).Columns(allCols).Prepare(), @@ -75,7 +75,7 @@ func NewDefaultUserStore(cache UserCache) (*DefaultUserStore, error) { nameExists: acc.Exists(u, "name").Prepare(), count: acc.Count(u).Prepare(), - countSearch: acc.Count(u).Where("(name=? OR ?='') AND (email=? OR ?='')").Prepare(), + countSearch: acc.Count(u).Where("(name=? OR ?='') AND (email=? OR ?='') AND (group=? OR ?='')").Prepare(), }, acc.FirstError() } @@ -180,8 +180,8 @@ func (s *DefaultUserStore) GetOffset(offset, perPage int) (users []*User, err er } return users, rows.Err() } -func (s *DefaultUserStore) SearchOffset(name, email string, offset, perPage int) (users []*User, err error) { - rows, err := s.searchOffset.Query(name, name, email, email, offset, perPage) +func (s *DefaultUserStore) SearchOffset(name, email string, gid, offset, perPage int) (users []*User, err error) { + rows, err := s.searchOffset.Query(name, name, email, email, gid, gid, offset, perPage) if err != nil { return users, err } @@ -384,8 +384,8 @@ func (s *DefaultUserStore) Count() (count int) { return Countf(s.count) } -func (s *DefaultUserStore) CountSearch(name, email string) (count int) { - return Countf(s.countSearch, name, name, email, email) +func (s *DefaultUserStore) CountSearch(name, email string, gid int) (count int) { + return Countf(s.countSearch, name, name, email, email, gid, gid) } func (s *DefaultUserStore) SetCache(cache UserCache) { diff --git a/langs/english.json b/langs/english.json index bc53e955..dcec3d90 100644 --- a/langs/english.json +++ b/langs/english.json @@ -900,7 +900,10 @@ "panel_users_search_name_placeholder":"John Doe", "panel_users_search_email":"Email", "panel_users_search_email_placeholder":"john.doe@example.com", + "panel_users_search_group":"Group", + "panel_users_search_group_none":"None", "panel_users_search_button":"Search", + "panel_users_search_title":"Search Users", "panel_user_head":"User Editor", "panel_user_avatar":"Avatar", diff --git a/routes/panel/users.go b/routes/panel/users.go index 44ed338d..54e788d8 100644 --- a/routes/panel/users.go +++ b/routes/panel/users.go @@ -21,20 +21,38 @@ func Users(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError { if !u.Perms.EditUserEmail && email != "" { return c.LocalError("Only users with the EditUserEmail permission can search by email.", w, r, u) } - hasParam := name != "" || email != "" + group := r.FormValue("s-group") + f := func(l ...string) bool { + for _, ll := range l { + if ll != "" { + return true + } + } + return false + } + hasParam := f(name, email, group) + gid, _ := strconv.Atoi(group) + /*if group == "" { + gid = -1 + }*/ + hasParam = hasParam && gid > 0 page, _ := strconv.Atoi(r.FormValue("page")) perPage := 15 userCount := basePage.Stats.Users if hasParam { - userCount = c.Users.CountSearch(name, email) + userCount = c.Users.CountSearch(name, email, gid) } offset, page, lastPage := c.PageOffset(userCount, page, perPage) + allGroups, e := c.Groups.GetAll() + if e != nil { + return c.InternalError(e, w, r) + } + var users []*c.User - var e error if hasParam { - users, e = c.Users.SearchOffset(name, email, offset, perPage) + users, e = c.Users.SearchOffset(name, email, gid, offset, perPage) } else { users, e = c.Users.GetOffset(offset, perPage) } @@ -44,7 +62,7 @@ func Users(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError { name = url.QueryEscape(name) email = url.QueryEscape(email) - search := c.PanelUserPageSearch{name, email} + search := c.PanelUserPageSearch{name, email, gid, hasParam} var params string if hasParam { @@ -56,7 +74,7 @@ func Users(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError { } } pageList := c.Paginate(page, lastPage, 5) - pi := c.PanelUserPage{basePage, users, search, c.PaginatorMod{template.URL(params), pageList, page, lastPage}} + pi := c.PanelUserPage{basePage, users, allGroups, search, c.PaginatorMod{template.URL(params), pageList, page, lastPage}} return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_users", &pi}) } diff --git a/templates/guilds_guild_list.html b/templates/guilds_guild_list.html index cb72bdae..74f5fbaf 100644 --- a/templates/guilds_guild_list.html +++ b/templates/guilds_guild_list.html @@ -6,7 +6,7 @@