Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #21

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions app/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Customer;
use App\Email;

class Conversation extends Model
{
Expand Down Expand Up @@ -410,7 +408,7 @@ public function setCc($emails)
/**
* Set BCC as JSON.
*/
public function setBcc( $emails)
public function setBcc($emails)
{
$emails_array = self::sanitizeEmails($emails);
if ($emails_array) {
Expand All @@ -422,8 +420,8 @@ public function setBcc( $emails)

/**
* Convert list of email to array.
*
* @return
*
* @return
*/
public static function sanitizeEmails($emails)
{
Expand All @@ -441,6 +439,7 @@ public static function sanitizeEmails($emails)
unset($emails_array[$i]);
}
}

return $emails_array;
}
}
15 changes: 8 additions & 7 deletions app/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Email;

class Customer extends Model
{
Expand Down Expand Up @@ -469,6 +468,7 @@ public function getFullName($email_if_empty = false)
return explode('@', $this->emails[0]->email)[0];
}
}

return '';
}

Expand Down Expand Up @@ -615,22 +615,23 @@ public function setWebsites(array $websites_array)

/**
* Create customer or get existing.
*
* @param string $email
* @param array $data [description]
* @return [type] [description]
*
* @param string $email
* @param array $data [description]
*
* @return [type] [description]
*/
public static function create($email, $data = [])
{
$email = Email::sanitizeEmail($email);
if (!$email) {
return null;
return;
}
$email_obj = Email::where('email', $email)->first();
if ($email_obj) {
$customer = $email_obj->customer;
} else {
$customer = new Customer();
$customer = new self();
$email_obj = new Email();
$email_obj->email = $email;
}
Expand Down
10 changes: 6 additions & 4 deletions app/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Email extends Model
const TYPE_OTHER = 3;

public static $types = [
self::TYPE_WORK => 'work',
self::TYPE_HOME => 'home',
self::TYPE_WORK => 'work',
self::TYPE_HOME => 'home',
self::TYPE_OTHER => 'other',
];

Expand All @@ -36,8 +36,9 @@ public function customer()

/**
* Sanitize email address.
*
* @param string $email
*
* @param string $email
*
* @return string
*/
public static function sanitizeEmail($email)
Expand All @@ -47,6 +48,7 @@ public static function sanitizeEmail($email)
}
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
$email = strtolower($email);

return $email;
}
}
22 changes: 11 additions & 11 deletions app/Http/Controllers/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use App\Conversation;
use App\Customer;
use App\Events\ConversationStatusChanged;
use App\Events\ConversationUserChanged;
use App\Folder;
use App\Mailbox;
use App\Thread;
use Validator;
use Illuminate\Http\Request;
use App\Events\ConversationStatusChanged;
use App\Events\ConversationUserChanged;
use Validator;

class ConversationsController extends Controller
{
Expand Down Expand Up @@ -276,7 +276,7 @@ public function ajax(Request $request)
case 'send_reply':

$mailbox = Mailbox::findOrFail($request->mailbox_id);

if (!$response['msg'] && !$user->can('view', $mailbox)) {
$response['msg'] = __('Not enough permissions');
}
Expand All @@ -296,11 +296,11 @@ public function ajax(Request $request)

if (!$response['msg']) {
$validator = Validator::make($request->all(), [
'to' => 'required|string',
'to' => 'required|string',
'subject' => 'required|string|max:998',
'body' => 'required|string',
'cc' => 'nullable|string',
'bcc' => 'nullable|string',
'body' => 'required|string',
'cc' => 'nullable|string',
'bcc' => 'nullable|string',
]);

if ($validator->fails()) {
Expand Down Expand Up @@ -329,11 +329,11 @@ public function ajax(Request $request)

if (!$response['msg']) {
$now = date('Y-m-d H:i:s');

if ($new) {
// New conversation
$customer = Customer::create($to_array[0]);

$conversation = new Conversation();
$conversation->type = Conversation::TYPE_EMAIL;
$conversation->status = $request->status;
Expand All @@ -354,7 +354,7 @@ public function ajax(Request $request)
$customer = $conversation->customer;
}
$conversation->status = $request->status;
if ((int)$request->user_id != -1) {
if ((int) $request->user_id != -1) {
// Check if user has access to the current mailbox
if ($mailbox->userHasAccess($request->user_id)) {
$conversation->user_id = $request->user_id;
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/SecureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers;

use App\ActivityLog;
use App\Conversation;
use Illuminate\Http\Request;

class SecureController extends Controller
Expand Down
3 changes: 2 additions & 1 deletion app/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public function userIdsHavingAccess()

/**
* Check if user has access to the mailbox.
*
* @return bool
*/
public function userHasAccess($user_id)
Expand All @@ -293,7 +294,7 @@ public function userHasAccess($user_id)
if ($user && $user->isAdmin()) {
return true;
} else {
return (bool)$this->users()->where('users.id', $user_id)->count();
return (bool) $this->users()->where('users.id', $user_id)->count();
}
}
}