Skip to content

Commit 88cf26e

Browse files
committed
Add custom_recipients setting to allow disable comment recipients selection
1 parent 97e6f42 commit 88cf26e

6 files changed

Lines changed: 153 additions & 120 deletions

File tree

src/Controllers/ConfigurationsController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function index()
2727
'email.template', 'email.owner.newticket.template', 'email.header', 'email.signoff', 'email.signature', 'email.dashboard',
2828
'email.google_plus_link', 'email.facebook_link', 'email.twitter_link', 'email.footer', 'email.footer_link',
2929
'email.color_body_bg', 'email.color_header_bg', 'email.color_content_bg', 'email.color_footer_bg',
30-
'email.color_button_bg', 'email.account.name', 'email.account.mailbox' ];
30+
'email.color_button_bg', 'email.account.name', 'email.account.mailbox', 'custom_recipients' ];
3131
$tickets_section = ['default_priority_id', 'default_status_id', 'default_close_status_id', 'default_reopen_status_id',
3232
'subject_content_column', 'paginate_items', 'attachments_ticket_max_size', 'attachments_ticket_max_files_num', 'attachments_mimes',
3333
'attachments_path', 'thumbnails_path', 'oldest_year', 'user_route', 'html_replacements', 'list_text_max_length', 'use_default_status_id', 'newest_list_reload_seconds'];
@@ -135,7 +135,7 @@ public function update(Request $request, $id)
135135
// refresh cached settings
136136
\Cache::forget('panichd::settings');
137137
\Cache::forget('panichd::settings.'.$configuration->slug);
138-
138+
139139
return redirect()->action('\PanicHD\PanicHD\Controllers\ConfigurationsController@index');
140-
}
141-
}
140+
}
141+
}

src/Controllers/NotificationsController.php

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,33 +149,49 @@ public function newComment(Comment $comment, $request)
149149
$category_level = $member->levelInCategory($ticket->category_id);
150150
$permission_level = ($member->currentLevel() > 1 and $category_level > 1) ? $category_level : 1;
151151

152-
if ($permission_level < 2){
153-
// Get defaults
154-
$a_defaults = $this->defaultRecipients($ticket, $notification_owner, $subject, $template);
152+
$a_recipients = [];
155153

156-
// Add recipients for each default one
157-
foreach ($a_defaults as $default){
154+
if($permission_level < 2 or !Setting::grab('custom_recipients')){
155+
// Add recipients for each default one (Ticket agent)
156+
foreach ($this->defaultRecipients($ticket, $notification_owner, $subject, $template) as $default){
158157
$a_recipients[] = $default['recipient']->id;
159158
}
160159

161-
// Add all members notified previously
162-
$a_recipients = array_unique(array_merge($a_recipients, $ticket->commentNotifications()->where('member_id', '!=', $member->id)->groupBy('member_id')->pluck('member_id')->toArray()));
160+
// Add ticket owner
161+
if(!$ticket->hidden and !is_null($ticket->owner) and !in_array($ticket->owner->email, [$notification_owner->email, $ticket->agent->email])
162+
and ($comment->type == 'reply' or ($comment->type != 'reply' and $ticket->owner->levelInCategory($ticket->category->id) > 1))){
163163

164-
// Add all comment / note authors
165-
foreach ($ticket->comments()->with('owner')->get() as $comm){
166-
if ($member->id != $comm->owner->id and !in_array($comm->owner->id, $a_recipients)) $a_recipients[] = $comm->owner->id;
167-
}
168-
169-
if (!is_null($ticket->owner) and $member->id != $ticket->owner->id and !in_array($ticket->owner->id, $a_recipients)){
170-
// Add ticket owner if it's not the same as who comments
171164
$a_recipients[] = $ticket->owner->id;
165+
}
166+
167+
foreach($ticket->comments()->whereIn('type', ['reply', 'note'])->with('owner', 'notifications')->get() as $comm){
168+
// Previous comment authors
169+
if ($comm->owner->id != $notification_owner->id and !in_array($comm->owner->id, $a_recipients)
170+
and ($comment->type == 'reply' or ($comment->type != 'reply' and $comm->owner->levelInCategory($ticket->category->id) > 1))){
171+
172+
$a_recipients[] = $comm->owner->id;
173+
}
174+
175+
// All previous comments recipients
176+
foreach ($comm->notifications as $notification){
177+
$recipient = Member::find($notification->member_id);
178+
if (count($recipient) == 1 and ($comment->type == 'reply' or ($comment->type != 'reply' and $recipient->levelInCategory($ticket->category->id) > 1))
179+
and $notification_owner->id!= $recipient->id and !in_array($recipient->id, $a_recipients)){
180+
181+
$a_recipients[] = $recipient->id;
182+
}
183+
}
172184
}
185+
}
173186

174-
}else{
175-
// Selected recipients
176-
// $comment->a_recipients come from embedded comments i TicketsController
177-
// $request recipients come from a comment modal in Ticket card
178-
$a_recipients = isset($comment->a_recipients) ? $comment->a_recipients : ($comment->type == 'note' ? $request->note_recipients : $request->reply_recipients);
187+
if($permission_level > 1){
188+
if (Setting::grab('custom_recipients')){
189+
/* About $a_recipients
190+
* $comment->a_recipients come from embedded comments i TicketsController
191+
* $request recipients come from a comment modal in Ticket card
192+
*/
193+
$a_recipients = isset($comment->a_recipients) ? $comment->a_recipients : ($comment->type == 'note' ? $request->note_recipients : $request->reply_recipients);
194+
}
179195

180196
if (count($a_recipients) > 0){
181197
if ($request->has('add_in_user_notification_text') or (isset($comment->add_in_user_notification_text))){

src/Seeds/SettingsTableSeeder.php

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,27 @@ public function getDefaults()
9696
* Default: panichd::master
9797
*/
9898
'master_template' => 'panichd::master',
99-
99+
100100
/*
101101
* Default Member model for PanicHD
102102
* Default: default (which means using PanicHD\PanicHD\Models\Member)
103103
*/
104104
'member_model_class' => 'default',
105-
106-
105+
106+
107107
/*
108108
* Admin navbar button text is configurable
109109
*/
110110
'admin_button_text' => 'PanicHD',
111-
111+
112112
/*
113113
* Tickets email account: The email address for all package notifications.
114114
* Overrides Laravel email and name but uses it's connection parameters
115115
* Default: use Laravel config('mail.from.name') and config('mail.from.address') parameters
116116
*/
117117
'email.account.name' => 'default',
118118
'email.account.mailbox' => 'default',
119-
119+
120120
/*
121121
* Template adherence: The email blade template to be extended
122122
* Default: panichd::emails.templates.panichd
@@ -138,45 +138,45 @@ public function getDefaults()
138138
'email.color_content_bg' => '#F46B45',
139139
'email.color_footer_bg' => '#414141',
140140
'email.color_button_bg' => '#AC4D2F',
141-
142-
141+
142+
143143
/**
144144
* Configurable notifications.
145145
*/
146-
146+
147147
/*
148148
* Agent notify: To notify assigned agent (either auto or manual assignment) of new assigned or transferred tickets
149149
* Default: 'yes'
150150
* not to notify agent: 'no'
151151
*/
152152
'assigned_notification' => 'yes',
153-
153+
154154
/*
155155
* Comment notification: Send notification when new comment is posted
156156
* Default is send notification: 'yes'
157157
* Do not send notification: 'no'
158158
*/
159159
'comment_notification' => 'yes',
160-
160+
161161
/*
162162
* Status notification: Send email notification to ticket owner/Agent when ticket status is changed
163163
* Default: 'yes'
164164
*/
165165
'status_notification' => 'yes',
166-
166+
167167
/*
168168
* Notify owner when ticket list changes (between active and complete only)
169169
* Default: 'yes'
170-
*/
170+
*/
171171
'list_owner_notification' => 'yes',
172172

173173
/*
174174
* Notify owner when ticket status changes
175175
* Default: 'yes'
176176
*/
177177
'status_owner_notification' => 'yes',
178-
179-
178+
179+
180180
/*
181181
* The default priority for new tickets
182182
* Default: 1
@@ -213,14 +213,14 @@ public function getDefaults()
213213
* Default: 1
214214
*/
215215
'paginate_items' => 10,
216-
216+
217217
/*
218218
* Ticket list: View combined column for subject and content?
219219
* Default: 'no'
220220
*/
221221
'subject_content_column' => 'no',
222-
223-
222+
223+
224224
/*
225225
* Max total size for attached files (ticket + comments)
226226
*
@@ -232,35 +232,35 @@ public function getDefaults()
232232
*
233233
*/
234234
'attachments_ticket_max_files_num' => '20',
235-
235+
236236
/**
237237
* Attachment allowed mimetypes
238238
*
239239
* Default: jpg,jpeg,png,gif,doc,docx,rtf,xls,xlsx,pdf
240240
*/
241241
'attachments_mimes' => 'jpg,jpeg,png,gif,doc,docx,rtf,xls,xlsx,pdf',
242-
242+
243243
/*
244244
* Defines relative path under storage_path() where to store attached files
245245
*
246246
* Default: <storage_path>/panichd_attachments
247247
*/
248248
'attachments_path' => 'panichd_attachments',
249249
'thumbnails_path' => 'panichd_thumbnails',
250-
250+
251251
/*
252252
* Oldest year for ticket start date or limit date
253253
*/
254254
'oldest_year' => '2017',
255-
255+
256256
/*
257257
* String replacements to execute within Purifiable trait before clean() method
258258
*/
259259
'html_replacements' => [
260260
'<br />' => '',
261261
'<br>' => ''
262262
],
263-
263+
264264
/*
265265
* If set to a number, limit texts in ticket list to specified character length and show plus / minus icons
266266
*/
@@ -272,22 +272,29 @@ public function getDefaults()
272272
*/
273273
'newest_list_reload_seconds' => '60',
274274

275-
275+
276276
/*
277277
* Pagination length: For tickets table.
278278
* Default: 1
279279
*/
280280
'length_menu' => [[10, 50, 100], [10, 50, 100]],
281-
282-
281+
282+
283283
/*
284284
* Use Queue method when sending emails (Mail::queue instead of Mail::send). Note that Mail::queue needs to be
285285
* configured first http://laravel.com/docs/5.1/queues
286286
* Default is to not use queue: 'no'
287287
* use queue: 'yes'
288288
*/
289289
'queue_emails' => 'no',
290-
290+
291+
/*
292+
* Enable comment option to select one or many recipients to send comment notification to
293+
*
294+
* Default: 'yes'
295+
*/
296+
'custom_recipients' => 'yes',
297+
291298
/*
292299
* Agent restrict: Restrict agents access to only their assigned tickets
293300
* Default: 'no'
@@ -373,38 +380,38 @@ public function getDefaults()
373380
'URI.SafeIframeRegexp' => '%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%',
374381
'URI.AllowedSchemes' => ['data' => true, 'http' => true, 'https' => true, 'mailto' => true, 'ftp' => true],
375382
],
376-
383+
377384
/*
378385
* Panic Help Desk optional features
379386
*/
380-
387+
381388
/*
382389
* View department and sub1 where ticket owner belongs
383390
*/
384-
'departments_feature' => 'no',
385-
391+
'departments_feature' => 'no',
392+
386393
/*
387394
* This feature represents two connected functionalities:
388395
* - Ability of associate certain users to departments.
389396
* - On new ticket menu: User department's associated users open tickets will be shown on special panel called "Notices"
390397
*/
391398
'departments_notices_feature' => 'no',
392-
399+
393400
/**
394401
* Allow file attachments for tickets and comments
395402
*/
396403
'ticket_attachments_feature' => 'yes',
397-
404+
398405
/*
399406
* Calendar filter options switch between week and month or 7 and 14 days
400407
*/
401408
'calendar_month_filter' => 'no',
402-
409+
403410
/*
404411
* Max number of agent specific buttons in filter panel. If agent count is bigger, select2 will be shown
405412
*/
406413
'max_agent_buttons' => '4',
407-
414+
408415
/**
409416
* User card route name if it exists in your app. Configuring it makes Owner name link to it's card by passing user id.
410417
*

src/Views/tickets/partials/comments/modal_new.blade.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,40 @@
2929
</div>
3030
</div>
3131

32-
<div class="form-group row">
33-
<label class="col-lg-2 col-form-label">{{ trans('panichd::lang.show-ticket-add-comment-notificate') . trans('panichd::lang.colon') }}</label>
34-
<div class="col-lg-10">
35-
<select name="reply_recipients[]" id="reply_recipients" class="form-control" multiple="multiple" style="display: none; width: 100%">
36-
@foreach ($c_members as $member)
37-
<option value="{{ $member->id }}" {{ in_array($member->id, $a_notifications['reply']) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
38-
@if ($setting->grab('departments_notices_feature'))
39-
@if ($member->ticketit_department == '0')
40-
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}
41-
@elseif ($member->ticketit_department != "")
42-
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . $member->userDepartment->getFullName() }}
32+
@if($setting->grab('custom_recipients'))
33+
<div class="form-group row">
34+
<label class="col-lg-2 col-form-label">{{ trans('panichd::lang.show-ticket-add-comment-notificate') . trans('panichd::lang.colon') }}</label>
35+
<div class="col-lg-10">
36+
<select name="reply_recipients[]" id="reply_recipients" class="form-control" multiple="multiple" style="display: none; width: 100%">
37+
@foreach ($c_members as $member)
38+
<option value="{{ $member->id }}" {{ in_array($member->id, $a_notifications['reply']) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
39+
@if ($setting->grab('departments_notices_feature'))
40+
@if ($member->ticketit_department == '0')
41+
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}
42+
@elseif ($member->ticketit_department != "")
43+
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . $member->userDepartment->getFullName() }}
44+
@endif
4345
@endif
44-
@endif
45-
</option>
46-
@endforeach
47-
</select>
46+
</option>
47+
@endforeach
48+
</select>
4849

49-
<select name="note_recipients[]" id="note_recipients" class="form-control" multiple="multiple" style="display: none; width: 100%">
50-
@foreach ($c_members as $member)
51-
<option value="{{ $member->id }}" {{ in_array($member->id, $a_notifications['note']) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
52-
@if ($setting->grab('departments_notices_feature'))
53-
@if ($member->ticketit_department == '0')
54-
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}
55-
@elseif ($member->ticketit_department != "")
56-
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . $member->userDepartment->getFullName() }}
50+
<select name="note_recipients[]" id="note_recipients" class="form-control" multiple="multiple" style="display: none; width: 100%">
51+
@foreach ($c_members as $member)
52+
<option value="{{ $member->id }}" {{ in_array($member->id, $a_notifications['note']) ? 'selected="selected"' : '' }}>{{ $member->name . ($member->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $member->email) }}
53+
@if ($setting->grab('departments_notices_feature'))
54+
@if ($member->ticketit_department == '0')
55+
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}
56+
@elseif ($member->ticketit_department != "")
57+
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . $member->userDepartment->getFullName() }}
58+
@endif
5759
@endif
58-
@endif
59-
</option>
60-
@endforeach
61-
</select>
60+
</option>
61+
@endforeach
62+
</select>
63+
</div>
6264
</div>
63-
</div>
65+
@endif
6466
@endif
6567
<div class="form-group row">
6668
<div class="col-lg-12 summernote-text-wrapper">

0 commit comments

Comments
 (0)