user softdelete

This commit is contained in:
StudioTem committed 2023-07-13 10:38:16 +02:00
1 parent d3f6d8a643
commit 4d4cb643ec
10 files changed
+53 -18

No files matched your search

@@ -28,7 +28,10 @@ class SendDeletedSubTaskNotification
public function handle(SubTaskDeleted $event)
{
$receiversArray[] = $event->subtask->user->email;
$receiversArray[] = \App\Models\User::find($event->subtask->created_by)->email;
$creator = \App\Models\User::find($event->subtask->created_by);
if ($creator)
$receiversArray[] = $creator->email;
Mail::to( $receiversArray )->send( new \App\Mail\SubTaskDeleted( $event->subtask ) );
}
@@ -59,10 +59,11 @@ class SendEditedSubTaskNotification implements ShouldQueue
// ukoncenie sub tasku - Pokiaľ je sub task ukončený s vyšším počtom vykázaných hodín ako bol pôvodne zadaný, posiela sa e-mailová notifikácia o tejto skutočnosti zadávateľovi master tasku (soft warning).
if ($key == 'is_finished' && $diff == 1 && $event->subtask->tracked_time > $event->subtask->estimated_time) {
$creatorEmail = User::find($event->subtask->created_by)->email;
Mail::to( $creatorEmail )->send( new \App\Mail\SubTaskFinishedWithHigherTrackedTime( $event->subtask ) );
$creator = User::find($event->subtask->created_by);
if ($creator) {
Mail::to( $creator->email )->send( new \App\Mail\SubTaskFinishedWithHigherTrackedTime( $event->subtask ) );
}
}
$difference[$key] = $diff;
@@ -28,8 +28,11 @@ class SendFinishedTimeBlockNotification implements ShouldQueue
*/
public function handle(TimeBlockFinished $event)
{
$receiver = User::find($event->timeblock->subtask->created_by)->email;
$receiver = User::find($event->timeblock->subtask->created_by);
Mail::to( $receiver )->send( new \App\Mail\TimeBlockFinished( $event->timeblock->subtask ) );
// pripad ked bol user soft deletnuty
if (!$receiver ) return;
Mail::to( $receiver->email )->send( new \App\Mail\TimeBlockFinished( $event->timeblock->subtask ) );
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ class Blocker extends Model
public function user()
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
public function getColorAttribute()
+2 -4
View File
@@ -35,18 +35,16 @@ class MasterTask extends Model
// vracia userov, ktori su priradeni k subtasku ale nepatria do teamu
public function getUsersOutsideTeamAttribute()
{
$users = $this->subtasks->pluck('user')->unique();
//remove null values - priprady, kedy bol user zmazany
$users = $users->filter();
// ak nie je uvedeny ziaden team, tak sa vratia vsetci useri
if (!$this->team){
return $users;
}
return $users->filter(function ($user) {
return !in_array($this->team->id, isset($user->teams) ? $user->teams->pluck('id')->unique()->toArray() : []);
return !in_array($this->team->id, $user->teams->pluck('id')->unique()->toArray());
});
}
+1 -1
View File
@@ -20,7 +20,7 @@ class SubTask extends Model
public function user()
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
public function timeblocks()
+1 -1
View File
@@ -15,6 +15,6 @@ class Team extends Model
public function users()
{
return $this->belongsToMany(User::class);
return $this->belongsToMany(User::class)->withTrashed();
}
}
+1 -1
View File
@@ -22,6 +22,6 @@ class Timesheet extends Model
public function user()
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}
+2 -4
View File
@@ -2,18 +2,16 @@
namespace App\Models;
use App\Mail\PasswordReset;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Http\Request;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Mail;
use Laravel\Sanctum\HasApiTokens;
use Laravel\Sanctum\PersonalAccessToken;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
use HasApiTokens, HasFactory, Notifiable, SoftDeletes;
/**
* The attributes that are mass assignable.
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
};