From 57b95064070b9b4551b014de49c7f2497e5b17e6 Mon Sep 17 00:00:00 2001 From: Karl Hughes Date: Sat, 31 Dec 2016 14:13:59 -0600 Subject: [PATCH 1/6] Moving all jobs into their own namespaced folders --- app/Console/Commands/EmailJobs.php | 5 +---- app/Http/Controllers/SearchesController.php | 6 +++--- app/Http/Controllers/UsersController.php | 6 +++--- app/Jobs/{ => Collections}/SearchAndNotifyUser.php | 2 +- app/Jobs/{DeleteSearch.php => Searches/Delete.php} | 4 ++-- app/Jobs/{ => Searches}/GetUserSearches.php | 2 +- app/Jobs/{ => Users}/CreateUserAndSearch.php | 2 +- app/Jobs/{DeleteUser.php => Users/Delete.php} | 4 ++-- .../Jobs/{ => Collections}/SearchAndNotifyUserTest.php | 4 ++-- .../{DeleteSearchTest.php => Searches/DeleteTest.php} | 8 ++++---- tests/unit/Jobs/{ => Searches}/GetUserSearchesTest.php | 5 ++--- tests/unit/Jobs/{ => Users}/CreateUserAndSearchTest.php | 4 ++-- .../Jobs/{DeleteUserTest.php => Users/DeleteTest.php} | 8 ++++---- 13 files changed, 28 insertions(+), 32 deletions(-) rename app/Jobs/{ => Collections}/SearchAndNotifyUser.php (97%) rename app/Jobs/{DeleteSearch.php => Searches/Delete.php} (93%) rename app/Jobs/{ => Searches}/GetUserSearches.php (92%) rename app/Jobs/{ => Users}/CreateUserAndSearch.php (98%) rename app/Jobs/{DeleteUser.php => Users/Delete.php} (94%) rename tests/unit/Jobs/{ => Collections}/SearchAndNotifyUserTest.php (97%) rename tests/unit/Jobs/{DeleteSearchTest.php => Searches/DeleteTest.php} (86%) rename tests/unit/Jobs/{ => Searches}/GetUserSearchesTest.php (83%) rename tests/unit/Jobs/{ => Users}/CreateUserAndSearchTest.php (97%) rename tests/unit/Jobs/{DeleteUserTest.php => Users/DeleteTest.php} (86%) diff --git a/app/Console/Commands/EmailJobs.php b/app/Console/Commands/EmailJobs.php index afbe806..9ee09c5 100644 --- a/app/Console/Commands/EmailJobs.php +++ b/app/Console/Commands/EmailJobs.php @@ -2,11 +2,8 @@ use Illuminate\Console\Command; use Illuminate\Foundation\Bus\DispatchesJobs; -use JobApis\JobsToMail\Jobs\CollectJobsForUser; -use JobApis\JobsToMail\Jobs\SearchAndNotifyUser; +use JobApis\JobsToMail\Jobs\Collections\SearchAndNotifyUser; use JobApis\JobsToMail\Repositories\Contracts\SearchRepositoryInterface; -use JobApis\JobsToMail\Repositories\SearchRepository; -use JobApis\JobsToMail\Repositories\UserRepository; class EmailJobs extends Command { diff --git a/app/Http/Controllers/SearchesController.php b/app/Http/Controllers/SearchesController.php index be15973..92b6b9d 100644 --- a/app/Http/Controllers/SearchesController.php +++ b/app/Http/Controllers/SearchesController.php @@ -5,8 +5,8 @@ use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Support\Facades\URL; -use JobApis\JobsToMail\Jobs\DeleteSearch; -use JobApis\JobsToMail\Jobs\GetUserSearches; +use JobApis\JobsToMail\Jobs\Searches\Delete; +use JobApis\JobsToMail\Jobs\Searches\GetUserSearches; class SearchesController extends BaseController { @@ -38,7 +38,7 @@ public function index(Request $request, $userId = null) */ public function unsubscribe(Request $request, $searchId) { - $message = $this->dispatchNow(new DeleteSearch($searchId)); + $message = $this->dispatchNow(new Delete($searchId)); $request->session()->flash($message->type, $message->message); diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index de5eb85..276b501 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -6,8 +6,8 @@ use Illuminate\Foundation\Validation\ValidatesRequests; use JobApis\JobsToMail\Http\Requests\CreateUser; use JobApis\JobsToMail\Http\Requests\PremiumUser; -use JobApis\JobsToMail\Jobs\CreateUserAndSearch; -use JobApis\JobsToMail\Jobs\DeleteUser; +use JobApis\JobsToMail\Jobs\Users\CreateUserAndSearch; +use JobApis\JobsToMail\Jobs\Users\Delete; use JobApis\JobsToMail\Jobs\Users\PremiumUserSignup; class UsersController extends BaseController @@ -33,7 +33,7 @@ public function create(CreateUser $request) */ public function delete(Request $request, $userId) { - $message = $this->dispatchNow(new DeleteUser($userId)); + $message = $this->dispatchNow(new Delete($userId)); $request->session()->flash($message->type, $message->message); diff --git a/app/Jobs/SearchAndNotifyUser.php b/app/Jobs/Collections/SearchAndNotifyUser.php similarity index 97% rename from app/Jobs/SearchAndNotifyUser.php rename to app/Jobs/Collections/SearchAndNotifyUser.php index 67ee7bf..31d3d93 100644 --- a/app/Jobs/SearchAndNotifyUser.php +++ b/app/Jobs/Collections/SearchAndNotifyUser.php @@ -1,4 +1,4 @@ -id = $this->faker->uuid(); - $this->job = new DeleteSearch($this->id); + $this->job = new Delete($this->id); } public function testItCanHandleIfUserConfirmed() diff --git a/tests/unit/Jobs/GetUserSearchesTest.php b/tests/unit/Jobs/Searches/GetUserSearchesTest.php similarity index 83% rename from tests/unit/Jobs/GetUserSearchesTest.php rename to tests/unit/Jobs/Searches/GetUserSearchesTest.php index 233aa13..85aa572 100644 --- a/tests/unit/Jobs/GetUserSearchesTest.php +++ b/tests/unit/Jobs/Searches/GetUserSearchesTest.php @@ -1,7 +1,6 @@ -userId = $this->faker->uuid(); - $this->job = new DeleteUser($this->userId); + $this->job = new Delete($this->userId); } public function testItCanHandleIfUserConfirmed() From 9daf679621fbb087220d3dcdc18c19422e145142 Mon Sep 17 00:00:00 2001 From: Karl Hughes Date: Sat, 31 Dec 2016 15:02:21 -0600 Subject: [PATCH 2/6] Removing premium features, all free --- .env.example | 1 + app/Http/Controllers/ApiController.php | 12 ---- app/Http/Controllers/UsersController.php | 26 +------ app/Http/Requests/CreateUser.php | 4 +- app/Http/Requests/PremiumUser.php | 41 ----------- app/Jobs/Users/CreateUserAndSearch.php | 10 +-- app/Jobs/Users/PremiumUserSignup.php | 44 ------------ app/Models/User.php | 10 --- app/Notifications/JobsCollected.php | 10 ++- app/Notifications/PremiumUserSignup.php | 55 --------------- app/Providers/AppServiceProvider.php | 8 +-- config/app.php | 25 +------ database/factories/UserFactory.php | 6 -- database/seeds/TestingDatabaseSeeder.php | 22 ------ resources/assets/sass/app.scss | 67 ------------------ resources/views/layouts/app.blade.php | 3 - .../components/action-links.blade.php | 2 +- .../no-recruiters-checkbox.blade.php | 9 +-- .../no-recruiters-checkbox.blade.php | 28 ++------ .../users/components/premium-info.blade.php | 55 --------------- .../users/components/premium-title.blade.php | 8 --- resources/views/users/premium.blade.php | 69 ------------------- routes/web.php | 6 -- tests/integration/UserModelTest.php | 6 -- .../Jobs/Users/CreateUserAndSearchTest.php | 16 +---- tests/unit/Jobs/Users/PremiumUserTest.php | 31 --------- .../unit/Notifications/JobsCollectedTest.php | 45 +----------- 27 files changed, 25 insertions(+), 594 deletions(-) delete mode 100644 app/Http/Controllers/ApiController.php delete mode 100644 app/Http/Requests/PremiumUser.php delete mode 100644 app/Jobs/Users/PremiumUserSignup.php delete mode 100644 app/Notifications/PremiumUserSignup.php delete mode 100644 resources/views/users/components/premium-info.blade.php delete mode 100644 resources/views/users/components/premium-title.blade.php delete mode 100644 resources/views/users/premium.blade.php delete mode 100644 tests/unit/Jobs/Users/PremiumUserTest.php diff --git a/.env.example b/.env.example index f3f459a..36a8778 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ APP_DEBUG=true APP_URL=http://localhost/ ADMIN_EMAIL= ADMIN_NAME= +MAX_SEARCHES= TIMEZONE= ## Database config diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php deleted file mode 100644 index 72fffcc..0000000 --- a/app/Http/Controllers/ApiController.php +++ /dev/null @@ -1,12 +0,0 @@ -only(array_keys($request->rules())); - - $message = $this->dispatchNow(new PremiumUserSignup($data)); - - $request->session()->flash($message->type, $message->message); - - return redirect('/premium'); - } } diff --git a/app/Http/Requests/CreateUser.php b/app/Http/Requests/CreateUser.php index ea522ce..f3b3281 100644 --- a/app/Http/Requests/CreateUser.php +++ b/app/Http/Requests/CreateUser.php @@ -24,8 +24,6 @@ public function messages() return [ 'regex' =>'The location should be formatted "City, ST". Currently only works for US locations.', - 'premium' =>'Only premium users can use this feature. - Contact upgrade@jobstomail.com to get access.', ]; } @@ -40,7 +38,7 @@ public function rules() 'email' => 'required|email', 'keyword' => 'required', 'location' => 'required|regex:/([^,]+), \s*(\w{2})/', - 'no_recruiters' => 'required|premium', + 'no_recruiters' => 'required', ]; } } diff --git a/app/Http/Requests/PremiumUser.php b/app/Http/Requests/PremiumUser.php deleted file mode 100644 index f54c382..0000000 --- a/app/Http/Requests/PremiumUser.php +++ /dev/null @@ -1,41 +0,0 @@ - 'required|email', - 'employer' => 'required', - 'location' => 'required', - 'name' => 'required', - ]; - } -} diff --git a/app/Jobs/Users/CreateUserAndSearch.php b/app/Jobs/Users/CreateUserAndSearch.php index 51a669c..ceb0984 100644 --- a/app/Jobs/Users/CreateUserAndSearch.php +++ b/app/Jobs/Users/CreateUserAndSearch.php @@ -36,15 +36,15 @@ public function handle( $user = $users->firstOrCreate($this->data); // Make sure the user isn't over their maximum - $maxSearches = config('app.user_tier_permissions.'.$user->tier.'.max_search_count'); + $maxSearches = config('app.max_searches'); + $adminEmail = env('ADMIN_EMAIL'); if ($user->existed === true && $user->searches()->count() >= $maxSearches) { return new FlashMessage( 'alert-danger', - "You have reached your maximum number of job searches. As a - {$user->tier} user you can create {$maxSearches} searches. - Unsubscribe from a search or contact upgrade@jobstomail.com - to upgrade your account." + "You have reached your maximum number of {$maxSearches} + job searches. Unsubscribe from a search or contact + {$adminEmail} to upgrade your account." ); } diff --git a/app/Jobs/Users/PremiumUserSignup.php b/app/Jobs/Users/PremiumUserSignup.php deleted file mode 100644 index 8c82123..0000000 --- a/app/Jobs/Users/PremiumUserSignup.php +++ /dev/null @@ -1,44 +0,0 @@ -data = $data; - $this->admin = new User( - ['email' => env('ADMIN_EMAIL', 'admin@jobstomail.com')] - ); - } - - /** - * Send an email to the admin about this new user signup - * - * @return FlashMessage - */ - public function handle() - { - $this->admin->notify(new Notification($this->data)); - - return new FlashMessage( - 'alert-success', - 'We have received your request for Premium access. We will reach out within 48 hours.' - ); - } -} diff --git a/app/Models/User.php b/app/Models/User.php index 3c3b2d2..54d3486 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -37,16 +37,6 @@ protected static function boot() }); } - /** - * Checks whether the user is premium - * - * @return boolean - */ - public function isPremium() - { - return $this->tier == config('app.user_tiers.premium'); - } - /** * Defines the relationship to Search model * diff --git a/app/Notifications/JobsCollected.php b/app/Notifications/JobsCollected.php index 3121614..355c8b6 100644 --- a/app/Notifications/JobsCollected.php +++ b/app/Notifications/JobsCollected.php @@ -90,12 +90,10 @@ public function toMail($notifiable) } // Add a link to download the collection - if ($notifiable->isPremium()) { - $message->action( - 'Download CSV', - url('/collections/' . $this->id . '/download') - ); - } + $message->action( + 'Download CSV', + url('/collections/' . $this->id . '/download') + ); return $message; } diff --git a/app/Notifications/PremiumUserSignup.php b/app/Notifications/PremiumUserSignup.php deleted file mode 100644 index dc8654e..0000000 --- a/app/Notifications/PremiumUserSignup.php +++ /dev/null @@ -1,55 +0,0 @@ -data = $data; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - $message = (new MailMessage()) - ->subject('New Premium User Signup') - ->line('A new user is interested in JobsToMail premium: '); - - foreach ($this->data as $key => $value) { - $message->line($key . ': ' . $value); - } - - return $message; - } -} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index e272e50..ada6f79 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -14,13 +14,7 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - // Only premium users can set this value to true - Validator::extend('premium', function ($attribute, $value, $parameters, $validator) { - if ($value == 1) { - return config('app.user_tiers.premium') === session()->get('user.tier'); - } - return true; - }); + // } /** diff --git a/config/app.php b/config/app.php index 355b7b4..d98fce0 100644 --- a/config/app.php +++ b/config/app.php @@ -15,30 +15,7 @@ 'name' => 'JobsToMail', 'description' => 'Your personal job-search assistant', 'ga_tracking_id' => env('GA_TRACKING_ID', null), - - /* - |-------------------------------------------------------------------------- - | Tiers and Permissions - |-------------------------------------------------------------------------- - | - | These values will eventually be moved into database tables, but we're - | keeping it simple for now and putting them here in the config file. - | - */ - - 'user_tiers' => [ - 'free' => 'free', - 'premium' => 'premium', - ], - - 'user_tier_permissions' => [ - 'free' => [ - 'max_search_count' => 3, - ], - 'premium' => [ - 'max_search_count' => 10, - ], - ], + 'max_searches' => env('MAX_SEARCHES', 10), /* |-------------------------------------------------------------------------- diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 3f8733c..2a35357 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -10,7 +10,6 @@ return [ 'email' => $faker->safeEmail(), 'confirmed_at' => null, - 'tier' => config('app.user_tiers.free'), ]; }); $factory->state(\JobApis\JobsToMail\Models\User::class, 'active', function (Faker\Generator $faker) { @@ -18,11 +17,6 @@ 'confirmed_at' => $faker->dateTimeThisYear(), ]; }); -$factory->state(\JobApis\JobsToMail\Models\User::class, 'premium', function (Faker\Generator $faker) { - return [ - 'tier' => config('app.user_tiers.premium'), - ]; -}); $factory->state(\JobApis\JobsToMail\Models\User::class, 'deleted', function (Faker\Generator $faker) { return [ 'deleted_at' => $faker->dateTimeThisYear(), diff --git a/database/seeds/TestingDatabaseSeeder.php b/database/seeds/TestingDatabaseSeeder.php index 1db2895..21cf40e 100644 --- a/database/seeds/TestingDatabaseSeeder.php +++ b/database/seeds/TestingDatabaseSeeder.php @@ -13,7 +13,6 @@ public function run() { $this->faker = Faker::create(); $this->createActiveUsers(); - $this->createPremiumUsers(); $this->createDeletedUsers(); $this->createUnconfirmedUsers(); } @@ -39,27 +38,6 @@ private function createActiveUsers($num = 10) }); } - private function createPremiumUsers($num = 2) - { - return factory(User::class, $num) - ->states('active', 'premium') - ->create() - ->each(function(User $user) { - $user->tokens()->save( - factory(Token::class)->make() - ); - })->each(function(User $user) { // Create searches - factory(Search::class, rand(2, 10))->create([ - 'user_id' => $user->id - ])->each(function(Search $search) { // Create notifications - factory(Notification::class, rand(1, 3))->create([ - 'notifiable_id' => $search->user_id, - 'search_id' => $search->id, - ]); - }); - }); - } - private function createDeletedUsers($num = 10) { return factory(User::class, $num) diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index 69376cd..1c9a3b4 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -74,70 +74,3 @@ footer { -webkit-filter: grayscale(0%); filter: grayscale(0%); } - -/* Premium page */ -.premium-title, -.premium-signup, -.premium-info { - margin-bottom: 40px; -} - -/* Corner ribbon */ -.corner-ribbon { - width: 200px; - background: $brand-danger; - position: absolute; - top: 25px; - left: -50px; - text-align: center; - line-height: 50px; - letter-spacing: 1px; - color: #fff; - transform: rotate(-45deg); - -webkit-transform: rotate(-45deg); - z-index: 1; -} - -.corner-ribbon a { - color: #fff; -} - -.corner-ribbon.sticky{ - position: fixed; -} - -.corner-ribbon.shadow{ - box-shadow: 0 0 3px rgba(0,0,0,.3); -} - -.corner-ribbon.top-left{ - top: 25px; - left: -50px; - transform: rotate(-45deg); - -webkit-transform: rotate(-45deg); -} - -.corner-ribbon.top-right{ - top: 25px; - right: -50px; - left: auto; - transform: rotate(45deg); - -webkit-transform: rotate(45deg); -} - -.corner-ribbon.bottom-left{ - top: auto; - bottom: 25px; - left: -50px; - transform: rotate(45deg); - -webkit-transform: rotate(45deg); -} - -.corner-ribbon.bottom-right{ - top: auto; - right: -50px; - bottom: 25px; - left: auto; - transform: rotate(-45deg); - -webkit-transform: rotate(-45deg); -} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 2ec6b07..aa5d2bc 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -2,9 +2,6 @@ @include('layouts.head') -
@include('layouts.navbar') diff --git a/resources/views/searches/components/action-links.blade.php b/resources/views/searches/components/action-links.blade.php index 74023ef..d1fb6af 100644 --- a/resources/views/searches/components/action-links.blade.php +++ b/resources/views/searches/components/action-links.blade.php @@ -1,5 +1,5 @@
-@if (session('user.tier') === config('app.user_tiers.premium') && $search->latestNotification) +@if ($search->latestNotification) diff --git a/resources/views/searches/components/no-recruiters-checkbox.blade.php b/resources/views/searches/components/no-recruiters-checkbox.blade.php index c23479c..a364c3a 100644 --- a/resources/views/searches/components/no-recruiters-checkbox.blade.php +++ b/resources/views/searches/components/no-recruiters-checkbox.blade.php @@ -1,12 +1,5 @@
-