|
8 | 8 | use PanicHD\PanicHD\Helpers\LaravelVersion; |
9 | 9 | use PanicHD\PanicHD\Models\Category; |
10 | 10 | use PanicHD\PanicHD\Models\Comment; |
| 11 | +use PanicHD\PanicHD\Models\Member; |
11 | 12 | use PanicHD\PanicHD\Models\Setting; |
12 | 13 | use PanicHD\PanicHD\Models\Ticket; |
13 | 14 |
|
@@ -143,26 +144,50 @@ public function newComment(Comment $comment, $request) |
143 | 144 | 'notification_type' => $comment->type |
144 | 145 | ]; |
145 | 146 |
|
146 | | - // Notificate assigned agent |
147 | | - $a_to = $this->defaultRecipients($ticket, $notification_owner, $subject, $template); |
| 147 | + $member = Member::find(auth()->user()->id); |
| 148 | + $category_level = $member->levelInCategory($ticket->category_id); |
| 149 | + $permission_level = ($member->currentLevel() > 1 and $category_level > 1) ? $category_level : 1; |
| 150 | + |
| 151 | + if ($permission_level < 2){ |
| 152 | + // Notificate assigned agent |
| 153 | + $a_to = $this->defaultRecipients($ticket, $notification_owner, $subject, $template); |
| 154 | + |
| 155 | + }elseif($comment->type == 'note' or !$ticket->hidden){ |
| 156 | + // Selected recipients |
| 157 | + $c_recipients = $comment->type == 'note' ? $request->note_recipients : $request->reply_recipients; |
| 158 | + |
| 159 | + foreach($c_recipients as $member_id){ |
| 160 | + $recipient = Member::find($member_id); |
| 161 | + if (count($recipient) == 1){ |
| 162 | + // Register the notified email |
| 163 | + \DB::table('panichd_comment_email')->insert([ |
| 164 | + ['comment_id' => $comment->id, |
| 165 | + 'name' => $recipient->name, |
| 166 | + 'email' => $recipient->email, |
| 167 | + 'member_id' => $member_id |
| 168 | + ] |
| 169 | + ]); |
| 170 | + |
| 171 | + // Add email to actual mail recipients |
| 172 | + $a_to[] = [ |
| 173 | + 'recipient' => $recipient, |
| 174 | + 'subject' => $subject, |
| 175 | + 'template' => $template |
| 176 | + ]; |
| 177 | + } |
| 178 | + |
| 179 | + } |
148 | 180 |
|
149 | | - // Notificate ticket owner |
150 | | - if ($comment->type == 'reply' and !$ticket->hidden and !in_array($ticket->owner->email, [$notification_owner->email, $ticket->agent->email])){ |
151 | 181 | if ($request->has('add_in_user_notification_text') or (isset($comment->add_in_user_notification_text))){ |
152 | 182 | // Element in request comes from Comment modal |
153 | 183 | // $comment property comes from an embedded comment when editing or creating a ticket |
154 | 184 | $data['add_in_user_notification_text'] = true; |
155 | 185 | } |
156 | 186 |
|
157 | | - $a_to[] = [ |
158 | | - 'recipient' => $ticket->owner, |
159 | | - 'subject' => $subject, |
160 | | - 'template' => $template |
161 | | - ]; |
162 | | - } |
| 187 | + } |
163 | 188 |
|
164 | 189 | // Send notifications |
165 | | - $this->sendNotification($a_to, $data); |
| 190 | + if(isset($a_to)) $this->sendNotification($a_to, $data); |
166 | 191 | } |
167 | 192 | } |
168 | 193 |
|
|
0 commit comments