[Bps-public-commit] rt-extension-formtools branch dynamic-forms-from-config updated. 0.53-31-g03ce4ee
BPS Git Server
git at git.bestpractical.com
Thu Oct 5 13:40:52 UTC 2023
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt-extension-formtools".
The branch, dynamic-forms-from-config has been updated
via 03ce4ee935190e379769071c5542fbabd72327cb (commit)
via 92009cbf35858819e434ae99d2bd7fc5f4bf8ec0 (commit)
via 47b3027da90b87b80e09e8af4ec9bb5dbb1fcf4f (commit)
via fcea9a6e057a25a0f124502da1496a0719ec1767 (commit)
via 7bdb20a3ab4b724e7027f0dc4ebedb60b5ff0e78 (commit)
via e82b385f37d5b5885fe3dbb347d843bdc235797a (commit)
via 143c3aaf1c889c6fb7c13f8e6f69afe962879004 (commit)
from d32cbe0b52ce78b6e1536370cecfeadac006f3f0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 03ce4ee935190e379769071c5542fbabd72327cb
Merge: d32cbe0 92009cb
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Oct 5 09:39:45 2023 -0400
Merge branch 'form-home-icon-upload' into dynamic-forms-from-config
diff --cc static/css/rt-extension-formtools.css
index f9288f3,50224f5..b5d719f
--- a/static/css/rt-extension-formtools.css
+++ b/static/css/rt-extension-formtools.css
@@@ -3,43 -3,15 +3,56 @@@ div .formtools-content
min-height: 400px;
}
+.formtools-form-pages .badge {
+ background-color: #4868b3;
+}
+
+.formtools-form-pages .remove {
+ position: absolute;
+ right: 2.5em;
+ color: #5C6273;
+}
+
+.formtools-component-menu .remove {
+ display: none;
+}
+
+.formtools-form-pages .edit {
+ position: absolute;
+ right: 4em;
+ color: #5C6273;
+}
+
+.formtools-component-menu .edit {
+ display: none;
+}
+
+.formtools-component-menu .badge {
+ display: none;
+}
+
+.formtools-element-placeholder {
+ border: 2px dotted #ffc107 !important;
+ display: none;
+}
+
+.formtools-element-placeholder.active {
+ display: block;
+}
+
+.formtools-element.current p {
+ opacity: 0.7;
- }
++}
++
+ p.formtools-form-graphic {
+ font-weight: bold;
+ font-size: 1.5rem;
+ }
+
+ div .formtools-form-list {
+ max-width: 1000px;
+ }
+
+ div .formtools-admin-description {
+ max-width: 1000px;
+ }
commit 92009cbf35858819e434ae99d2bd7fc5f4bf8ec0
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Wed Oct 4 15:55:50 2023 -0400
Add icon upload and display for forms
diff --git a/html/Admin/FormTools/Describe.html b/html/Admin/FormTools/Describe.html
index a29ae35..a4a1635 100644
--- a/html/Admin/FormTools/Describe.html
+++ b/html/Admin/FormTools/Describe.html
@@ -2,16 +2,28 @@
<& /Elements/Tabs &>
<& /Elements/ListActions, actions => \@results &>
-<&| /Widgets/TitleBox, title => '' &>
+<&| /Widgets/TitleBox, title => '', class => 'formtools-admin-description ml-auto mr-auto' &>
<p>Forms are shown to users on a page in the RT Self Service interface. Below you can manage how the form details will appear to end users.</p>
<form name="EditFormDescription" action="<%RT->Config->Get('WebPath')%>/Admin/FormTools/Describe.html" method="post" enctype="multipart/form-data">
<input type="hidden" class="hidden" name="id" value="<% $id %>" />
<&| /Widgets/TitleBox, title => loc('Icon') &>
- <p>Form to upload an icon</p>
+% if ( $current_form_icon ) {
+<& /Elements/Forms/ShowFormIcon, FormID => $id &>
+% } else {
+ <p>Upload an icon to be shown to users on the Forms page or select a color for the background of graphical box users can click.</p>
+% }
+
+ <div class="row">
+ <div class="col ml-5 mr-5">
+ <div class="custom-file">
+ <input type="file" name="FormUploadIcon" class="custom-file-input" id="formtools-upload-icon" />
+ <label class="custom-file-label" for="formtools-upload-icon"><&|/l&>Upload an icon for this form</&></label>
+ </div>
+ </div>
+ </div>
</&>
<&| /Widgets/TitleBox, title => loc('Description') &>
<p>Describe what the form should be used for and include instructions to help users pick the correct form.</p>
- <p>An HTML edit box for instructions</p>
<div class="form-row">
<div class="col-12">
<input type="hidden" class="hidden" name="FormDescriptionType" value="text/html" />
@@ -27,6 +39,7 @@
</div>
</form>
<%init>
+use Digest::MD5 'md5_hex';
# Handle id getting submitted twice and becoming an array
my @id = ( ref $id eq 'ARRAY' ) ? @{$id} : ($id);
@@ -61,6 +74,35 @@ if ( $ARGS{'SubmitDescription'} ) {
}
}
+my ($current_form_icon) = RT::Extension::FormTools::LoadFormIcon( $session{'CurrentUser'}, $form_attribute->Id );
+
+if ( my $file_hash = _UploadedFile( 'FormUploadIcon' ) ) {
+
+ my ($form_icon, $msg) = RT::Extension::FormTools::LoadFormIcon( $session{'CurrentUser'}, $form_attribute->Id );
+
+ if ( $form_icon ) {
+ # Delete the existing icon
+ my ( $del_ok, $del_msg ) = $form_icon->Delete;
+
+ RT->Logger->error("Unable to delete icon attribute id $ok, $del_msg") unless $del_ok;
+ }
+
+ my $new_form_icon = RT::Attribute->new( $session{CurrentUser} );
+ ( $ok, $msg ) = $new_form_icon->Create(
+ Name => "FormTools Icon",
+ Description => "Icon for " . $form_attribute->Description,
+ Object => $form_attribute,
+ Content => {
+ type => $file_hash->{ContentType},
+ data => $file_hash->{LargeContent},
+ hash => md5_hex($file_hash->{LargeContent}),
+ },
+ );
+
+ push @results, loc("Unable to set form icon") unless $ok;
+ RT->Logger->error("Unable to set form icon: $msg") unless $ok;
+}
+
MaybeRedirectForResults(
Actions => \@results,
Arguments => { id => $id, FormDescription => $ARGS{'FormDescription'} },
diff --git a/html/Elements/Forms/ListForms b/html/Elements/Forms/ListForms
index 17bed2f..f14f482 100644
--- a/html/Elements/Forms/ListForms
+++ b/html/Elements/Forms/ListForms
@@ -6,7 +6,7 @@
<div class="row mt-3 mb-3">
<div class="col-4">
<a href="<% RT->Config->Get('WebPath') %>/SelfService/Forms/<% $form_attribute->Description %>">
- <% $m->scomp('/Elements/Forms/ShowFormGraphic', FormName => $form_attribute->Description, ItemNumber => $item_number) |n %>
+ <% $m->scomp('/Elements/Forms/ShowFormGraphic', FormObj => $form_attribute, ItemNumber => $item_number) |n %>
</a>
</div>
<div class="col">
diff --git a/html/Elements/Forms/ShowFormGraphic b/html/Elements/Forms/ShowFormGraphic
index 2cc953e..fd14ab8 100644
--- a/html/Elements/Forms/ShowFormGraphic
+++ b/html/Elements/Forms/ShowFormGraphic
@@ -1,12 +1,21 @@
<div class="formtools-form-graphic w-50 mt-2 mb-2 ml-auto mr-auto">
+% if ( $has_icon ) {
+<& /Elements/Forms/ShowFormIcon, FormID => $FormObj->Id &>
+% } else {
<div class="rounded pt-5 pb-5" style="background-color: <%$color%>;">
<p class="text-center formtools-form-graphic">
- <% $FormName %>
+ <% $FormObj->Description %>
</p>
</div>
+% }
</div>
<%init>
+unless ( $FormObj and $FormObj->Id ) {
+ RT->Logger->error("No valid form attribute object passed");
+ return;
+}
+
my $color_list = [
"#1f77b4", "#ff7f0e", "#2ca02c", "#d62728",
"#9467bd", "#8c564b", "#e377c2", "#7f7f7f"
@@ -14,8 +23,16 @@ my $color_list = [
my $color = $color_list->[ $ItemNumber % 8 ];
+my $has_icon = 0;
+my $form_icon = RT::Attribute->new( RT->SystemUser );
+my ($ok, $msg) = $form_icon->LoadByCols( ObjectType => 'RT::Attribute', ObjectId => $FormObj->Id );
+
+if ( $ok and $form_icon->Id ) {
+ $has_icon = 1;
+}
+
</%init>
<%args>
-$FormName => "Form"
+$FormObj
$ItemNumber => 1
</%args>
diff --git a/html/Elements/Forms/ShowFormIcon b/html/Elements/Forms/ShowFormIcon
new file mode 100644
index 0000000..cdbc216
--- /dev/null
+++ b/html/Elements/Forms/ShowFormIcon
@@ -0,0 +1,28 @@
+<div id="formtools-icon-<% $FormID %>" class="">
+% if ($form_icon) {
+<img
+ class="d-block mx-auto",
+ width="100px", height="100px",
+ src="<% RT->Config->Get('WebPath') %>/NoAuth/Helpers/FormLogo/<% $form_icon->Id %>"
+ alt="<%$ARGS{'LogoAltText'}%>" />
+% }
+</div>
+<%init>
+
+my ($form_icon, $msg) = RT::Extension::FormTools::LoadFormIcon( $session{'CurrentUser'}, $FormID );
+
+if ( $form_icon ) {
+ my $content = $form_icon->Content;
+ undef $form_icon
+ unless ref $content eq 'HASH'
+ and defined $content->{'data'};
+}
+else {
+ RT->Logger->error("Unable to load logo for form id $FormID");
+}
+
+</%init>
+<%args>
+$LogoAltText => ''
+$FormID => undef
+</%args>
diff --git a/html/NoAuth/Helpers/FormLogo/dhandler b/html/NoAuth/Helpers/FormLogo/dhandler
new file mode 100644
index 0000000..f2c33e3
--- /dev/null
+++ b/html/NoAuth/Helpers/FormLogo/dhandler
@@ -0,0 +1,17 @@
+<%init>
+my $icon_id = $m->dhandler_arg;
+
+my $form_icon = RT::Attribute->new( RT->SystemUser );
+my ($ok, $msg) = $form_icon->Load($icon_id);
+
+if ( $ok ) {
+ RT::Interface::Web::StaticFileHeaders();
+ my $content = $form_icon->Content;
+ $r->content_type( $content->{type} );
+ $m->out( $content->{data} );
+}
+else {
+ # 404
+ return $m->decline;
+}
+</%init>
diff --git a/lib/RT/Extension/FormTools.pm b/lib/RT/Extension/FormTools.pm
index c1dbd38..56cfbc2 100644
--- a/lib/RT/Extension/FormTools.pm
+++ b/lib/RT/Extension/FormTools.pm
@@ -213,6 +213,33 @@ sub has_value {
return (0, "You must provide a value for this field");
}
+=head2 LoadFormIcon($current_user, $form_id)
+
+Loads the form icon attribute associated with the passed form id.
+
+Returns a tuple of attribute object or false, and a message.
+
+=cut
+
+sub LoadFormIcon {
+ my $current_user = shift;
+ my $form_id = shift;
+
+ my $form_icon = RT::Attribute->new( $current_user );
+ my ( $ok, $msg ) = $form_icon->LoadByCols(
+ Name => 'FormTools Icon',
+ ObjectType => 'RT::Attribute',
+ ObjectId => $form_id );
+
+ if ( $ok ) {
+ return ( $form_icon, $msg );
+ }
+ else {
+ RT->Logger->error("Unable to load icon: $msg");
+ return ( 0, $msg );
+ }
+}
+
=head1 AUTHOR
Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>
diff --git a/static/css/rt-extension-formtools.css b/static/css/rt-extension-formtools.css
index 1108657..50224f5 100644
--- a/static/css/rt-extension-formtools.css
+++ b/static/css/rt-extension-formtools.css
@@ -11,3 +11,7 @@ p.formtools-form-graphic {
div .formtools-form-list {
max-width: 1000px;
}
+
+div .formtools-admin-description {
+ max-width: 1000px;
+}
commit 47b3027da90b87b80e09e8af4ec9bb5dbb1fcf4f
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Mon Oct 2 16:49:13 2023 -0400
Improve spacing and layout for Forms page
diff --git a/html/Elements/Forms/ListForms b/html/Elements/Forms/ListForms
index 73185f1..17bed2f 100644
--- a/html/Elements/Forms/ListForms
+++ b/html/Elements/Forms/ListForms
@@ -1,16 +1,18 @@
-<&|/Widgets/TitleBox, title => '', class => 'fullwidth' &>
+<&|/Widgets/TitleBox, title => '', class => 'fullwidth formtools-form-list ml-auto mr-auto' &>
<div class="container">
% my $item_number = 1;
% while ( my $form_attribute = $forms->Next ) {
% my $form = $form_attribute->Content;
-<div class="row border border-primary">
+<div class="row mt-3 mb-3">
<div class="col-4">
<a href="<% RT->Config->Get('WebPath') %>/SelfService/Forms/<% $form_attribute->Description %>">
<% $m->scomp('/Elements/Forms/ShowFormGraphic', FormName => $form_attribute->Description, ItemNumber => $item_number) |n %>
</a>
</div>
<div class="col">
- <% $form->{'form-description'} |n %>
+ <div class="formtools-form-text w-100 mt-2 mb-2 mr-auto ml-auto">
+ <% $form->{'form-description'} |n %>
+ </div>
</div>
</div>
% $item_number++;
diff --git a/html/Elements/Forms/ShowFormGraphic b/html/Elements/Forms/ShowFormGraphic
index 37679ea..2cc953e 100644
--- a/html/Elements/Forms/ShowFormGraphic
+++ b/html/Elements/Forms/ShowFormGraphic
@@ -1,6 +1,6 @@
-<div class="formtools-form-graphic w-50 mt-2 mb-2">
+<div class="formtools-form-graphic w-50 mt-2 mb-2 ml-auto mr-auto">
<div class="rounded pt-5 pb-5" style="background-color: <%$color%>;">
- <p class="text-center" style="font-color: white; font-weight: bold; font-size: 2rem;">
+ <p class="text-center formtools-form-graphic">
<% $FormName %>
</p>
</div>
diff --git a/static/css/rt-extension-formtools.css b/static/css/rt-extension-formtools.css
index ad60315..1108657 100644
--- a/static/css/rt-extension-formtools.css
+++ b/static/css/rt-extension-formtools.css
@@ -2,3 +2,12 @@
div .formtools-content {
min-height: 400px;
}
+
+p.formtools-form-graphic {
+ font-weight: bold;
+ font-size: 1.5rem;
+}
+
+div .formtools-form-list {
+ max-width: 1000px;
+}
commit fcea9a6e057a25a0f124502da1496a0719ec1767
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Tue Sep 26 17:11:36 2023 -0400
Customize RTs Abort to prevent permission errors from CreateTicket
By default, CreateTicket calls Abort at the end if the current
user doesn't have ShowTicket. In FormTools, we aren't showing
the ticket at the end, we're showing the last configured form
page. Since end users are using a form wizard to create one
or more tickets, it's possible they don't have rights to directly
see the newly created ticket, especially in Self Service.
Add an exception to Abort so we can get the ticket object if
the create was successful, even if the current user can't
see the ticket.
diff --git a/html/Forms/dhandler b/html/Forms/dhandler
index c49a320..d8272ea 100644
--- a/html/Forms/dhandler
+++ b/html/Forms/dhandler
@@ -92,7 +92,16 @@ $base_path = '/SelfService' . $base_path if $SelfService;
my ($ticket_obj, @results);
if ( $create_ticket ) {
- ($ticket_obj, @results) = CreateTicket(
+
+ # We override Abort elsewhere so we'll get $ticket_obj here even if
+ # the current user has no rights to see the newly created ticket.
+
+ # We deliberately don't pass along @results because the work
+ # behind the scenes is "magic" and we don't want the form user to
+ # see any details, like ticket ids or queues, if they are not supposed
+ # to see them.
+
+ ($ticket_obj) = CreateTicket(
Subject => 'Ticket created from FormTools form ' . $form_name,
Queue => $queue_obj->Id,
Status => 'new',
diff --git a/lib/RT/Interface/Web_Vendor.pm b/lib/RT/Interface/Web_Vendor.pm
new file mode 100644
index 0000000..16757a1
--- /dev/null
+++ b/lib/RT/Interface/Web_Vendor.pm
@@ -0,0 +1,26 @@
+package HTML::Mason::Commands;
+
+no warnings qw(redefine);
+
+# This should be the same class we are overlaying here
+my $original_abort = \&HTML::Mason::Commands::Abort;
+
+*HTML::Mason::Commands::Abort = sub {
+ my $why = shift;
+ my %args = @_;
+
+ if ( $why =~ /^No permission to view newly created ticket #(\d+)/ ) {
+ # We're showing a custom "form submitted" page, not the ticket,
+ # so we don't want to abort if the user doesn't have rights to
+ # see the ticket.
+
+ # Just return for this case so the create ticket form can get
+ # the ticket object and any actual error messages.
+
+ return;
+ }
+
+ &$original_abort( $why, %args );
+};
+
+1;
-----------------------------------------------------------------------
Summary of changes:
html/Admin/FormTools/Describe.html | 48 ++++++++++++++++++++++++++++++++---
html/Elements/Forms/ListForms | 20 ++++++++++-----
html/Elements/Forms/ShowFormGraphic | 38 +++++++++++++++++++++++++++
html/Elements/Forms/ShowFormIcon | 28 ++++++++++++++++++++
html/FormTools/Field | 6 +++--
html/Forms/dhandler | 19 +++++++++++---
html/NoAuth/Helpers/FormLogo/dhandler | 17 +++++++++++++
html/SelfService/Forms/dhandler | 2 ++
lib/RT/Extension/FormTools.pm | 27 ++++++++++++++++++++
lib/RT/Interface/Web_Vendor.pm | 26 +++++++++++++++++++
static/css/rt-extension-formtools.css | 15 ++++++++++-
11 files changed, 231 insertions(+), 15 deletions(-)
create mode 100644 html/Elements/Forms/ShowFormGraphic
create mode 100644 html/Elements/Forms/ShowFormIcon
create mode 100644 html/NoAuth/Helpers/FormLogo/dhandler
create mode 100644 html/SelfService/Forms/dhandler
create mode 100644 lib/RT/Interface/Web_Vendor.pm
hooks/post-receive
--
rt-extension-formtools
More information about the Bps-public-commit
mailing list