-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip organizations * wip * init export * cleanup * fix , bug * Review/organizations add counties (#278) * Add counties to OrganizationResource * Fix return type * wip * Add request for update organization * Fix update in vue * Add actions for approve / reject changes on organizations * Php-cs-fixer * Remove old changes when you change the same attribute and the old changes are not approved * Refactoring move where login in a scope for reusing * Add waring in edit ong view for changes in pending * Add widget for pending changes * cs-fixer * fix: activitylog config * refactor * renaming organizations action * wip * wip * wip * Add org resource (#279) * add resource * cleanup * wip * wip * wip * fix org logo in admin * add org filters * fix filter display in org list * wip * wip * wip --------- Co-authored-by: Lupu Gheorghe <[email protected]> Co-authored-by: Lupu Gheorghe <[email protected]>
- Loading branch information
1 parent
54dda91
commit 582156b
Showing
95 changed files
with
3,635 additions
and
1,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Pipeline\Pipeline; | ||
use Spatie\Activitylog\ActivityLogger; | ||
use Spatie\Activitylog\EventLogBag; | ||
use Spatie\Activitylog\Traits\LogsActivity as SpatieLogsActivity; | ||
|
||
trait LogsActivity | ||
{ | ||
use SpatieLogsActivity; | ||
|
||
protected static function bootLogsActivity(): void | ||
{ | ||
// Hook into eloquent events that only specified in $eventToBeRecorded array, | ||
// checking for "updated" event hook explicitly to temporary hold original | ||
// attributes on the model as we'll need them later to compare against. | ||
|
||
static::eventsToBeRecorded()->each(function ($eventName) { | ||
if ($eventName === 'updated') { | ||
static::updating(function (Model $model) { | ||
$oldValues = (new static())->setRawAttributes($model->getRawOriginal()); | ||
$model->oldAttributes = static::logChanges($oldValues); | ||
}); | ||
} | ||
|
||
static::$eventName(function (Model $model) use ($eventName) { | ||
$model->activitylogOptions = $model->getActivitylogOptions(); | ||
|
||
if (! $model->shouldLogEvent($eventName)) { | ||
return; | ||
} | ||
|
||
$changes = $model->attributeValuesToBeLogged($eventName); | ||
|
||
$description = $model->getDescriptionForEvent($eventName); | ||
|
||
$logName = $model->getLogNameToUse(); | ||
|
||
// Submitting empty description will cause place holder replacer to fail. | ||
if ($description == '') { | ||
return; | ||
} | ||
|
||
if ($model->isLogEmpty($changes) && ! $model->activitylogOptions->submitEmptyLogs) { | ||
return; | ||
} | ||
|
||
// User can define a custom pipelines to mutate, add or remove from changes | ||
// each pipe receives the event carrier bag with changes and the model in | ||
// question every pipe should manipulate new and old attributes. | ||
$event = app(Pipeline::class) | ||
->send(new EventLogBag($eventName, $model, $changes, $model->activitylogOptions)) | ||
->through(static::$changesPipes) | ||
->thenReturn(); | ||
|
||
if ($eventName === 'updated' || $eventName === 'updating') { | ||
foreach ($event->changes['attributes'] as $key => $value) { | ||
static::actuallyLog($logName, $eventName, $model, [ | ||
$key => [ | ||
'old' => $event->changes['old'][$key], | ||
'new' => $value, | ||
], | ||
], $description); | ||
} | ||
} else { | ||
static::actuallyLog($logName, $eventName, $model, $event->changes, $description); | ||
} | ||
|
||
// Reset log options so the model can be serialized. | ||
$model->activitylogOptions = null; | ||
}); | ||
}); | ||
} | ||
|
||
protected static function actuallyLog(?string $logName, string $eventName, Model $model, array $properties, string $description): void | ||
{ | ||
// Actual logging | ||
$logger = app(ActivityLogger::class) | ||
->useLog($logName) | ||
->event($eventName) | ||
->performedOn($model) | ||
->withProperties($properties); | ||
|
||
if (method_exists($model, 'tapActivity')) { | ||
$logger->tap([$model, 'tapActivity'], $eventName); | ||
} | ||
|
||
$logger->log($description); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use App\Models\Activity; | ||
use Spatie\Activitylog\ActivityLogger; | ||
use Spatie\Activitylog\Traits\LogsActivity as SpatieLogsActivity; | ||
|
||
trait LogsActivityForApproval | ||
{ | ||
use SpatieLogsActivity; | ||
|
||
public function saveForApproval(): void | ||
{ | ||
$changes = collect($this->getDirty()) | ||
->map(fn ($value, $key) => [ | ||
'old' => $this->getOriginal($key), | ||
'new' => $value, | ||
]); | ||
|
||
if ($changes->isEmpty()) { | ||
return; | ||
} | ||
|
||
Activity::pendingChangesFor($this, $changes->keys()->all())->delete(); | ||
|
||
$eventName = 'updated'; | ||
|
||
$description = $this->getDescriptionForEvent($eventName) ?: $eventName; | ||
|
||
// Actual logging | ||
app(ActivityLogger::class) | ||
->useLog('pending') | ||
->event($eventName) | ||
->performedOn($this) | ||
->withProperties($changes) | ||
->log($description); | ||
} | ||
|
||
public function tapActivity(Activity $activity, string $eventName) | ||
{ | ||
// Flip properties | ||
$properties = []; | ||
|
||
foreach ($activity->properties->get('attributes', []) as $key => $value) { | ||
$properties[$key] = [ | ||
'old' => data_get($activity->properties, "old.{$key}"), | ||
'new' => $value, | ||
]; | ||
} | ||
|
||
if (! empty($properties)) { | ||
$activity->properties = $properties; | ||
} | ||
|
||
if (auth()->guest()) { | ||
return; | ||
} | ||
|
||
if (auth()->user()->isBbAdmin() || auth()->user()->isBbManager()) { | ||
activity()->disableLogging(); | ||
|
||
if (! $activity->description) { | ||
$activity->description = $this->getDescriptionForEvent($eventName); | ||
} | ||
|
||
$activity->properties->each( | ||
fn ($values, $key) => $activity | ||
->replicate() | ||
->fill([ | ||
'properties' => [$key => $values], | ||
'approved_at' => now(), | ||
]) | ||
->save() | ||
); | ||
} else { | ||
if ( | ||
$activity->properties->count() === 1 && | ||
property_exists($this, 'requiresApproval') && | ||
! \in_array($activity->properties->keys()->first(), $this->requiresApproval) | ||
) { | ||
$activity->log_name = 'auto_approved'; | ||
$activity->approved_at = now(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,4 @@ public function translationKeyPrefix(): string | |
{ | ||
return 'user.roles'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Forms\Components; | ||
|
||
use Closure; | ||
use Filament\Forms\Components\Component; | ||
use Filament\Forms\Components\Concerns; | ||
use Illuminate\Support\Collection; | ||
use Spatie\MediaLibrary\MediaCollections\Models\Media; | ||
|
||
class Download extends Component | ||
{ | ||
use Concerns\HasHelperText; | ||
use Concerns\HasHint; | ||
use Concerns\HasName; | ||
|
||
protected string $view = 'forms.components.download'; | ||
|
||
protected string | Closure $collectionName = 'default'; | ||
|
||
final public function __construct(string $collectionName) | ||
{ | ||
$this->collectionName($collectionName); | ||
$this->statePath($collectionName); | ||
} | ||
|
||
public static function make(string $collectionName): static | ||
{ | ||
$static = app(static::class, ['collectionName' => $collectionName]); | ||
$static->configure(); | ||
|
||
return $static; | ||
} | ||
|
||
public function collectionName(string | Closure $collectionName): static | ||
{ | ||
$this->collectionName = $collectionName; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCollectionName(): string | ||
{ | ||
return $this->evaluate($this->collectionName); | ||
} | ||
|
||
public function getDownloadItems(): Collection | ||
{ | ||
return $this->getRecord() | ||
->getMedia($this->getCollectionName()) | ||
->map(fn (Media $media) => [ | ||
'url' => $media->getFullUrl(), | ||
'name' => $media->name . '.' . $media->extension, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.