Skip to content

Commit

Permalink
Overriding header templates to hide profile and
Browse files Browse the repository at this point in the history
communities links from non-admin users
  • Loading branch information
monotasker committed Sep 9, 2023
1 parent 75abe01 commit f25da88
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 0 deletions.
142 changes: 142 additions & 0 deletions templates/semantic-ui/invenio_app_rdm/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{#
-*- coding: utf-8 -*-
Copyright (C) 2019-2020 CERN.
Copyright (C) 2019-2020 Northwestern University.
Copyright (C) 2021 New York University.

Invenio App RDM is free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
#}

<div>
<header class="theme header">
{%- block site_banner %}
{%- endblock site_banner %}
<div class="outer-navbar">
{%- block banner %}
{% from 'invenio_banners/banner.html' import banner %}
{{ banner() }}
{%- endblock banner %}
{%- block navbar %}
<div class="ui container invenio-header-container">
<nav id="invenio-nav" class="ui inverted menu borderless stackable p-0">
<div class="item logo p-0">
{%- block navbar_header %}
{%- block brand %}
{%- if config.THEME_LOGO %}
<a class="logo-link" href="/">
<img class="ui image rdm-logo"
src="{{ url_for('static', filename=config.THEME_LOGO) }}"
alt="{{ _(config.THEME_SITENAME) }}"/>
</a>
{%- else %}
<a class="logo" href="/">{{ _(config.THEME_SITENAME) }}</a>
{%- endif %}
{%- endblock brand %}
{%- endblock navbar_header %}
</div>

<div id="rdm-burger-toggle">
<button
id="rdm-burger-menu-icon"
class="ui button transparent"
aria-label="{{ _('Menu') }}"
aria-haspopup="menu"
aria-expanded="false"
aria-controls="invenio-menu"
>
<span class="navicon"></span>
</button>
</div>

<div
role="menu"
id="invenio-menu"
aria-labelledby="rdm-burger-menu-icon"
class="ui fluid menu borderless mobile-hidden"
>
<button
id="rdm-close-burger-menu-icon"
class="ui button transparent"
aria-label="{{ _('Close menu') }}"
>
<span class="navicon"></span>
</button>

{%- if config.THEME_SEARCHBAR %}
{%- block navbar_search %}
{%- include "invenio_app_rdm/searchbar.html" %}
{%- endblock navbar_search %}
{%- endif %}

{%- block navbar_nav %}
{%- for item in current_menu.submenu('main').children|sort(attribute='order') if item.visible recursive %}

{%- if item.name != "communities" or (current_user.roles | selectattr("name", "equalto", "administrator") | list) %}

{%- if item.children %}
<div class="item">
<div class="dropdown {{ ' active' if item.active else '' }}">
<a role="menuitem"
class="dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
href="{{ item.url }}"
>
{{ item.text|safe }}
<b class="caret"></b>
</a>
<ul class="dropdown-menu">{{ loop(item.children|sort(attribute='order')) }}</ul>
</div>
</div>
{%- else %}
<div class="{{' item active' if item.active and loop.depth == 0 else ' item' }}">
<a role="menuitem" href="{{ item.url }}">{{ item.text|safe }}</a>
</div>
{%- endif %}

{%- endif %}

{%- endfor %}

{% for item in current_menu.submenu('actions').children|sort(attribute='order') if item.visible recursive %}

{%- if config.ACCOUNTS and current_user.is_authenticated %}
<div class="item">
<a role="menuitem" href="{{ item.url }}">{{ item.text|safe }}</a>
</div>
{%- endif %}

{% endfor %}
{%- endblock navbar_nav %}

{%- block navbar_right %}
<div class="right menu item">
{%- if config.ACCOUNTS and current_user.is_authenticated %}
{% for item in current_menu.submenu('notifications').children|sort(attribute='order') if item.visible recursive %}
<div class="item inbox">
<a role="menuitem" href="{{ item.url }}" aria-label="{{ _("Requests") }}">
<i class="fitted inbox icon inverted"></i>
<span class="mobile tablet only inline">{{ _("Inbox") }}</span>
</a>
</div>
{% endfor %}
{% endif %}
{%- include config.THEME_HEADER_LOGIN_TEMPLATE %}
</div>
{%- endblock navbar_right %}
</div>
</nav>
{%- endblock navbar %}
</div>

{%- block flashmessages %}
{%- from "invenio_theme/macros/messages.html" import flashed_messages with context -%}
{{ flashed_messages() }}
{%- endblock %}
</header>

{%- block breadcrumbs %}
{%- endblock breadcrumbs %}
</div>
146 changes: 146 additions & 0 deletions templates/semantic-ui/invenio_app_rdm/header_login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{# -*- coding: utf-8 -*-

This file is part of Invenio.
Copyright (C) 2015-2021 CERN.

Invenio is free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
#}


{%- if config.ACCOUNTS %}
{%- if not current_user.is_authenticated %}
<form>
<a href="{{ url_for_security('login', next=request.path) }}"
class="ui button">
<i class="sign-in icon"></i>
{{ _('Log in') }}</a>

{%- if False %}
{% if security.registerable %}
<a href="{{ url_for_security('register') }}" class="ui button signup">
<i class="edit outline icon"></i>
{{ _('Sign up') }}
</a>
{% endif %}
{% endif %}
</form>
{%- else %}

{# Quick-create ("plus") menu #}
{%- set plus_menu_items = current_menu.submenu('plus').children %}
{%- if plus_menu_items %}
<div role="menuitem" class="rdm-plus-menu rdm-plus-menu-responsive ui dropdown floating pr-15 computer only" aria-label="{{ _("Quick create") }}">
<i class="fitted plus icon inverted"></i>
<i class="fitted dropdown icon inverted"></i>
<div class="menu">
{%- for item in plus_menu_items if item.visible %}
{%- if item.text != "New community" or (current_user.roles | selectattr("name", "equalto", "administrator") | list) %}
<a class="item" href="{{ item.url }}">{{ item.text|safe }} </a>
{%- endif %}
{%- endfor %}
</div>
</div>

<div class="sub-menu mobile tablet only">
<h2 class="ui small header">{{ _("Actions") }}</h2>

{%- for item in plus_menu_items if item.visible %}
{%- if item.text != "New community" or (current_user.roles | selectattr("name", "equalto", "administrator") | list) %}
<a role="menuitem" class="item" href="{{ item.url }}">
<i class="plus icon"></i>
{{ item.text|safe }}
</a>
{%- endif %}
{%- endfor %}
</div>
{% endif %}

{%- if config.USERPROFILES and (current_user.roles | selectattr("name", "equalto", "administrator") | list) %}
<div role="menuitem" id="user-profile-dropdown" class="ui floating dropdown computer only">
<button id="user-profile-dropdown-btn"
class="ui right labeled right floated icon button text"
aria-controls="user-profile-menu"
aria-expanded="false"
aria-haspopup="menu"
aria-label="{{ _('My account') }}"
>
<span>
<i class="user icon"></i>
{{ current_user.email|truncate(31,true) }}
</span>
<i class="dropdown icon"></i>
</button>

<div id="user-profile-menu"
class="ui menu"
role="menu"
aria-labelledby="user-profile-dropdown-btn"
>
{%- for item in current_menu.submenu('settings').children if item.visible %}
<a role="menuitem" class="item" href="{{ item.url }}" tabindex="-1">
{{ item.text|safe }}
</a>
{%- endfor %}

<div class="ui divider"></div>

{% set ns = namespace(admin_menu=False) %}
{%- for item in current_menu.submenu('profile-admin').children if item.visible %}
{% set ns.admin_menu = True %}
<a role="menuitem" class="item" href="{{ item.url }}" tabindex="-1">
{{ item.text|safe }}
</a>
{%- endfor %}
{% if ns.admin_menu %}
<div class="ui divider"></div>
{% endif %}

<a role="menuitem" class="item" href="{{ url_for_security('logout') }}" tabindex="-1">
<i class="sign-out icon"></i>
{{ _('Log out') }}
</a>
</div>
</div>

<div class="sub-menu mobile tablet only">
<h2 class="ui small header">{{ _("My account") }}</h2>

{%- for item in current_menu.submenu('settings').children if item.visible %}
<a role="menuitem" class="item" href="{{ item.url }}">
{{ item.text|safe }}
</a>
{%- endfor %}

<div class="ui divider"></div>

{% set ns = namespace(admin_menu=False) %}
{%- for item in current_menu.submenu('profile-admin').children if item.visible %}
{% set ns.admin_menu = True %}
<a role="menuitem" class="item" href="{{ item.url }}">
{{ item.text|safe }}
</a>
{%- endfor %}
{% if ns.admin_menu %}
<div class="ui divider"></div>
{% endif %}

<a role="menuitem" class="item" href="{{ url_for_security('logout') }}">
<i class="sign-out icon"></i>
{{ _('Log out') }}
</a>
</div>

{%- else %}

<span>
<i class="user icon"></i>
{{ current_user.email|truncate(31,true) }}
</span>
<a role="button" href="{{ url_for_security('logout') }}" class="ui button">
<i class="sign-out icon"></i>
{{ _('Log out') }}
</a>
{%- endif %}
{%- endif %}
{%- endif %}

0 comments on commit f25da88

Please sign in to comment.