From: Louis Jeckel Date: Fri, 18 Sep 2020 09:45:28 +0000 (+0200) Subject: downloadable url X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=bf5ec435d1a9cb49737759e6f7c0a3951533c083;p=psq.git downloadable url --- diff --git a/app/Nova/User.php b/app/Nova/User.php index b6d0bf6..c89f575 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -80,17 +80,21 @@ class User extends Resource Text::make('Position'), Text::make('Téléphone', 'phone'), new Panel('Adresse', $this->addressFields()), + new Panel('Réglages', [ + Select::make('Type')->options([ + AppUser::TYPE_SUBSCRIBER => 'Abonné', + AppUser::TYPE_PROSPECT => 'Prospect', + AppUser::TYPE_SPECIAL => 'Autre', + AppUser::TYPE_DISCOVER => 'Découverte', + ])->hideFromIndex()->required()->withMeta(['value' => $this->type ?? static::$type ?? AppUser::TYPE_SUBSCRIBER]), + Boolean::make('Compte activé', 'reg_complete')->hideWhenCreating()->hideWhenUpdating()->readonly(), + Boolean::make('Reçoit fichier PDF', 'receives_pdf')->hideFromIndex(), + + ]), new Panel('Affiliation', [ BelongsTo::make('Organisation', 'organization', Organization::class)->searchable()->nullable(), ]), - ], $this->extraFields(), [ - Boolean::make('Compte activé', 'reg_complete')->hideWhenCreating(), - Select::make('Type')->options([ - AppUser::TYPE_SUBSCRIBER => 'Abonné', - AppUser::TYPE_PROSPECT => 'Prospect', - AppUser::TYPE_SPECIAL => 'Autre', - AppUser::TYPE_DISCOVER => 'Découverte', - ])->hideFromIndex()->required()->withMeta(['value' => $this->type ?? static::$type ?? AppUser::TYPE_SUBSCRIBER]), + ], $this->extraFields(), [ Badge::make('Etat', fn() => AppUser::STATUSES[$this->status]['label']) ->map(Arr::pluck(AppUser::STATUSES, 'badge', 'label')), ]); diff --git a/app/PdfFile.php b/app/PdfFile.php index 3448765..22135c9 100644 --- a/app/PdfFile.php +++ b/app/PdfFile.php @@ -368,12 +368,28 @@ class PdfFile extends TwillModel implements Sortable ); } + /** + * @return string + * Returns download link. + */ + public function getDownloadUrl(): string + { + return \URL::temporarySignedRoute( + 'pdf.download', + now()->addDays(3), + ['file' => $this->slug] + ); + } + /** * @param User $user * @return string */ public function getMailableUrl(User $user): string { + if($user->receives_pdf) { + return $this->getDownloadUrl(); + } return ($user->type === User::TYPE_DISCOVER && !$user->self_registered) ? $this->getSignedUrl($user) : $this->getUrlWithToken($user); diff --git a/app/User.php b/app/User.php index c9f0d26..21df16f 100644 --- a/app/User.php +++ b/app/User.php @@ -36,6 +36,7 @@ use Laravel\Scout\Searchable; * @property int $type * @property bool $unsubscribed * @property bool $reg_complete + * @property bool $receives_pdf * * @property string $status */ @@ -90,6 +91,7 @@ class User extends Authenticatable implements MustVerifyEmail 'self_registered' => 'bool', 'early_access' => 'bool', 'unsubscribed' => 'bool', + 'receives_pdf' => 'bool', ]; diff --git a/database/migrations/2020_09_18_093346_add_receives_pdf_col_to_users.php b/database/migrations/2020_09_18_093346_add_receives_pdf_col_to_users.php new file mode 100644 index 0000000..b7b80c1 --- /dev/null +++ b/database/migrations/2020_09_18_093346_add_receives_pdf_col_to_users.php @@ -0,0 +1,32 @@ +boolean('receives_pdf')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('receives_pdf'); + }); + } +}