Merge pull request #1378 from raunz/global_search_for_all_users

Global Search available for all users
This commit is contained in:
Matt Scott 2023-03-04 10:54:49 -05:00 committed by GitHub
commit f4f1f31575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -2021,7 +2021,6 @@ def delete_template(template):
@admin_bp.route('/global-search', methods=['GET']) @admin_bp.route('/global-search', methods=['GET'])
@login_required @login_required
@operator_role_required
def global_search(): def global_search():
if request.method == 'GET': if request.method == 'GET':
domains = [] domains = []
@ -2033,6 +2032,22 @@ def global_search():
server = Server(server_id='localhost') server = Server(server_id='localhost')
results = server.global_search(object_type='all', query=query) results = server.global_search(object_type='all', query=query)
# Filter results to domains to which the user has access permission
if current_user.role.name not in [ 'Administrator', 'Operator' ]:
allowed_domains = db.session.query(Domain) \
.outerjoin(DomainUser, Domain.id == DomainUser.domain_id) \
.outerjoin(Account, Domain.account_id == Account.id) \
.outerjoin(AccountUser, Account.id == AccountUser.account_id) \
.filter(
db.or_(
DomainUser.user_id == current_user.id,
AccountUser.user_id == current_user.id
)) \
.with_entities(Domain.name) \
.all()
allowed_domains = [value for value, in allowed_domains]
results = list(filter(lambda r: r['zone_id'][:-1] in allowed_domains, results))
# Format the search result # Format the search result
for result in results: for result in results:
if result['object_type'] == 'zone': if result['object_type'] == 'zone':

View File

@ -85,6 +85,12 @@
<p>Dashboard</p> <p>Dashboard</p>
</a> </a>
</li> </li>
<li class="{{ 'nav-item active' if active_page == 'admin_global_search' else 'nav-item' }}">
<a href="{{ url_for('admin.global_search') }}" class="nav-link">
<i class="nav-icon fa-solid fa-search"></i>
<p>Global Search</p>
</a>
</li>
{% if SETTING.get('allow_user_create_domain') or current_user.role.name in ['Administrator', 'Operator'] %} {% if SETTING.get('allow_user_create_domain') or current_user.role.name in ['Administrator', 'Operator'] %}
<li class="{{ 'nav-item active' if active_page == 'nav-item new_domain' else 'nav-item' }}"> <li class="{{ 'nav-item active' if active_page == 'nav-item new_domain' else 'nav-item' }}">
<a href="{{ url_for('domain.add') }}" class="nav-link"> <a href="{{ url_for('domain.add') }}" class="nav-link">
@ -115,12 +121,6 @@
<p>Server Configuration</p> <p>Server Configuration</p>
</a> </a>
</li> </li>
<li class="{{ 'nav-item active' if active_page == 'admin_global_search' else 'nav-item' }}">
<a href="{{ url_for('admin.global_search') }}" class="nav-link">
<i class="nav-icon fa-solid fa-search"></i>
<p>Global Search</p>
</a>
</li>
<li class="{{ 'nav-item active' if active_page == 'admin_history' else 'nav-item' }}"> <li class="{{ 'nav-item active' if active_page == 'admin_history' else 'nav-item' }}">
<a href="{{ url_for('admin.history') }}" class="nav-link"> <a href="{{ url_for('admin.history') }}" class="nav-link">
<i class="nav-icon fa-solid fa-timeline"></i> <i class="nav-icon fa-solid fa-timeline"></i>