Skip to content

Commit

Permalink
Merge PR25 to Master
Browse files Browse the repository at this point in the history
  • Loading branch information
heloufir committed Jan 9, 2023
1 parent 72fac8d commit 0e38cd8
Show file tree
Hide file tree
Showing 10 changed files with 562 additions and 394 deletions.
10 changes: 0 additions & 10 deletions app/Filament/Resources/ActivityResource/Pages/CreateActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@
namespace App\Filament\Resources\ActivityResource\Pages;

use App\Filament\Resources\ActivityResource;
use App\Models\TicketType;
use Filament\Resources\Pages\CreateRecord;

class CreateActivity extends CreateRecord
{
protected static string $resource = ActivityResource::class;

protected function afterCreate(): void
{
if ($this->record->is_default) {
TicketType::where('id', '<>', $this->record->id)
->where('is_default', true)
->update(['is_default' => false]);
}
}
}
10 changes: 0 additions & 10 deletions app/Filament/Resources/ActivityResource/Pages/EditActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Resources\ActivityResource\Pages;

use App\Filament\Resources\ActivityResource;
use App\Models\TicketStatus;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;

Expand All @@ -18,13 +17,4 @@ protected function getActions(): array
Actions\DeleteAction::make(),
];
}

protected function afterSave(): void
{
if ($this->record->is_default) {
TicketStatus::where('id', '<>', $this->record->id)
->where('is_default', true)
->update(['is_default' => false]);
}
}
}
3 changes: 2 additions & 1 deletion app/Models/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Activity extends Model
{
use HasFactory;
use HasFactory, SoftDeletes;

protected $fillable = [
'name',
Expand Down
94 changes: 94 additions & 0 deletions app/Policies/ActivityPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace App\Policies;

use App\Models\Activity;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class ActivityPolicy
{
use HandlesAuthorization;

/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function viewAny(User $user)
{
return $user->can('List activities');
}

/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $user
* @param \App\Models\Activity $activity
* @return \Illuminate\Auth\Access\Response|bool
*/
public function view(User $user, Activity $activity)
{
return $user->can('View activity');
}

/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create(User $user)
{
return $user->can('Create activity');
}

/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $user
* @param \App\Models\Activity $activity
* @return \Illuminate\Auth\Access\Response|bool
*/
public function update(User $user, Activity $activity)
{
return $user->can('Update activity');
}

/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\Activity $activity
* @return \Illuminate\Auth\Access\Response|bool
*/
public function delete(User $user, Activity $activity)
{
return $user->can('Delete activity');
}

/**
* Determine whether the user can restore the model.
*
* @param \App\Models\User $user
* @param \App\Models\Activity $activity
* @return \Illuminate\Auth\Access\Response|bool
*/
public function restore(User $user, Activity $activity)
{
//
}

/**
* Determine whether the user can permanently delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\Activity $activity
* @return \Illuminate\Auth\Access\Response|bool
*/
public function forceDelete(User $user, Activity $activity)
{
//
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function up()
$table->mediumText('description');

$table->timestamps();
$table->softDeletes();
});
}

Expand Down
12 changes: 12 additions & 0 deletions database/referential.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@ INSERT INTO `ticket_types` (`id`, `name`, `icon`, `color`, `is_default`, `delete
(2, 'Evolution', 'heroicon-o-clipboard-list', '#008000', 0, NULL, '2022-11-14 12:06:56', '2022-11-14 12:06:56'),
(3, 'Bug', 'heroicon-o-x', '#ff0000', 0, NULL, '2022-11-14 12:06:56', '2022-11-14 12:06:56');


INSERT INTO `activities` (`id`, `name`, `description`, `created_at`, `updated_at`, `deleted_at`) VALUES
(1, 'Programming', 'Programming related activities', '2023-01-09 13:10:52', '2023-01-09 13:10:52', NULL),
(2, 'Testing', 'Testing related activities', '2023-01-09 13:10:52', '2023-01-09 13:10:52', NULL),
(3, 'Learning', 'Activities related to learning and training', '2023-01-09 13:10:52', '2023-01-09 13:10:52', NULL),
(4, 'Research', 'Activities related to research', '2023-01-09 13:10:52', '2023-01-09 13:10:52', NULL),
(5, 'Other', 'Other activities', '2023-01-09 13:10:52', '2023-01-09 13:10:52', NULL);

ALTER TABLE `ticket_priorities`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

ALTER TABLE `ticket_statuses`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

ALTER TABLE `ticket_types`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

ALTER TABLE `activities`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
Loading

0 comments on commit 0e38cd8

Please sign in to comment.