diff options
author | Jonathan Prykop <jonathan@freeside.biz> | 2015-10-20 20:56:13 -0500 |
---|---|---|
committer | Mitch Jackson <mitch@freeside.biz> | 2018-10-09 12:20:05 -0400 |
commit | 6d42808bbd3ac9c840c6259aef1dc79a0dc620ff (patch) | |
tree | cdcdeeb07f00b43774408e43930c06c398cf7f42 /httemplate | |
parent | 61d5de1214428faa8bae0a50653ce8dff8d98ad8 (diff) |
RT#38217: Send email when logging conditions are met
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/browse/log_email.html | 92 | ||||
-rw-r--r-- | httemplate/edit/log_email.html | 45 | ||||
-rw-r--r-- | httemplate/edit/process/log_email.html | 18 | ||||
-rw-r--r-- | httemplate/elements/menu.html | 4 | ||||
-rw-r--r-- | httemplate/elements/tr-select-msg_template.html | 12 | ||||
-rw-r--r-- | httemplate/misc/delete-log_email.html | 20 | ||||
-rw-r--r-- | httemplate/search/log.html | 4 |
7 files changed, 195 insertions, 0 deletions
diff --git a/httemplate/browse/log_email.html b/httemplate/browse/log_email.html new file mode 100644 index 000000000..0f64dd454 --- /dev/null +++ b/httemplate/browse/log_email.html @@ -0,0 +1,92 @@ +<% include('/elements/init_overlib.html') %> +<% include('/browse/elements/browse.html', + 'title' => 'Log email condition configuration', + 'name_singular' => 'condition', + 'html_init' => '<P STYLE="margin-top: 0">' + . $add_condition_link + . ' | ' + . $system_log_link + . '</P>' + . '<SCRIPT>' + . $areyousure + . '</SCRIPT>', + 'query' => $query, + 'count_query' => $count_query, + 'header' => [ '#', + 'Context', + 'Min. Level', + 'Template', + 'To', + '', + ], + 'fields' => [ 'logemailnum', + sub { $_[0]->context || '(all)' }, + sub { $FS::Log::LEVELS[$_[0]->min_level] }, + 'msgname', + 'to_addr', + $actions, + ], + 'sort_fields' => [ 'logemailnum', + 'context', + 'min_level', + 'msgname', + 'to_addr', + '', + ], + 'links' => [ $editlink, + $editlink, + $editlink, + $editlink, + $editlink, + '', + ], + + ) %> + +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right([ 'View system logs', 'Configuration' ]); + +my $add_condition_link = include('/elements/popup_link.html', + 'action' => $p.'edit/log_email.html?popup=1', + 'label' => 'Add log email condition', + 'actionlabel' => 'Add log email condition', +); + +my $system_log_link = qq(<A HREF="${p}search/log.html">System Log</A>); + +my $query = { + 'table' => 'log_email', + 'select' => '*', + 'addl_from' => 'LEFT JOIN msg_template USING (msgnum)', + 'hashref' => { }, +}; + +my $count_query = "SELECT COUNT(*) FROM log_email"; + +my $actions = sub { + my $log_email = shift; + my $logemailnum = $log_email->logemailnum; + qq!<A HREF="javascript:areyousure_delete_log_email($logemailnum)">(delete)</A>!; +}; + +my $areyousure_onclick = include('/elements/popup_link_onclick.html', + 'js_action' => q(') . $p . q(misc/delete-log_email.html?logemailnum=' + logemailnum), + 'actionlabel' => 'Delete log email condition', +); + +my $areyousure = <<EOF; +function areyousure_delete_log_email(logemailnum) { + if (confirm('Are you sure you want to delete log email condition #'+logemailnum+'?')) { +${areyousure_onclick} + } +} +EOF + +my $editlink = [ $p.'edit/log_email.html?logemailnum=', 'logemailnum' ]; + +</%init> + diff --git a/httemplate/edit/log_email.html b/httemplate/edit/log_email.html new file mode 100644 index 000000000..bbce7c708 --- /dev/null +++ b/httemplate/edit/log_email.html @@ -0,0 +1,45 @@ +<% include( 'elements/edit.html', + 'name_singular' => 'log email condition', + 'table' => 'log_email', + 'fields' => [ + { 'field' => 'context', + 'type' => 'select', + 'options' => [ '', @contexts ], + 'labels' => { '' => '(all)', map { $_ => $_ } @contexts }, + 'curr_value' => scalar($cgi->param('context')), + }, + { 'field' => 'min_level', + 'type' => 'select', + 'options' => [ 0..7 ], + 'labels' => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 }, + 'curr_value' => scalar($cgi->param('min_level')), + }, + 'to_addr', + { 'field' => 'msgnum', + 'type' => 'select-msg_template', + 'empty_label' => 'Select template', + 'required' => 1, + }, + ], + 'labels' => { + 'context' => 'Context', + 'min_level' => 'Min. Level', + 'to_addr' => 'To', + 'msgnum' => 'Message', + }, + 'viewall_dir' => 'browse', + 'popup' => $opts{'popup'}, + 'form_init' => $opts{'popup'} ? q(<INPUT TYPE="hidden" NAME="popup" VALUE="1">) : '', + ) +%> +<%once> +my @contexts = sort FS::log_context->contexts; +</%once> +<%init> + +my %opts = @_; + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right([ 'View system logs', 'Configuration' ]); + +</%init> diff --git a/httemplate/edit/process/log_email.html b/httemplate/edit/process/log_email.html new file mode 100644 index 000000000..769e180a8 --- /dev/null +++ b/httemplate/edit/process/log_email.html @@ -0,0 +1,18 @@ +<% include('elements/process.html', + 'table' => 'log_email', + %processopts + ) %> +<%init> + +my %opts = @_; + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right([ 'View system logs', 'Configuration' ]); + +my %processopts = $opts{'popup'} + ? ( 'popup_reload' => 'Logging email added' ) + : ( 'redirect' => $fsurl.'browse/log_email.html?' ); # id will be needlessly appended, should be harmless + +</%init> diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 9b30b6cd0..759ae338c 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -801,6 +801,10 @@ $config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_cla $config_misc{'Upload targets'} = [ $fsurl.'browse/upload_target.html', 'Billing and payment upload destinations' ] if $curuser->access_right('Configuration'); +$config_misc{'System log emails'} = [ $fsurl.'browse/log_email.html', 'Configure conditions for sending email when logging' ] + if $curuser->access_right('View system logs') + || $curuser->access_right('Configuration'); + tie my %config_menu, 'Tie::IxHash'; if ( $curuser->access_right('Configuration' ) ) { %config_menu = ( diff --git a/httemplate/elements/tr-select-msg_template.html b/httemplate/elements/tr-select-msg_template.html new file mode 100644 index 000000000..1f899e01c --- /dev/null +++ b/httemplate/elements/tr-select-msg_template.html @@ -0,0 +1,12 @@ +<% include('/elements/tr-td-label.html', + 'label' => $opt{'label'} || 'Message template: ', + 'required' => $opt{'required'} ) %> + <TD><% include('select-msg_template.html', %opt) %></TD> +</TR> + +<%init> + +my %opt = @_; + +</%init> + diff --git a/httemplate/misc/delete-log_email.html b/httemplate/misc/delete-log_email.html new file mode 100644 index 000000000..cc17b15a0 --- /dev/null +++ b/httemplate/misc/delete-log_email.html @@ -0,0 +1,20 @@ +% if ($error) { +<P STYLE="color: red"><% $error %></P> +% } else { +<H1>Log email condition deleted</H1> +<SCRIPT> +window.top.location.reload(); +</SCRIPT> +% } + +<%init> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right([ 'View system logs', 'Configuration' ]); + +my $logemailnum = $cgi->param('logemailnum'); +$logemailnum =~ /^\d+$/ or die "bad logemailnum '$logemailnum'"; +my $log_email = FS::log_email->by_key($logemailnum) + or die "logemailnum '$logemailnum' not found"; +my $error = $log_email->delete; +</%init> + diff --git a/httemplate/search/log.html b/httemplate/search/log.html index 9aa37365d..9a61a71e1 100644 --- a/httemplate/search/log.html +++ b/httemplate/search/log.html @@ -1,6 +1,7 @@ <& elements/search.html, 'title' => 'System Log', 'name_singular' => 'event', + 'menubar' => \@menubar, 'html_init' => include('.head'), 'query' => $query, 'count_query' => $count_query, @@ -210,6 +211,9 @@ my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" unless $curuser->access_right([ 'View system logs', 'Configuration' ]); +my @menubar = (); +push @menubar, qq(<A HREF="${fsurl}browse/log_email.html" STYLE="text-decoration: underline;">Configure conditions for sending email when logging</A>), + $cgi->param('min_level', 0) unless defined($cgi->param('min_level')); $cgi->param('max_level', 7) unless defined($cgi->param('max_level')); |