mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
deleted pro code
This commit is contained in:
@@ -11,8 +11,6 @@ use Illuminate\Support\Facades\DB;
|
||||
use Domain\Settings\Models\Setting;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Domain\Teams\Models\TeamFolderInvitation;
|
||||
use Domain\Pages\Actions\SeedDefaultPagesAction;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
use Domain\Settings\Actions\SeedDefaultSettingsAction;
|
||||
use Domain\Localization\Actions\SeedDefaultLanguageAction;
|
||||
@@ -25,7 +23,7 @@ class SetupDevEnvironment extends Command
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'setup:dev {license=extended}';
|
||||
protected $signature = 'setup:dev';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -36,7 +34,6 @@ class SetupDevEnvironment extends Command
|
||||
private CreateDiskDirectoriesAction $createDiskDirectories,
|
||||
private SeedDefaultSettingsAction $seedDefaultSettings,
|
||||
private SeedDefaultLanguageAction $seedDefaultLanguage,
|
||||
private SeedDefaultPagesAction $seedDefaultPages,
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->setUpFaker();
|
||||
@@ -56,8 +53,7 @@ class SetupDevEnvironment extends Command
|
||||
$this->migrate_and_generate();
|
||||
|
||||
$this->info('Storing default settings and content...');
|
||||
($this->seedDefaultPages)();
|
||||
($this->seedDefaultSettings)($this->argument('license'));
|
||||
($this->seedDefaultSettings)();
|
||||
($this->seedDefaultLanguage)();
|
||||
$this->store_default_settings();
|
||||
|
||||
@@ -69,15 +65,9 @@ class SetupDevEnvironment extends Command
|
||||
|
||||
$this->info('Creating default demo content...');
|
||||
$this->create_admin_default_content();
|
||||
$this->create_team_folders_content();
|
||||
$this->create_share_with_me_team_folders_content();
|
||||
$this->create_share_records();
|
||||
$this->generate_traffic();
|
||||
|
||||
$this->generateCommonNotification();
|
||||
$this->generateTeamInvitationNotification();
|
||||
$this->generateFileRequestFilledNotification();
|
||||
|
||||
$this->info('Clearing application cache...');
|
||||
$this->clear_cache();
|
||||
|
||||
@@ -91,135 +81,6 @@ class SetupDevEnvironment extends Command
|
||||
$this->info('Everything is done, congratulations! 🥳🥳🥳');
|
||||
}
|
||||
|
||||
private function generateCommonNotification()
|
||||
{
|
||||
$howdy = User::whereEmail('howdy@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
DB::table('notifications')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'App\Users\Notifications\RegistrationBonusAddedNotification',
|
||||
'notifiable_type' => 'App\Users\Models\User',
|
||||
'notifiable_id' => $howdy->id,
|
||||
'data' => json_encode([
|
||||
'category' => 'gift',
|
||||
'title' => 'You Received $10.00',
|
||||
'description' => 'You received credit bonus $10.00 for your registration. Happy spending!',
|
||||
]),
|
||||
'read_at' => now()->subMinutes(5),
|
||||
'created_at' => now()->subMinutes(5),
|
||||
'updated_at' => now()->subMinutes(5),
|
||||
]);
|
||||
}
|
||||
|
||||
private function generateTeamInvitationNotification()
|
||||
{
|
||||
$alice = User::whereEmail('alice@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$howdy = User::whereEmail('howdy@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$newV2Wallpaper = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $alice->id,
|
||||
'team_folder' => true,
|
||||
'name' => 'New v2 Wallpaper',
|
||||
]);
|
||||
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
'parent_id' => $newV2Wallpaper->id,
|
||||
'inviter_id' => $newV2Wallpaper->user_id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
DB::table('notifications')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification',
|
||||
'notifiable_type' => 'App\Users\Models\User',
|
||||
'notifiable_id' => $howdy->id,
|
||||
'data' => json_encode([
|
||||
'category' => 'team-invitation',
|
||||
'title' => 'New Team Invitation',
|
||||
'description' => 'Jane Doe invite you to join into Team Folder.',
|
||||
'action' => [
|
||||
'type' => 'invitation',
|
||||
'params' => [
|
||||
'id' => $invitation->id,
|
||||
],
|
||||
],
|
||||
]),
|
||||
'read_at' => now(),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function generateFileRequestFilledNotification()
|
||||
{
|
||||
$howdy = User::whereEmail('howdy@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$sharedFolder = Folder::where('name', 'Shared Folder')
|
||||
->first();
|
||||
|
||||
$fileRequestFolder = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $sharedFolder->id,
|
||||
'user_id' => $howdy->id,
|
||||
'team_folder' => false,
|
||||
'name' => 'Upload Request from 10. Mar. 2022',
|
||||
]);
|
||||
|
||||
DB::table('notifications')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification',
|
||||
'notifiable_type' => 'App\Users\Models\User',
|
||||
'notifiable_id' => $howdy->id,
|
||||
'data' => json_encode([
|
||||
'category' => 'file-request',
|
||||
'title' => 'File Request Filled',
|
||||
'description' => "Your file request for 'Shared Folder' folder was filled successfully.",
|
||||
'action' => [
|
||||
'type' => 'route',
|
||||
'params' => [
|
||||
'route' => 'Files',
|
||||
'button' => 'Show Files',
|
||||
'id' => $fileRequestFolder->id,
|
||||
],
|
||||
],
|
||||
]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
// Get meme gallery
|
||||
collect([
|
||||
'demo/request/v2-wallpaper.jpg',
|
||||
])
|
||||
->each(function ($file) use ($howdy, $fileRequestFolder) {
|
||||
$thumbnail = $this->generate_thumbnails($file, $howdy);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $fileRequestFolder->id,
|
||||
'user_id' => $howdy->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default admin account
|
||||
*/
|
||||
@@ -830,527 +691,6 @@ class SetupDevEnvironment extends Command
|
||||
});
|
||||
}
|
||||
|
||||
private function create_team_folders_content(): void
|
||||
{
|
||||
$user = User::whereEmail('howdy@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$alice = User::whereEmail('alice@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$johan = User::whereEmail('johan@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$users = [$user, $alice, $johan];
|
||||
|
||||
// 1. Company project
|
||||
$companyProjectFolder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => true,
|
||||
'name' => 'Company Project',
|
||||
]);
|
||||
|
||||
$presentationMaterial = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $companyProjectFolder->id,
|
||||
'name' => 'Presentation Materials',
|
||||
'team_folder' => true,
|
||||
]);
|
||||
|
||||
$teamGallery = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $companyProjectFolder->id,
|
||||
'name' => 'Team Gallery',
|
||||
'team_folder' => true,
|
||||
]);
|
||||
|
||||
collect([
|
||||
'demo/images/team-gallery/photo-1.jpeg',
|
||||
'demo/images/team-gallery/photo-2.jpeg',
|
||||
'demo/images/team-gallery/photo-3.jpeg',
|
||||
])
|
||||
->each(function ($file) use ($users, $user, $teamGallery) {
|
||||
$author = $users[rand(0, 2)];
|
||||
|
||||
$thumbnail = $this->generate_thumbnails($file, $user);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $teamGallery->id,
|
||||
'user_id' => $user->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
collect([
|
||||
'demo/images/presentation/photo-1.jpeg',
|
||||
'demo/images/presentation/photo-2.jpeg',
|
||||
])
|
||||
->each(function ($file) use ($users, $user, $presentationMaterial) {
|
||||
$author = $users[rand(0, 2)];
|
||||
|
||||
$thumbnail = $this->generate_thumbnails($file, $user);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $presentationMaterial->id,
|
||||
'user_id' => $user->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
// 2. Finance Documents
|
||||
$financeDocumentsFolder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => true,
|
||||
'name' => 'Finance Documents',
|
||||
]);
|
||||
|
||||
$reserves = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $financeDocumentsFolder->id,
|
||||
'name' => 'Reserves',
|
||||
'team_folder' => true,
|
||||
]);
|
||||
|
||||
$otherDocuments = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $financeDocumentsFolder->id,
|
||||
'name' => 'Other Documents',
|
||||
'team_folder' => true,
|
||||
]);
|
||||
|
||||
collect([
|
||||
'demo/images/finance-documents/photo-1.jpeg',
|
||||
'demo/images/finance-documents/photo-2.jpeg',
|
||||
'demo/images/finance-documents/photo-3.jpeg',
|
||||
])
|
||||
->each(function ($file) use ($users, $user, $financeDocumentsFolder) {
|
||||
$author = $users[rand(0, 2)];
|
||||
|
||||
$thumbnail = $this->generate_thumbnails($file, $user);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $financeDocumentsFolder->id,
|
||||
'user_id' => $user->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
collect([
|
||||
'demo/images/finance-documents/photo-4.jpeg',
|
||||
'demo/images/finance-documents/photo-5.jpeg',
|
||||
])
|
||||
->each(function ($file) use ($users, $user, $reserves) {
|
||||
$author = $users[rand(0, 2)];
|
||||
|
||||
$thumbnail = $this->generate_thumbnails($file, $user);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $reserves->id,
|
||||
'user_id' => $user->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
// Get documents to root directory
|
||||
collect([
|
||||
[
|
||||
'name' => 'Next Year Projection',
|
||||
'basename' => 'Licence.pdf',
|
||||
'mimetype' => 'pdf',
|
||||
],
|
||||
[
|
||||
'name' => 'Budget.pdf',
|
||||
'basename' => 'Project Notes.pdf',
|
||||
'mimetype' => 'pdf',
|
||||
],
|
||||
[
|
||||
'name' => '2022 Yearly Report.pages',
|
||||
'basename' => 'School Report.pages',
|
||||
'mimetype' => 'pages',
|
||||
],
|
||||
[
|
||||
'name' => 'Company Project Notes.pages',
|
||||
'basename' => 'Stories of the Night Skies.pages',
|
||||
'mimetype' => 'pages',
|
||||
],
|
||||
[
|
||||
'name' => 'Finance Stories.pages',
|
||||
'basename' => 'Stories of the Night Skies.pages',
|
||||
'mimetype' => 'pages',
|
||||
],
|
||||
])
|
||||
->each(function ($file) use ($users, $user, $financeDocumentsFolder, $otherDocuments) {
|
||||
$author = $users[rand(0, 2)];
|
||||
$folder = [$financeDocumentsFolder, $otherDocuments][rand(0, 1)];
|
||||
|
||||
$basename = Str::random(12) . '-' . $file['basename'];
|
||||
|
||||
// Copy file into app storage
|
||||
Storage::putFileAs("files/$user->id", storage_path("demo/documents/{$file['basename']}"), $basename, 'private');
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $file['name'],
|
||||
'basename' => $basename,
|
||||
'type' => 'file',
|
||||
'mimetype' => $file['mimetype'],
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
// 3. Holiday 2022
|
||||
$holiday2022Folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => true,
|
||||
'name' => 'Holiday 2022',
|
||||
]);
|
||||
|
||||
$destinationGallery = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $holiday2022Folder->id,
|
||||
'name' => 'Destination Gallery',
|
||||
'team_folder' => true,
|
||||
]);
|
||||
|
||||
collect([
|
||||
'demo/images/destination-gallery/photo-1.jpeg',
|
||||
'demo/images/destination-gallery/photo-2.jpeg',
|
||||
'demo/images/destination-gallery/photo-3.jpeg',
|
||||
'demo/images/destination-gallery/photo-4.jpeg',
|
||||
'demo/images/destination-gallery/photo-5.jpeg',
|
||||
])
|
||||
->each(function ($file) use ($users, $user, $destinationGallery) {
|
||||
$author = $users[rand(0, 2)];
|
||||
|
||||
$thumbnail = $this->generate_thumbnails($file, $user);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $destinationGallery->id,
|
||||
'user_id' => $user->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
// Get documents to root directory
|
||||
collect([
|
||||
[
|
||||
'name' => 'Finance.pages',
|
||||
'basename' => 'Licence.pdf',
|
||||
'mimetype' => 'pdf',
|
||||
],
|
||||
[
|
||||
'name' => 'Fly tickets.pdf',
|
||||
'basename' => 'Project Notes.pdf',
|
||||
'mimetype' => 'pdf',
|
||||
],
|
||||
[
|
||||
'name' => 'Documentation.pdf',
|
||||
'basename' => 'School Report.pages',
|
||||
'mimetype' => 'pages',
|
||||
],
|
||||
])
|
||||
->each(function ($file) use ($users, $user, $holiday2022Folder) {
|
||||
$author = $users[rand(0, 2)];
|
||||
|
||||
$basename = Str::random(12) . '-' . $file['basename'];
|
||||
|
||||
// Copy file into app storage
|
||||
Storage::putFileAs("files/$user->id", storage_path("demo/documents/{$file['basename']}"), $basename, 'private');
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $holiday2022Folder->id,
|
||||
'user_id' => $user->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $file['name'],
|
||||
'basename' => $basename,
|
||||
'type' => 'file',
|
||||
'mimetype' => $file['mimetype'],
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
collect([$companyProjectFolder, $financeDocumentsFolder, $holiday2022Folder])
|
||||
->each(function ($folder) use ($user) {
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
'permission' => 'owner',
|
||||
]);
|
||||
});
|
||||
|
||||
// Attach members
|
||||
$members = User::whereNotIn('email', ['howdy@hi5ve.digital'])
|
||||
->get();
|
||||
|
||||
collect([$members[0]->id, $members[1]->id, $members[5]->id])
|
||||
->each(
|
||||
fn ($id) => DB::table('team_folder_members')
|
||||
->insert([
|
||||
'parent_id' => $companyProjectFolder->id,
|
||||
'user_id' => $id,
|
||||
'permission' => 'can-edit',
|
||||
])
|
||||
);
|
||||
|
||||
collect([$members[3]->id, $members[2]->id])
|
||||
->each(
|
||||
fn ($id) => DB::table('team_folder_members')
|
||||
->insert([
|
||||
'parent_id' => $financeDocumentsFolder->id,
|
||||
'user_id' => $id,
|
||||
'permission' => 'can-edit',
|
||||
])
|
||||
);
|
||||
|
||||
collect([$members[2]->id, $members[3]->id, $members[5]->id, $members[0]->id])
|
||||
->each(
|
||||
fn ($id) => DB::table('team_folder_members')
|
||||
->insert([
|
||||
'parent_id' => $holiday2022Folder->id,
|
||||
'user_id' => $id,
|
||||
'permission' => 'can-edit',
|
||||
])
|
||||
);
|
||||
|
||||
// Create invitations
|
||||
collect([$members[4], $members[5]])
|
||||
->each(
|
||||
fn ($user) => TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'email' => $user->email,
|
||||
'parent_id' => $companyProjectFolder->id,
|
||||
'inviter_id' => $companyProjectFolder->user_id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function create_share_with_me_team_folders_content(): void
|
||||
{
|
||||
$member = User::whereEmail('howdy@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$owner = User::whereEmail('alice@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$johan = User::whereEmail('johan@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$users = [$member, $johan];
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'team_folder' => true,
|
||||
'name' => "Alice's Project Files",
|
||||
]);
|
||||
|
||||
$videos = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'parent_id' => $folder->id,
|
||||
'name' => 'Videos',
|
||||
'team_folder' => true,
|
||||
]);
|
||||
|
||||
$hug = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $owner->id,
|
||||
'parent_id' => $folder->id,
|
||||
'name' => 'Digital Hug',
|
||||
'team_folder' => true,
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $owner->id,
|
||||
'permission' => 'owner',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $johan->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
// Get videos
|
||||
collect([
|
||||
'Apple Watch App Video Promotion.mp4',
|
||||
'Smart Watch 3D Device Pack for Element 3D.mp4',
|
||||
])
|
||||
->each(function ($file) use ($users, $owner, $videos) {
|
||||
$author = $users[rand(0, 1)];
|
||||
|
||||
$basename = Str::random(12) . '-' . $file;
|
||||
|
||||
// Copy file into app storage
|
||||
Storage::putFileAs("files/$owner->id", storage_path("demo/video/$file"), $basename, 'private');
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $videos->id,
|
||||
'user_id' => $owner->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $file,
|
||||
'basename' => $basename,
|
||||
'type' => 'video',
|
||||
'mimetype' => 'mp4',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
collect([
|
||||
[
|
||||
'name' => 'Notes',
|
||||
'basename' => 'Licence.pdf',
|
||||
'mimetype' => 'pdf',
|
||||
],
|
||||
])
|
||||
->each(function ($file) use ($users, $owner, $folder) {
|
||||
$basename = Str::random(12) . '-' . $file['basename'];
|
||||
|
||||
$author = $users[rand(0, 1)];
|
||||
|
||||
// Copy file into app storage
|
||||
Storage::putFileAs("files/$owner->id", storage_path("demo/documents/{$file['basename']}"), $basename, 'private');
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $owner->id,
|
||||
'creator_id' => $author->id,
|
||||
'name' => $file['name'],
|
||||
'basename' => $basename,
|
||||
'type' => 'file',
|
||||
'mimetype' => $file['mimetype'],
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
// Get meme gallery
|
||||
collect([
|
||||
'demo/images/memes/Sofishticated.jpg',
|
||||
'demo/images/memes/whaaaaat.jpg',
|
||||
])
|
||||
->each(function ($file) use ($owner, $folder) {
|
||||
$thumbnail = $this->generate_thumbnails($file, $owner);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $owner->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
// Get meme gallery
|
||||
collect([
|
||||
'demo/images/memes/You Are My Sunshine.jpg',
|
||||
])
|
||||
->each(function ($file) use ($johan, $owner, $folder) {
|
||||
$thumbnail = $this->generate_thumbnails($file, $owner);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $owner->id,
|
||||
'creator_id' => $johan->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
|
||||
collect([
|
||||
'demo/images/memes/Eggcited bro.jpg',
|
||||
'demo/images/memes/Get a Rest.jpg',
|
||||
])
|
||||
->each(function ($file) use ($member, $owner, $hug) {
|
||||
$thumbnail = $this->generate_thumbnails($file, $owner);
|
||||
|
||||
// Create file record
|
||||
File::create([
|
||||
'parent_id' => $hug->id,
|
||||
'user_id' => $owner->id,
|
||||
'creator_id' => $member->id,
|
||||
'name' => $thumbnail['name'],
|
||||
'basename' => $thumbnail['basename'],
|
||||
'type' => 'image',
|
||||
'mimetype' => 'jpg',
|
||||
'filesize' => rand(1000000, 4000000),
|
||||
'created_at' => now()->subMinutes(rand(1, 5)),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
private function create_share_records(): void
|
||||
{
|
||||
$user = User::whereEmail('howdy@hi5ve.digital')
|
||||
@@ -1450,14 +790,6 @@ class SetupDevEnvironment extends Command
|
||||
'name' => 'registration',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'user_verification',
|
||||
'value' => 0,
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_payments',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'storage_limitation',
|
||||
'value' => 1,
|
||||
@@ -1466,17 +798,13 @@ class SetupDevEnvironment extends Command
|
||||
'name' => 'default_max_storage_amount',
|
||||
'value' => 5,
|
||||
],
|
||||
[
|
||||
'name' => 'default_max_team_member',
|
||||
'value' => 10,
|
||||
],
|
||||
[
|
||||
'name' => 'setup_wizard_success',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'license',
|
||||
'value' => $this->argument('license'),
|
||||
'value' => 'regular',
|
||||
],
|
||||
[
|
||||
'name' => 'purchase_code',
|
||||
@@ -1514,30 +842,6 @@ class SetupDevEnvironment extends Command
|
||||
'name' => 'billing_vat_number',
|
||||
'value' => '41241241234',
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_registration_bonus',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'registration_bonus_amount',
|
||||
'value' => 10,
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_paypal',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_paystack',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_stripe',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'subscription_type',
|
||||
'value' => 'none',
|
||||
],
|
||||
[
|
||||
'name' => 'allowed_recaptcha',
|
||||
'value' => 0,
|
||||
|
||||
@@ -5,7 +5,6 @@ use App\Users\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Domain\Settings\Models\Setting;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Domain\Pages\Actions\SeedDefaultPagesAction;
|
||||
use Domain\Settings\Actions\SeedDefaultSettingsAction;
|
||||
use Domain\Localization\Actions\SeedDefaultLanguageAction;
|
||||
use Domain\SetupWizard\Actions\CreateDiskDirectoriesAction;
|
||||
@@ -17,7 +16,7 @@ class SetupProdEnvironment extends Command
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'setup:prod {license=extended}';
|
||||
protected $signature = 'setup:prod';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -30,7 +29,6 @@ class SetupProdEnvironment extends Command
|
||||
private CreateDiskDirectoriesAction $createDiskDirectories,
|
||||
private SeedDefaultSettingsAction $seedDefaultSettings,
|
||||
private SeedDefaultLanguageAction $seedDefaultLanguage,
|
||||
private SeedDefaultPagesAction $seedDefaultPages,
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->setUpFaker();
|
||||
@@ -54,7 +52,6 @@ class SetupProdEnvironment extends Command
|
||||
$this->info('Storing default settings and content...');
|
||||
$this->store_default_settings();
|
||||
|
||||
($this->seedDefaultPages)();
|
||||
($this->seedDefaultSettings)($this->argument('license'));
|
||||
($this->seedDefaultLanguage)();
|
||||
|
||||
@@ -129,14 +126,6 @@ class SetupProdEnvironment extends Command
|
||||
'name' => 'contact_email',
|
||||
'value' => null,
|
||||
],
|
||||
[
|
||||
'name' => 'registration',
|
||||
'value' => 0,
|
||||
],
|
||||
[
|
||||
'name' => 'user_verification',
|
||||
'value' => 0,
|
||||
],
|
||||
[
|
||||
'name' => 'storage_limitation',
|
||||
'value' => 1,
|
||||
@@ -145,17 +134,13 @@ class SetupProdEnvironment extends Command
|
||||
'name' => 'default_max_storage_amount',
|
||||
'value' => 5,
|
||||
],
|
||||
[
|
||||
'name' => 'default_max_team_member',
|
||||
'value' => 10,
|
||||
],
|
||||
[
|
||||
'name' => 'setup_wizard_success',
|
||||
'value' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'license',
|
||||
'value' => $this->argument('license'),
|
||||
'value' => 'regular',
|
||||
],
|
||||
[
|
||||
'name' => 'purchase_code',
|
||||
@@ -203,20 +188,6 @@ class SetupProdEnvironment extends Command
|
||||
'value' => $col['value'],
|
||||
]);
|
||||
});
|
||||
|
||||
if ($this->argument('license') === 'extended') {
|
||||
$choice = $this->choice('Choose subscription type', [
|
||||
'metered' => 'Metered',
|
||||
'fixed' => 'Fixed',
|
||||
'none' => 'None',
|
||||
]);
|
||||
|
||||
Setting::updateOrCreate([
|
||||
'name' => 'subscription_type',
|
||||
], [
|
||||
'value' => $choice,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,16 +4,12 @@ namespace App\Console;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use App\Console\Commands\SetupDevEnvironment;
|
||||
use App\Console\Commands\SetupProdEnvironment;
|
||||
use Support\Scheduler\Actions\ReportUsageAction;
|
||||
use Support\Upgrading\Actions\UpdateSystemAction;
|
||||
use Support\Demo\Actions\ClearHowdyDemoDataAction;
|
||||
use App\Console\Commands\SetupWebsocketEnvironment;
|
||||
use Support\Scheduler\Actions\DeleteFailedFilesAction;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Support\Scheduler\Actions\DeleteUnverifiedUsersAction;
|
||||
use Support\Scheduler\Actions\DeleteExpiredShareLinksAction;
|
||||
use App\Console\Commands\GenerateDemoSubscriptionContentCommand;
|
||||
use Support\Scheduler\Actions\ExpireUnfilledUploadRequestAction;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
@@ -26,10 +22,6 @@ class Kernel extends ConsoleKernel
|
||||
// Basic demo content generator
|
||||
SetupDevEnvironment::class,
|
||||
SetupProdEnvironment::class,
|
||||
SetupWebsocketEnvironment::class,
|
||||
|
||||
// Subscription demo generator
|
||||
GenerateDemoSubscriptionContentCommand::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -53,10 +45,6 @@ class Kernel extends ConsoleKernel
|
||||
fn () => resolve(DeleteExpiredShareLinksAction::class)()
|
||||
)->everyTenMinutes();
|
||||
|
||||
$schedule->call(
|
||||
fn () => resolve(ExpireUnfilledUploadRequestAction::class)()
|
||||
)->hourly();
|
||||
|
||||
$schedule->call(
|
||||
fn () => resolve(UpdateSystemAction::class)()
|
||||
)->everyMinute();
|
||||
@@ -65,10 +53,6 @@ class Kernel extends ConsoleKernel
|
||||
fn () => resolve(DeleteUnverifiedUsersAction::class)()
|
||||
)->daily()->at('00:05');
|
||||
|
||||
$schedule->call(
|
||||
fn () => resolve(ReportUsageAction::class)()
|
||||
)->daily()->at('00:10');
|
||||
|
||||
// Run queue jobs every minute
|
||||
$schedule->command('queue:work --queue=high,default --max-time=300')
|
||||
->everyFiveMinutes()
|
||||
|
||||
@@ -15,7 +15,6 @@ use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
use Support\Middleware\PreventRequestsDuringMaintenance;
|
||||
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Domain\UploadRequest\Middleware\ProtectUploadRequestRoutes;
|
||||
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
|
||||
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
|
||||
|
||||
@@ -78,6 +77,5 @@ class Kernel extends HttpKernel
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'admin' => AdminCheck::class,
|
||||
'setup-wizard' => ProtectSetupWizardRoutes::class,
|
||||
'upload-request' => ProtectUploadRequestRoutes::class,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -45,9 +45,6 @@ class AuthServiceProvider extends ServiceProvider
|
||||
if ($user?->id === $item->user_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check team member ability to access into requested item
|
||||
return $this->teamMemberGuard($item, $user, $ability);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,17 +82,4 @@ class AuthServiceProvider extends ServiceProvider
|
||||
|
||||
return $share->user_id === $item->user_id;
|
||||
}
|
||||
|
||||
private function teamMemberGuard(Folder | File $item, ?User $user, $ability): bool
|
||||
{
|
||||
$teamFolder = $item->getLatestParent();
|
||||
|
||||
$membership = DB::table('team_folder_members')
|
||||
->where('parent_id', $teamFolder->id)
|
||||
->where('user_id', $user->id)
|
||||
->first();
|
||||
|
||||
// check existing members permission or check team folder owner privileges
|
||||
return $membership?->permission === $ability || $teamFolder->user_id === Auth::id();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
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;
|
||||
|
||||
@@ -25,7 +24,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
* @var array
|
||||
*/
|
||||
protected $subscribe = [
|
||||
SubscriptionEventSubscriber::class,
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,10 +43,6 @@ class RouteServiceProvider extends ServiceProvider
|
||||
->middleware('api')
|
||||
->group(base_path('routes/share.php'));
|
||||
|
||||
Route::prefix('api/upload-request')
|
||||
->middleware('api')
|
||||
->group(base_path('routes/upload-request.php'));
|
||||
|
||||
Route::prefix('api/admin')
|
||||
->middleware(['api', 'auth:sanctum', 'admin'])
|
||||
->group(base_path('routes/admin.php'));
|
||||
@@ -64,10 +60,6 @@ class RouteServiceProvider extends ServiceProvider
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/file.php'));
|
||||
|
||||
Route::prefix('api/teams')
|
||||
->middleware(['api'])
|
||||
->group(base_path('routes/teams.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
|
||||
@@ -12,32 +12,14 @@ use VueFileManager\Subscription\Domain\Plans\Exceptions\MeteredBillingPlanDoesnt
|
||||
|
||||
class CreateNewUserAction extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AutoSubscribeForMeteredBillingAction $autoSubscribeForMeteredBilling,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and create a new user.
|
||||
*
|
||||
* @throws MeteredBillingPlanDoesntExist
|
||||
*/
|
||||
public function __invoke(CreateUserData $data): User
|
||||
{
|
||||
// Check if subscription metered billing plan exist
|
||||
$this->checkMeteredBillingPlan($data);
|
||||
|
||||
// Create user
|
||||
$user = $this->createUser($data);
|
||||
|
||||
// Join to previously accepted team folder invitations
|
||||
$this->applyExistingTeamInvitations($user);
|
||||
|
||||
// Subscribe user for metered billing
|
||||
if (get_settings('subscription_type') === 'metered' && $data->role !== 'admin') {
|
||||
($this->autoSubscribeForMeteredBilling)($user);
|
||||
}
|
||||
|
||||
// Mark as verified if verification is disabled
|
||||
if (! $data->password || ! intval(get_settings('user_verification'))) {
|
||||
$user->markEmailAsVerified();
|
||||
@@ -48,43 +30,10 @@ class CreateNewUserAction extends Controller
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MeteredBillingPlanDoesntExist
|
||||
*/
|
||||
private function checkMeteredBillingPlan(CreateUserData $data): void
|
||||
{
|
||||
if (get_settings('subscription_type') === 'metered' && $data->role !== 'admin') {
|
||||
// Get metered plan
|
||||
$plan = Plan::where('status', 'active')
|
||||
->where('type', 'metered');
|
||||
|
||||
if ($plan->doesntExist()) {
|
||||
throw new MeteredBillingPlanDoesntExist();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function applyExistingTeamInvitations(User $user): void
|
||||
{
|
||||
TeamFolderInvitation::where('email', $user->email)
|
||||
->where('status', 'waiting-for-registration')
|
||||
->cursor()
|
||||
->each(function ($invitation) use ($user) {
|
||||
TeamFolderMember::create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $invitation->parent_id,
|
||||
'permission' => $invitation->permission,
|
||||
]);
|
||||
|
||||
$invitation->accept();
|
||||
});
|
||||
}
|
||||
|
||||
private function createUser(CreateUserData $data): User
|
||||
{
|
||||
$user = User::create([
|
||||
'password' => $data->password ? bcrypt($data->password) : null,
|
||||
'oauth_provider' => $data->oauth_provider,
|
||||
'email' => $data->email,
|
||||
]);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class CheckAccountController extends Controller
|
||||
'name' => $user->settings->first_name,
|
||||
'avatar' => $user->settings->avatar,
|
||||
'verified' => $user->email_verified_at ? 1 : 0,
|
||||
'oauth_provider' => $user->password ? null : $user->oauth_provider,
|
||||
'oauth_provider' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
namespace App\Users\Controllers\Authentication;
|
||||
|
||||
use App\Users\DTO\CreateUserData;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Users\Actions\CreateNewUserAction;
|
||||
use App\Users\Requests\RegisterUserRequest;
|
||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
use VueFileManager\Subscription\Domain\Plans\Exceptions\MeteredBillingPlanDoesntExist;
|
||||
|
||||
class RegisterUserController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected CreateNewUserAction $createNewUser,
|
||||
protected StatefulGuard $guard,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(RegisterUserRequest $request)
|
||||
{
|
||||
// Check if account registration is enabled
|
||||
if (! intval(get_settings('registration'))) {
|
||||
return response([
|
||||
'type' => 'error',
|
||||
'message' => 'User registration is not allowed',
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Map registration data
|
||||
$data = CreateUserData::fromArray([
|
||||
'name' => $request->input('name'),
|
||||
'email' => $request->input('email'),
|
||||
'password' => $request->input('password'),
|
||||
]);
|
||||
|
||||
// Register user
|
||||
try {
|
||||
$user = ($this->createNewUser)($data);
|
||||
} catch (MeteredBillingPlanDoesntExist $e) {
|
||||
return response([
|
||||
'type' => 'error',
|
||||
'message' => 'User registrations are temporarily disabled',
|
||||
], 409);
|
||||
}
|
||||
|
||||
// Log in if verification is disabled
|
||||
if (! $user->password || ! intval(get_settings('user_verification'))) {
|
||||
$this->guard->login($user);
|
||||
}
|
||||
|
||||
return response('User successfully registered.', 201);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ class CreateUserData extends DataTransferObject
|
||||
public string $name;
|
||||
public string $email;
|
||||
public ?string $password;
|
||||
public ?string $oauth_provider;
|
||||
public ?string $avatar;
|
||||
|
||||
public static function fromRequest($request): self
|
||||
@@ -20,7 +19,6 @@ class CreateUserData extends DataTransferObject
|
||||
'email' => $request->input('email'),
|
||||
'avatar' => $request->input('avatar') ?? null,
|
||||
'password' => $request->input('password'),
|
||||
'oauth_provider' => $request->input('oauth_provider') ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -32,7 +30,6 @@ class CreateUserData extends DataTransferObject
|
||||
'email' => $array['email'],
|
||||
'avatar' => $array['avatar'] ?? null,
|
||||
'password' => $array['password'] ?? null,
|
||||
'oauth_provider' => $array['oauth_provider'] ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use App\Users\Notifications\ResetPassword;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use Domain\UploadRequest\Models\UploadRequest;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Users\Restrictions\RestrictionsManager;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
@@ -23,7 +22,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use VueFileManager\Subscription\App\User\Traits\Billable;
|
||||
|
||||
/**
|
||||
* @property string id
|
||||
@@ -47,7 +45,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
use Notifiable;
|
||||
use HasFactory;
|
||||
use Sortable;
|
||||
use Billable;
|
||||
|
||||
protected $guarded = [
|
||||
'id',
|
||||
@@ -57,7 +54,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
protected $fillable = [
|
||||
'email',
|
||||
'password',
|
||||
'oauth_provider',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -138,8 +134,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*/
|
||||
public function favouriteFolders(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Folder::class, 'favourite_folder', 'user_id', 'parent_id', 'id', 'id')
|
||||
->where('team_folder', false);
|
||||
return $this->belongsToMany(Folder::class, 'favourite_folder', 'user_id', 'parent_id', 'id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,11 +177,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return $this->hasMany(Traffic::class);
|
||||
}
|
||||
|
||||
public function uploadRequest(): HasOne
|
||||
{
|
||||
return $this->hasOne(UploadRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the password reset notification.
|
||||
*/
|
||||
@@ -216,7 +206,6 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
// Create default limitations
|
||||
$user->limitations()->create([
|
||||
'max_storage_amount' => get_settings('default_max_storage_amount') ?? 1,
|
||||
'max_team_members' => get_settings('default_max_team_member') ?? 10,
|
||||
]);
|
||||
|
||||
// Create user directory for his files
|
||||
|
||||
@@ -46,7 +46,6 @@ class UserLimitation extends Model
|
||||
{
|
||||
return [
|
||||
'max_storage_amount' => $this->getMaxStorageAmount(),
|
||||
'max_team_members' => $this->getMaxTeamMembers(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -63,44 +62,4 @@ class UserLimitation extends Model
|
||||
'percentage' => get_storage_percentage($userCapacity, $this->max_storage_amount),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get usage data of team members
|
||||
*/
|
||||
private function getMaxTeamMembers(): array
|
||||
{
|
||||
$userTeamFolderIds = DB::table('team_folder_members')
|
||||
->where('user_id', $this->user_id)
|
||||
->pluck('parent_id');
|
||||
|
||||
$memberIds = DB::table('team_folder_members')
|
||||
->where('user_id', '!=', $this->user_id)
|
||||
->whereIn('parent_id', $userTeamFolderIds)
|
||||
->pluck('user_id')
|
||||
->unique();
|
||||
|
||||
// Get member emails
|
||||
$memberEmails = User::whereIn('id', $memberIds)
|
||||
->pluck('email');
|
||||
|
||||
// Get active invitation emails
|
||||
$InvitationEmails = DB::table('team_folder_invitations')
|
||||
->where('status', 'pending')
|
||||
->where('inviter_id', $this->user_id)
|
||||
->pluck('email')
|
||||
->unique();
|
||||
|
||||
// Get allowed emails in the limit
|
||||
$totalUsedEmails = $memberEmails->merge($InvitationEmails)
|
||||
->unique();
|
||||
|
||||
return [
|
||||
'use' => $totalUsedEmails->count(),
|
||||
'total' => (int) $this->max_team_members,
|
||||
'percentage' => ($totalUsedEmails->count() / $this->max_team_members) * 100,
|
||||
'meta' => [
|
||||
'allowed_emails' => $totalUsedEmails,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,6 @@ namespace App\Users\Resources;
|
||||
|
||||
use Domain\Folders\Resources\FolderCollection;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Users\Actions\FormatUsageEstimatesAction;
|
||||
use Domain\Notifications\Resources\NotificationCollection;
|
||||
use VueFileManager\Subscription\Domain\Credits\Resources\BalanceResource;
|
||||
use VueFileManager\Subscription\Domain\CreditCards\Resources\CreditCardCollection;
|
||||
use VueFileManager\Subscription\Domain\BillingAlerts\Resources\BillingAlertResource;
|
||||
use VueFileManager\Subscription\Domain\Subscriptions\Resources\SubscriptionResource;
|
||||
use VueFileManager\Subscription\Domain\Usage\Actions\SumUsageForCurrentPeriodAction;
|
||||
use VueFileManager\Subscription\Domain\FailedPayments\Resources\FailedPaymentsCollection;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
@@ -22,11 +14,6 @@ class UserResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$subscriptionType = get_settings('subscription_type');
|
||||
|
||||
$isMeteredSubscription = $subscriptionType === 'metered';
|
||||
$isFixedSubscription = $subscriptionType === 'fixed';
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'id' => $this->id,
|
||||
@@ -44,63 +31,17 @@ class UserResource extends JsonResource
|
||||
'updated_at' => format_date($this->updated_at, 'd. M. Y'),
|
||||
],
|
||||
'relationships' => [
|
||||
'readNotifications' => new NotificationCollection($this->readNotifications),
|
||||
'unreadNotifications' => new NotificationCollection($this->unreadNotifications),
|
||||
'settings' => new SettingsResource($this->settings),
|
||||
'favourites' => new FolderCollection($this->favouriteFolders),
|
||||
'creditCards' => new CreditCardCollection($this->creditCards),
|
||||
$this->mergeWhen($this->hasSubscription(), fn () => [
|
||||
'subscription' => new SubscriptionResource($this->subscription),
|
||||
]),
|
||||
$this->mergeWhen($isMeteredSubscription && $this->hasSubscription(), fn () => [
|
||||
'balance' => new BalanceResource($this->balance),
|
||||
]),
|
||||
$this->mergeWhen($isMeteredSubscription && $this->hasSubscription(), fn () => [
|
||||
'alert' => new BillingAlertResource($this->billingAlert),
|
||||
]),
|
||||
$this->mergeWhen($isMeteredSubscription && $this->hasSubscription(), fn () => [
|
||||
'failedPayments' => new FailedPaymentsCollection($this->failedPayments),
|
||||
]),
|
||||
],
|
||||
'meta' => [
|
||||
'restrictions' => [
|
||||
'canUpload' => $this->canUpload(),
|
||||
'canDownload' => $this->canDownload(),
|
||||
'canCreateFolder' => $this->canCreateFolder(),
|
||||
'canCreateTeamFolder' => $this->canCreateTeamFolder(),
|
||||
'canInviteTeamMembers' => $this->canInviteTeamMembers(),
|
||||
],
|
||||
$this->mergeWhen($isFixedSubscription, fn () => [
|
||||
'limitations' => $this->limitations->summary(),
|
||||
]),
|
||||
$this->mergeWhen($isMeteredSubscription && $this->hasSubscription(), fn () => [
|
||||
'usages' => $this->getUsageEstimates(),
|
||||
]),
|
||||
$this->mergeWhen($isMeteredSubscription && $this->hasSubscription(), fn () => [
|
||||
'totalDebt' => [
|
||||
'formatted' => format_currency($this->failedPayments->sum('amount'), $this->subscription->plan->currency),
|
||||
'amount' => $this->failedPayments->sum('amount'),
|
||||
],
|
||||
]),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function getUsageEstimates()
|
||||
{
|
||||
// Get plan currency
|
||||
$currency = $this->subscription->plan->currency;
|
||||
|
||||
// Get usage
|
||||
$usage = resolve(SumUsageForCurrentPeriodAction::class)($this->subscription);
|
||||
|
||||
// Format usages
|
||||
$estimates = resolve(FormatUsageEstimatesAction::class)($currency, $usage);
|
||||
|
||||
return [
|
||||
'costEstimate' => format_currency($estimates->sum('amount'), $currency),
|
||||
'featureEstimates' => $estimates->toArray(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,7 @@ class UserStorageResource extends JsonResource
|
||||
list($images, $audios, $videos, $documents, $others) = $this->get_file_type_distribution();
|
||||
list($downloadTotal, $uploadTotal, $upload, $download) = $this->get_traffic_distribution();
|
||||
|
||||
$totalCapacity = match (get_settings('subscription_type')) {
|
||||
'metered' => $this->usedCapacity / 1000000000,
|
||||
'fixed' => $this->limitations->max_storage_amount,
|
||||
default => $this->limitations->max_storage_amount,
|
||||
};
|
||||
$totalCapacity = $this->limitations->max_storage_amount;
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
|
||||
@@ -33,16 +33,6 @@ class DefaultRestrictionsEngine implements RestrictionsEngine
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canCreateTeamFolder(User $user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canInviteTeamMembers(User $user, array $newInvites = []): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canVisitShared(User $user): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -11,9 +11,5 @@ interface RestrictionsEngine
|
||||
|
||||
public function canCreateFolder(User $user): bool;
|
||||
|
||||
public function canCreateTeamFolder(User $user): bool;
|
||||
|
||||
public function canInviteTeamMembers(User $user, array $newInvites = []): bool;
|
||||
|
||||
public function canVisitShared(User $user): bool;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ namespace App\Users\Restrictions;
|
||||
|
||||
use Illuminate\Support\Manager;
|
||||
use App\Users\Restrictions\Engines\DefaultRestrictionsEngine;
|
||||
use App\Users\Restrictions\Engines\FixedBillingRestrictionsEngine;
|
||||
use App\Users\Restrictions\Engines\MeteredBillingRestrictionsEngine;
|
||||
|
||||
class RestrictionsManager extends Manager
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user