diff --git a/routes/admin.php b/routes/admin.php index abd335e3..c7353870 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -9,13 +9,13 @@ use Domain\Admin\Controllers\Users\DeleteUserController; use Domain\Settings\Controllers\GetSettingsValueController; use Domain\Admin\Controllers\Dashboard\GetNewbiesController; use Domain\Admin\Controllers\Users\ChangeUserRoleController; -use Domain\Settings\Controllers\StoreSocialServiceCredentialsController; use Domain\Settings\Controllers\UpdateSettingValueController; use Domain\Admin\Controllers\Users\ResetUserPasswordController; use Domain\Admin\Controllers\Dashboard\GetDashboardDataController; use Domain\Localization\Controllers\UpdateLanguageStringController; use Domain\Admin\Controllers\Users\ShowUserStorageCapacityController; use Domain\Admin\Controllers\Users\ChangeUserStorageCapacityController; +use Domain\Settings\Controllers\StoreSocialServiceCredentialsController; use Domain\Settings\Controllers\StorePaymentServiceCredentialsController; // Dashboard diff --git a/src/App/Console/Commands/GenerateDemoSubscriptionContentCommand.php b/src/App/Console/Commands/GenerateDemoSubscriptionContentCommand.php index a9f52c6b..6506255d 100644 --- a/src/App/Console/Commands/GenerateDemoSubscriptionContentCommand.php +++ b/src/App/Console/Commands/GenerateDemoSubscriptionContentCommand.php @@ -45,6 +45,9 @@ class GenerateDemoSubscriptionContentCommand extends Command // Create plans and subscriptions for fixed billing if ($this->argument('type') === 'fixed') { + + // TODO: check for credentials + $this->info('Setting up new fixed plans demo data...'); $this->generateFixedPlans(); diff --git a/src/App/Users/Actions/AutoSubscribeForMeteredBillingAction.php b/src/App/Users/Actions/AutoSubscribeForMeteredBillingAction.php index 46ad7d2c..5c8fc836 100644 --- a/src/App/Users/Actions/AutoSubscribeForMeteredBillingAction.php +++ b/src/App/Users/Actions/AutoSubscribeForMeteredBillingAction.php @@ -39,7 +39,7 @@ class AutoSubscribeForMeteredBillingAction } else { // Create balance with 0 amount $user->balance()->create([ - 'amount' => 0, + 'amount' => 0, 'currency' => $plan->currency, ]); } diff --git a/src/App/Users/Actions/CreateNewUserAction.php b/src/App/Users/Actions/CreateNewUserAction.php index e92ead14..800dc303 100644 --- a/src/App/Users/Actions/CreateNewUserAction.php +++ b/src/App/Users/Actions/CreateNewUserAction.php @@ -1,8 +1,8 @@ $this->usedCapacity / 1000000000, - 'fixed' => $this->limitations->max_storage_amount, - default => $this->limitations->max_storage_amount, + 'fixed' => $this->limitations->max_storage_amount, + default => $this->limitations->max_storage_amount, }; return [ 'data' => [ - 'id' => (string)$this->id, + 'id' => (string) $this->id, 'type' => 'storage', 'attributes' => [ 'used' => Metric::bytes($this->usedCapacity)->format(), 'capacity' => format_gigabytes($totalCapacity), - 'percentage' => (float)get_storage_percentage($this->usedCapacity, $totalCapacity), + 'percentage' => (float) get_storage_percentage($this->usedCapacity, $totalCapacity), ], 'meta' => [ 'traffic' => [ @@ -46,23 +44,23 @@ class UserStorageResource extends JsonResource ], 'images' => [ 'used' => Metric::bytes($images)->format(), - 'percentage' => (float)get_storage_percentage($images, $totalCapacity), + 'percentage' => (float) get_storage_percentage($images, $totalCapacity), ], 'audios' => [ 'used' => Metric::bytes($audios)->format(), - 'percentage' => (float)get_storage_percentage($audios, $totalCapacity), + 'percentage' => (float) get_storage_percentage($audios, $totalCapacity), ], 'videos' => [ 'used' => Metric::bytes($videos)->format(), - 'percentage' => (float)get_storage_percentage($videos, $totalCapacity), + 'percentage' => (float) get_storage_percentage($videos, $totalCapacity), ], 'documents' => [ 'used' => Metric::bytes($documents)->format(), - 'percentage' => (float)get_storage_percentage($documents, $totalCapacity), + 'percentage' => (float) get_storage_percentage($documents, $totalCapacity), ], 'others' => [ 'used' => Metric::bytes($others)->format(), - 'percentage' => (float)get_storage_percentage($others, $totalCapacity), + 'percentage' => (float) get_storage_percentage($others, $totalCapacity), ], ], ], @@ -134,12 +132,12 @@ class UserStorageResource extends JsonResource ->orderBy('created_at') ->get(); - $upload = $trafficRecords->map(fn($record) => [ + $upload = $trafficRecords->map(fn ($record) => [ 'created_at' => format_date($record->created_at), 'amount' => $uploadMax !== 0 ? round(($record->upload / $uploadMax) * 100, 2) : 0, ]); - $download = $trafficRecords->map(fn($record) => [ + $download = $trafficRecords->map(fn ($record) => [ 'created_at' => format_date($record->created_at), 'amount' => $downloadMax !== 0 ? round(($record->download / $downloadMax) * 100, 2) : 0, ]); diff --git a/src/Domain/Admin/Controllers/Dashboard/GetDashboardDataController.php b/src/Domain/Admin/Controllers/Dashboard/GetDashboardDataController.php index 5208ef40..419f87a3 100644 --- a/src/Domain/Admin/Controllers/Dashboard/GetDashboardDataController.php +++ b/src/Domain/Admin/Controllers/Dashboard/GetDashboardDataController.php @@ -1,14 +1,13 @@ select( DB::raw('DATE(created_at) as created_at'), DB::raw('sum(download) as download'), - DB::raw('sum(upload) as upload')) + DB::raw('sum(upload) as upload') + ) ->groupBy('created_at') ->get(); - $upload = $trafficRecords->map(fn($record) => [ + $upload = $trafficRecords->map(fn ($record) => [ 'created_at' => format_date($record->created_at, '%d. %B. %Y'), 'amount' => intval($trafficRecords->max('upload')) !== 0 ? round(($record->upload / $trafficRecords->max('upload')) * 100, 2) : 0, ]); - $download = $trafficRecords->map(fn($record) => [ + $download = $trafficRecords->map(fn ($record) => [ 'created_at' => format_date($record->created_at, '%d. %B. %Y'), 'amount' => intval($trafficRecords->max('download')) !== 0 ? round(($record->download / $trafficRecords->max('download')) * 100, 2) : 0, ]); diff --git a/src/Domain/Settings/Controllers/StoreSocialServiceCredentialsController.php b/src/Domain/Settings/Controllers/StoreSocialServiceCredentialsController.php index 45c414e3..f541a43d 100644 --- a/src/Domain/Settings/Controllers/StoreSocialServiceCredentialsController.php +++ b/src/Domain/Settings/Controllers/StoreSocialServiceCredentialsController.php @@ -27,11 +27,11 @@ class StoreSocialServiceCredentialsController if (! app()->runningUnitTests()) { $credentials = [ 'facebook' => [ - 'FACEBOOK_CLIENT_ID' => $request->input('client_id'), + 'FACEBOOK_CLIENT_ID' => $request->input('client_id'), 'FACEBOOK_CLIENT_SECRET' => $request->input('client_secret'), ], 'google' => [ - 'GOOGLE_CLIENT_ID' => $request->input('client_id'), + 'GOOGLE_CLIENT_ID' => $request->input('client_id'), 'GOOGLE_CLIENT_SECRET' => $request->input('client_secret'), ], 'github' => [ diff --git a/src/Domain/Settings/Requests/StoreSocialServiceCredentialsRequest.php b/src/Domain/Settings/Requests/StoreSocialServiceCredentialsRequest.php index 370c8821..55f577d1 100644 --- a/src/Domain/Settings/Requests/StoreSocialServiceCredentialsRequest.php +++ b/src/Domain/Settings/Requests/StoreSocialServiceCredentialsRequest.php @@ -1,5 +1,4 @@ (string) $user->id, 'type' => 'user', 'attributes' => [ - 'avatar' => null, + 'avatar' => [ + 'md' => 'http://localhost/assets/images/default-avatar.png', + 'sm' => 'http://localhost/assets/images/default-avatar.png', + 'xs' => 'http://localhost/assets/images/default-avatar.png', + ], 'email' => $user->email, 'role' => $user->role, + 'socialite_account' => false, 'two_factor_authentication' => false, 'folders' => [], 'storage' => [ @@ -151,9 +156,21 @@ class UserAccountTest extends TestCase 'capacity_formatted' => '1GB', ], 'created_at' => format_date($user->created_at, '%d. %b. %Y'), - 'updated_at' => format_date($user->updated_at, '%d. %b. %Y'), + 'updated_at' => format_date($user->updated_at, '%d. %B. %Y'), + ], + 'meta' => [ + 'restrictions' => [ + 'canCreateFolder' => true, + 'canCreateTeamFolder' => true, + 'canDownload' => true, + 'canInviteTeamMembers' => true, + 'canUpload' => true, + ], ], 'relationships' => [ + 'creditCards' => [ + 'data' => [], + ], 'settings' => [ 'data' => [ 'id' => (string) $user->id, @@ -174,13 +191,6 @@ class UserAccountTest extends TestCase 'favourites' => [ 'data' => [], ], - 'limitations' => [ - 'id' => $user->id, - 'type' => 'limitations', - 'data' => [ - 'attributes' => $user->limitations, - ], - ], ], ], ]); diff --git a/tests/Domain/Admin/AdminTest.php b/tests/Domain/Admin/AdminTest.php index 432c9b76..784110b7 100644 --- a/tests/Domain/Admin/AdminTest.php +++ b/tests/Domain/Admin/AdminTest.php @@ -131,6 +131,14 @@ class AdminTest extends TestCase 'used' => '1.00MB', 'percentage' => 0.1, ], + 'traffic' => [ + 'chart' => [ + 'download' => [], + 'upload' => [], + ], + 'download' => '0B', + 'upload' => '0B', + ], ], ], ]); diff --git a/tests/Domain/Admin/DashboardTest.php b/tests/Domain/Admin/DashboardTest.php index 3e2669b5..e9ae1166 100644 --- a/tests/Domain/Admin/DashboardTest.php +++ b/tests/Domain/Admin/DashboardTest.php @@ -3,7 +3,6 @@ namespace Tests\Domain\Admin; use Tests\TestCase; use App\Users\Models\User; -use Laravel\Sanctum\Sanctum; use Domain\Files\Models\File; class DashboardTest extends TestCase @@ -25,11 +24,26 @@ class DashboardTest extends TestCase ->getJson('/api/admin/dashboard') ->assertStatus(200) ->assertExactJson([ - 'license' => 'extended', - 'total_premium_users' => 0, - 'app_version' => config('vuefilemanager.version'), - 'total_users' => 1, - 'total_used_space' => '2.00MB', + 'app' => [ + 'earnings' => '$0.00', + 'license' => 'extended', + 'version' => config('vuefilemanager.version'), + ], + 'disk' => [ + 'download' => [ + 'records' => [], + 'total' => '0B', + ], + 'upload' => [ + 'records' => [], + 'total' => '0B', + ], + 'used' => '2.00MB', + ], + 'users' => [ + 'total' => 1, + 'usersPremiumTotal' => 0, + ], ]); } @@ -39,20 +53,21 @@ class DashboardTest extends TestCase public function it_get_new_users_for_dashboard() { $users = User::factory() - ->count(5) + ->count(3) ->create(['role' => 'user']); $admin = User::factory() ->create(['role' => 'admin']); - Sanctum::actingAs($admin); - - $users->each(function ($user) { - $this->getJson('/api/admin/dashboard/newbies') + $users->each( + fn ($user) => + $this + ->actingAs($admin) + ->getJson('/api/admin/dashboard/newbies') ->assertStatus(200) ->assertJsonFragment([ 'id' => $user->id, - ]); - }); + ]) + ); } } diff --git a/tests/Domain/Settings/SettingsTest.php b/tests/Domain/Settings/SettingsTest.php index d82e41d5..25a58d70 100644 --- a/tests/Domain/Settings/SettingsTest.php +++ b/tests/Domain/Settings/SettingsTest.php @@ -1,5 +1,4 @@