From 44de4c182108b296e4bc54f288cab008c574575c Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sat, 4 Nov 2017 21:41:37 +0800 Subject: [PATCH] Remove agency entity --- app/Entities/Agencies/Agency.php | 36 --------------------- app/Entities/Payments/Payment.php | 13 -------- app/Entities/Projects/Project.php | 6 ---- app/Entities/Users/User.php | 5 --- app/Entities/Users/UsersRepository.php | 9 ++---- app/Http/Controllers/AuthController.php | 8 ----- .../Controllers/Partners/CustomersController.php | 2 -- .../Controllers/Partners/VendorsController.php | 2 -- app/Http/Controllers/Users/AgencyController.php | 35 -------------------- app/Http/Requests/Accounts/RegisterRequest.php | 4 --- app/Policies/AgencyPolicy.php | 17 ---------- app/Policies/UserPolicy.php | 6 ++-- app/Providers/AuthServiceProvider.php | 9 ++++-- app/Traits/OwnedByAgency.php | 17 ---------- ...17_11_02_175711_create_agency_workers_table.php | 37 ---------------------- resources/lang/id/agency.php | 33 ------------------- resources/lang/id/auth.php | 1 - resources/views/auth/register.blade.php | 12 ------- resources/views/layouts/partials/sidebar.blade.php | 2 +- .../pages/partials/dashboard-nav-tabs.blade.php | 5 +-- resources/views/payments/pdf.blade.php | 12 +++---- routes/web/account.php | 19 ----------- tests/Feature/Auth/MemberLoginTest.php | 2 -- tests/Feature/Auth/MemberRegistrationTest.php | 6 ---- tests/Feature/ManageFeaturesTest.php | 4 +-- tests/Feature/Users/ManageUsersTest.php | 15 ++------- tests/Feature/Users/UserProfileTest.php | 35 -------------------- tests/TestCase.php | 2 -- tests/Unit/Models/UserTest.php | 11 ------- tests/Unit/Policies/ProjectPolicyTest.php | 7 +--- tests/Unit/Policies/UserPolicyTest.php | 3 -- 31 files changed, 24 insertions(+), 351 deletions(-) delete mode 100644 app/Entities/Agencies/Agency.php delete mode 100644 app/Http/Controllers/Users/AgencyController.php delete mode 100644 app/Policies/AgencyPolicy.php delete mode 100644 app/Traits/OwnedByAgency.php delete mode 100644 database/migrations/2017_11_02_175711_create_agency_workers_table.php delete mode 100644 resources/lang/id/agency.php diff --git a/app/Entities/Agencies/Agency.php b/app/Entities/Agencies/Agency.php deleted file mode 100644 index 93d4da2..0000000 --- a/app/Entities/Agencies/Agency.php +++ /dev/null @@ -1,36 +0,0 @@ -belongsTo('App\Entities\Users\User'); - } - - public function projects() - { - return $this->hasMany('App\Entities\Projects\Project', 'owner_id'); - } - - public function workers() - { - return $this->belongsToMany('App\Entities\Users\User', 'agency_workers', 'agency_id', 'worker_id'); - } - - public function addWorker(User $worker) - { - $this->workers()->attach($worker); - } - - public function removeWorker(User $worker) - { - $this->workers()->detach($worker); - } -} diff --git a/app/Entities/Payments/Payment.php b/app/Entities/Payments/Payment.php index ac97243..17a28b9 100755 --- a/app/Entities/Payments/Payment.php +++ b/app/Entities/Payments/Payment.php @@ -4,7 +4,6 @@ namespace App\Entities\Payments; use App\Entities\Payments\PaymentPresenter; use App\Entities\Projects\Project; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Laracasts\Presenter\PresentableTrait; @@ -15,18 +14,6 @@ class Payment extends Model protected $presenter = PaymentPresenter::class; protected $guarded = ['id', 'created_at', 'updated_at']; - protected static function boot() - { - parent::boot(); - - // static::addGlobalScope('by_owner_project', function (Builder $builder) { - // if (auth()->user() && auth()->user()->agency) { - // $projectIds = auth()->user()->agency->projects->pluck('id')->all(); - // $builder->whereIn('project_id', $projectIds); - // } - // }); - } - public function project() { return $this->belongsTo(Project::class); diff --git a/app/Entities/Projects/Project.php b/app/Entities/Projects/Project.php index cf99cb1..52ff6c2 100755 --- a/app/Entities/Projects/Project.php +++ b/app/Entities/Projects/Project.php @@ -2,7 +2,6 @@ namespace App\Entities\Projects; -use App\Entities\Agencies\Agency; use App\Entities\Invoices\Invoice; use App\Entities\Partners\Customer; use App\Entities\Payments\Payment; @@ -65,11 +64,6 @@ class Project extends Model return $this->belongsTo(Customer::class); } - public function owner() - { - return $this->belongsTo(Agency::class); - } - public function cashInTotal() { return $this->payments->sum(function ($payment) { diff --git a/app/Entities/Users/User.php b/app/Entities/Users/User.php index 384cc14..42d6e3b 100644 --- a/app/Entities/Users/User.php +++ b/app/Entities/Users/User.php @@ -24,9 +24,4 @@ class User extends Authenticatable { return link_to_route('users.show', $this->name, [$this->id], ['target' => '_blank']); } - - public function agency() - { - return $this->hasOne('App\Entities\Agencies\Agency', 'owner_id'); - } } diff --git a/app/Entities/Users/UsersRepository.php b/app/Entities/Users/UsersRepository.php index 36b05b5..f2da1e8 100755 --- a/app/Entities/Users/UsersRepository.php +++ b/app/Entities/Users/UsersRepository.php @@ -20,9 +20,8 @@ class UsersRepository extends BaseRepository public function getUsers($q) { - return auth()->user()->agency->workers() - ->where('name', 'like', '%'.$q.'%') - ->get(); + return User::where('name', 'like', '%'.$q.'%') + ->paginate($this->_paginate); } public function create($userData) @@ -33,8 +32,6 @@ class UsersRepository extends BaseRepository $user = $this->storeArray($userData); - auth()->user()->agency->addWorker($user); - return $user; } @@ -57,8 +54,6 @@ class UsersRepository extends BaseRepository { $user = $this->requireById($userId); - \DB::table('agency_workers')->where('worker_id', $userId)->delete(); - return $user->delete(); } } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 2efdbab..9bae1bf 100755 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers; -use App\Entities\Agencies\Agency; use App\Entities\Users\User; use App\Http\Requests\Accounts\RegisterRequest; use Auth; @@ -32,13 +31,6 @@ class AuthController extends Controller $user = User::create($registerData); - $agency = Agency::create([ - 'name' => $request->get('agency_name'), - 'email' => $request->get('email'), - 'website' => $request->get('agency_website'), - 'owner_id' => $user->id, - ]); - Auth::login($user); flash()->success(trans('auth.welcome', ['name' => $user->name])); diff --git a/app/Http/Controllers/Partners/CustomersController.php b/app/Http/Controllers/Partners/CustomersController.php index efc0404..7462aee 100644 --- a/app/Http/Controllers/Partners/CustomersController.php +++ b/app/Http/Controllers/Partners/CustomersController.php @@ -52,8 +52,6 @@ class CustomersController extends Controller 'notes' => 'nullable|max:255', ]); - $newCustomerData['owner_id'] = auth()->user()->agency->id; - Customer::create($newCustomerData); flash(trans('customer.created'), 'success'); diff --git a/app/Http/Controllers/Partners/VendorsController.php b/app/Http/Controllers/Partners/VendorsController.php index 0787114..b9fe53b 100644 --- a/app/Http/Controllers/Partners/VendorsController.php +++ b/app/Http/Controllers/Partners/VendorsController.php @@ -41,8 +41,6 @@ class VendorsController extends Controller 'website' => 'nullable|url|max:255', ]); - $newVendorData['owner_id'] = auth()->user()->agency->id; - Vendor::create($newVendorData); flash(trans('vendor.created'), 'success'); diff --git a/app/Http/Controllers/Users/AgencyController.php b/app/Http/Controllers/Users/AgencyController.php deleted file mode 100644 index 23a7962..0000000 --- a/app/Http/Controllers/Users/AgencyController.php +++ /dev/null @@ -1,35 +0,0 @@ -user()->agency; - return view('users.agency.show', compact('agency')); - } - - public function edit() - { - return view('users.agency.edit'); - } - - public function update() - { - $agency = auth()->user()->agency; - - $agency->name = request('name'); - $agency->email = request('email'); - $agency->website = request('website'); - $agency->address = request('address'); - $agency->phone = request('phone'); - $agency->save(); - - flash(trans('agency.updated'), 'success'); - - return redirect()->route('users.agency.show'); - } -} diff --git a/app/Http/Requests/Accounts/RegisterRequest.php b/app/Http/Requests/Accounts/RegisterRequest.php index b078562..b010081 100644 --- a/app/Http/Requests/Accounts/RegisterRequest.php +++ b/app/Http/Requests/Accounts/RegisterRequest.php @@ -24,8 +24,6 @@ class RegisterRequest extends Request public function rules() { return [ - 'agency_name' => 'required|max:255', - 'agency_website' => 'nullable|url|max:255', 'name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users,email|unique:agencies,email', 'password' => 'required|between:6,15|confirmed', @@ -36,8 +34,6 @@ class RegisterRequest extends Request public function messages() { return [ - 'agency_name.required' => 'Nama Agensi harus diisi.', - 'agency_website.url' => 'Alamat Website Agensi tidak valid.', 'name.required' => 'Nama harus diisi.', 'email.required' => 'Email harus diisi.', 'email.email' => 'Email tidak valid.', diff --git a/app/Policies/AgencyPolicy.php b/app/Policies/AgencyPolicy.php deleted file mode 100644 index b0eccf6..0000000 --- a/app/Policies/AgencyPolicy.php +++ /dev/null @@ -1,17 +0,0 @@ -id == $agency->owner_id; - } -} diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php index 4ed1d53..c852b2d 100644 --- a/app/Policies/UserPolicy.php +++ b/app/Policies/UserPolicy.php @@ -19,7 +19,7 @@ class UserPolicy */ public function view(User $user, Worker $worker) { - return $user->id == $user->id; + return true; } /** @@ -31,7 +31,7 @@ class UserPolicy */ public function create(User $user, Worker $worker) { - return ! ! $user->agency; + return true; } /** @@ -43,7 +43,7 @@ class UserPolicy */ public function update(User $user, Worker $worker) { - return $user->agency->workers->contains($worker); + return true; } /** diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index b444f14..5a3bbf4 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -18,7 +18,6 @@ class AuthServiceProvider extends ServiceProvider 'App\Entities\Partners\Customer' => 'App\Policies\Partners\CustomerPolicy', 'App\Entities\Projects\Project' => 'App\Policies\Projects\ProjectPolicy', 'App\Entities\Users\User' => 'App\Policies\UserPolicy', - 'App\Entities\Agencies\Agency' => 'App\Policies\AgencyPolicy', 'App\Entities\Users\Event' => 'App\Policies\EventPolicy', ]; @@ -34,12 +33,16 @@ class AuthServiceProvider extends ServiceProvider // Dynamically register permissions with Laravel's Gate. foreach ($this->getPermissions() as $permission) { Gate::define($permission, function ($user) { - return true; + return true; }); } + Gate::define('manage_agency', function ($user) { + return true; + }); + Gate::define('add_project', function ($user) { - return ! is_null($user->agency); + return true; }); Gate::define('manage_project', function ($user, $project) { diff --git a/app/Traits/OwnedByAgency.php b/app/Traits/OwnedByAgency.php deleted file mode 100644 index 9834022..0000000 --- a/app/Traits/OwnedByAgency.php +++ /dev/null @@ -1,17 +0,0 @@ -user() && auth()->user()->agency) { - $builder->where('owner_id', auth()->user()->agency->id); - } - }); - } -} diff --git a/database/migrations/2017_11_02_175711_create_agency_workers_table.php b/database/migrations/2017_11_02_175711_create_agency_workers_table.php deleted file mode 100644 index fd5a58d..0000000 --- a/database/migrations/2017_11_02_175711_create_agency_workers_table.php +++ /dev/null @@ -1,37 +0,0 @@ -increments('id'); - $table->unsignedInteger('agency_id'); - $table->unsignedInteger('worker_id'); - $table->timestamps(); - - $table->unique(['agency_id', 'worker_id'], 'agency_worker_unique'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('agency_workers', function (Blueprint $table) { - // - }); - } -} diff --git a/resources/lang/id/agency.php b/resources/lang/id/agency.php deleted file mode 100644 index ae9b8c5..0000000 --- a/resources/lang/id/agency.php +++ /dev/null @@ -1,33 +0,0 @@ - 'Agensi', - 'list' => 'Daftar Agensi', - 'search' => 'Cari Agensi', - 'not_found' => 'Agensi tidak ditemukan', - 'empty' => 'Belum ada Agensi', - 'back_to_show' => 'Kembali ke detail Agensi', - 'back_to_index' => 'Kembali ke daftar Agensi', - - // Actions - 'create' => 'Input Agensi Baru', - 'created' => 'Input Agensi baru telah berhasil.', - 'show' => 'Detail Agensi', - 'edit' => 'Edit Agensi', - 'update' => 'Update Agensi', - 'updated' => 'Update data Agensi telah berhasil.', - 'delete' => 'Hapus Agensi', - 'delete_confirm' => 'Anda yakin akan menghapus Agensi ini?', - 'deleted' => 'Hapus data Agensi telah berhasil.', - 'undeleted' => 'Data Agensi gagal dihapus.', - 'undeleteable' => 'Data Agensi tidak dapat dihapus.', - - // Attributes - 'name' => 'Nama Agensi', - 'email' => 'Email Agensi', - 'website' => 'Website Agensi', - 'address' => 'Alamat Agensi', - 'phone' => 'Telp. Agensi', - 'owner' => 'Pemilik Agensi', -]; diff --git a/resources/lang/id/auth.php b/resources/lang/id/auth.php index 7bfd313..b56935c 100644 --- a/resources/lang/id/auth.php +++ b/resources/lang/id/auth.php @@ -6,7 +6,6 @@ return [ 'profile_edit' => 'Edit Profil Saya', 'update_profile' => 'Update Profil', 'profile_updated' => 'Profil sudah diupdate.', - 'agency' => 'Agensi Saya', // Registration 'register' => 'Buat Akun Baru', diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 22f602a..777dd00 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -9,18 +9,6 @@
@include('auth.partials._notifications') {!! Form::open(['route'=>'auth.register','class'=>'form-horizontal']) !!} -
- {!! Form::label('agency_name', trans('agency.name'), ['class'=>'col-md-4 control-label']) !!} -
- {!! Form::text('agency_name', null, ['class'=>'form-control','placeholder' => trans('agency.name')]) !!} -
-
-
- {!! Form::label('agency_website', trans('agency.website'), ['class'=>'col-md-4 control-label']) !!} -
- {!! Form::text('agency_website', null, ['class'=>'form-control','placeholder' => trans('agency.website')]) !!} -
-
{!! Form::label('name', trans('app.name'), ['class'=>'col-md-4 control-label']) !!}
diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index d146a6a..3e931e2 100755 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -15,7 +15,7 @@