Skip to content

Commit

Permalink
Add new account limit for free accounts (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Aug 29, 2017
1 parent dce77a7 commit a3af477
Show file tree
Hide file tree
Showing 72 changed files with 407 additions and 91 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
UNRELEASED CHANGES:

* Fix typo when displaying message of no existing contact to link when adding a child
*

RELEASED VERSIONS:

v0.6.5 - 2017-08-28
-------------------

* Add a new welcome screen for new users
* Fix typo when displaying message of no existing contact to link when adding a child
* Monicahq.com only: add limitations to free accounts

v0.6.4 - 2017-08-23
-------------------

Expand Down
36 changes: 36 additions & 0 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class Account extends Model
'number_of_invitations_sent', 'api_key',
];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'has_access_to_paid_version_for_free' => 'boolean',
];

/**
* Get the activity records associated with the account.
*
Expand Down Expand Up @@ -246,6 +255,10 @@ public function canDowngrade()
*/
public function isSubscribed()
{
if ($this->has_access_to_paid_version_for_free) {
return true;
}

$isSubscribed = false;

if ($this->subscribed(config('monica.paid_plan_friendly_name'))) {
Expand Down Expand Up @@ -286,4 +299,27 @@ public function getNextBillingDate()

return \App\Helpers\DateHelper::getShortDate($timestamp);
}

/**
* Indicates whether the current account has limitations with her current
* plan.
*
* @return bool
*/
public function hasLimitations()
{
if ($this->has_access_to_paid_version_for_free) {
return false;
}

if (! config('monica.requires_subscription')) {
return false;
}

if ($this->isSubscribed()) {
return false;
}

return true;
}
}
6 changes: 4 additions & 2 deletions app/Console/Commands/SendNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public function handle()
}

if ($sendEmailToUser == true) {
foreach ($account->users as $user) {
dispatch(new SendReminderEmail($reminder, $user));
if (! $account->hasLimitations()) {
foreach ($account->users as $user) {
dispatch(new SendReminderEmail($reminder, $user));
}
}

dispatch(new SetNextReminderDate($reminder, $userTimezone));
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public function import()
*/
public function upload()
{
if (config('monica.requires_subscription') && ! auth()->user()->account->isSubscribed()) {
return redirect('/settings/subscriptions');
}

return view('settings.imports.upload');
}

Expand Down
2 changes: 1 addition & 1 deletion config/monica.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@
| bad things will happen.
|
*/
'app_version' => '0.6.4',
'app_version' => '0.6.5',
];
6 changes: 6 additions & 0 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@
'account_id' => 1,
];
});

$factory->define(App\Invitation::class, function (Faker\Generator $faker) {
return [
'account_id' => 1,
];
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class RemovePaidLimitationsForCurrentUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('accounts', function (Blueprint $table) {
$table->boolean('has_access_to_paid_version_for_free')->after('id')->default(false);
});

DB::table('accounts')
->update(['has_access_to_paid_version_for_free' => true]);
}
}
Loading

0 comments on commit a3af477

Please sign in to comment.