mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Better usage of cache for groups and clubs related operations (#634)
* Better usage of cache for group retrieval * Cache clearing on object deletion or update * replace signals by save and delete override * add is_anonymous check in is_owned_by Add in many is_owned_by(self, user) methods that user is not anonymous. Since many of those functions do db queries, this should reduce a little bit the load of the db. * Stricter usage of User.is_in_group Constrain the parameters that can be passed to the function to make sure only a str or an int can be used. Also force to explicitly specify if the group id or the group name is used. * write test and correct bugs * remove forgotten populate commands * Correct test
This commit is contained in:
@ -61,7 +61,7 @@
|
||||
{% if not file.home_of and not file.home_of_club and file.parent %}
|
||||
<p><a href="{{ url('core:file_delete', file_id=file.id, popup=popup) }}">{% trans %}Delete{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) %}
|
||||
{% if user.is_com_admin %}
|
||||
<p><a href="{{ url('core:file_moderate', file_id=file.id) }}">{% trans %}Moderate{% endtrans %}</a></p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
@ -67,7 +67,10 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if profile.mailing_subscriptions.exists() and (profile.id == user.id or user.is_root or user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)) %}
|
||||
{% if
|
||||
profile.mailing_subscriptions.exists()
|
||||
and (profile.id == user.id or user.is_root or user.is_com_admin)
|
||||
%}
|
||||
<h4>{% trans %}Subscribed mailing lists{% endtrans %}</h4>
|
||||
{% for sub in profile.mailing_subscriptions.all() %}
|
||||
<p>{{ sub.mailing.email }} <a href="{{ url('club:mailing_subscription_delete', mailing_subscription_id=sub.id) }}">{% trans %}Unsubscribe{% endtrans %}</a></p>
|
||||
|
@ -136,7 +136,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% if user.memberships.filter(end_date=None).exists() or user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user == profile or user.is_in_group(settings.SITH_BAR_MANAGER_BOARD_GROUP) %}
|
||||
{% if
|
||||
user == profile
|
||||
or user.memberships.ongoing().exists()
|
||||
or user.is_board_member
|
||||
or user.is_in_group(name=settings.SITH_BAR_MANAGER_BOARD_GROUP)
|
||||
%}
|
||||
{# if the user is member of a club, he can view the subscription state #}
|
||||
<hr>
|
||||
{% if profile.is_subscribed %}
|
||||
|
@ -35,7 +35,7 @@
|
||||
{%- else -%}
|
||||
<em>{% trans %}To edit your profile picture, ask a member of the AE{% endtrans %}</em>
|
||||
{%- endif -%}
|
||||
{%- if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) and form.instance.profile_pict.id -%}
|
||||
{%- if user.is_board_member and form.instance.profile_pict.id -%}
|
||||
<a href="{{ url('core:file_delete', file_id=form.instance.profile_pict.id, popup='') }}">
|
||||
{%- trans -%}Delete{%- endtrans -%}
|
||||
</a>
|
||||
@ -55,7 +55,7 @@
|
||||
<div class="profile-picture-edit">
|
||||
<p>{{ form["avatar_pict"].label }}</p>
|
||||
{{ form["avatar_pict"] }}
|
||||
{%- if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) and form.instance.avatar_pict.id -%}
|
||||
{%- if user.is_board_member and form.instance.avatar_pict.id -%}
|
||||
<a href="{{ url('core:file_delete', file_id=form.instance.avatar_pict.id, popup='') }}">
|
||||
{%- trans -%}Delete{%- endtrans -%}
|
||||
</a>
|
||||
@ -75,7 +75,7 @@
|
||||
<div class="profile-picture-edit">
|
||||
<p>{{ form["scrub_pict"].label }}</p>
|
||||
{{ form["scrub_pict"] }}
|
||||
{%- if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) and form.instance.scrub_pict.id -%}
|
||||
{%- if user.is_board_member and form.instance.scrub_pict.id -%}
|
||||
<a href="{{ url('core:file_delete', file_id=form.instance.scrub_pict.id, popup='') }}">
|
||||
{%- trans -%}Delete{%-endtrans -%}
|
||||
</a>
|
||||
|
@ -35,18 +35,21 @@
|
||||
{% endif %}
|
||||
|
||||
{% set is_admin_on_a_counter = false %}
|
||||
{% for b in settings.SITH_COUNTER_BARS if user.is_in_group(b[1] + " admin") %}
|
||||
{% for b in settings.SITH_COUNTER_BARS if user.is_in_group(name=b[1] + " admin") %}
|
||||
{% set is_admin_on_a_counter = true %}
|
||||
{% endfor %}
|
||||
|
||||
{% if
|
||||
user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID) or user.is_root
|
||||
or is_admin_on_a_counter
|
||||
is_admin_on_a_counter
|
||||
or user.is_root
|
||||
or user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
||||
%}
|
||||
<div>
|
||||
<h4>{% trans %}Counters{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% if user.is_in_group(settings.SITH_GROUP_COUNTER_ADMIN_ID) or user.is_root %}
|
||||
{% if user.is_root
|
||||
or user.is_in_group(pk=settings.SITH_GROUP_COUNTER_ADMIN_ID)
|
||||
%}
|
||||
<li><a href="{{ url('counter:admin_list') }}">{% trans %}General counters management{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('counter:product_list') }}">{% trans %}Products management{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('counter:producttype_list') }}">{% trans %}Product types management{% endtrans %}</a></li>
|
||||
@ -57,7 +60,7 @@
|
||||
</ul>
|
||||
<ul>
|
||||
{% for b in settings.SITH_COUNTER_BARS %}
|
||||
{% if user.is_in_group(b[1]+" admin") %}
|
||||
{% if user.is_in_group(name=b[1]+" admin") %}
|
||||
{% set c = Counter.objects.filter(id=b[0]).first() %}
|
||||
|
||||
<li class="rows counter">
|
||||
@ -85,13 +88,16 @@
|
||||
{% endif %}
|
||||
|
||||
{% if
|
||||
user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) or user.is_root
|
||||
or user.memberships.filter(end_date=None).filter(role__gte=7).all() | length > 10
|
||||
user.is_root
|
||||
or user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)
|
||||
or user.memberships.ongoing().filter(role__gte=7).count() > 10
|
||||
%}
|
||||
<div>
|
||||
<h4>{% trans %}Accounting{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) or user.is_root %}
|
||||
{% if user.is_root
|
||||
or user.is_in_group(pk=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID)
|
||||
%}
|
||||
<li><a href="{{ url('accounting:refound_account') }}">{% trans %}Refound Account{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('accounting:bank_list') }}">{% trans %}General accounting{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('accounting:co_list') }}">{% trans %}Company list{% endtrans %}</a></li>
|
||||
@ -118,11 +124,15 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) or user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %}
|
||||
{% if
|
||||
user.is_root
|
||||
or user.is_com_admin
|
||||
or user.is_in_group(pk=settings.SITH_GROUP_SAS_ADMIN_ID)
|
||||
%}
|
||||
<div>
|
||||
<h4>{% trans %}Communication{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %}
|
||||
{% if user.is_com_admin or user.is_root %}
|
||||
<li><a href="{{ url('com:weekmail_article') }}">{% trans %}Create weekmail article{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:weekmail') }}">{% trans %}Weekmail{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:weekmail_destinations') }}">{% trans %}Weekmail destinations{% endtrans %}</a></li>
|
||||
@ -135,7 +145,7 @@
|
||||
<li><a href="{{ url('com:poster_list') }}">{% trans %}Posters{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:screen_list') }}">{% trans %}Screens{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
{% if user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) %}
|
||||
{% if user.is_in_group(pk=settings.SITH_GROUP_SAS_ADMIN_ID) %}
|
||||
<li><a href="{{ url('sas:moderation') }}">{% trans %}Moderate pictures{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
@ -153,7 +163,10 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_in_group(settings.SITH_GROUP_PEDAGOGY_ADMIN_ID) or user.is_root %}
|
||||
{% if
|
||||
user.is_root
|
||||
or user.is_in_group(pk=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
|
||||
%}
|
||||
<div>
|
||||
<h4>{% trans %}Pedagogy{% endtrans %}</h4>
|
||||
<ul>
|
||||
|
Reference in New Issue
Block a user