From df4f5a813fe3fb57b2f954dfc7802cc3ffd86e7e Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Mon, 6 Jan 2025 12:26:52 +0100 Subject: [PATCH 1/5] fix registrationStatus not being shown correctly --- app/webpacker/lib/utils/competition-table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/webpacker/lib/utils/competition-table.js b/app/webpacker/lib/utils/competition-table.js index c4665be2ae..04dc0898c4 100644 --- a/app/webpacker/lib/utils/competition-table.js +++ b/app/webpacker/lib/utils/competition-table.js @@ -32,7 +32,7 @@ const competitionStatusHint = (competition) => { return text; }; -export const competitionStatusText = (competition, registrationStatus) => `${registrationStatusHint(registrationStatus?.competing_status)} ${competitionStatusHint(competition)}`; +export const competitionStatusText = (competition, registrationStatus) => `${registrationStatusHint(registrationStatus)} ${competitionStatusHint(competition)}`; export function dayDifferenceFromToday(yyyymmddDateString) { const dateLuxon = parseDateString(yyyymmddDateString); From 5d2fc3ff7d60e164ed97ca69779cdc860c21ca83 Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Mon, 6 Jan 2025 12:27:37 +0100 Subject: [PATCH 2/5] add new can_view_delegate report permission --- app/models/user.rb | 3 +++ app/webpacker/components/MyCompetitions/TableCells.jsx | 6 +++--- .../components/MyCompetitions/UpcomingCompetitionTable.jsx | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 706790fcf1..73bda5b3dd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -751,6 +751,9 @@ def permissions can_view_delegate_admin_page: { scope: can_view_delegate_matters? ? "*" : [], }, + can_view_delegate_report: { + scope: can_view_delegate_matters? ? "*" : delegated_competitions.pluck(:id), + }, can_create_groups: { scope: groups_with_create_access, }, diff --git a/app/webpacker/components/MyCompetitions/TableCells.jsx b/app/webpacker/components/MyCompetitions/TableCells.jsx index 4a511e6f2c..c4423deba0 100644 --- a/app/webpacker/components/MyCompetitions/TableCells.jsx +++ b/app/webpacker/components/MyCompetitions/TableCells.jsx @@ -34,9 +34,9 @@ export function DateTableCell({ competition }) { } export function ReportTableCell({ - permissions, competitionId, isReportPosted, canAdminCompetitions, + permissions, competitionId, isReportPosted, canViewDelegateReport, }) { - if (permissions.can_administer_competitions.scope === '*' || permissions.can_administer_competitions.scope.includes(competitionId)) { + if (permissions.can_view_delegate_report.scope === '*' || permissions.can_view_delegate_report.scope.includes(competitionId)) { return ( <> @@ -72,7 +72,7 @@ export function ReportTableCell({ // A user might be able to see only certain reports in the list, so we return an empty cell - if (canAdminCompetitions) { + if (canViewDelegateReport) { return ; } } diff --git a/app/webpacker/components/MyCompetitions/UpcomingCompetitionTable.jsx b/app/webpacker/components/MyCompetitions/UpcomingCompetitionTable.jsx index 71401d3498..b639aeb377 100644 --- a/app/webpacker/components/MyCompetitions/UpcomingCompetitionTable.jsx +++ b/app/webpacker/components/MyCompetitions/UpcomingCompetitionTable.jsx @@ -55,7 +55,7 @@ export default function UpcomingCompetitionTable({ shouldShowRegistrationStatus = true, fallbackMessage = null, }) { - const canAdminCompetitions = permissions.can_administer_competitions.scope === '*' || competitions.some((c) => permissions.can_administer_competitions.scope.includes(c.id)); + const canViewDelegateReport = permissions.can_view_delegate_report.scope === '*' || competitions.some((c) => permissions.can_view_delegate_report.scope.includes(c.id)); if (competitions.length === 0 && fallbackMessage) { return ( @@ -81,7 +81,7 @@ export default function UpcomingCompetitionTable({ {I18n.t('competitions.competition_info.date')} - {canAdminCompetitions && ( + {canViewDelegateReport && ( <> @@ -134,7 +134,7 @@ export default function UpcomingCompetitionTable({ )} From 2bbc425c8e99ffc1119456bc57c39a416059723a Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Wed, 8 Jan 2025 11:57:33 +0100 Subject: [PATCH 3/5] add can_edit_delegate_report permission --- app/models/user.rb | 5 +- .../_my_competitions_table.html.erb | 93 ------------------- .../components/MyCompetitions/TableCells.jsx | 32 ++++--- 3 files changed, 21 insertions(+), 109 deletions(-) delete mode 100644 app/views/competitions/_my_competitions_table.html.erb diff --git a/app/models/user.rb b/app/models/user.rb index 73bda5b3dd..725494ad8b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -752,7 +752,10 @@ def permissions scope: can_view_delegate_matters? ? "*" : [], }, can_view_delegate_report: { - scope: can_view_delegate_matters? ? "*" : delegated_competitions.pluck(:id), + scope: can_view_delegate_matters? ? "*" : delegated_competitions_ids + }, + can_edit_delegate_report: { + scope: can_admin_results? ? "*" : delegated_competitions_ids }, can_create_groups: { scope: groups_with_create_access, diff --git a/app/views/competitions/_my_competitions_table.html.erb b/app/views/competitions/_my_competitions_table.html.erb deleted file mode 100644 index 89d1b28c79..0000000000 --- a/app/views/competitions/_my_competitions_table.html.erb +++ /dev/null @@ -1,93 +0,0 @@ -<% show_delegates ||= false %> -<% bookmarked ||= false %> -<% registrations_by_competition_id ||= {} %> -<% if competitions.length < 1 %> - <%= alert :info do %> - <% if bookmarked %> - <%= t '.no_bookmarked_competitions' %> - <% elsif !past %> - <%= t '.no_upcoming_competitions_html', link: link_to(t('.competitions_list'), competitions_path) %> - <% else %> - <%= t '.no_past_competitions' %> - <% end %> - <% end %> -<% else %> -
- "> - - - <% if @show_registration_status && bookmarked %> - - <% end %> - - - - - - - - - - - - <% competitions.each do |competition| %> - <% registration = registrations_by_competition_id[competition.id] %> - <% tr_classes = [ competition.confirmed? ? "confirmed" : "not-confirmed", - competition.showAtAll? ? "visible" : "not-visible", - competition.cancelled? ? "cancelled" : "", - past ? "past" : "not-past" ].join(' ') %> - - <% if @show_registration_status && bookmarked %> - - <% end %> - - - - - - - - - - <% end %> - -
<%= t 'competitions.adjacent_competitions.name' %><%= t 'competitions.adjacent_competitions.location' %><%= t 'competitions.adjacent_competitions.date' %><%= "Delegates" if show_delegates %>
<%= registration_status_icon(competition) %> - <%= link_to competition.display_name, competition_path(competition) %> - <% if competition.championships.any? %> - "> - <%= ui_icon('trophy') %> - - <% end %> - <%= competition.city_and_country %><%= wca_date_range(competition.start_date, competition.end_date) %> - <% if registration %> - <%= ui_icon(registration.accepted? ? "calendar check" : "hourglass half") %> - <% end %> - - <% if !past && current_user.can_manage_competition?(competition) %> - <%= link_to t('.edit'), edit_competition_path(competition) %> - <% elsif competition.results_posted? %> - <%= ui_icon("check circle", data: { toggle: "tooltip", placement: "top", container: "body" }, title: t('.results_up')) %> - <% end %> - - <% if !past && competition.use_wca_registration? && current_user.can_manage_competition?(competition) %> - <%= link_to t('.registrations'), competition_edit_registrations_path(competition) %> - <% end %> - - <% if show_delegates %> - <%= competition.delegates.map(&:name).join(", ") %> - <% else %> - <% if current_user.can_view_delegate_report?(competition.delegate_report) %> - <%= link_to ui_icon('file alt'), delegate_report_path(competition), title: t('.report'), data: { 'toggle': 'tooltip', 'container': 'body' } %> - <% end %> - <% if current_user.can_edit_delegate_report?(competition.delegate_report) %> - <%= link_to ui_icon('edit'), delegate_report_edit_path(competition), title: t('.edit_report'), data: { 'toggle': 'tooltip', 'container': 'body' } %> - <% end %> - <% if competition.user_should_post_delegate_report?(current_user) %> - <%= ui_icon('warning', title: t('.missing_report'), data: { 'toggle': 'tooltip', 'container': 'body' }) %> - <% end %> - <% end %> -
-
-<% end %> diff --git a/app/webpacker/components/MyCompetitions/TableCells.jsx b/app/webpacker/components/MyCompetitions/TableCells.jsx index c4423deba0..80890dd3a1 100644 --- a/app/webpacker/components/MyCompetitions/TableCells.jsx +++ b/app/webpacker/components/MyCompetitions/TableCells.jsx @@ -36,26 +36,34 @@ export function DateTableCell({ competition }) { export function ReportTableCell({ permissions, competitionId, isReportPosted, canViewDelegateReport, }) { - if (permissions.can_view_delegate_report.scope === '*' || permissions.can_view_delegate_report.scope.includes(competitionId)) { + if (canViewDelegateReport) { return ( <> + {(permissions.can_view_delegate_report.scope === '*' || permissions.can_view_delegate_report.scope.includes(competitionId)) + && ( - )} + )} /> - - - )} - /> + + {(permissions.can_edit_delegate_report.scope === '*' || permissions.can_edit_delegate_report.scope.includes(competitionId)) + && ( + + + + )} + /> + )} + { !isReportPosted && permissions.can_administer_competitions.scope.includes(competitionId) && ( ); } - - // A user might be able to see only certain reports in the list, so we return an empty cell - - if (canViewDelegateReport) { - return ; - } } From 7821b7a09881cc0583a43b4d051d176c41d9246f Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Wed, 8 Jan 2025 12:00:19 +0100 Subject: [PATCH 4/5] fix rubocop --- app/models/user.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 725494ad8b..0d084f2f00 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -752,10 +752,10 @@ def permissions scope: can_view_delegate_matters? ? "*" : [], }, can_view_delegate_report: { - scope: can_view_delegate_matters? ? "*" : delegated_competitions_ids + scope: can_view_delegate_matters? ? "*" : delegated_competitions_ids, }, can_edit_delegate_report: { - scope: can_admin_results? ? "*" : delegated_competitions_ids + scope: can_admin_results? ? "*" : delegated_competitions_ids, }, can_create_groups: { scope: groups_with_create_access, From 62cd02bba14655a6d0768593cd6fe1dd79d1ded2 Mon Sep 17 00:00:00 2001 From: FinnIckler Date: Wed, 8 Jan 2025 14:13:12 +0100 Subject: [PATCH 5/5] undelete my_competitions_table --- .../_my_competitions_table.html.erb | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 app/views/competitions/_my_competitions_table.html.erb diff --git a/app/views/competitions/_my_competitions_table.html.erb b/app/views/competitions/_my_competitions_table.html.erb new file mode 100644 index 0000000000..74ac34ff40 --- /dev/null +++ b/app/views/competitions/_my_competitions_table.html.erb @@ -0,0 +1,93 @@ +<% show_delegates ||= false %> +<% bookmarked ||= false %> +<% registrations_by_competition_id ||= {} %> +<% if competitions.length < 1 %> + <%= alert :info do %> + <% if bookmarked %> + <%= t '.no_bookmarked_competitions' %> + <% elsif !past %> + <%= t '.no_upcoming_competitions_html', link: link_to(t('.competitions_list'), competitions_path) %> + <% else %> + <%= t '.no_past_competitions' %> + <% end %> + <% end %> +<% else %> +
+ "> + + + <% if @show_registration_status && bookmarked %> + + <% end %> + + + + + + + + + + + + <% competitions.each do |competition| %> + <% registration = registrations_by_competition_id[competition.id] %> + <% tr_classes = [ competition.confirmed? ? "confirmed" : "not-confirmed", + competition.showAtAll? ? "visible" : "not-visible", + competition.cancelled? ? "cancelled" : "", + past ? "past" : "not-past" ].join(' ') %> + + <% if @show_registration_status && bookmarked %> + + <% end %> + + + + + + + + + + <% end %> + +
<%= t 'competitions.adjacent_competitions.name' %><%= t 'competitions.adjacent_competitions.location' %><%= t 'competitions.adjacent_competitions.date' %><%= "Delegates" if show_delegates %>
<%= registration_status_icon(competition) %> + <%= link_to competition.display_name, competition_path(competition) %> + <% if competition.championships.any? %> + "> + <%= ui_icon('trophy') %> + + <% end %> + <%= competition.city_and_country %><%= wca_date_range(competition.start_date, competition.end_date) %> + <% if registration %> + <%= ui_icon(registration.accepted? ? "calendar check" : "hourglass half") %> + <% end %> + + <% if !past && current_user.can_manage_competition?(competition) %> + <%= link_to t('.edit'), edit_competition_path(competition) %> + <% elsif competition.results_posted? %> + <%= ui_icon("check circle", data: { toggle: "tooltip", placement: "top", container: "body" }, title: t('.results_up')) %> + <% end %> + + <% if !past && competition.use_wca_registration? && current_user.can_manage_competition?(competition) %> + <%= link_to t('.registrations'), competition_edit_registrations_path(competition) %> + <% end %> + + <% if show_delegates %> + <%= competition.delegates.map(&:name).join(", ") %> + <% else %> + <% if current_user.can_view_delegate_report?(competition.delegate_report) %> + <%= link_to ui_icon('file alt'), delegate_report_path(competition), title: t('.report'), data: { 'toggle': 'tooltip', 'container': 'body' } %> + <% end %> + <% if current_user.can_edit_delegate_report?(competition.delegate_report) %> + <%= link_to ui_icon('edit'), delegate_report_edit_path(competition), title: t('.edit_report'), data: { 'toggle': 'tooltip', 'container': 'body' } %> + <% end %> + <% if competition.user_should_post_delegate_report?(current_user) %> + <%= ui_icon('warning', title: t('.missing_report'), data: { 'toggle': 'tooltip', 'container': 'body' }) %> + <% end %> + <% end %> +
+
+<% end %>