Skip to content

Commit

Permalink
Merge pull request coollabsio#1775 from coollabsio/next
Browse files Browse the repository at this point in the history
v4.0.0-beta.224
  • Loading branch information
andrasbacsai authored Feb 23, 2024
2 parents a07fa8c + 3b94204 commit 8c803f1
Show file tree
Hide file tree
Showing 35 changed files with 503 additions and 255 deletions.
2 changes: 1 addition & 1 deletion app/Http/Middleware/DecideWhatToDoWithUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function handle(Request $request, Closure $next): Response
if (auth()->user()->hasVerifiedEmail() && $request->path() === 'verify') {
return redirect(RouteServiceProvider::HOME);
}
if (isSubscriptionActive() && $request->path() === 'subscription') {
if (isSubscriptionActive() && $request->routeIs('subscription.index')) {
return redirect(RouteServiceProvider::HOME);
}
return $next($request);
Expand Down
10 changes: 9 additions & 1 deletion app/Livewire/Subscription/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

class Actions extends Component
{
public $server_limits = 0;
public function mount()
{
$limits = currentTeam()->limits;
$this->server_limits = data_get($limits, 'serverLimit', 0);

}
public function cancel()
{
try {
Expand Down Expand Up @@ -69,7 +76,8 @@ public function resume()
return handleError($e, $this);
}
}
public function stripeCustomerPortal() {
public function stripeCustomerPortal()
{
$session = getStripeCustomerPortalSession(currentTeam());
redirect($session->url);
}
Expand Down
9 changes: 7 additions & 2 deletions app/Livewire/Subscription/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ class Index extends Component
{
public InstanceSettings $settings;
public bool $alreadySubscribed = false;
public function mount() {
public function mount()
{
if (!isCloud()) {
return redirect(RouteServiceProvider::HOME);
}
if (data_get(currentTeam(), 'subscription')) {
return redirect()->route('subscription.show');
}
$this->settings = InstanceSettings::get();
$this->alreadySubscribed = currentTeam()->subscription()->exists();
}
public function stripeCustomerPortal() {
public function stripeCustomerPortal()
{
$session = getStripeCustomerPortalSession(currentTeam());
if (is_null($session)) {
return;
Expand Down
22 changes: 22 additions & 0 deletions app/Livewire/Subscription/Show.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Livewire\Subscription;

use Livewire\Component;

class Show extends Component
{
public function mount()
{
if (!isCloud()) {
return redirect()->route('dashboard');
}
if (!data_get(currentTeam(), 'subscription')) {
return redirect()->route('subscription.index');
}
}
public function render()
{
return view('livewire.subscription.show');
}
}
7 changes: 6 additions & 1 deletion app/Livewire/Team/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public function makeAdmin()
$this->dispatch('reloadWindow');
}

public function makeOwner()
{
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => 'owner']);
$this->dispatch('reloadWindow');
}
public function makeReadonly()
{
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => 'member']);
Expand All @@ -26,7 +31,7 @@ public function remove()
{
$this->member->teams()->detach(currentTeam());
Cache::forget("team:{$this->member->id}");
Cache::remember('team:' . $this->member->id, 3600, function() {
Cache::remember('team:' . $this->member->id, 3600, function () {
return $this->member->teams()->first();
});
$this->dispatch('reloadWindow');
Expand Down
79 changes: 52 additions & 27 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

class Service extends BaseModel
{
Expand All @@ -28,47 +27,73 @@ public function tags()
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function status() {
$foundRunning = false;
$isDegraded = false;
$foundRestaring = false;
public function status()
{
$applications = $this->applications;
$databases = $this->databases;

$complexStatus = null;
$complexHealth = null;

foreach ($applications as $application) {
if ($application->exclude_from_status) {
continue;
}
if (Str::of($application->status)->startsWith('running')) {
$foundRunning = true;
} else if (Str::of($application->status)->startsWith('restarting')) {
$foundRestaring = true;
$status = str($application->status)->before('(')->trim();
$health = str($application->status)->between('(', ')')->trim();
if ($complexStatus === 'degraded') {
continue;
}
if ($status->startsWith('running')) {
if ($complexStatus === 'exited') {
$complexStatus = 'degraded';
} else {
$complexStatus = 'running';
}
} else if ($status->startsWith('restarting')) {
$complexStatus = 'degraded';
} else if ($status->startsWith('exited')) {
$complexStatus = 'exited';
}
if ($health->value() === 'healthy') {
if ($complexHealth === 'unhealthy') {
continue;
}
$complexHealth = 'healthy';
} else {
$isDegraded = true;
$complexHealth = 'unhealthy';
}
}
foreach ($databases as $database) {
if ($database->exclude_from_status) {
continue;
}
if (Str::of($database->status)->startsWith('running')) {
$foundRunning = true;
} else if (Str::of($database->status)->startsWith('restarting')) {
$foundRestaring = true;
$status = str($database->status)->before('(')->trim();
$health = str($database->status)->between('(', ')')->trim();
if ($complexStatus === 'degraded') {
continue;
}
if ($status->startsWith('running')) {
if ($complexStatus === 'exited') {
$complexStatus = 'degraded';
} else {
$complexStatus = 'running';
}
} else if ($status->startsWith('restarting')) {
$complexStatus = 'degraded';
} else if ($status->startsWith('exited')) {
$complexStatus = 'exited';
}
if ($health->value() === 'healthy') {
if ($complexHealth === 'unhealthy') {
continue;
}
$complexHealth = 'healthy';
} else {
$isDegraded = true;
$complexHealth = 'unhealthy';
}
}
if ($foundRestaring) {
return 'degraded';
}
if ($foundRunning && !$isDegraded) {
return 'running';
} else if ($foundRunning && $isDegraded) {
return 'degraded';
} else if (!$foundRunning && !$isDegraded) {
return 'exited';
}
return 'exited';
return "{$complexStatus}:{$complexHealth}";
}
public function extraFields()
{
Expand Down Expand Up @@ -414,7 +439,7 @@ public function link()
public function documentation()
{
$services = getServiceTemplates();
$service = data_get($services, Str::of($this->name)->beforeLast('-')->value, []);
$service = data_get($services, str($this->name)->beforeLast('-')->value, []);
return data_get($service, 'documentation', config('constants.docs.base_url'));
}
public function applications()
Expand Down
5 changes: 2 additions & 3 deletions app/Models/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public function type()
if (in_array($subscription, $ultimate)) {
return 'ultimate';
}
}
if (isStripe()) {
} else if (isStripe()) {
if (!$this->stripe_plan_id) {
return 'zero';
}
Expand All @@ -55,7 +54,7 @@ public function type()
};
})->first();
if ($stripePlanId) {
return Str::of($stripePlanId)->after('stripe_price_id_')->before('_')->lower();
return str($stripePlanId)->after('stripe_price_id_')->before('_')->lower();
}
}
return 'zero';
Expand Down
13 changes: 10 additions & 3 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function createToken(string $name, array $abilities = ['*'], DateTimeInte
'team_id' => session('currentTeam')->id
]);

return new NewAccessToken($token, $token->getKey().'|'.$plainTextToken);
return new NewAccessToken($token, $token->getKey() . '|' . $plainTextToken);
}
public function teams()
{
Expand Down Expand Up @@ -103,9 +103,13 @@ public function sendPasswordResetNotification($token): void

public function isAdmin()
{
return data_get($this->pivot, 'role') === 'admin' || data_get($this->pivot, 'role') === 'owner';
return $this->role() === 'admin' || $this->role() === 'owner';
}

public function isOwner()
{
return $this->role() === 'owner';
}
public function isAdminFromSession()
{
if (auth()->user()->id === 0) {
Expand Down Expand Up @@ -155,6 +159,9 @@ public function otherTeams()

public function role()
{
return session('currentTeam')->pivot->role;
if (data_get($this, 'pivot')) {
return $this->pivot->role;
}
return auth()->user()->teams->where('id', currentTeam()->id)->first()->pivot->role;
}
}
4 changes: 2 additions & 2 deletions bootstrap/helpers/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function isPaddle()
function getStripeCustomerPortalSession(Team $team)
{
Stripe::setApiKey(config('subscription.stripe_api_key'));
$return_url = route('team.index');
$return_url = route('subscription.show');
$stripe_customer_id = data_get($team,'subscription.stripe_customer_id');
if (!$stripe_customer_id) {
return null;
Expand All @@ -123,7 +123,7 @@ function getStripeCustomerPortalSession(Team $team)
function allowedPathsForUnsubscribedAccounts()
{
return [
'subscription',
'subscription/new',
'login',
'logout',
'waitlist',
Expand Down
2 changes: 1 addition & 1 deletion config/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
'release' => '4.0.0-beta.223',
'release' => '4.0.0-beta.224',
// When left empty or `null` the Laravel environment will be used
'environment' => config('app.env'),

Expand Down
6 changes: 6 additions & 0 deletions config/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
'stripe_price_id_ultimate_yearly' => env('STRIPE_PRICE_ID_ULTIMATE_YEARLY', null),
'stripe_excluded_plans' => env('STRIPE_EXCLUDED_PLANS', null),

'stripe_price_id_basic_monthly_old' => env('STRIPE_PRICE_ID_BASIC_MONTHLY_OLD', null),
'stripe_price_id_basic_yearly_old' => env('STRIPE_PRICE_ID_BASIC_YEARLY_OLD', null),
'stripe_price_id_pro_monthly_old' => env('STRIPE_PRICE_ID_PRO_MONTHLY_OLD', null),
'stripe_price_id_pro_yearly_old' => env('STRIPE_PRICE_ID_PRO_YEARLY_OLD', null),
'stripe_price_id_ultimate_monthly_old' => env('STRIPE_PRICE_ID_ULTIMATE_MONTHLY_OLD', null),
'stripe_price_id_ultimate_yearly_old' => env('STRIPE_PRICE_ID_ULTIMATE_YEARLY_OLD', null),

// Paddle
'paddle_vendor_id' => env('PADDLE_VENDOR_ID', null),
Expand Down
2 changes: 1 addition & 1 deletion config/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

return '4.0.0-beta.223';
return '4.0.0-beta.224';
6 changes: 6 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ services:
- STRIPE_PRICE_ID_PRO_YEARLY
- STRIPE_PRICE_ID_ULTIMATE_MONTHLY
- STRIPE_PRICE_ID_ULTIMATE_YEARLY
- STRIPE_PRICE_ID_BASIC_MONTHLY_OLD
- STRIPE_PRICE_ID_BASIC_YEARLY_OLD
- STRIPE_PRICE_ID_PRO_MONTHLY_OLD
- STRIPE_PRICE_ID_PRO_YEARLY_OLD
- STRIPE_PRICE_ID_ULTIMATE_MONTHLY_OLD
- STRIPE_PRICE_ID_ULTIMATE_YEARLY_OLD
- STRIPE_EXCLUDED_PLANS
- PADDLE_VENDOR_ID
- PADDLE_WEBHOOK_SECRET
Expand Down
21 changes: 21 additions & 0 deletions public/svgs/firefly.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 20 additions & 6 deletions resources/views/components/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class="{{ request()->is('project/*') || request()->is('projects') ? 'text-warnin
<div>
<button x-on:click.prevent="open = !open" x-on:click.away="open = false" type="button"
class="py-4 mx-4" id="menu-button" aria-expanded="true" aria-haspopup="true">
<svg class="icon" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
<path fill="currentColor"
d="M224 128a8 8 0 0 1-8 8h-80v80a8 8 0 0 1-16 0v-80H40a8 8 0 0 1 0-16h80V40a8 8 0 0 1 16 0v80h80a8 8 0 0 1 8 8" />
<svg class="icon text-neutral-400" xmlns="http://www.w3.org/2000/svg" width="200" height="200"
viewBox="0 0 24 24">
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
</svg>
</button>
</div>
Expand Down Expand Up @@ -131,11 +132,24 @@ class="{{ request()->is('team*') ? 'text-warning icon' : 'icon' }}"
<path d="M5 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
<path d="M3 13v-1a2 2 0 0 1 2 -2h2" />
</svg>
Teams @if (isCloud())
/ Subscription
@endif
Teams
</a>
</li>
@if (isCloud())
<li title="Subscription" class="hover:bg-coolgray-200">
<a class="hover:bg-transparent hover:no-underline"
href="{{ route('subscription.show') }}">
<svg xmlns="http://www.w3.org/2000/svg"
class="{{ request()->is('subscription*') ? 'text-warning icon' : 'icon' }}"
viewBox="0 0 24 24">
<path fill="none" stroke="currentColor" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2"
d="M3 8a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v8a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3zm0 2h18M7 15h.01M11 15h2" />
</svg>
Subscription
</a>
</li>
@endif

@if (isInstanceAdmin())
<li title="Settings" class="hover:bg-coolgray-200">
Expand Down
Loading

0 comments on commit 8c803f1

Please sign in to comment.