Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to show only unregistered users in participant roles list #4822

Merged
merged 2 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ Improvements
(:pr:`4817`)
- Failed login attempts now trigger rate limiting to prevent brute-force attacks
(:issue:`1550`, :pr:`4817`)
- Allow filtering the "Participant Roles" page by users who have not registered for the event
(:issue:`4763`, :pr:`4822`)

Bugfixes
^^^^^^^^

- Take registrations of users who are only members of a custom event role into account on the
"Participant Roles" page (:pr:`4822`)

Internal Changes
^^^^^^^^^^^^^^^^
Expand Down
30 changes: 27 additions & 3 deletions indico/modules/events/management/client/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import './badges';
function toggleResetBtn() {
const isInitialState =
$('#person-filters [data-filter]:checked').length ===
$('#person-filters [data-filter]:not(#filter-no-account)').length;
$('#person-filters [data-filter]:not(#filter-no-account,#filter-no-registration)').length;
$('.js-reset-role-filter').toggleClass('disabled', isInitialState);
}

Expand All @@ -129,6 +129,7 @@ import './badges';
options = $.extend(
{
hasNoAccountFilter: false,
hasNoRegistrationFilter: false,
},
options
);
Expand Down Expand Up @@ -235,6 +236,27 @@ import './badges';
});
}

if (options.hasNoRegistrationFilter) {
$('.js-event-person-list [data-filter]:not(#filter-no-registration)').on(
'change',
function() {
$('#filter-no-registration').prop('checked', false);
refreshPersonFilters();
applySearchFilters();
}
);
$('#filter-no-registration').on('change', function() {
if (this.checked) {
$('.js-event-person-list [data-filter]:checked:not(#filter-no-registration)').prop(
'checked',
false
);
}
refreshPersonFilters();
applySearchFilters();
});
}

initTooltip();

const $personFilters = $('#person-filters');
Expand All @@ -248,8 +270,10 @@ import './badges';
$personFilters.find('.js-reset-role-filter').on('click', function() {
$('.js-event-person-list [data-filter]').each(function() {
const $this = $(this);
$this.prop('checked', !$this.is('#filter-no-account'));
$this.parent().toggleClass('enabled', !$this.is('#filter-no-account'));
$this.prop('checked', !$this.is('#filter-no-account, #filter-no-registration'));
$this
.parent()
.toggleClass('enabled', !$this.is('#filter-no-account, #filter-no-registration'));
});
refreshPersonFilters();
applySearchFilters();
Expand Down
11 changes: 11 additions & 0 deletions indico/modules/events/persons/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def get_persons(self):

internal_role_users = defaultdict(lambda: {'roles': {},
'person': [],
'registrations': [],
'has_event_person': False,
'id_field_name': 'user_id'})
for user, roles in event_user_roles.items():
Expand All @@ -180,6 +181,13 @@ def get_persons(self):
user_metadata['roles'][f'custom_{role.id}'] = {'name': role.name, 'code': role.code, 'css': role.css}
user_metadata['roles'] = dict(sorted(user_metadata['roles'].items(), key=lambda x: x[1]['code']))

regs = (Registration.query
.with_parent(self.event)
.filter(Registration.user_id.in_(data['person'].id for data in internal_role_users.values()))
.all())
for reg in regs:
internal_role_users[reg.user.email]['registrations'].append(reg)

# Some EventPersons will have no roles since they were connected to deleted things
persons = {email: data for email, data in persons.items() if any(data['roles'].values())}
persons = dict(persons, **internal_role_users)
Expand Down Expand Up @@ -218,6 +226,9 @@ def _process(self):
num_no_account += 1
custom_roles = {f'custom_{r.id}': {'name': r.name, 'code': r.code, 'color': r.color}
for r in self.event.roles}
for person_data in persons.values():
if not person_data['registrations']:
person_data['roles']['no_registration'] = True
return WPManagePersons.render_template('management/person_list.html', self.event, persons=person_list,
num_no_account=num_no_account, builtin_roles=BUILTIN_ROLES,
custom_roles=custom_roles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</td>
<td class="i-table roles-column">
{% for role, role_data in person_data.roles.items() %}
{%- if role != 'no_account' %}
{%- if role not in ('no_account', 'no_registration') %}
{%- if role_data.elements -%}
<span class="i-tag outline contrast js-count-label" style="{{ role_data.css }};"
data-role-name="{{ role_data.name }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@
<i class="icon-stop colored-square no-account"></i>
<label for="filter-no-account">{% trans %}Users with no account{% endtrans %}</label>
</li>
<li class="separator">
<span class="titled-rule">{% trans %}or{% endtrans %}</span>
</li>
<li for="filter-no-registration">
<input type="checkbox" id="filter-no-registration" data-filter="no_registration">
<i class="icon-checkmark"></i>
<i class="icon-stop colored-square no-registration"></i>
<label for="filter-no-registration">{% trans %}Unregistered users{% endtrans %}</label>
</li>
</ul>
<a class="i-button highlight icon-close disabled js-reset-role-filter"
title="{% trans %}Reset role filters{% endtrans %}"></a>
Expand Down Expand Up @@ -237,7 +246,8 @@
</div>
<script>
setupEventPersonsList({
hasNoAccountFilter: true
hasNoAccountFilter: true,
hasNoRegistrationFilter: true
});
</script>
{% endblock %}
4 changes: 4 additions & 0 deletions indico/web/client/styles/modules/abstracts/_roles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
color: $yellow;
}

.icon-stop.no-registration {
color: $orange;
}

span.titled-rule {
width: 100%;
}
Expand Down