Skip to content

Commit

Permalink
Update all modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemjohn committed Jun 28, 2023
1 parent f30cb12 commit 6c55700
Show file tree
Hide file tree
Showing 569 changed files with 25,545 additions and 9,627 deletions.
20 changes: 14 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@
}
],
"require": {
"php": "^7.3|^8.0|^8.1",
"php": "^8.1",
"hashids/hashids": "~4.1",
"intervention/imagecache": "~2.5",
"laravel/socialite": "~5.1",
"league/fractal": "~0.19",
"mcamara/laravel-localization": "^1.6",
"mcamara/laravel-localization": "^1.8",
"rachidlaasri/laravel-installer": "^4.0",
"spatie/laravel-activitylog": "^4.0"
"spatie/laravel-activitylog": "^4.7",
"league/flysystem-aws-s3-v3": "^3.0",
"lorisleiva/laravel-actions": "^2.4",
"symfony/workflow": "^6.0",
"symfony/process": "^6.0",
"symfony/event-dispatcher-contracts": "^2.4|^3.0",
"illuminate/console": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"illuminate/contracts": "^9.0|^10.0"
},
"replace": {
"litepie/activities": "self.version",
Expand All @@ -46,19 +54,19 @@
"doctrine/dbal": "^2.6|^3.0",
"filp/whoops": "^2.8",
"guzzlehttp/guzzle": "^6.5.5|^7.0.1",
"league/flysystem-cached-adapter": "^1.0",
"league/flysystem-cached-adapter": "^1.1",
"mockery/mockery": "^1.4.2",
"orchestra/testbench-core": "^6.23",
"pda/pheanstalk": "^4.0",
"phpunit/phpunit": "^8.5.8|^9.3.3",
"predis/predis": "^1.1.2",
"symfony/cache": "^5.1.4",
"laravel/framework": "^9.0|^8.40"
"laravel/framework": "^10.4"
},
"autoload": {
"files": [
"src/Litepie/Foundation/helpers.php",
"src/Litepie/Settings/helpers.php",
"src/Litepie/Setting/helpers.php",
"src/Litepie/Form/helpers.php",
"src/Litepie/Theme/helpers.php"
],
Expand Down
94 changes: 94 additions & 0 deletions src/Litepie/Actions/Action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
namespace Litepie\Actions;

use Illuminate\Support\Facades\Auth;

class Action
{
protected $name = null;
protected $roles = null;
protected $type = [];
protected $form = [];

public function __construct($name = null)
{
$this->name = $name;
}

public function roles(array $roles = [])
{
if (!empty($roles)) {
$this->roles = $roles;
}
return $this->roles;
}

public function name(string $name = null): string
{
if (!empty($name)) {
$this->name = $name;
}
return $this->name;
}

public function type(array $types = [])
{
if (is_array($types)) {
foreach ($types as $type) {
$this->type[] = ActionType::tryFrom($type);
}
}
return $this->type;
}

public function form(array $form = null)
{
if (!empty($form)) {
return $this->form = $form;
}

if (empty($this->form)) {
return null;
}
foreach ($this->form as $key => $val) {
$this->form[$key]['label'] = trans($val['label']);
$this->form[$key]['placeholder'] = trans($val['placeholder']);
}

return $this->form;
}

public function authorized()
{
if (!isset($this->roles)) {
return true;
}

if (isset($this->roles['permission'])
&& Auth::user()->can($this->roles['permission'])) {
return true;
}

if (isset($this->roles['user'])
&& Auth::user()->hasRole($this->roles['user'])) {
return true;
}

if (isset($this->roles['team'])
&& Auth::user()->teams()->hasRole($this->roles['team'])) {
return true;
}

return false;
}

public function isType($type = ActionType::List)
{
if (in_array($type, $this->type())) {
return true;
}

return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace Litepie\Activities;
namespace Litepie\Actions;

use Illuminate\Auth\AuthManager;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Litepie\Activities\Contracts\Action as ActionContract;
use Litepie\Actions\Contracts\Action as ActionContract;
use Litepie\Actions\Models\Action;
use Spatie\Activitylog\Exceptions\CouldNotLogActivity;

class ActionLogger
Expand All @@ -24,16 +23,13 @@ class ActionLogger
/** @var string */
protected $authDriver;

/** @var \Spatie\Activitylog\Contracts\Activity */
protected $action;

public function __construct(AuthManager $auth, Repository $config)
{
$this->auth = $auth;

$this->authDriver = $config['activitylog']['default_auth_driver'] ?? $auth->getDefaultDriver();

$this->defaultLogName = $config['activitylog']['default_log_name'];
$this->authDriver = $config['actionlog']['default_auth_driver'] ?? $auth->getDefaultDriver();
$this->defaultLogName = $config['actionlog']['default_log_name'];
}

public function performedOn(Model $model)
Expand Down Expand Up @@ -79,61 +75,17 @@ public function byAnonymous()
return $this->causedByAnonymous();
}

public function withProperties($properties)
{
$this->getAction()->properties = collect($properties);

return $this;
}

public function withProperty(string $key, $value)
{
$this->getAction()->properties = $this->getAction()->properties->put($key, $value);

return $this;
}

public function createdAt(Carbon $dateTime)
{
$this->getAction()->created_at = $dateTime;

return $this;
}

public function useLog(string $logName)
{
$this->getAction()->log_name = $logName;

return $this;
}

public function performAction(string $action)
{
$this->getAction()->action = $action;

return $this;
}

public function inLog(string $logName)
{
return $this->useLog($logName);
}

public function tap(callable $callback, string $eventName = null)
{
call_user_func($callback, $this->getAction(), $eventName);

return $this;
}

public function log(string $description)
public function save()
{
$action = $this->action;

$action->description = $this->replacePlaceholders(
$action->description ?? $description,
$action
);
$action->save();

$this->action = null;
Expand All @@ -158,41 +110,32 @@ protected function normalizeCauser($modelOrId): Model
throw CouldNotLogActivity::couldNotDetermineUser($modelOrId);
}

protected function replacePlaceholders(string $description, ActionContract $action): string
{
return preg_replace_callback('/:[a-z0-9._-]+/i', function ($match) use ($action) {
$match = $match[0];

$attribute = Str::before(Str::after($match, ':'), '.');

if (!in_array($attribute, ['subject', 'causer', 'properties'])) {
return $match;
}

$propertyName = substr($match, strpos($match, '.') + 1);

$attributeValue = $action->$attribute;

if (is_null($attributeValue)) {
return $match;
}

$attributeValue = $attributeValue->toArray();

return Arr::get($attributeValue, $propertyName, $match);
}, $description);
}

protected function getAction(): ActionContract
{
if (!$this->action instanceof ActionContract) {
$this->action = ActivitiesServiceProvider::getActionModelInstance();
$this
->useLog($this->defaultLogName)
->withProperties([])
$this->action = app(Action::class);
$this->action($this->defaultLogName)
->causedBy($this->auth->guard($this->authDriver)->user());
}

return $this->action;
}

public function action($action = null)
{
$this->getAction()->action = $action;
return $this;
}

public function description($description = null)
{
$this->getAction()->description = $description;
return $this;
}

public function property($property = null)
{
$this->getAction()->properties = $property;
return $this;
}
}
9 changes: 9 additions & 0 deletions src/Litepie/Actions/ActionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Litepie\Actions;

use Lorisleiva\Actions\ActionRequest as BaseActionRequest;

class ActionRequest extends BaseActionRequest
{
}
20 changes: 20 additions & 0 deletions src/Litepie/Actions/ActionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Litepie\Actions;

use Illuminate\Support\Arr;

enum ActionType: string
{
case List = 'List';
case Details = 'Details';

public function values(): array
{
return array_column(self::cases(), 'value');
}

public function names(): array
{
return array_column(self::cases(), 'name');
}
}
Loading

0 comments on commit 6c55700

Please sign in to comment.