Skip to content

Commit

Permalink
Merge branch 'master' into tenancy
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Apr 27, 2024
2 parents e3b969c + d3d462c commit 4ad61ff
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 93 deletions.
72 changes: 46 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,78 @@ GASdotto è il gestionale web-based per gruppi di acquisto.
* non è possibile inoltrare le email usando GMail, a causa delle restrizioni imposte all'autenticazione

# Scarica e Installa
GASdotto può essere installato localmente o in un container Docker tramite Laravel Sail.
GASdotto può essere installato localmente o in un container Docker utilizzando Laravel Sail.

Per installare GASdotto localmente, segui le istruzioni fornite sul sito ufficiale all'indirizzo [www.gasdotto.net/docs/installazione](https://www.gasdotto.net/docs/installazione).

Se preferisci installarlo in un container Docker, segui i seguenti passaggi.

## Installazione container Docker tramite Laravel Sail
## Installazione container Docker utilizzando Laravel Sail

##### Requisiti:
- php (comprese le estensioni necessarie per far funzionare Laravel)

- composer

- Docker e Docker Compose

### Installazione

#### 1. Clona GASdottoNG e naviga nella cartella `<cartella di instaliazione>/GASdottoNG/code/`
`git clone https://github.com/madbob/GASdottoNG.git && cd GASdottoNG/code/`
```shell
git clone https://github.com/madbob/GASdottoNG.git && cd GASdottoNG/code/
```

#### 2. Installa le dipendenze del progetto dal file *composer.lock*.
`composer install`

#### 3. Crea il file *.env* e imposta la chiave *APP_KEY*.
`cp .env.example .env`

`php artisan key:generate`

*Se stai utilizzando Docker, assicurati di aver configurato correttamente le impostazioni nel file .env, seguendo le istruzioni fornite nella sezione 'For Docker' all'interno del medesimo file.*
#### 2. Installa le dipendenze con Composer tramite Docker
```shell
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php82-composer:latest \
composer install --ignore-platform-reqs
```

#### 3. Crea il file .env e configuralo per Docker
```shell
cp .env.example .env
```
**Ricordati di configurare le impostazioni Docker nel file .env, abilitando o sostituendo i parametri commentati con quelli di default nella sezione 'For Docker' all'interno dello stesso file.*

#### 4. Avvia i contenitori Docker ed entra nella Terminale all'interno del container del progetto.
`sail up -d`

`sail shell`
*Il primo avvio potrebbe richiedere più o meno tempo a seconda delle caratteristiche del tuo computer e della connessione internet.*
```shell
sail up -d
```
```shell
sail shell
```

*Se non hai configurato un alias per `sail`, puoi utilizzare:*

`./vendor/bin/sail up -d`
```shell
./vendor/bin/sail up -d
```

`./vendor/bin/sail shell`
```shell
./vendor/bin/sail shell
```

#### 5. All'interno del container, esegui i comandi per le migrazioni e il popolamento del database.
`php artisan migrate`
#### 5. All'interno del container:
Imposta la chiave APP_KEY

`php artisan db:seed`
```shell
php artisan key:generate
```
Migrazioni e popolamento del database

`php artisan db:seed --class=FirstInstallSeed`
```shell
php artisan migrate && php artisan db:seed && php artisan db:seed --class=FirstInstallSeed
```

#### 6. Installa i pacchetti npm necessari ed esegui Laravel Mix.
`npm install`
```shell
npm install && npm run development
```

`npm run development`
Adesso puoi visitare `localhost` e iniziare a testare e sviluppare.

### Uscita

Expand Down
5 changes: 2 additions & 3 deletions code/app/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
Expand All @@ -16,9 +17,7 @@ class Attachment extends Model

public function attached(): MorphTo
{
$uses = class_uses($this->target_type);

if ($this->target_type && $uses && in_array('Illuminate\Database\Eloquent\SoftDeletes', $uses)) {
if ($this->target_type && hasTrait($this->target_type, SoftDeletes::class)) {
// @phpstan-ignore-next-line
return $this->morphTo('target')->withoutGlobalScopes()->withTrashed();
}
Expand Down
2 changes: 1 addition & 1 deletion code/app/Console/Commands/CloseOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CloseOrders extends Command

public function handle()
{
$orders = Order::where('status', 'open')->where('end', '<', date('Y-m-d'))->get();
$orders = Order::withoutGlobalScopes()->where('status', 'open')->where('end', '<', date('Y-m-d'))->get();
$closed = [];

foreach($orders as $order) {
Expand Down
32 changes: 32 additions & 0 deletions code/app/Console/Commands/GenerateAutologin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

use App\User;

class GenerateAutologin extends Command
{
protected $signature = 'generate:autologin {user}';
protected $description = "Controlla la scadenza delle quote di iscrizione alla chiusura dell'anno sociale";

public function handle()
{
$username = $this->argument('user');

$user = User::withoutGlobalScopes()->where('username', $username)->orWhere('id', $username)->first();
if ($user) {
if (blank($user->access_token)) {
$user->access_token = Str::random(10);
$user->save();
}

echo route('autologin', ['token' => $user->access_token]) . "\n";
}
else {
echo "Utente non trovato\n";
}
}
}
6 changes: 3 additions & 3 deletions code/app/Console/Commands/OpenOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;

Expand Down Expand Up @@ -52,7 +53,7 @@ private function getDates()
oggi per il fornitore desiderato, passo oltre
*/
$supplier = $d->target;
if (is_null($supplier) || $supplier->orders()->where('start', $today)->count() != 0) {
if (is_null($supplier) || $supplier->orders()->withoutGlobalScopes()->where('start', $today)->count() != 0) {
continue;
}

Expand All @@ -66,7 +67,6 @@ private function getDates()
}

if ($all_previous) {
Log::debug('Rimosso ordine ricorrente non più operativo: ' . $date->id);
$date->delete();
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public function handle()
futura
*/

$pending = Order::where('status', 'suspended')->where('start', Carbon::today()->format('Y-m-d'))->get();
$pending = Order::withoutGlobalScopes()->where('status', 'suspended')->where('start', Carbon::today()->format('Y-m-d'))->get();
foreach($pending as $p) {
$p->status = 'open';
$p->save();
Expand Down
16 changes: 12 additions & 4 deletions code/app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ class Kernel extends ConsoleKernel

protected function schedule(Schedule $schedule)
{
$schedule->command('check:fees')->daily();
$schedule->command('close:orders')->daily();
$schedule->command('open:orders')->daily();
$schedule->command('remind:orders')->daily();
/*
Le istanze su gasdotto.net vengono gestite con l'apposito script
cron_daily.sh per evitare sovrapposizioni sugli orari di esecuzione.
Se si fa qualche modifica nell'elenco di questi comandi, apportare
le stesse modifiche nel suddetto script
*/
if (env('GASDOTTO_NET', false) == false) {
$schedule->command('check:fees')->daily();
$schedule->command('close:orders')->daily();
$schedule->command('open:orders')->daily();
$schedule->command('remind:orders')->daily();
}
}

protected function commands()
Expand Down
5 changes: 3 additions & 2 deletions code/app/GASModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App;

use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\SoftDeletes;

use Auth;
use URL;
Expand All @@ -24,7 +25,7 @@ public static function tFind($id, $fail = false)
{
$class = get_called_class();

if (in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($class))) {
if (hasTrait($class, SoftDeletes::class)) {
// @phpstan-ignore-next-line
$ret = $class::where('id', $id)->withoutGlobalScopes()->withTrashed()->first();
}
Expand All @@ -47,7 +48,7 @@ public static function tAll()
{
$class = get_called_class();

if (in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($class))) {
if (hasTrait($class, SoftDeletes::class)) {
// @phpstan-ignore-next-line
return $class::withTrashed()->get();
}
Expand Down
5 changes: 3 additions & 2 deletions code/app/Helpers/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function modelsUsingTrait($trait_name)
}

$classname = 'App\\' . substr($result, 0, -4);
if (class_exists($classname) && in_array($trait_name, class_uses($classname))) {
if (class_exists($classname) && hasTrait($classname, $trait_name)) {
$out[$classname] = $classname::commonClassName();
}
}
Expand All @@ -81,7 +81,8 @@ function modelsUsingTrait($trait_name)

function hasTrait($obj, $trait)
{
return in_array($trait, class_uses(get_class($obj)));
$traits = class_uses_recursive($obj);
return in_array($trait, $traits);
}

function accessAttr($obj, $name, $default = '')
Expand Down
1 change: 0 additions & 1 deletion code/app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function autologin(Request $request, $token)
}

$user->access_token = '';
$user->enforce_password_change = true;
$user->save();

Auth::loginUsingId($user->id);
Expand Down
14 changes: 9 additions & 5 deletions code/app/Http/Controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use DB;
use Log;
use Illuminate\Support\Facades\DB;

use FeedIo\FeedIo;
use FeedIo\Feed;
use FeedIo\Feed\Item\Author;
use FeedIo\Factory\Builder\GuzzleClientBuilder;
use Psr\Log\NullLogger;

use App\Http\Controllers\Controller;
use App\Services\OrdersService;
use App\Services\BookingsService;
use App\Printers\Order as Printer;
Expand Down Expand Up @@ -87,7 +86,12 @@ public function rss(Request $request)
$feed->add($item);
}

$feedIo = new FeedIo((new GuzzleClientBuilder())->getClient(), Log::getLogger());
/*
FeedIo genera il suo proprio log di debug che va a mischiarsi con le
informazioni utili per GASdotto: qui disabilito del tutto il suo
proprio logging
*/
$feedIo = new FeedIo((new GuzzleClientBuilder())->getClient(), new NullLogger());
return $feedIo->getPsrResponse($feed, 'rss');
}

Expand Down
5 changes: 3 additions & 2 deletions code/app/Movement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
Expand Down Expand Up @@ -44,7 +45,7 @@ protected static function boot()

public function sender(): MorphTo
{
if ($this->sender_type && in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($this->sender_type))) {
if ($this->sender_type && hasTrait($this->sender_type, SoftDeletes::class)) {
// @phpstan-ignore-next-line
return $this->morphTo()->withoutGlobalScopes()->withTrashed();
}
Expand All @@ -55,7 +56,7 @@ public function sender(): MorphTo

public function target(): MorphTo
{
if ($this->target_type && in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($this->target_type))) {
if ($this->target_type && hasTrait($this->target_type, SoftDeletes::class)) {
// @phpstan-ignore-next-line
return $this->morphTo()->withoutGlobalScopes()->withTrashed();
}
Expand Down
2 changes: 1 addition & 1 deletion code/app/Notifications/Concerns/ManyMailNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function initMailMessage($notifiable, $replyTo = null)
{
$message = new MailMessage();

if (in_array(ContactableTrait::class, class_uses(get_class($notifiable)))) {
if (hasTrait($notifiable, ContactableTrait::class)) {
$notifiable->messageAll($message);
}

Expand Down
3 changes: 2 additions & 1 deletion code/app/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand Down Expand Up @@ -287,7 +288,7 @@ public function applications($all = false, $exclude_trashed = false, $target_cla
continue;
}

if ($exclude_trashed == false && in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses($class))) {
if ($exclude_trashed == false && hasTrait($class, SoftDeletes::class)) {
$objs = $class::withTrashed()->whereIn('id', $ids)->get();
}
else {
Expand Down
1 change: 1 addition & 0 deletions code/app/Scopes/RestrictedGAS.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function apply(Builder $builder, Model $model)
*/
if ($hub->hubRequired() && $hub->enabled()) {
$gas_id = $hub->getGas();

/*
Deve inoltre esserci un GAS attivo, altrimenti i risultati delle
successive query alterate dallo scope sono non definiti.
Expand Down
1 change: 0 additions & 1 deletion code/app/Singletons/ModifierEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ public function apply($modifier, $booking, $aggregate_data)
$modifier_value->delete();
}

Log::debug('Modificatore non applicabile');
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/gasdotto.js": "/js/gasdotto.js?id=ea625caf2e83f8e727cf308404ededa9",
"/js/gasdotto.js": "/js/gasdotto.js?id=8cecf642fcbb1fa75121ccab0939d838",
"/css/gasdotto.css": "/css/gasdotto.css?id=9f62fdf8e27345aa16d289be04885ed2"
}
Loading

0 comments on commit 4ad61ff

Please sign in to comment.