mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 23:23:52 +08:00
Add a permission check to the Search sources (#1527)
This commit is contained in:
parent
77e99e0961
commit
bdb6f3ae88
|
@ -37,7 +37,7 @@ export default class ForumApplication extends Application {
|
|||
/**
|
||||
* The page's search component instance.
|
||||
*
|
||||
* @type {SearchBox}
|
||||
* @type {Search}
|
||||
*/
|
||||
search = new Search();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user