event implementation

This commit is contained in:
Čarodej
2021-11-19 17:08:49 +01:00
parent 496a6ea5a7
commit 7c5cb79677
32 changed files with 135 additions and 121 deletions
@@ -103,16 +103,16 @@ class SetupDevEnvironment extends Command
$user
->settings()
->create([
'avatar' => $avatar_name,
'storage_capacity' => 5,
'name' => 'Jane Doe',
'address' => $this->faker->address,
'state' => $this->faker->state,
'city' => $this->faker->city,
'postal_code' => $this->faker->postcode,
'country' => $this->faker->randomElement(['SK', 'CZ', 'DE', 'FR']),
'phone_number' => $this->faker->phoneNumber,
'timezone' => $this->faker->randomElement(['+1.0', '+2.0', '+3.0']),
'avatar' => $avatar_name,
'max_storage_amount' => 5,
'name' => 'Jane Doe',
'address' => $this->faker->address,
'state' => $this->faker->state,
'city' => $this->faker->city,
'postal_code' => $this->faker->postcode,
'country' => $this->faker->randomElement(['SK', 'CZ', 'DE', 'FR']),
'phone_number' => $this->faker->phoneNumber,
'timezone' => $this->faker->randomElement(['+1.0', '+2.0', '+3.0']),
]);
// Show user credentials
@@ -162,16 +162,16 @@ class SetupDevEnvironment extends Command
$newbie
->settings()
->create([
'avatar' => $avatar_name,
'storage_capacity' => 5,
'name' => $this->faker->name,
'address' => $this->faker->address,
'state' => $this->faker->state,
'city' => $this->faker->city,
'postal_code' => $this->faker->postcode,
'country' => $this->faker->randomElement(['SK', 'CZ', 'DE', 'FR']),
'phone_number' => $this->faker->phoneNumber,
'timezone' => $this->faker->randomElement(['+1.0', '+2.0', '+3.0']),
'avatar' => $avatar_name,
'max_storage_amount' => 5,
'name' => $this->faker->name,
'address' => $this->faker->address,
'state' => $this->faker->state,
'city' => $this->faker->city,
'postal_code' => $this->faker->postcode,
'country' => $this->faker->randomElement(['SK', 'CZ', 'DE', 'FR']),
'phone_number' => $this->faker->phoneNumber,
'timezone' => $this->faker->randomElement(['+1.0', '+2.0', '+3.0']),
]);
$this->info("Generated user with email: $newbie->email and Password: vuefilemanager");
@@ -195,8 +195,8 @@ class SetupProdEnvironment extends Command
$user
->settings()
->create([
'storage_capacity' => 5,
'name' => 'Admin',
'max_storage_amount' => 5,
'name' => 'Admin',
]);
// Show user credentials
+1 -1
View File
@@ -2,9 +2,9 @@
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Support\Listeners\SubscriptionEventSubscriber;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Support\Listeners\SubscriptionEventSubscriber;
class EventServiceProvider extends ServiceProvider
{
@@ -49,8 +49,8 @@ class CreateNewUserAction extends Controller
$user
->settings()
->create([
'name' => $request->input('name'),
'storage_capacity' => $settings['storage_default'],
'name' => $request->input('name'),
'max_storage_amount' => $settings['storage_default'],
]);
UserSettings::reguard();
+5 -5
View File
@@ -74,7 +74,7 @@ class User extends Authenticatable implements MustVerifyEmail
'name',
'role',
'created_at',
'storage_capacity',
'max_storage_amount',
];
public $incrementing = false;
@@ -101,10 +101,10 @@ class User extends Authenticatable implements MustVerifyEmail
}
return [
'used' => (float) get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity),
'used_formatted' => get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity) . '%',
'capacity' => $this->settings->storage_capacity,
'capacity_formatted' => format_gigabytes($this->settings->storage_capacity),
'used' => (float) get_storage_fill_percentage($this->usedCapacity, $this->settings->max_storage_amount),
'used_formatted' => get_storage_fill_percentage($this->usedCapacity, $this->settings->max_storage_amount) . '%',
'capacity' => $this->settings->max_storage_amount,
'capacity_formatted' => format_gigabytes($this->settings->max_storage_amount),
];
}
+1 -1
View File
@@ -10,7 +10,7 @@ class UserSettings extends Model
protected $guarded = [
'id',
'storage_capacity',
'max_storage_amount',
];
/**
+9 -9
View File
@@ -20,15 +20,15 @@ class UserResource extends JsonResource
'id' => $this->id,
'type' => 'user',
'attributes' => [
'storage_capacity' => $this->settings->storage_capacity,
'email' => is_demo() ? obfuscate_email($this->email) : $this->email,
'role' => $this->role,
'two_factor_authentication' => $this->two_factor_secret ? true : false,
'folders' => $this->folder_tree,
'storage' => $this->storage,
'created_at_formatted' => format_date($this->created_at, '%d. %B. %Y'),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'max_storage_amount' => $this->settings->max_storage_amount,
'email' => is_demo() ? obfuscate_email($this->email) : $this->email,
'role' => $this->role,
'two_factor_authentication' => $this->two_factor_secret ? true : false,
'folders' => $this->folder_tree,
'storage' => $this->storage,
'created_at_formatted' => format_date($this->created_at, '%d. %B. %Y'),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
],
'relationships' => [
'settings' => [
@@ -47,29 +47,29 @@ class UserStorageResource extends JsonResource
'type' => 'storage',
'attributes' => [
'used' => Metric::bytes($this->usedCapacity)->format(),
'capacity' => format_gigabytes($this->settings->storage_capacity),
'percentage' => (float) get_storage_fill_percentage($this->usedCapacity, $this->settings->storage_capacity),
'capacity' => format_gigabytes($this->settings->max_storage_amount),
'percentage' => (float) get_storage_fill_percentage($this->usedCapacity, $this->settings->max_storage_amount),
],
'meta' => [
'images' => [
'used' => Metric::bytes($images)->format(),
'percentage' => (float) get_storage_fill_percentage($images, $this->settings->storage_capacity),
'percentage' => (float) get_storage_fill_percentage($images, $this->settings->max_storage_amount),
],
'audios' => [
'used' => Metric::bytes($audios)->format(),
'percentage' => (float) get_storage_fill_percentage($audios, $this->settings->storage_capacity),
'percentage' => (float) get_storage_fill_percentage($audios, $this->settings->max_storage_amount),
],
'videos' => [
'used' => Metric::bytes($videos)->format(),
'percentage' => (float) get_storage_fill_percentage($videos, $this->settings->storage_capacity),
'percentage' => (float) get_storage_fill_percentage($videos, $this->settings->max_storage_amount),
],
'documents' => [
'used' => Metric::bytes($documents)->format(),
'percentage' => (float) get_storage_fill_percentage($documents, $this->settings->storage_capacity),
'percentage' => (float) get_storage_fill_percentage($documents, $this->settings->max_storage_amount),
],
'others' => [
'used' => Metric::bytes($others)->format(),
'percentage' => (float) get_storage_fill_percentage($others, $this->settings->storage_capacity),
'percentage' => (float) get_storage_fill_percentage($others, $this->settings->max_storage_amount),
],
],
],
@@ -3,7 +3,6 @@ namespace Domain\Admin\Controllers\Dashboard;
use ByteUnits\Metric;
use App\Users\Models\User;
use Laravel\Cashier\Subscription;
use App\Http\Controllers\Controller;
class GetWidgetsValuesController extends Controller
@@ -48,9 +48,9 @@ class UserController extends Controller
$user
->settings()
->create([
'storage_capacity' => $request->input('storage_capacity'),
'avatar' => store_avatar($request, 'avatar'),
'name' => $request->input('name'),
'max_storage_amount' => $request->input('max_storage_amount'),
'avatar' => store_avatar($request, 'avatar'),
'name' => $request->input('name'),
]);
UserSettings::reguard();
@@ -23,8 +23,8 @@ class ChangeStorageCapacityRequest extends FormRequest
public function rules()
{
return [
'attributes' => 'required|array',
'attributes.storage_capacity' => 'required|digits_between:1,9',
'attributes' => 'required|array',
'attributes.max_storage_amount' => 'required|digits_between:1,9',
];
}
}
@@ -23,12 +23,12 @@ class CreateUserByAdmin extends FormRequest
public function rules()
{
return [
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'name' => 'required|string|max:255',
'storage_capacity' => 'required|digits_between:1,9',
'role' => 'required|string',
'avatar' => 'sometimes|file',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'name' => 'required|string|max:255',
'max_storage_amount' => 'required|digits_between:1,9',
'role' => 'required|string',
'avatar' => 'sometimes|file',
];
}
}
@@ -48,9 +48,9 @@ class CreateAdminAccountController extends Controller
$user
->settings()
->create([
'storage_capacity' => get_settings('storage_default') ?? 5,
'avatar' => store_avatar($request, 'avatar'),
'name' => $request->input('name'),
'max_storage_amount' => get_settings('storage_default') ?? 5,
'avatar' => store_avatar($request, 'avatar'),
'name' => $request->input('name'),
]);
collect([
@@ -8,7 +8,8 @@ class UpdateMembersAction
{
public function __construct(
public TransferContentOwnershipToTeamFolderOwnerAction $transferContentOwnership,
) {}
) {
}
public function __invoke(Folder $folder, $members): void
{
+1 -1
View File
@@ -1,12 +1,12 @@
<?php
namespace Domain\Zip\Controllers;
use ZipStream\ZipStream;
use Illuminate\Http\Request;
use Domain\Zip\Actions\ZipAction;
use App\Http\Controllers\Controller;
use Domain\Traffic\Actions\RecordDownloadAction;
use Domain\Zip\Actions\GetItemsListFromUrlParamAction;
use ZipStream\ZipStream;
class ZipController extends Controller
{
@@ -1,20 +1,31 @@
<?php
namespace Support\Listeners;
use Illuminate\Events\Dispatcher;
use VueFileManager\Subscription\Support\Events\SubscriptionWasCreated;
use VueFileManager\Subscription\Support\Events\SubscriptionWasExpired;
use VueFileManager\Subscription\Support\Events\SubscriptionWasUpdated;
class SubscriptionEventSubscriber
{
public function handleSubscriptionWasCreated($subscription) {
// Get plan features
$features = $subscription->plan->features()->pluck('value', 'key');
// Set user storage size
public function handleSubscriptionWasCreated($subscription)
{
$subscription->user->settings->update([
'storage_capacity' => $features['max_storage_amount']
'max_storage_amount' => $subscription->feature('max_storage_amount'),
]);
}
public function handleSubscriptionWasUpdated($subscription)
{
$subscription->user->settings->update([
'max_storage_amount' => $subscription->feature('max_storage_amount'),
]);
}
public function handleSubscriptionWasExpired($subscription)
{
$subscription->user->settings->update([
'max_storage_amount' => get_settings('storage_default'),
]);
}
@@ -25,6 +36,8 @@ class SubscriptionEventSubscriber
{
return [
SubscriptionWasCreated::class => 'handleSubscriptionWasCreated',
SubscriptionWasExpired::class => 'handleSubscriptionWasExpired',
SubscriptionWasUpdated::class => 'handleSubscriptionWasUpdated',
];
}
}
}
+1 -1
View File
@@ -499,7 +499,7 @@ if (! function_exists('user_storage_percentage')) {
$used = $user->usedCapacity + $additionals;
}
return get_storage_fill_percentage($used, $user->settings->storage_capacity);
return get_storage_fill_percentage($used, $user->settings->max_storage_amount);
}
}