Add a permission check to the Search sources (#1527)

This commit is contained in:
David Sevilla Martín 2018-08-19 17:43:49 -04:00 committed by Franz Liedke
parent 77e99e0961
commit bdb6f3ae88
2 changed files with 13 additions and 4 deletions

View File

@ -37,7 +37,7 @@ export default class ForumApplication extends Application {
/**
* The page's search component instance.
*
* @type {SearchBox}
* @type {Search}
*/
search = new Search();

View File

@ -38,7 +38,7 @@ export default class Search extends Component {
*
* @type {SearchSource[]}
*/
this.sources = this.sourceItems().toArray();
this.sources = null;
/**
* The number of sources that are still loading results.
@ -74,6 +74,15 @@ export default class Search extends Component {
this.value(currentSearch || '');
}
// Initialize search sources in the view rather than the constructor so
// that we have access to app.forum.
if (!this.sources) {
this.sources = this.sourceItems().toArray();
}
// Hide the search view if no sources were loaded
if (!this.sources.length) return <div></div>;
return (
<div className={'Search ' + classList({
open: this.value() && this.hasFocus,
@ -210,8 +219,8 @@ export default class Search extends Component {
sourceItems() {
const items = new ItemList();
items.add('discussions', new DiscussionsSearchSource());
items.add('users', new UsersSearchSource());
if (app.forum.attribute('canViewDiscussions')) items.add('discussions', new DiscussionsSearchSource());
if (app.forum.attribute('canViewUserList')) items.add('users', new UsersSearchSource());
return items;
}