Skip to content

Commit

Permalink
[BF] - Customer Notes spam
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrobin authored and barryo committed Jul 15, 2019
1 parent 9e17870 commit 976f9bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,21 @@
use IXP\Exceptions\GeneralException;

use IXP\Http\Controllers\Controller;

use Illuminate\Http\{
JsonResponse,
Request
};


use Entities\{
Customer as CustomerEntity, CustomerNote as CustomerNoteEntity, CustomerNote
Customer as CustomerEntity,
CustomerNote as CustomerNoteEntity
};



use IXP\Events\Customer\Note\{
Added as CustomerNoteAddedEvent,
Deleted as CustomerNoteDeletedEvent,
Edited as CustomerNoteUpdatedEvent
Edited as CustomerNoteUpdatedEvent
};

/**
Expand All @@ -65,7 +64,8 @@ class CustomerNotesController extends Controller
*
* @throws
*/
public function add( Request $request ): JsonResponse{
public function add( Request $request ): JsonResponse
{

/** @var CustomerEntity $c */
if( !( $c = D2EM::getRepository( CustomerEntity::class )->find( $request->input( 'custid' ) ) ) ) {
Expand Down Expand Up @@ -118,7 +118,8 @@ public function add( Request $request ): JsonResponse{
*
* @throws
*/
public function get( int $id = null ) {
public function get( int $id = null )
{
if( !( $n = D2EM::getRepository( CustomerNoteEntity::class )->find( $id ) ) ) {
abort( 404, 'Note not found.' );
}
Expand Down Expand Up @@ -147,7 +148,8 @@ public function get( int $id = null ) {
*
* @throws
*/
public function delete( int $id = null ) : JsonResponse {
public function delete( int $id = null ) : JsonResponse
{
if( !( $n = D2EM::getRepository( CustomerNoteEntity::class )->find( $id ) ) ) {
abort( 404, 'Note not found.' );
}
Expand All @@ -167,9 +169,10 @@ public function delete( int $id = null ) : JsonResponse {
*
* @param int|null $id
* @return JsonResponse
* @throws \Doctrine\ORM\OptimisticLockException
* @throws
*/
public function ping( int $id = null ): JsonResponse {
public function ping( int $id = null ): JsonResponse
{

if( Auth::getUser()->isSuperUser() ) {
if( !( $c = D2EM::getRepository( CustomerEntity::class )->find( $id ) ) ) {
Expand All @@ -189,30 +192,39 @@ public function ping( int $id = null ): JsonResponse {

/**
* @param int $id Customer ID
*
* @return JsonResponse
*
* @throws
*/
public function notifyToggleCustomer( int $id ): JsonResponse {
public function notifyToggleCustomer( int $id ): JsonResponse
{
return $this->notifyToggle( $id, null );
}

/**
* @param int $id Note ID
*
* @return JsonResponse
*
* @throws
*/
public function notifyToggleNote( int $id ): JsonResponse {
public function notifyToggleNote( int $id ): JsonResponse
{
return $this->notifyToggle( null, $id );
}

/**
*
* @param int|null $custid
* @param int|null $noteId
*
* @return JsonResponse
* @throws \Doctrine\ORM\OptimisticLockException
* @throws GeneralException
*
* @throws
*/
private function notifyToggle( int $custid = null, int $noteId = null ): JsonResponse {
private function notifyToggle( int $custid = null, int $noteId = null ): JsonResponse
{
if( $custid ) {
$id = $custid;
$name = sprintf( "customer-notes.%d.notify", $id );
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Controllers/Customer/CustomerNotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@
* @copyright Copyright (C) 2009 - 2019 Internet Neutral Exchange Association Company Limited By Guarantee
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL V2.0
*/
class CustomerNotesController extends Controller {
class CustomerNotesController extends Controller
{

/**
* @return RedirectResponse
* @throws \Doctrine\ORM\OptimisticLockException
* @throws
*/
public function readAll() : RedirectResponse{
public function readAll() : RedirectResponse
{
$lastReads = Auth::getUser()->getAssocPreference( 'customer-notes' )[0];
foreach( $lastReads as $id => $data ) {
if( is_numeric( $id ) )
Expand All @@ -69,7 +71,8 @@ public function readAll() : RedirectResponse{
*
* @return View
*/
public function unreadNotes() : View {
public function unreadNotes() : View
{
$lastRead = Auth::getUser()->getAssocPreference( 'customer-notes' )[0];

$latestNotes = [];
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/Customer/Note/EmailOnChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function handle( $e )
$to = [ config( 'ixp_fe.customer.notes.only_send_to' ) ];
} else {
// get admin users
$users = D2EM::getRepository( UserEntity::class )->findBy( [ 'privs' => UserEntity::AUTH_SUPERUSER ] );
$users = D2EM::getRepository( UserEntity::class )->findBy( [ 'privs' => UserEntity::AUTH_SUPERUSER, 'disabled' => false ] );
$to = [];

foreach( $users as $user ) {
Expand Down

0 comments on commit 976f9bf

Please sign in to comment.