From d2f91084702876f49416bb50d317ee90dfbc92fd Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 12 Oct 2021 19:46:39 +0530 Subject: [PATCH] FIX: show group filter only when user is logged in and groups are present (#14578) --- .../discourse/app/controllers/users.js | 23 +++++++++++-------- .../discourse/app/templates/users.hbs | 20 ++++++++-------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/users.js b/app/assets/javascripts/discourse/app/controllers/users.js index ce9d403182..ce5fd7efdd 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 e6e8334515..fa71b79db8 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"