feat: disable custom script for trial users (#371)

* feat: disable custom script for  trial users

* fix: logic error for trial users

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Favour Olayinka
2024-04-15 15:14:21 +01:00
committed by GitHub
parent 75c2107b6c
commit 8d35fc8b1a
6 changed files with 111 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ class Workspace extends Model implements CachableAttributes
protected $appends = [
'is_pro',
'is_trialing',
'is_enterprise',
];
@@ -107,6 +108,24 @@ class Workspace extends Model implements CachableAttributes
});
}
public function getIsTrialingAttribute()
{
if (is_null(config('cashier.key'))) {
return false; // If no paid plan so FALSE for ALL
}
return $this->remember('is_trialing', 15 * 60, function (): bool {
// Make sure at least one owner is pro
foreach ($this->owners as $owner) {
if ($owner->onTrial()) {
return true;
}
}
return false;
});
}
public function getIsEnterpriseAttribute()
{
if (is_null(config('cashier.key'))) {