Change projects table to sites table
This commit is contained in:
parent
4e3a1635ee
commit
ce461a403b
32 changed files with 160 additions and 121 deletions
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Models\Project;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Project;
|
||||
|
||||
class ProjectController extends CrudController
|
||||
{
|
||||
|
||||
/** @var Project */
|
||||
protected static $modelClass = Project::class;
|
||||
}
|
||||
12
app/Http/Controllers/SiteController.php
Normal file
12
app/Http/Controllers/SiteController.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Site;
|
||||
|
||||
class SiteController extends CrudController
|
||||
{
|
||||
|
||||
/** @var Site */
|
||||
protected static $modelClass = Site::class;
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ use App\Http\Requests\StoreTicket;
|
|||
use App\Http\Requests\UpdateTicket;
|
||||
use App\Mail\NewTicket;
|
||||
use App\Models\Message;
|
||||
use App\Models\Project;
|
||||
use App\Models\Site;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
|
|
@ -35,9 +35,9 @@ class TicketController extends Controller
|
|||
{
|
||||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
$tickets = Ticket::with('project')->has('project');
|
||||
$tickets = Ticket::with('site')->has('site');
|
||||
if (!$user->isAdmin()) {
|
||||
$tickets = $tickets->whereHas('project', function ($q) use ($user) {
|
||||
$tickets = $tickets->whereHas('site', function ($q) use ($user) {
|
||||
$q->whereHas('users', function ($q) use ($user) {
|
||||
$q->whereId($user->id);
|
||||
});
|
||||
|
|
@ -50,9 +50,9 @@ class TicketController extends Controller
|
|||
$tickets = $this->filterTickets($tickets, $request);
|
||||
$tickets = $tickets->paginate();
|
||||
|
||||
$projects = Project::select('id', 'name')->orderBy('name')->get();
|
||||
$sites = Site::select('id', 'name')->orderBy('name')->get();
|
||||
|
||||
return view('ticket.index', compact('tickets', 'projects'));
|
||||
return view('ticket.index', compact('tickets', 'sites'));
|
||||
}
|
||||
|
||||
private function filterTickets(Builder $tickets, Request $request): Builder
|
||||
|
|
@ -77,14 +77,14 @@ class TicketController extends Controller
|
|||
Session::save();
|
||||
|
||||
if (Session::has('tickets.pr')) {
|
||||
$tickets = $tickets->where('project_id', Session::get('tickets.pr'));
|
||||
$tickets = $tickets->where('site_id', Session::get('tickets.pr'));
|
||||
}
|
||||
|
||||
if (
|
||||
Session::has('tickets.sort_col') and
|
||||
Session::has('tickets.sort_way') and
|
||||
in_array(Session::get('tickets.sort_col'), [
|
||||
'id', 'project_id', 'created_at', 'created_by',
|
||||
'id', 'site_id', 'created_at', 'created_by',
|
||||
'type', 'status'
|
||||
])
|
||||
) {
|
||||
|
|
@ -139,29 +139,29 @@ class TicketController extends Controller
|
|||
{
|
||||
$user = Auth::user();
|
||||
if ($user->role->value === 1) {
|
||||
$projects = Project::orderBy('name')->get();
|
||||
$sites = Site::orderBy('name')->get();
|
||||
} else {
|
||||
$projects = $user->projects;
|
||||
$sites = $user->sites;
|
||||
}
|
||||
|
||||
if (!count($projects)) {
|
||||
return redirect()->route('project.create')
|
||||
if (!count($sites)) {
|
||||
return redirect()->route('site.create')
|
||||
->with('warning', 'Vous devez tout d\'abord créer un projet pour y ajouter un ticket');
|
||||
}
|
||||
return view('ticket.create', compact('projects'));
|
||||
return view('ticket.create', compact('sites'));
|
||||
}
|
||||
|
||||
public function store(StoreTicket $request)
|
||||
{
|
||||
$project = Project::findOrFail($request->project_id);
|
||||
$site = Site::findOrFail($request->site_id);
|
||||
|
||||
$ticket = new Ticket($request->validated());
|
||||
|
||||
if ($request->file_ticket) {
|
||||
$ticket->file = Ticket::saveFile($project, $ticket, $ticket->type, $request->file_ticket);
|
||||
$ticket->file = Ticket::saveFile($site, $ticket, $ticket->type, $request->file_ticket);
|
||||
}
|
||||
if ($request->file_ticket2) {
|
||||
$ticket->file2 = Ticket::saveFile($project, $ticket, $ticket->type, $request->file_ticket2);
|
||||
$ticket->file2 = Ticket::saveFile($site, $ticket, $ticket->type, $request->file_ticket2);
|
||||
}
|
||||
|
||||
if ($request->type === TicketType::evolution()) {
|
||||
|
|
@ -188,29 +188,29 @@ class TicketController extends Controller
|
|||
{
|
||||
$user = Auth::user();
|
||||
if ($user->role->value === 1) {
|
||||
$projects = Project::orderBy('name')->get();
|
||||
$sites = Site::orderBy('name')->get();
|
||||
} else {
|
||||
$projects = $user->projects;
|
||||
$sites = $user->sites;
|
||||
}
|
||||
return view('ticket.edit', compact('ticket', 'projects'));
|
||||
return view('ticket.edit', compact('ticket', 'sites'));
|
||||
}
|
||||
|
||||
public function update(UpdateTicket $request, Ticket $ticket)
|
||||
{
|
||||
$project = Project::findOrFail($request->project_id);
|
||||
$site = Site::findOrFail($request->site_id);
|
||||
$ticket->fill($request->validated());
|
||||
|
||||
if ($request->file_ticket) {
|
||||
if (File::exists($ticket->file)) {
|
||||
File::delete($ticket->file);
|
||||
}
|
||||
$ticket->file = Ticket::saveFile($project, $ticket, $ticket->type, $request->file_ticket);
|
||||
$ticket->file = Ticket::saveFile($site, $ticket, $ticket->type, $request->file_ticket);
|
||||
}
|
||||
if ($request->file_ticket2) {
|
||||
if (File::exists($ticket->file2)) {
|
||||
File::delete($ticket->file2);
|
||||
}
|
||||
$ticket->file2 = Ticket::saveFile($project, $ticket, $ticket->type, $request->file_ticket2);
|
||||
$ticket->file2 = Ticket::saveFile($site, $ticket, $ticket->type, $request->file_ticket2);
|
||||
}
|
||||
|
||||
$ticket->save();
|
||||
|
|
@ -247,11 +247,11 @@ class TicketController extends Controller
|
|||
}
|
||||
|
||||
if ($request->file_message) {
|
||||
$projectSlug = Str::slug($ticket->project->name);
|
||||
$siteSlug = Str::slug($ticket->site->name);
|
||||
$fileMessage = $request->file_message;
|
||||
$fileName = $projectSlug . '-ticket-' . $ticket->id . '-message-' . $message->id . '.' . $fileMessage->extension();
|
||||
$fileMessage->move(public_path('fichiers/' . $projectSlug . '/' . $ticket->id . '/'), $fileName);
|
||||
$filePath = 'fichiers/' . $projectSlug . '/' . $ticket->id . '/' . $fileName;
|
||||
$fileName = $siteSlug . '-ticket-' . $ticket->id . '-message-' . $message->id . '.' . $fileMessage->extension();
|
||||
$fileMessage->move(public_path('fichiers/' . $siteSlug . '/' . $ticket->id . '/'), $fileName);
|
||||
$filePath = 'fichiers/' . $siteSlug . '/' . $ticket->id . '/' . $fileName;
|
||||
$message->file = $filePath;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class CreateMessage extends FormRequest
|
|||
'subscribe' => $this->subscribe ? true : false
|
||||
]);
|
||||
return auth()->check() and ($user->isAdmin() or
|
||||
auth()->user()->projects->contains(request()->route()->ticket->project_id));
|
||||
auth()->user()->sites->contains(request()->route()->ticket->site_id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class SortTickets extends FormRequest
|
|||
}
|
||||
}
|
||||
],
|
||||
'pr' => 'sometimes|int|exists:projects,id'
|
||||
'pr' => 'sometimes|int|exists:sites,id'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace App\Http\Requests;
|
|||
use App\Enums\Role;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreProject extends FormRequest
|
||||
class StoreSite extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
|
|
@ -34,9 +34,9 @@ class StoreTicket extends FormRequest
|
|||
public function rules()
|
||||
{
|
||||
return [
|
||||
'project_id' => [
|
||||
'site_id' => [
|
||||
'required',
|
||||
'exists:projects,id',
|
||||
'exists:sites,id',
|
||||
// @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
/** @var \App\Models\User */
|
||||
|
|
@ -44,9 +44,9 @@ class StoreTicket extends FormRequest
|
|||
if ($user->isAdmin()) {
|
||||
return;
|
||||
}
|
||||
if (!in_array($value, $user->projects()->pluck('id')->all())) {
|
||||
if (!in_array($value, $user->sites()->pluck('id')->all())) {
|
||||
$fail(__('Veuillez choisir entre :values', [
|
||||
'values' => $user->projects()->pluck('name')->implode(',')
|
||||
'values' => $user->sites()->pluck('name')->implode(',')
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
class UpdateProject extends StoreProject
|
||||
class UpdateSite extends StoreSite
|
||||
{
|
||||
}
|
||||
|
|
@ -12,8 +12,7 @@ class UpdateTicket extends StoreTicket
|
|||
/** @var \App\Models\User */
|
||||
$user = auth()->user();
|
||||
if (!$user->isAdmin()) {
|
||||
$this->merge([
|
||||
'status' => $this->project->status->value,
|
||||
$this->merge(['status' => $this->site->status->value,
|
||||
]);
|
||||
}
|
||||
return auth()->check() and ($user->isAdmin() or
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class Message extends Model
|
|||
// find @user + send mail si un seul user est trouvé
|
||||
$usersNotified = collect([]);
|
||||
$matches = [];
|
||||
$ticket->load('project');
|
||||
$ticket->load('site');
|
||||
\preg_match_all('/@\w*/', $message->message, $matches);
|
||||
$matches = collect($matches[0] ?? [])->unique();
|
||||
foreach ($matches as $pseudo_usertag) {
|
||||
|
|
@ -46,8 +46,8 @@ class Message extends Model
|
|||
$user = User::where('name', 'LIKE', '%' . ltrim($pseudo_usertag, '@') . '%')
|
||||
->where('email', '!=', $ticket->user->email)
|
||||
->where(function ($q) use ($ticket) {
|
||||
$q->whereHas('projects', function ($q) use ($ticket) {
|
||||
$q->where('id', $ticket->project->id);
|
||||
$q->whereHas('sites', function ($q) use ($ticket) {
|
||||
$q->where('id', $ticket->site->id);
|
||||
})->orWhere('role', Role::admin()->value)
|
||||
->orWhere('role', Role::developper()->value);
|
||||
})->firstOrFail();
|
||||
|
|
@ -90,18 +90,18 @@ class Message extends Model
|
|||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function saveFile(Project $project, Ticket $ticket, UploadedFile $file)
|
||||
public function saveFile(Site $site, Ticket $ticket, UploadedFile $file)
|
||||
{
|
||||
$projectAssetFullPath = Project::ticketAssetsFullPath($project->slug_name);
|
||||
$fileAssetPath = Project::ticketAssetsPath($project->slug_name);
|
||||
$siteAssetFullPath = Site::ticketAssetsFullPath($site->slug_name);
|
||||
$fileAssetPath = Site::ticketAssetsPath($site->slug_name);
|
||||
$fileName = sprintf(
|
||||
'%s-%s-%d-%d.%s',
|
||||
$project->slug_name,
|
||||
$site->slug_name,
|
||||
$ticket->id,
|
||||
rand(),
|
||||
$file->extension()
|
||||
);
|
||||
$file->move(sprintf('%s/messages/%d', $projectAssetFullPath, $ticket->id), $fileName);
|
||||
$file->move(sprintf('%s/messages/%d', $siteAssetFullPath, $ticket->id), $fileName);
|
||||
return sprintf('%s/%d/%s', $fileAssetPath, $ticket->id, $fileName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Project extends Model
|
||||
class Site extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use IsCrudModel;
|
||||
|
|
@ -67,24 +67,24 @@ class Project extends Model
|
|||
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function (Project $project) {
|
||||
$path = Project::ticketAssetsFullPath($project->slug_name);
|
||||
static::created(function (Site $site) {
|
||||
$path = Site::ticketAssetsFullPath($site->slug_name);
|
||||
if (!File::exists($path)) {
|
||||
File::makeDirectory($path, 0755, true);
|
||||
}
|
||||
});
|
||||
static::updating(function (Project $project) {
|
||||
$oldName = Project::where('id', $project->id)->first()->name;
|
||||
$oldPath = Project::ticketAssetsFullPath($oldName);
|
||||
$newPath = Project::ticketAssetsFullPath($project->slug_name);
|
||||
static::updating(function (Site $site) {
|
||||
$oldName = Site::where('id', $site->id)->first()->name;
|
||||
$oldPath = Site::ticketAssetsFullPath($oldName);
|
||||
$newPath = Site::ticketAssetsFullPath($site->slug_name);
|
||||
if (File::exists($oldPath)) {
|
||||
File::move($oldPath, $newPath);
|
||||
} else {
|
||||
File::makeDirectory($newPath, 0755, true);
|
||||
}
|
||||
});
|
||||
static::deleted(function (Project $project) {
|
||||
$path = Project::ticketAssetsFullPath($project->slug_name);
|
||||
static::deleted(function (Site $site) {
|
||||
$path = Site::ticketAssetsFullPath($site->slug_name);
|
||||
if (File::exists($path)) {
|
||||
File::deleteDirectory($path);
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ class Project extends Model
|
|||
|
||||
public function tickets()
|
||||
{
|
||||
return $this->hasMany(Ticket::class, 'project_id');
|
||||
return $this->hasMany(Ticket::class, 'site_id');
|
||||
}
|
||||
|
||||
public function getSlugNameAttribute()
|
||||
|
|
@ -4,7 +4,7 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
class ProjectUser extends Pivot
|
||||
class SiteUser extends Pivot
|
||||
{
|
||||
|
||||
public $timestamps = false;
|
||||
|
|
@ -22,7 +22,7 @@ class Ticket extends Model
|
|||
];
|
||||
|
||||
protected $fillable = [
|
||||
'project_id',
|
||||
'site_id',
|
||||
'type',
|
||||
'status',
|
||||
'text'
|
||||
|
|
@ -48,9 +48,9 @@ class Ticket extends Model
|
|||
});
|
||||
}
|
||||
|
||||
public function project()
|
||||
public function site()
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
|
|
@ -68,19 +68,19 @@ class Ticket extends Model
|
|||
return $this->belongsToMany(User::class, 'subscriptions');
|
||||
}
|
||||
|
||||
public static function saveFile(Project $project, Ticket $ticket, TicketType $type, UploadedFile $file)
|
||||
public static function saveFile(Site $site, Ticket $ticket, TicketType $type, UploadedFile $file)
|
||||
{
|
||||
$projectAssetFullPath = Project::ticketAssetsFullPath($project->slug_name);
|
||||
$fileAssetPath = Project::ticketAssetsPath($project->slug_name);
|
||||
$siteAssetFullPath = Site::ticketAssetsFullPath($site->slug_name);
|
||||
$fileAssetPath = Site::ticketAssetsPath($site->slug_name);
|
||||
$fileName = sprintf(
|
||||
'%s-%s-%d-%d.%s',
|
||||
$project->slug_name,
|
||||
$site->slug_name,
|
||||
$type->getDefinition(),
|
||||
$ticket->id,
|
||||
rand(),
|
||||
$file->extension()
|
||||
);
|
||||
$file->move(sprintf('%s/%d', $projectAssetFullPath, $ticket->id), $fileName);
|
||||
$file->move(sprintf('%s/%d', $siteAssetFullPath, $ticket->id), $fileName);
|
||||
return sprintf('%s/%d/%s', $fileAssetPath, $ticket->id, $fileName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,10 +123,10 @@ class User extends Authenticatable
|
|||
CrudAction::update(),
|
||||
]
|
||||
],
|
||||
'projects' => [
|
||||
'sites' => [
|
||||
'label' => trans('Projets'),
|
||||
'type' => CrudType::belongsToMany(),
|
||||
'belongsToMany' => Project::class,
|
||||
'belongsToMany' => Site::class,
|
||||
'belongsToManyLabel' => 'name',
|
||||
'nullable' => true,
|
||||
'readonly' => function () {
|
||||
|
|
@ -178,9 +178,9 @@ class User extends Authenticatable
|
|||
return $this->belongsToMany(Ticket::class, 'subscriptions');
|
||||
}
|
||||
|
||||
public function projects()
|
||||
public function sites()
|
||||
{
|
||||
return $this->belongsToMany(Project::class);
|
||||
return $this->belongsToMany(Site::class);
|
||||
}
|
||||
|
||||
public function sendMailConfirm()
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class AppPolicies extends RootPolicy
|
|||
* This first rule to return true in a policy action authorises the action
|
||||
*/
|
||||
$this->policies = [
|
||||
'project' => [
|
||||
'site' => [
|
||||
'viewAny' => URR::make('userIsAdmin', $user),
|
||||
'view' => URR::make('userIsAdmin', $user),
|
||||
'update' => URR::make('userIsAdmin', $user),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace App\Policies;
|
|||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class ProjectPolicy extends AppPolicies
|
||||
class SitePolicy extends AppPolicies
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ class TicketPolicy
|
|||
*/
|
||||
public function update(User $user, Ticket $ticket)
|
||||
{
|
||||
return $user->isAdmin() or $user->projects->contains($ticket->project_id);
|
||||
return $user->isAdmin() or $user->sites->contains($ticket->site_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,7 +85,7 @@ class TicketPolicy
|
|||
*/
|
||||
public function restore(User $user, Ticket $ticket)
|
||||
{
|
||||
return $user->isAdmin() or $user->projects->contains($ticket->project_id);
|
||||
return $user->isAdmin() or $user->sites->contains($ticket->site_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,9 +119,9 @@ class TicketPolicy
|
|||
{
|
||||
//can create if
|
||||
//role == 1
|
||||
// OR project_id IN user->projects
|
||||
// OR site_id IN user->sites
|
||||
|
||||
if (!($user->isAdmin() or $user->projects->contains($ticket->project_id))) {
|
||||
if (!($user->isAdmin() or $user->sites->contains($ticket->site_id))) {
|
||||
return Response::deny(trans('Vous ne pouvez modifier un ticket qui ne vous appartient pas.'));
|
||||
}
|
||||
return $ticket->status->equals(TicketStatus::archived()) ?
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Providers;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use App\Policies\ProjectPolicy;
|
||||
use App\Policies\SitePolicy;
|
||||
use App\Policies\TicketPolicy;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\Site;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
|
|
@ -51,9 +51,9 @@ class RouteServiceProvider extends ServiceProvider
|
|||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
Route::model('user', User::class);
|
||||
Route::model('project', Project::class);
|
||||
Route::model('site', Site::class);
|
||||
Route::bind('ticket', function ($value) {
|
||||
return Ticket::where('id', $value)->has('project')->firstOrFail();
|
||||
return Ticket::where('id', $value)->has('site')->firstOrFail();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
|||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateProjects extends Migration
|
||||
class CreateSites extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\ProjectUser;
|
||||
use App\Models\SiteUser;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateProjectUserTable extends Migration
|
||||
class CreateSiteUserTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
|
|
@ -24,7 +24,7 @@ class CreateProjectUserTable extends Migration
|
|||
/** @var \App\Models\User */
|
||||
foreach (User::all() as $user) {
|
||||
if ($user->project_id) {
|
||||
$uP = new ProjectUser();
|
||||
$uP = new SiteUser();
|
||||
$uP->project_id = $user->project_id;
|
||||
$uP->user_id = $user->id;
|
||||
$uP->saveOrFail();
|
||||
|
|
@ -47,8 +47,8 @@ class CreateProjectUserTable extends Migration
|
|||
$table->foreignId('project_id')->nullable()
|
||||
->after('role')->constrained('projects');
|
||||
});
|
||||
/** @var \App\Models\ProjectUser */
|
||||
foreach (ProjectUser::all() as $uP) {
|
||||
/** @var \App\Models\SiteUser */
|
||||
foreach (SiteUser::all() as $uP) {
|
||||
try {
|
||||
/** @var \App\Models\User */
|
||||
$user = User::whereId($uP->user_id)->firstOrFail();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
|||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddSoftDeleteOnProjects extends Migration
|
||||
class AddSoftDeleteOnSites extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class RenameProjectsTableIntoSitesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::rename('projects', 'sites');
|
||||
Schema::rename('project_user', 'site_user');
|
||||
Schema::table('site_user', function (Blueprint $table) {
|
||||
$table->dropForeign('project_user_project_id_foreign');
|
||||
$table->renameColumn('project_id ', 'site_id');
|
||||
$table->foreignId('site_id')->constrained('sites');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::rename('sites', 'projects');
|
||||
Schema::rename('site_user', 'project_user');
|
||||
Schema::table('project_user', function (Blueprint $table) {
|
||||
$table->dropForeign('site_user_site_id_foreign');
|
||||
$table->renameColumn('site_id ', 'project_id');
|
||||
$table->foreignId('project_id')->constrained('projects');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<p>Bonjour,</p>
|
||||
<p>Un nouveau ticket (n°{{ $ticket->id }}) a été créer sur le support web :</p>
|
||||
<ul>
|
||||
<li>Projet : {{ $ticket->project->name }}</li>
|
||||
<li>Projet : {{ $ticket->site->name }}</li>
|
||||
<li>Type : {{ $ticket->type->label }}</li>
|
||||
<li>Créé par : {{ $ticket->user->name }}</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<p>Bonjour,</p>
|
||||
<p>Vous avez été mentionné sur le ticket n°{{ $ticket->id }}:</p>
|
||||
<ul>
|
||||
<li>Projet : {{ $ticket->project->name }}</li>
|
||||
<li>Projet : {{ $ticket->site->name }}</li>
|
||||
<li>Type : {{ $ticket->type === 0 ? "Bug" : "Évolution" }}</li>
|
||||
<li>Créé par : {{ $ticket->user->name }}</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<p>Bonjour,</p>
|
||||
<p>Le ticket n°{{ $ticket->id }} à été mis à jour :</p>
|
||||
<ul>
|
||||
<li>Projet : {{ $ticket->project->name }}</li>
|
||||
<li>Projet : {{ $ticket->site->name }}</li>
|
||||
<li>Type : {{ $ticket->type === 0 ? "Bug" : "Évolution" }}</li>
|
||||
<li>Créé par : {{ $ticket->user->name }}</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="{{ url('/') }}">
|
||||
@if(auth()->user()->project ?? false)
|
||||
Projet : <b class="text-primary">{{ ucwords(auth()->user()->project->name) }}</b>
|
||||
@if(auth()->user()->site ?? false)
|
||||
Projet : <b class="text-primary">{{ ucwords(auth()->user()->site->name) }}</b>
|
||||
@else
|
||||
{{ config('app.name', 'Laravel') }}
|
||||
@endif
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
<a class="nav-link @if(strpos(request()->route()->getName(), 'ticket') === 0)active @endif" href="{{ route('ticket.index') }}">Tickets</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'project') === 0)active @endif" href="{{ route('project.index') }}">Projets</a>
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'site') === 0)active @endif" href="{{ route('site.index') }}">Projets</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @if(strpos(request()->route()->getName(), 'users') === 0)active @endif" href="{{ route('users.index') }}">Utilisateurs</a>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
@include('modules.error-messages')
|
||||
@php
|
||||
$userPr = Auth::user()->projects ?? collect([]);
|
||||
$userPr = Auth::user()->sites ?? collect([]);
|
||||
@endphp
|
||||
<div class="form-row">
|
||||
<div class="form-group col">
|
||||
<label for="project" class="col-form-label">{{ __('Projet') }}</label>
|
||||
<select class="form-select" name="project_id" id="project">
|
||||
@foreach($projects as $project)
|
||||
<label for="site" class="col-form-label">{{ __('Projet') }}</label>
|
||||
<select class="form-select" name="site_id" id="site">
|
||||
@foreach($sites as $site)
|
||||
@if (Auth::user()->isAdmin())
|
||||
<option value="{{ $project->id }}" @if ($project->id == old('project_id') or (isset($ticket) and $ticket->project->id == $project->id))selected @endif>{{ $project->name }}</option>
|
||||
@elseif ($userPr->filter(function($pr) use($project) { return $pr->id === $project->id; })->count())
|
||||
<option value="{{ $project->id }}" selected>{{ $project->name }}</option>
|
||||
<option value="{{ $site->id }}" @if ($site->id == old('site_id') or (isset($ticket) and $ticket->site->id == $site->id))selected @endif>{{ $site->name }}</option>
|
||||
@elseif ($userPr->filter(function($pr) use($site) { return $pr->id === $site->id; })->count())
|
||||
<option value="{{ $site->id }}" selected>{{ $site->name }}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
@section('content')
|
||||
@php
|
||||
$userPr = Auth::user()->projects ?? collect([]);
|
||||
$userPr = Auth::user()->sites ?? collect([]);
|
||||
@endphp
|
||||
<div class="container container-xxl">
|
||||
<h2>
|
||||
|
|
@ -22,11 +22,11 @@ $userPr = Auth::user()->projects ?? collect([]);
|
|||
<div class="float-end me-2">
|
||||
<select class="form-select" onchange="window.location='{{ route('ticket.index') }}?'+(this.value == -1 ? 'prs=-1' : 'pr='+this.value);">
|
||||
<option value="-1">{{ __('Tous') }}</option>
|
||||
@foreach($projects as $project)
|
||||
@foreach($sites as $site)
|
||||
@if (Auth::user()->isAdmin())
|
||||
<option value="{{ $project->id }}" @if(intval(session('tickets.pr')) == $project->id)selected="selected" @endif>{{ $project->name }}</option>
|
||||
@elseif ($userPr->filter(function($pr) use($project) { return $pr->id === $project->id; })->count())
|
||||
<option value="{{ $project->id }}" @if(intval(session('tickets.pr')) == $project->id)selected="selected" @endif>{{ $project->name }}</option>
|
||||
<option value="{{ $site->id }}" @if(intval(session('tickets.pr')) == $site->id)selected="selected" @endif>{{ $site->name }}</option>
|
||||
@elseif ($userPr->filter(function($pr) use($site) { return $pr->id === $site->id; })->count())
|
||||
<option value="{{ $site->id }}" @if(intval(session('tickets.pr')) == $site->id)selected="selected" @endif>{{ $site->name }}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</select>
|
||||
|
|
@ -55,7 +55,7 @@ $userPr = Auth::user()->projects ?? collect([]);
|
|||
</th>
|
||||
<th scope="col">
|
||||
{{__('Projet') }}
|
||||
@include('modules.sorter', ['colname' => 'project_id'])
|
||||
@include('modules.sorter', ['colname' => 'site_id'])
|
||||
</th>
|
||||
<th scope="col">
|
||||
{{__('Type') }}
|
||||
|
|
@ -87,7 +87,7 @@ $userPr = Auth::user()->projects ?? collect([]);
|
|||
<td scope="row">
|
||||
{{ $ticket->id }}
|
||||
</td>
|
||||
<td>{{ $ticket->project->name }}</td>
|
||||
<td>{{ $ticket->site->name }}</td>
|
||||
<td>
|
||||
@if ($ticket->type->equals(TicketType::bug()))
|
||||
<span class="badge bg-danger">{{ $ticket->type->label }}</span>
|
||||
|
|
@ -130,7 +130,7 @@ $userPr = Auth::user()->projects ?? collect([]);
|
|||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="ticket{{ $ticket->id }}ModalLabel">
|
||||
{{ $ticket->project->name }} - {{__('Ticket N°') }}{{ $ticket->id }} - {{ $ticket->type === 0 ? "Bug" : "Évolution" }}
|
||||
{{ $ticket->site->name }} - {{__('Ticket N°') }}{{ $ticket->id }} - {{ $ticket->type === 0 ? "Bug" : "Évolution" }}
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<div class="form-row row">
|
||||
<h2 class="col">
|
||||
<a href="{{ route('home') }}" class="text-decoration-none">←</a>
|
||||
Ticket n°{{ $ticket->id }} : {{ $ticket->project->name }} - {{ $ticket->type->label }}
|
||||
Ticket n°{{ $ticket->id }} : {{ $ticket->site->name }} - {{ $ticket->type->label }}
|
||||
{{--@cannot('createMessage', $ticket)--}}
|
||||
<span class="badge bg-secondary">{{ $ticket->status->label }}</span>
|
||||
{{--@endcan--}}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\LoginController;
|
||||
use App\Http\Controllers\ProjectController;
|
||||
use App\Http\Controllers\SiteController;
|
||||
use App\Http\Controllers\TicketController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
|
@ -29,7 +29,7 @@ Route::middleware(['auth'])->group(function () {
|
|||
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');
|
||||
// Ticket
|
||||
Route::resource('ticket', TicketController::class)->except(['destroy']);
|
||||
Route::resource('projects', ProjectController::class);
|
||||
Route::resource('sites', SiteController::class);
|
||||
Route::resource('users', UserController::class);
|
||||
Route::prefix('/ticket')->name('ticket.')->group(function () {
|
||||
Route::post('/{ticket}/status', [TicketController::class, 'changeStatus'])
|
||||
|
|
@ -47,6 +47,6 @@ Route::middleware(['auth'])->group(function () {
|
|||
});
|
||||
// Projets
|
||||
Route::middleware(['is-admin'])->group(function () {
|
||||
Route::resource('project', ProjectController::class)->except('show');
|
||||
Route::resource('site', SiteController::class)->except('show');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue