diff --git a/app/Http/Requests/User/StoreUserRequest.php b/app/Http/Requests/User/StoreUserRequest.php index 09b4e149aa76..ea5571140c3c 100644 --- a/app/Http/Requests/User/StoreUserRequest.php +++ b/app/Http/Requests/User/StoreUserRequest.php @@ -47,10 +47,13 @@ class StoreUserRequest extends Request } else { $rules['email'] = ['email', new AttachableUser()]; } - + if (Ninja::isHosted()) { $rules['id'] = new CanAddUserRule(); - $rules['phone'] = ['sometimes', new HasValidPhoneNumber()]; + + if($this->phone && isset($this->phone)) + $rules['phone'] = ['bail', 'string', 'sometimes', new HasValidPhoneNumber()]; + } return $rules; diff --git a/app/Http/Requests/User/UpdateUserRequest.php b/app/Http/Requests/User/UpdateUserRequest.php index 8c1cae259bf5..c96417ae885c 100644 --- a/app/Http/Requests/User/UpdateUserRequest.php +++ b/app/Http/Requests/User/UpdateUserRequest.php @@ -43,7 +43,7 @@ class UpdateUserRequest extends Request $rules['email'] = ['email', 'sometimes', new UniqueUserRule($this->user, $input['email'])]; } - if(Ninja::isHosted() && $this->phone_has_changed) + if(Ninja::isHosted() && $this->phone_has_changed && $this->phone && isset($this->phone)) $rules['phone'] = ['sometimes', 'bail', 'string', new HasValidPhoneNumber()]; return $rules; @@ -65,7 +65,7 @@ class UpdateUserRequest extends Request $input['last_name'] = strip_tags($input['last_name']); } - if(array_key_exists('phone', $input) && strlen($input['phone']) > 1 && ($this->user->phone != $input['phone'])) + if(array_key_exists('phone', $input) && isset($input['phone']) && strlen($input['phone']) > 1 && ($this->user->phone != $input['phone'])) $this->phone_has_changed = true; if(array_key_exists('oauth_provider_id', $input) && $input['oauth_provider_id'] == '') diff --git a/app/Services/Invoice/UpdateReminder.php b/app/Services/Invoice/UpdateReminder.php index 42e43f47d4e0..44b382a030d0 100644 --- a/app/Services/Invoice/UpdateReminder.php +++ b/app/Services/Invoice/UpdateReminder.php @@ -138,11 +138,14 @@ class UpdateReminder extends AbstractService } if ($this->invoice->last_sent_date && - $this->settings->enable_reminder_endless) { + $this->settings->enable_reminder_endless && + ($this->invoice->reminder1_sent || $this->settings->schedule_reminder1 == "") && + ($this->invoice->reminder2_sent || $this->settings->schedule_reminder2 == "") && + ($this->invoice->reminder3_sent || $this->settings->schedule_reminder3 == "")) { $reminder_date = $this->addTimeInterval($this->invoice->last_sent_date, (int) $this->settings->endless_reminder_frequency_id); if ($reminder_date) { - $reminder_date->addSeconds($offset); + // $reminder_date->addSeconds($offset); if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date))) { $date_collection->push($reminder_date); diff --git a/lang/en/texts.php b/lang/en/texts.php index 607399fe2b0c..14402b9df12a 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4777,7 +4777,7 @@ $LANG = array( 'invoice_task_project' => 'Invoice Task Project', 'invoice_task_project_help' => 'Add the project to the invoice line items', 'bulk_action' => 'Bulk Action', - 'phone_validation_error' => 'This phone number is not valid, please enter in E.164 format', + 'phone_validation_error' => 'This mobile/cell phone number is not valid, please enter in E.164 format', 'transaction' => 'Transaction', ); diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php index 1766d693c324..e424640f4885 100644 --- a/tests/Feature/UserTest.php +++ b/tests/Feature/UserTest.php @@ -56,9 +56,6 @@ class UserTest extends TestCase PasswordProtection::class ); - // if (config('ninja.testvars.travis') !== false) { - // $this->markTestSkipped('Skip test for Travis'); - // } } public function testUserList() @@ -72,6 +69,82 @@ class UserTest extends TestCase $response->assertStatus(200); } + public function testValidationRulesPhoneIsNull() + { + $this->withoutMiddleware(PasswordProtection::class); + + $data = [ + 'first_name' => 'hey', + 'last_name' => 'you', + 'email' => 'bob1@good.ole.boys.com', + 'company_user' => [ + 'is_admin' => false, + 'is_owner' => false, + 'permissions' => 'create_client,create_invoice', + ], + 'phone' => null, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users?include=company_user', $data); + + $response->assertStatus(200); + + } + + public function testValidationRulesPhoneIsBlankString() + { + $this->withoutMiddleware(PasswordProtection::class); + + $data = [ + 'first_name' => 'hey', + 'last_name' => 'you', + 'email' => 'bob1@good.ole.boys.com', + 'company_user' => [ + 'is_admin' => false, + 'is_owner' => false, + 'permissions' => 'create_client,create_invoice', + ], + 'phone' => "", + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users?include=company_user', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $user_id = $this->decodePrimaryKey($arr['data']['id']); + $user = User::find($user_id); + + + $data = [ + 'first_name' => 'hey', + 'last_name' => 'you', + 'email' => 'bob1@good.ole.boys.com', + 'company_user' => [ + 'is_admin' => false, + 'is_owner' => false, + 'permissions' => 'create_client,create_invoice', + ], + 'phone' => "", + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->putJson('/api/v1/users/'.$user->hashed_id.'?include=company_user', $data); + + } + public function testUserStore() { $this->withoutMiddleware(PasswordProtection::class);