Skip to content

Commit a3f67a0

Browse files
committed
feat(mshp-req): only show membership request/discussion button if feature enabled [+]
- also optimizes for reduced chance of hitting the DB
1 parent 7d4ae17 commit a3f67a0

File tree

1 file changed

+29
-18
lines changed
  • invenio_communities/templates/semantic-ui/invenio_communities/details

1 file changed

+29
-18
lines changed

invenio_communities/templates/semantic-ui/invenio_communities/details/header.html

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,36 @@
1414

1515

1616
{% macro button_for_membership(community_ui) %}
17-
{% set request_id_of_pending_member = get_request_id_of_pending_member(g.identity, community_ui.id) %}
18-
{# None if no pending membership or invitation request #}
19-
20-
{% if request_id_of_pending_member %}
21-
<a href="{{ url_for('invenio_app_rdm_requests.user_dashboard_request_view', request_pid_value=request_id_of_pending_member) }}"
22-
class="ui button labeled icon rel-mt-1 theme-secondary">
23-
<i class="sign-in icon" aria-hidden="true"></i>
24-
{{ _("Membership discussion") }}
25-
</a>
26-
{% elif permissions.can_request_membership %}
27-
<div
28-
id="request-membership-app"
29-
data-community='{{ community_ui | tojson }}'
30-
class="display-inline-block"
31-
>
32-
</div>
33-
{% else %}
34-
{# show nothing #}
17+
{# Macro to display the button related to membership (request or discussion) #}
18+
19+
{# Ths conditionals try hard to reduce the need for a DB hit #}
20+
{% if config.COMMUNITIES_ALLOW_MEMBERSHIP_REQUESTS %}
21+
{% if community_ui["access"]["member_policy"] == "open" %}
22+
{# The below permission check includes the above checks among other checks, so
23+
it was not enough on its own to prevent a large swath of cases where the DB
24+
could be hit.
25+
#}
26+
{% if permissions.can_request_membership %}
27+
<div
28+
id="request-membership-app"
29+
data-community='{{ community_ui | tojson }}'
30+
class="display-inline-block"
31+
>
32+
</div>
33+
{% else %}
34+
{% set request_id_of_pending_member = get_request_id_of_pending_member(g.identity, community_ui["id"]) %}
35+
{# None if no pending membership or invitation request #}
36+
{% if request_id_of_pending_member %}
37+
<a href="{{ url_for('invenio_app_rdm_requests.user_dashboard_request_view', request_pid_value=request_id_of_pending_member) }}"
38+
class="ui button labeled icon rel-mt-1 theme-secondary">
39+
<i class="sign-in icon" aria-hidden="true"></i>
40+
{{ _("Membership discussion") }}
41+
</a>
42+
{% endif %}
43+
{% endif %}
44+
{% endif %}
3545
{% endif %}
46+
3647
{% endmacro %}
3748

3849
{% macro community_title(community_ui) %}

0 commit comments

Comments
 (0)