From 10f4508a1e04dacd3f9aaa1dd227b23c96834e09 Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Fri, 12 Dec 2025 22:21:31 -0700 Subject: [PATCH] Allow viewing achievement items when acting as another user. Instead of greying out the "Use Achievement Reward" button when acting as another user, which only lists the available achievement items to use, grey out the actual use button to let an instructor be able to view which items a student could use on that assignment. It is still not possible to actually use an achievement as another user if that button was active, and further the form tags are also removed from the list of items. This address #2856. --- lib/WeBWorK/AchievementItems.pm | 6 +++--- .../ProblemSet/auxiliary_tools.html.ep | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/WeBWorK/AchievementItems.pm b/lib/WeBWorK/AchievementItems.pm index 71086e3e95..a9ad736516 100644 --- a/lib/WeBWorK/AchievementItems.pm +++ b/lib/WeBWorK/AchievementItems.pm @@ -59,9 +59,6 @@ sub UserItems ($c, $userName, $set, $records) { # Return unless achievement items are enabled. return unless $ce->{achievementsEnabled} && $ce->{achievementItemsEnabled}; - # When acting as another user, achievement items can be listed but not used. - return if $set && $userName ne $c->param('user'); - # Return unless the user has global achievement data. my $globalUserAchievement = $c->{globalData} // $db->getGlobalUserAchievement($userName); return unless $globalUserAchievement && $globalUserAchievement->frozen_hash; @@ -70,6 +67,9 @@ sub UserItems ($c, $userName, $set, $records) { my $use_item_id = $c->param('use_achievement_item_id') // ''; my @items; + # When acting as another user, achievement items can be listed but not used. + $use_item_id = '' if $userName ne $c->param('user'); + for my $item (@{ +ITEMS }) { next unless $globalData->{$item}; my $achievementItem = "WeBWorK::AchievementItems::$item"->new; diff --git a/templates/ContentGenerator/ProblemSet/auxiliary_tools.html.ep b/templates/ContentGenerator/ProblemSet/auxiliary_tools.html.ep index 3fdbfcf5d6..0b81b30b71 100644 --- a/templates/ContentGenerator/ProblemSet/auxiliary_tools.html.ep +++ b/templates/ContentGenerator/ProblemSet/auxiliary_tools.html.ep @@ -34,6 +34,7 @@ % my ($item, $form) = @$_;
<%= $item->name %>
+ % if (param('user') eq param('effectiveUser')) { <%= form_for current_route, method => 'POST', name => 'use_reward', begin =%> <%= hidden_field 'use_achievement_item_id' => $item->id %> <%= $form %> @@ -43,6 +44,17 @@ value="<%= maketext('Use [_1]', $item->remaining_title($c)) %>"> % } <%= end =%> + % } else { + <%= $form %> + + + + % }
% } @@ -53,13 +65,6 @@ - % } elsif (param('user') ne param('effectiveUser')) { - - - % } else {