From 0dfbc93bfbbde59c8f95a79f3e5925be762815a2 Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Sat, 21 Jun 2025 11:04:10 -0600 Subject: [PATCH 1/5] Warn instructors if using deprecated_macros. This adds a warning next to the problem comment on the PGProblemEditor, Library Browser (and maybe other places that use the Library Browser render) right before any instructor problem if deprecated macros are used in the problem. --- htdocs/js/PGProblemEditor/pgproblemeditor.js | 11 +++++++++++ htdocs/js/RenderProblem/renderproblem.js | 11 +++++++++++ lib/FormatRenderedProblem.pm | 7 ++++++- lib/WeBWorK/Utils/Rendering.pm | 1 + lib/WebworkWebservice/RenderProblem.pm | 5 +++-- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/htdocs/js/PGProblemEditor/pgproblemeditor.js b/htdocs/js/PGProblemEditor/pgproblemeditor.js index f48214574f..684b19b100 100644 --- a/htdocs/js/PGProblemEditor/pgproblemeditor.js +++ b/htdocs/js/PGProblemEditor/pgproblemeditor.js @@ -512,6 +512,17 @@ container.innerHTML = data.pg_flags.comment; iframe.after(container); } + if (data.deprecated_macros?.length) { + const container = document.createElement('div'); + container.classList.add('alert', 'alert-danger', 'mx-2'); + container.innerHTML = + 'Warning!! This problem uses the following deprecated macros:' + + 'If this is an OPL problem, please report this issue to the OPL. ' + + 'If this is a custom problem, please update the problem to use modern macros.'; + iframe.after(container); + } iframe.addEventListener( 'load', diff --git a/htdocs/js/RenderProblem/renderproblem.js b/htdocs/js/RenderProblem/renderproblem.js index ec4503a64a..65f610a2a8 100644 --- a/htdocs/js/RenderProblem/renderproblem.js +++ b/htdocs/js/RenderProblem/renderproblem.js @@ -77,6 +77,17 @@ container.innerHTML = data.pg_flags.comment; iframe.after(container); } + if (data.deprecated_macros?.length) { + const container = document.createElement('div'); + container.classList.add('alert', 'alert-danger'); + container.innerHTML = + 'Warning!! This problem uses the following deprecated macros:' + + 'If this is an OPL problem, please report this issue to the OPL. ' + + 'If this is a custom problem, please update the problem to use modern macros.'; + iframe.after(container); + } iFrameResize( { checkOrigin: false, diff --git a/lib/FormatRenderedProblem.pm b/lib/FormatRenderedProblem.pm index dbbc2754c7..4bc6a9c9be 100644 --- a/lib/FormatRenderedProblem.pm +++ b/lib/FormatRenderedProblem.pm @@ -286,7 +286,12 @@ sub formatRenderedProblem { return $ws->c->render(%template_params) if $formatName eq 'json' || !$ws->{inputs_ref}{send_pg_flags}; return $ws->c->render( - json => { html => $ws->c->render_to_string(%template_params)->to_string, pg_flags => $rh_result->{flags} }); + json => { + html => $ws->c->render_to_string(%template_params)->to_string, + pg_flags => $rh_result->{flags}, + deprecated_macros => $rh_result->{deprecated_macros} + } + ); } sub saveGradeToLTI { diff --git a/lib/WeBWorK/Utils/Rendering.pm b/lib/WeBWorK/Utils/Rendering.pm index c75d1e57ac..1842eb648b 100644 --- a/lib/WeBWorK/Utils/Rendering.pm +++ b/lib/WeBWorK/Utils/Rendering.pm @@ -272,6 +272,7 @@ sub renderPG ($c, $effectiveUser, $set, $problem, $psvn, $formFields, $translati $ret->{internal_debug_messages} = $pg->{pgcore}->get_internal_debug_messages; $ret->{warning_messages} = $pg->{pgcore}->get_warning_messages(); $ret->{debug_messages} = $pg->{pgcore}->get_debug_messages(); + $ret->{deprecated_macros} = $pg->{pgcore}{PG_loadMacros}{deprecated_macros}; $ret->{PG_ANSWERS_HASH} = { map { $_ => { diff --git a/lib/WebworkWebservice/RenderProblem.pm b/lib/WebworkWebservice/RenderProblem.pm index f68a353141..43ed1abc6a 100644 --- a/lib/WebworkWebservice/RenderProblem.pm +++ b/lib/WebworkWebservice/RenderProblem.pm @@ -279,8 +279,9 @@ async sub renderProblem { psvn => $psvn, problem_seed => $problemSeed, resource_list => $pg->{resource_list}, - warning_messages => ref $pg->{warning_messages} eq 'ARRAY' ? $pg->{warning_messages} : [], - debug_messages => ref $pg->{debug_messages} eq 'ARRAY' ? $pg->{debug_messages} : [], + warning_messages => ref $pg->{warning_messages} eq 'ARRAY' ? $pg->{warning_messages} : [], + debug_messages => ref $pg->{debug_messages} eq 'ARRAY' ? $pg->{debug_messages} : [], + deprecated_macros => ref $pg->{deprecated_macros} eq 'ARRAY' ? $pg->{deprecated_macros} : [], internal_debug_messages => ref $pg->{internal_debug_messages} eq 'ARRAY' ? $pg->{internal_debug_messages} : [], From 41dd678a91aa96c912a8c0477ed52be1c0437cbe Mon Sep 17 00:00:00 2001 From: Peter Staab Date: Mon, 23 Jun 2025 08:41:35 -0400 Subject: [PATCH 2/5] Added some

tags... --- htdocs/js/PGProblemEditor/pgproblemeditor.js | 6 +++--- htdocs/js/RenderProblem/renderproblem.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/js/PGProblemEditor/pgproblemeditor.js b/htdocs/js/PGProblemEditor/pgproblemeditor.js index 684b19b100..7be77b98e8 100644 --- a/htdocs/js/PGProblemEditor/pgproblemeditor.js +++ b/htdocs/js/PGProblemEditor/pgproblemeditor.js @@ -516,11 +516,11 @@ const container = document.createElement('div'); container.classList.add('alert', 'alert-danger', 'mx-2'); container.innerHTML = - 'Warning!! This problem uses the following deprecated macros:' + + '

Warning!! This problem uses the following deprecated macros:

' + 'If this is an OPL problem, please report this issue to the OPL. ' + - 'If this is a custom problem, please update the problem to use modern macros.'; + '

If this is an OPL problem, please report this issue to the OPL. ' + + 'If this is a custom problem, please update the problem to use modern macros.

'; iframe.after(container); } diff --git a/htdocs/js/RenderProblem/renderproblem.js b/htdocs/js/RenderProblem/renderproblem.js index 65f610a2a8..42ae4cc3ce 100644 --- a/htdocs/js/RenderProblem/renderproblem.js +++ b/htdocs/js/RenderProblem/renderproblem.js @@ -81,11 +81,11 @@ const container = document.createElement('div'); container.classList.add('alert', 'alert-danger'); container.innerHTML = - 'Warning!! This problem uses the following deprecated macros:' + + '

Warning!! This problem uses the following deprecated macros:

' + 'If this is an OPL problem, please report this issue to the OPL. ' + - 'If this is a custom problem, please update the problem to use modern macros.'; + '

If this is an OPL problem, please report this issue to the OPL. ' + + 'If this is a custom problem, please update the problem to use modern macros.

'; iframe.after(container); } iFrameResize( From 257cc36e4a0fdced4133109f760edb1b938fb89d Mon Sep 17 00:00:00 2001 From: Peter Staab Date: Tue, 24 Jun 2025 15:59:26 -0400 Subject: [PATCH 3/5] Get the list of deprecated macros from the macrosList. --- lib/WeBWorK/Utils/Rendering.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/WeBWorK/Utils/Rendering.pm b/lib/WeBWorK/Utils/Rendering.pm index 1842eb648b..78c3a6b7df 100644 --- a/lib/WeBWorK/Utils/Rendering.pm +++ b/lib/WeBWorK/Utils/Rendering.pm @@ -268,11 +268,18 @@ sub renderPG ($c, $effectiveUser, $set, $problem, $psvn, $formFields, $translati flags => $pg->{flags}, }; + # get a list of the deprecated macros + my @deprecated_macros; + for (keys %{ $pg->{pgcore}{PG_loadMacros}{macroFileList} }) { + my @dirs = split('/', $_); + push(@deprecated_macros, $dirs[$#dirs]) if $dirs[ $#dirs - 1 ] eq 'deprecated'; + } + if (ref($pg->{pgcore}) eq 'PGcore') { $ret->{internal_debug_messages} = $pg->{pgcore}->get_internal_debug_messages; $ret->{warning_messages} = $pg->{pgcore}->get_warning_messages(); $ret->{debug_messages} = $pg->{pgcore}->get_debug_messages(); - $ret->{deprecated_macros} = $pg->{pgcore}{PG_loadMacros}{deprecated_macros}; + $ret->{deprecated_macros} = \@deprecated_macros; $ret->{PG_ANSWERS_HASH} = { map { $_ => { From 2693b62886bd7a3203d86b9f3b2d490fb9ec58fd Mon Sep 17 00:00:00 2001 From: Peter Staab Date: Wed, 25 Jun 2025 05:56:23 -0400 Subject: [PATCH 4/5] A bit of code cleanup. --- lib/WeBWorK/Utils/Rendering.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WeBWorK/Utils/Rendering.pm b/lib/WeBWorK/Utils/Rendering.pm index 78c3a6b7df..abb09a8484 100644 --- a/lib/WeBWorK/Utils/Rendering.pm +++ b/lib/WeBWorK/Utils/Rendering.pm @@ -272,7 +272,7 @@ sub renderPG ($c, $effectiveUser, $set, $problem, $psvn, $formFields, $translati my @deprecated_macros; for (keys %{ $pg->{pgcore}{PG_loadMacros}{macroFileList} }) { my @dirs = split('/', $_); - push(@deprecated_macros, $dirs[$#dirs]) if $dirs[ $#dirs - 1 ] eq 'deprecated'; + push(@deprecated_macros, $dirs[-1]) if $dirs[-2] eq 'deprecated'; } if (ref($pg->{pgcore}) eq 'PGcore') { From 53516536e6ba6db74d7a676df08b265f5c75afaf Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Wed, 25 Jun 2025 05:41:26 -0500 Subject: [PATCH 5/5] Improvements to showing the deprecated macros warning. Only parse the macro file list if the PGcore object is in the result. Also, remove the `p` tags and tweak the style of the html generated to display the deprecated macros list to get consistent spacing. --- htdocs/js/PGProblemEditor/pgproblemeditor.js | 10 +++++----- htdocs/js/RenderProblem/renderproblem.js | 10 +++++----- lib/WeBWorK/Utils/Rendering.pm | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/htdocs/js/PGProblemEditor/pgproblemeditor.js b/htdocs/js/PGProblemEditor/pgproblemeditor.js index 7be77b98e8..a62dcdae62 100644 --- a/htdocs/js/PGProblemEditor/pgproblemeditor.js +++ b/htdocs/js/PGProblemEditor/pgproblemeditor.js @@ -514,13 +514,13 @@ } if (data.deprecated_macros?.length) { const container = document.createElement('div'); - container.classList.add('alert', 'alert-danger', 'mx-2'); + container.classList.add('alert', 'alert-danger', 'mx-2', 'p-2'); container.innerHTML = - '

Warning!! This problem uses the following deprecated macros:

' + - '
    ' + + 'Warning!! This problem uses the following deprecated macros:' + + '
      ' + data.deprecated_macros.reduce((acc, item) => `${acc}
    • ${item}
    • `, '') + - '

    If this is an OPL problem, please report this issue to the OPL. ' + - 'If this is a custom problem, please update the problem to use modern macros.

    '; + '
If this is an OPL problem, please report this issue to the OPL. ' + + 'If this is a custom problem, please update the problem to use modern macros.'; iframe.after(container); } diff --git a/htdocs/js/RenderProblem/renderproblem.js b/htdocs/js/RenderProblem/renderproblem.js index 42ae4cc3ce..c14dd244e5 100644 --- a/htdocs/js/RenderProblem/renderproblem.js +++ b/htdocs/js/RenderProblem/renderproblem.js @@ -79,13 +79,13 @@ } if (data.deprecated_macros?.length) { const container = document.createElement('div'); - container.classList.add('alert', 'alert-danger'); + container.classList.add('alert', 'alert-danger', 'p-2'); container.innerHTML = - '

Warning!! This problem uses the following deprecated macros:

' + - '
    ' + + 'Warning!! This problem uses the following deprecated macros:' + + '
      ' + data.deprecated_macros.reduce((acc, item) => `${acc}
    • ${item}
    • `, '') + - '

    If this is an OPL problem, please report this issue to the OPL. ' + - 'If this is a custom problem, please update the problem to use modern macros.

    '; + '
If this is an OPL problem, please report this issue to the OPL. ' + + 'If this is a custom problem, please update the problem to use modern macros.'; iframe.after(container); } iFrameResize( diff --git a/lib/WeBWorK/Utils/Rendering.pm b/lib/WeBWorK/Utils/Rendering.pm index abb09a8484..6605e1b082 100644 --- a/lib/WeBWorK/Utils/Rendering.pm +++ b/lib/WeBWorK/Utils/Rendering.pm @@ -268,19 +268,12 @@ sub renderPG ($c, $effectiveUser, $set, $problem, $psvn, $formFields, $translati flags => $pg->{flags}, }; - # get a list of the deprecated macros - my @deprecated_macros; - for (keys %{ $pg->{pgcore}{PG_loadMacros}{macroFileList} }) { - my @dirs = split('/', $_); - push(@deprecated_macros, $dirs[-1]) if $dirs[-2] eq 'deprecated'; - } - if (ref($pg->{pgcore}) eq 'PGcore') { $ret->{internal_debug_messages} = $pg->{pgcore}->get_internal_debug_messages; $ret->{warning_messages} = $pg->{pgcore}->get_warning_messages(); $ret->{debug_messages} = $pg->{pgcore}->get_debug_messages(); - $ret->{deprecated_macros} = \@deprecated_macros; - $ret->{PG_ANSWERS_HASH} = { + + $ret->{PG_ANSWERS_HASH} = { map { $_ => { response_obj => unbless($pg->{pgcore}{PG_ANSWERS_HASH}{$_}->response_obj), @@ -294,6 +287,14 @@ sub renderPG ($c, $effectiveUser, $set, $problem, $psvn, $formFields, $translati keys %{ $pg->{pgcore}{PG_alias}{resource_list} } }; $ret->{PERSISTENCE_HASH} = $pg->{pgcore}{PERSISTENCE_HASH}; + + # Get a list of the deprecated macros used in the problem. + my @deprecated_macros; + for (keys %{ $pg->{pgcore}{PG_loadMacros}{macroFileList} }) { + my @dirs = split('/', $_); + push(@deprecated_macros, $dirs[-1]) if $dirs[-2] eq 'deprecated'; + } + $ret->{deprecated_macros} = \@deprecated_macros; } # Save the problem source. This is used by Caliper::Entity. Why?