diff --git a/api/users.go b/api/users.go
index aed805dd8..fd18551ad 100644
--- a/api/users.go
+++ b/api/users.go
@@ -125,9 +125,11 @@ func (r usersRoutes) updateUser(c *gin.Context) {
func (r usersRoutes) prepareUserSearch(c *gin.Context) (users []model.User, err error) {
q := c.Query("q")
+ rQ := c.Query("r")
reg, _ := regexp.Compile("[^a-zA-Z0-9 ]+")
q = reg.ReplaceAllString(q, "")
- if len(q) < 3 {
+ // Removed in order to make the search work with empty query but selected role
+ if len(q) < 3 && (rQ == "-1" || rQ == "") {
_ = c.Error(tools.RequestError{
Status: http.StatusBadRequest,
CustomMessage: "query too short (minimum length is 3)",
diff --git a/web/template/admin/admin_tabs/users.gohtml b/web/template/admin/admin_tabs/users.gohtml
index 7460d2344..68bdf4bbd 100644
--- a/web/template/admin/admin_tabs/users.gohtml
+++ b/web/template/admin/admin_tabs/users.gohtml
@@ -6,6 +6,15 @@
Search
+
+
+
+
diff --git a/web/ts/admin.ts b/web/ts/admin.ts
index 3a63cbc8a..e8b5f01d3 100755
--- a/web/ts/admin.ts
+++ b/web/ts/admin.ts
@@ -15,25 +15,27 @@ export class AdminUserList {
showSearchResults: boolean;
searchLoading: boolean;
searchInput: string;
+ roles: number;
constructor(usersAsJson: object[]) {
this.list = usersAsJson;
this.rowsPerPage = 10;
this.showSearchResults = false;
this.currentIndex = 0;
+ this.searchInput = "";
+ this.roles = -1;
this.numberOfPages = Math.ceil(this.list.length / this.rowsPerPage);
this.updateVisibleRows();
}
async search() {
- if (this.searchInput.length < 3) {
+ if (this.searchInput.length < 3 && this.roles == -1) {
this.showSearchResults = false;
this.updateVisibleRows();
return;
- }
- if (this.searchInput.length > 2) {
+ } else {
this.searchLoading = true;
- fetch("/api/searchUser?q=" + this.searchInput)
+ fetch("/api/searchUser?q=" + this.searchInput + "&r=" + this.roles)
.then((response) => {
this.searchLoading = false;
if (!response.ok) {
@@ -42,7 +44,13 @@ export class AdminUserList {
return response.json();
})
.then((r) => {
- this.currentPage = r; // show all results on page one.
+ if (this.roles != -1) {
+ this.currentPage = r.filter((obj) => {
+ return obj.role == this.roles;
+ }); // show all results on page one.
+ } else {
+ this.currentPage = r;
+ }
this.showSearchResults = true;
})
.catch((err) => {