mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-17 10:14:17 +00:00
Changes auto-committed by Conductor
This commit is contained in:
1 parent
1906278101
commit
975d1b8a6b
5 files changed
+790
-115
No files matched your search
@@ -30,7 +30,7 @@ class CancelSubscription
|
||||
$subscriptions = collect();
|
||||
|
||||
// Get all teams the user belongs to
|
||||
$teams = $this->user->teams;
|
||||
$teams = $this->user->teams()->get();
|
||||
|
||||
foreach ($teams as $team) {
|
||||
// Only include subscriptions from teams where user is owner
|
||||
@@ -49,6 +49,64 @@ class CancelSubscription
|
||||
return $subscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify subscriptions exist and are active in Stripe API
|
||||
*
|
||||
* @return array ['verified' => Collection, 'not_found' => Collection, 'errors' => array]
|
||||
*/
|
||||
public function verifySubscriptionsInStripe(): array
|
||||
{
|
||||
if (! isCloud()) {
|
||||
return [
|
||||
'verified' => collect(),
|
||||
'not_found' => collect(),
|
||||
'errors' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$stripe = new StripeClient(config('subscription.stripe_api_key'));
|
||||
$subscriptions = $this->getSubscriptionsPreview();
|
||||
|
||||
$verified = collect();
|
||||
$notFound = collect();
|
||||
$errors = [];
|
||||
|
||||
foreach ($subscriptions as $subscription) {
|
||||
try {
|
||||
$stripeSubscription = $stripe->subscriptions->retrieve($subscription->stripe_subscription_id);
|
||||
|
||||
// Check if subscription is actually active in Stripe
|
||||
if (in_array($stripeSubscription->status, ['active', 'trialing', 'past_due'])) {
|
||||
$verified->push([
|
||||
'subscription' => $subscription,
|
||||
'stripe_status' => $stripeSubscription->status,
|
||||
'current_period_end' => $stripeSubscription->current_period_end,
|
||||
]);
|
||||
} else {
|
||||
$notFound->push([
|
||||
'subscription' => $subscription,
|
||||
'reason' => "Status in Stripe: {$stripeSubscription->status}",
|
||||
]);
|
||||
}
|
||||
} catch (\Stripe\Exception\InvalidRequestException $e) {
|
||||
// Subscription doesn't exist in Stripe
|
||||
$notFound->push([
|
||||
'subscription' => $subscription,
|
||||
'reason' => 'Not found in Stripe',
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = "Error verifying subscription {$subscription->stripe_subscription_id}: ".$e->getMessage();
|
||||
\Log::error("Error verifying subscription {$subscription->stripe_subscription_id}: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'verified' => $verified,
|
||||
'not_found' => $notFound,
|
||||
'errors' => $errors,
|
||||
];
|
||||
}
|
||||
|
||||
public function execute(): array
|
||||
{
|
||||
if ($this->isDryRun) {
|
||||
|
||||
@@ -24,23 +24,46 @@ class DeleteUserResources
|
||||
$services = collect();
|
||||
|
||||
// Get all teams the user belongs to
|
||||
$teams = $this->user->teams;
|
||||
$teams = $this->user->teams()->get();
|
||||
|
||||
foreach ($teams as $team) {
|
||||
// Only delete resources from teams that will be FULLY DELETED
|
||||
// This means: user is the ONLY member of the team
|
||||
//
|
||||
// DO NOT delete resources if:
|
||||
// - User is just a member (not owner)
|
||||
// - Team has other members (ownership will be transferred or user just removed)
|
||||
|
||||
$userRole = $team->pivot->role;
|
||||
$memberCount = $team->members->count();
|
||||
|
||||
// Skip if user is not owner
|
||||
if ($userRole !== 'owner') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip if team has other members (will be transferred/user removed, not deleted)
|
||||
if ($memberCount > 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only delete resources from teams where user is the ONLY member
|
||||
// These teams will be fully deleted
|
||||
|
||||
// Get all servers for this team
|
||||
$servers = $team->servers;
|
||||
$servers = $team->servers()->get();
|
||||
|
||||
foreach ($servers as $server) {
|
||||
// Get applications
|
||||
$serverApplications = $server->applications;
|
||||
// Get applications (custom method returns Collection)
|
||||
$serverApplications = $server->applications();
|
||||
$applications = $applications->merge($serverApplications);
|
||||
|
||||
// Get databases
|
||||
$serverDatabases = $this->getAllDatabasesForServer($server);
|
||||
// Get databases (custom method returns Collection)
|
||||
$serverDatabases = $server->databases();
|
||||
$databases = $databases->merge($serverDatabases);
|
||||
|
||||
// Get services
|
||||
$serverServices = $server->services;
|
||||
// Get services (relationship needs ->get())
|
||||
$serverServices = $server->services()->get();
|
||||
$services = $services->merge($serverServices);
|
||||
}
|
||||
}
|
||||
@@ -105,21 +128,4 @@ class DeleteUserResources
|
||||
|
||||
return $deletedCounts;
|
||||
}
|
||||
|
||||
private function getAllDatabasesForServer($server): Collection
|
||||
{
|
||||
$databases = collect();
|
||||
|
||||
// Get all standalone database types
|
||||
$databases = $databases->merge($server->postgresqls);
|
||||
$databases = $databases->merge($server->mysqls);
|
||||
$databases = $databases->merge($server->mariadbs);
|
||||
$databases = $databases->merge($server->mongodbs);
|
||||
$databases = $databases->merge($server->redis);
|
||||
$databases = $databases->merge($server->keydbs);
|
||||
$databases = $databases->merge($server->dragonflies);
|
||||
$databases = $databases->merge($server->clickhouses);
|
||||
|
||||
return $databases;
|
||||
}
|
||||
}
|
||||
@@ -23,13 +23,13 @@ class DeleteUserServers
|
||||
$servers = collect();
|
||||
|
||||
// Get all teams the user belongs to
|
||||
$teams = $this->user->teams;
|
||||
$teams = $this->user->teams()->get();
|
||||
|
||||
foreach ($teams as $team) {
|
||||
// Only include servers from teams where user is owner or admin
|
||||
$userRole = $team->pivot->role;
|
||||
if ($userRole === 'owner' || $userRole === 'admin') {
|
||||
$teamServers = $team->servers;
|
||||
$teamServers = $team->servers()->get();
|
||||
$servers = $servers->merge($teamServers);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user