FIX: show group filter only when user is logged in and groups are present (#14578)

FIX: show group filter only when user is logged in and groups are present (#14578)

diff --git a/app/assets/javascripts/discourse/app/controllers/users.js b/app/assets/javascripts/discourse/app/controllers/users.js
index ce9d403..ce5fd7e 100644
--- a/app/assets/javascripts/discourse/app/controllers/users.js
+++ b/app/assets/javascripts/discourse/app/controllers/users.js
@@ -3,7 +3,7 @@ import Group from "discourse/models/group";
 import { action } from "@ember/object";
 import discourseDebounce from "discourse-common/lib/debounce";
 import showModal from "discourse/lib/show-modal";
-import { equal } from "@ember/object/computed";
+import { and, equal } from "@ember/object/computed";
 import { longDate } from "discourse/lib/formatter";
 import { observes } from "discourse-common/utils/decorators";
 
@@ -19,8 +19,9 @@ export default Controller.extend({
   exclude_usernames: null,
   isLoading: false,
   columns: null,
-  groupsOptions: null,
+  groupOptions: null,
   params: null,
+  showGroupFilter: and("currentUser", "groupOptions"),
 
   showTimeRead: equal("period", "all"),
 
@@ -66,15 +67,17 @@ export default Controller.extend({
   },
 
   loadGroups() {
-    return Group.findAll({ ignore_automatic: true }).then((groups) => {
-      const groupOptions = groups.map((group) => {
-        return {
-          name: group.full_name || group.name,
-          id: group.name,
-        };
+    if (this.currentUser) {
+      return Group.findAll({ ignore_automatic: true }).then((groups) => {
+        const groupOptions = groups.map((group) => {
+          return {
+            name: group.full_name || group.name,
+            id: group.name,
+          };
+        });
+        this.set("groupOptions", groupOptions);
       });
-      this.set("groupOptions", groupOptions);
-    });
+    }
   },
 
   @action
diff --git a/app/assets/javascripts/discourse/app/templates/users.hbs b/app/assets/javascripts/discourse/app/templates/users.hbs
index e6e8334..fa71b79 100644
--- a/app/assets/javascripts/discourse/app/templates/users.hbs
+++ b/app/assets/javascripts/discourse/app/templates/users.hbs
@@ -25,15 +25,17 @@
               placeholderKey="directory.filter_name"
               class="filter-name no-blur"
             }}
-            {{combo-box
-              class="directory-group-selector"
-              value=group
-              content=groupOptions
-              onChange=(action groupChanged)
-              options=(hash
-                none="directory.group.all"
-              )
-            }}
+            {{#if showGroupFilter}}
+              {{combo-box
+                class="directory-group-selector"
+                value=group
+                content=groupOptions
+                onChange=(action groupChanged)
+                options=(hash
+                  none="directory.group.all"
+                )
+              }}
+            {{/if}}
             {{#if currentUser.staff}}
               {{d-button
                 icon="wrench"

GitHub sha: d2f91084702876f49416bb50d317ee90dfbc92fd

This commit appears in #14578 which was approved by CvX. It was merged by techAPJ.