fix: remove relation between media and users + update 'historiques' lines to make user nullable
This commit is contained in:
parent
99209888a9
commit
7456b31bf3
11 changed files with 83 additions and 57 deletions
|
|
@ -104,7 +104,6 @@ class DossierController extends Controller
|
|||
fn (Builder $q) =>
|
||||
$q->where('statut', MediaStatut::public_etendu)
|
||||
->orWhere('statut', MediaStatut::public)
|
||||
->orWhere('created_by', $user->id)
|
||||
);
|
||||
}
|
||||
Arr::set($folders, 'racineCount', $racineCountQuery->count());
|
||||
|
|
|
|||
|
|
@ -488,7 +488,6 @@ class MediaController extends Controller
|
|||
}
|
||||
|
||||
$clonedMedia->isDefault = true;
|
||||
$clonedMedia->owner()->associate($user);
|
||||
|
||||
$clonedMedia->typeMedia()->associate(TypeMedia::getMediaType($clonedMedia->extension));
|
||||
|
||||
|
|
@ -892,8 +891,7 @@ class MediaController extends Controller
|
|||
// * OR
|
||||
$esShould = array_merge($esShould, [
|
||||
\array_undot(['match.statut' => MediaStatut::public_etendu]),
|
||||
\array_undot(['match.statut' => MediaStatut::public]),
|
||||
\array_undot(['match.created_by' => $user->id])
|
||||
\array_undot(['match.statut' => MediaStatut::public])
|
||||
]);
|
||||
return;
|
||||
} //end if
|
||||
|
|
@ -926,10 +924,6 @@ class MediaController extends Controller
|
|||
]],
|
||||
'bool.adjust_pure_negative' => true,
|
||||
'bool.boost' => 1.0
|
||||
]),
|
||||
\array_undot([
|
||||
'term.created_by.value' => $user->id,
|
||||
'term.created_by.boost' => 1.0
|
||||
])
|
||||
],
|
||||
'bool.adjust_pure_negative' => true,
|
||||
|
|
|
|||
|
|
@ -293,7 +293,6 @@ class UploadController extends Controller
|
|||
// * Si on upload un média pour remplacer un fichier par un autre
|
||||
if ($isNewMedia) {
|
||||
$media->libelle = Str::limit($sanitizedFileBasename, 50, '');
|
||||
$media->owner()->associate($user);
|
||||
$media->dossier()->associate($dossier);
|
||||
$media->sujet()->associate($sujet);
|
||||
// * Par défaut FR
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use App\Events\MediaLinkWithArcadia;
|
|||
use App\Events\MediaMoved;
|
||||
use App\Events\MediaUpdated;
|
||||
use App\Models\Historique;
|
||||
use \Illuminate\Support\Str;
|
||||
|
||||
class HistorizeMediaEvent
|
||||
{
|
||||
|
|
@ -54,10 +55,18 @@ class HistorizeMediaEvent
|
|||
$description = trans('Ajout de la liaison Arcadia');
|
||||
}
|
||||
|
||||
$historique->user()->associate($event->getUser());
|
||||
$eventUser = $event->getUser();
|
||||
|
||||
$historique->user()->associate($eventUser);
|
||||
$historique->media()->associate($event->getMedia());
|
||||
$historique->type = $type;
|
||||
$historique->description = $description;
|
||||
$historique->description = sprintf(
|
||||
'%s - %s %s (%s)',
|
||||
$description,
|
||||
$eventUser->firstname,
|
||||
Str::upper($eventUser->lastname),
|
||||
$eventUser->matricule
|
||||
);
|
||||
|
||||
if (!$historique->save()) {
|
||||
throw new \RuntimeException('Failed to save historic to Database');
|
||||
|
|
|
|||
|
|
@ -91,8 +91,7 @@ class Dossier extends Model
|
|||
|
||||
// * Tous les non brouillons ou liés à une marque du user.
|
||||
return $this->mediaList()
|
||||
->where(fn (Builder $q) => $q->where('statut', '!=', MediaStatut::brouillon)
|
||||
->orWhere('created_by', $user->id))
|
||||
->where(fn (Builder $q) => $q->where('statut', '!=', MediaStatut::brouillon))
|
||||
->count();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ use App\Events\MediaDestroyed;
|
|||
use App\Events\MediaUpdated;
|
||||
use App\Lib\ToolboxHelper;
|
||||
use App\Traits\Models\BindedToElasticSearch;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Prunable;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
|
@ -52,7 +51,6 @@ class Media extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $with = [
|
||||
'owner',
|
||||
'tags',
|
||||
'etiquette',
|
||||
'articles',
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ use Illuminate\Notifications\Notifiable;
|
|||
* Dossiers BelongsToMany relationship.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Sujet> $sujets
|
||||
* Sujets BelongsToMany relationship.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Media> $mediaList
|
||||
* Medias HasMany relationship.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Historique> $historiques
|
||||
* Historiques HasMany relationship.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Recherche> $recherches
|
||||
|
|
@ -111,17 +109,6 @@ class User extends Authenticatable
|
|||
return $this->belongsToMany(Sujet::class, 'sujet_user', 'user_id', 'sujet_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* HasMany media relation
|
||||
* Get the media for the user.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function mediaList()
|
||||
{
|
||||
return $this->hasMany(Media::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* HasMany historiques relation
|
||||
* Get the historiques for the user.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Remove 'created_by' column in media.
|
||||
Schema::table('media', function (Blueprint $table) {
|
||||
$table->dropForeign('FK_medias_users');
|
||||
$table->dropColumn('created_by');
|
||||
});
|
||||
|
||||
Schema::table('historiques', function(Blueprint $table) {
|
||||
$table->dropForeign('FK_historiques_users');
|
||||
$table->unsignedBigInteger('user_id')->nullable()->change();
|
||||
$table->foreign('user_id')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->nullOnDelete();
|
||||
});
|
||||
// Update 'historiques' descriptions with user datas.
|
||||
DB::transaction(function () {
|
||||
DB::statement(
|
||||
"UPDATE historiques h
|
||||
JOIN users u ON u.id = h.user_id
|
||||
SET h.description = CONCAT(
|
||||
IFNULL(h.description, ''),
|
||||
' - ',
|
||||
u.firstname, ' ',
|
||||
UPPER(u.lastname),
|
||||
' (', u.matricule, ')'
|
||||
);"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('media', function (Blueprint $table) {
|
||||
$table->foreignId('created_by')->nullable()->after('commentaire');
|
||||
$table->foreign('created_by', 'FK_medias_users')->on('users')->references('id');
|
||||
});
|
||||
|
||||
Schema::table('media', function (Blueprint $table) {
|
||||
$table->dropForeign('historiques_user_id_foreign');
|
||||
$table->unsignedBigInteger('user_id')->nullable()->change();
|
||||
$table->foreign('user_id', 'FK_historiques_users')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -48,20 +48,10 @@ $(document).ready(function() {
|
|||
// ---- Edition des utilisateurs : suppression d'utilisateur
|
||||
$(".btn_delete_user").on('click', function(event) {
|
||||
event.preventDefault();
|
||||
let form = $('.deleteform'), created_by = $('select[name="created_by"]').val(),
|
||||
created_by_text = $('select[name="created_by"] option:selected').text()
|
||||
if (!created_by.length) {
|
||||
$.fancyConfirm({
|
||||
title: 'Impossible de lancer cet action.',
|
||||
message: 'Vous devez choisir autre un utilisateur à qui assigner les fiches.',
|
||||
okButton: 'Compris',
|
||||
noButton: 'Retour'
|
||||
})
|
||||
return;
|
||||
}
|
||||
let form = $('.deleteform');
|
||||
$.fancyConfirm({
|
||||
title: 'Suppression d\'un utilisateur',
|
||||
message: 'Les média seront assignés à ' + created_by_text + '. Êtes-vous sûr de vouloir supprimer cet utilisateur ?',
|
||||
message: 'Êtes-vous sûr de vouloir supprimer cet utilisateur ?',
|
||||
okButton: 'Supprimer',
|
||||
noButton: 'Annuler',
|
||||
callback: function (value) {
|
||||
|
|
|
|||
|
|
@ -41,17 +41,6 @@
|
|||
>
|
||||
<label>Date de création : {{ this.oMedia.created_at }}</label>
|
||||
<label>Date de modification : {{ this.oMedia.updated_at }}</label>
|
||||
<label v-if="this.oMedia.owner !== null"
|
||||
>Créé par :
|
||||
{{
|
||||
this.oMedia.owner.firstname +
|
||||
" " +
|
||||
this.oMedia.owner.lastname +
|
||||
" (" +
|
||||
this.oMedia.owner.matricule +
|
||||
")"
|
||||
}}</label
|
||||
>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Intitulé <span>*</span></label>
|
||||
|
|
|
|||
|
|
@ -94,12 +94,6 @@
|
|||
<a href="{{ route('user.index') }}" class="btn btn-black ml-10">Annuler</a>
|
||||
{!! Form::model($user, ['route' => ['user.destroy', $user], 'enctype' => 'multipart/form-data', 'class' => 'deleteform floatr']) !!}
|
||||
@method('DELETE')
|
||||
<select class="custom-select" name="created_by" required>
|
||||
<option value="" selected>{{ __('Sélectionnez un utilisateur à qui assigner les fiches') }}</option>
|
||||
@foreach($users as $user)
|
||||
<option value="{{ $user->id }}">{{ $user->email }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<button class="btn btn-black btn_delete_user">{{ __('Supprimer cet utilisateur') }}</button>
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue