Skip to content

Commit

Permalink
several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed May 14, 2021
1 parent 7ac5368 commit b8057a7
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 75 deletions.
8 changes: 6 additions & 2 deletions app/Http/Controllers/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public function update(Request $request)
}

if ($real_key == 'default.locale') {
if (!in_array($value, config('language.allowed'))) {
continue;
}

user()->setAttribute('locale', $value)->save();
}

Expand Down Expand Up @@ -156,10 +160,10 @@ protected function oneCompany($real_key, $value)
Installer::updateEnv(['MAIL_FROM_NAME' => '"' . $value . '"']);
break;
case 'company.email':
Installer::updateEnv(['MAIL_FROM_ADDRESS' => $value]);
Installer::updateEnv(['MAIL_FROM_ADDRESS' => '"' . $value . '"']);
break;
case 'default.locale':
Installer::updateEnv(['APP_LOCALE' => $value]);
Installer::updateEnv(['APP_LOCALE' => '"' . $value . '"']);
break;
case 'schedule.time':
Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Middleware/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function handle($request, Closure $next)

$money_format = $request->get($parameter);

if (!preg_match("/^(?=.*?[0-9])[0-9.,]+$/", $money_format)) {
continue;
}

if ($parameter == 'sale_price' || $parameter == 'purchase_price') {
$money_format = Str::replaceFirst(',', '.', $money_format);
}
Expand All @@ -62,6 +66,10 @@ public function handle($request, Closure $next)
continue;
}

if (!preg_match("/^(?=.*?[0-9])[0-9.,]+$/", $item['price'])) {
continue;
}

$amount = $item['price'];

if (strpos($item['price'], config('money.' . $currency_code . '.symbol')) !== false) {
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/Auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function rules()
{
$picture = 'nullable';

if ($this->request->get('picture', null)) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
if ($this->files->get('picture')) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}

$email = 'required|email';
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Banking/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function rules()
{
$attachment = 'nullable';

if ($this->request->get('attachment', null)) {
if ($this->files->get('attachment')) {
$attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/Common/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function rules()
{
$logo = 'nullable';

if ($this->request->get('logo', null)) {
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
if ($this->files->get('logo')) {
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}

return [
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Requests/Common/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function rules()
{
$email = '';
$required = '';
$logo = 'nullable';

$type = $this->request->get('type', 'customer');
$company_id = $this->request->get('company_id');
Expand Down Expand Up @@ -54,6 +55,10 @@ public function rules()
}
}

if ($this->files->get('logo')) {
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}

return [
'type' => 'required|string',
'name' => 'required|string',
Expand All @@ -62,6 +67,7 @@ public function rules()
'currency_code' => 'required|string|currency',
'password' => $required . 'confirmed',
'enabled' => 'integer|boolean',
'logo' => $logo,
];
}
}
8 changes: 4 additions & 4 deletions app/Http/Requests/Common/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function rules()
{
$picture = 'nullable';

if ($this->request->get('picture', null)) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
if ($this->files->get('picture')) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}

return [
'name' => 'required|string',
'sale_price' => 'required',
'purchase_price' => 'required',
'sale_price' => 'required|regex:/^(?=.*?[0-9])[0-9.,]+$/',
'purchase_price' => 'required|regex:/^(?=.*?[0-9])[0-9.,]+$/',
'tax_ids' => 'nullable|array',
'category_id' => 'nullable|integer',
'enabled' => 'integer|boolean',
Expand Down
13 changes: 6 additions & 7 deletions app/Http/Requests/Document/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function authorize()
*/
public function rules()
{
$company_logo = 'nullable';
$attachment = 'nullable';

$type = $this->request->get('type', Model::INVOICE_TYPE);

$type = config('type.' . $type . '.route.parameter');
Expand All @@ -39,15 +42,11 @@ public function rules()
$id = null;
}

$company_logo = 'nullable';

if ($this->request->get('company_logo', null)) {
$company_logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
if ($this->files->get('company_logo')) {
$company_logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}

$attachment = 'nullable';

if ($this->request->get('attachment', null)) {
if ($this->files->get('attachment')) {
$attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Setting/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function rules()
if ($this->request->get('_prefix', null) == 'company') {
$name = 'required|string';
$email = 'required|email';
$logo = 'mimes:' . config('filesystems.mimes', 'pdf,jpeg,jpg,png');
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}

return [
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Wizard/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function authorize()
public function rules()
{
$rules = [
'company_logo' => 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024,
'company_logo' => 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000',
];

if (!setting('apps.api_key', false) && !empty($this->request->get('api_key'))) {
Expand Down
10 changes: 9 additions & 1 deletion app/Jobs/Auth/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public function handle()
}

if ($this->request->has('companies')) {
$this->user->companies()->attach($this->request->get('companies'));
$user = user();

$companies = $user->withoutEvents(function () use ($user) {
return $user->companies()->whereIn('id', $this->request->get('companies'))->pluck('id');
});

if ($companies->isNotEmpty()) {
$this->user->companies()->attach($companies->toArray());
}
}

if (empty($this->user->companies)) {
Expand Down
10 changes: 9 additions & 1 deletion app/Jobs/Auth/UpdateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ public function handle()
}

if ($this->request->has('companies')) {
$this->user->companies()->sync($this->request->get('companies'));
$user = user();

$companies = $user->withoutEvents(function () use ($user) {
return $user->companies()->whereIn('id', $this->request->get('companies'))->pluck('id');
});

if ($companies->isNotEmpty()) {
$this->user->companies()->sync($companies->toArray());
}
}

if ($this->user->contact) {
Expand Down
14 changes: 13 additions & 1 deletion app/Listeners/Update/V21/Version2112.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Common\Media;
use App\Utilities\Date;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;

Expand All @@ -29,11 +30,22 @@ public function handle(Event $event)
return;
}

Artisan::call('migrate', ['--force' => true]);
$this->updateDatabase();

$this->updateCompanies();
}

public function updateDatabase()
{
DB::table('migrations')->insert([
'id' => DB::table('migrations')->max('id') + 1,
'migration' => '2016_06_27_000001_create_mediable_test_tables',
'batch' => DB::table('migrations')->max('batch') + 1,
]);

Artisan::call('migrate', ['--force' => true]);
}

public function updateCompanies()
{
$companies = Company::withTrashed()->cursor();
Expand Down
4 changes: 4 additions & 0 deletions app/Providers/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function boot()
$status = true;
}

if (!preg_match("/^(?=.*?[0-9])[0-9.,]+$/", $value)) {
$status = false;
}

$amount = $value;

return $status;
Expand Down
32 changes: 4 additions & 28 deletions app/Traits/Uploads.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,44 +112,20 @@ public function getMediaPathOnStorage($media)
return Storage::path($path);
}

public function streamMedia($media, $path = '', $action = '')
{
if ($this->isLocalStorage()) {
if (empty($path)) {
$path = $this->getMediaPathOnStorage($media);
}

if (empty($action)) {
$action = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
}

return $this->streamLocalMedia($path, $action);
}

return $this->streamRemoteMedia($media);
}

public function streamLocalMedia($path, $action)
{
$function = ($action == 'get') ? 'file' : $action;

return response()->$function($path);
}

public function streamRemoteMedia($media)
public function streamMedia($media, $path = '')
{
return response()->streamDownload(
function() use ($media) {
$stream = $media->stream();

while($bytes = $stream->read(1024)) {
while ($bytes = $stream->read(1024)) {
echo $bytes;
}
},
$media->basename,
[
'Content-Type' => $media->mime_type,
'Content-Length' => $media->size,
'Content-Type' => $media->mime_type,
'Content-Length' => $media->size,
],
);
}
Expand Down

0 comments on commit b8057a7

Please sign in to comment.