Skip to content

Commit 843aa17

Browse files
authored
Merge pull request #39 from eporsche/add_account_admins
Add account admins
2 parents 7a674a5 + 463cad7 commit 843aa17

12 files changed

+84
-22
lines changed

app/AbsenceCalendar/EmployeeAbsenceCalendar.php

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ protected function calculatePaidHours()
8585
if ($this->startAndEndDayAreSame()) {
8686
$calcHours = BigDecimal::of($this->startDay->diffInMinutes($this->endDay))
8787
->dividedBy('60', 2, RoundingMode::HALF_EVEN);
88-
// dd($calcHours);
8988
return $calcHours->isGreaterThanOrEqualTo($absenceDay->getTargetHours()) ?
9089
$absenceDay->getTargetHours() : $calcHours;
9190
}

app/Actions/UpdateEmployeeProfile.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ public function update($user, $data)
2727
Validator::make($data, [
2828
'name' => ['required','string','max:255'],
2929
'date_of_employment' => ['nullable', $this->dateFormatter->dateFormatRule()],
30-
'opening_overtime_balance' => ['nullable','numeric']
30+
'opening_overtime_balance' => ['nullable','numeric'],
31+
'is_account_admin' => ['required','boolean'],
3132
])->validateWithBag('saveEmployee');
3233

3334
$user->forceFill([
3435
'name' => $data['name'],
3536
'date_of_employment' =>
3637
$this->dateFormatter->strToDate($data['date_of_employment']),
3738
'opening_overtime_balance' =>
38-
$data['opening_overtime_balance']
39+
$data['opening_overtime_balance'],
40+
'is_account_admin' => $data['is_account_admin'],
3941
])->save();
4042
}
4143
}

app/Http/Controllers/EditEmployeeController.php

+4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
use App\Models\User;
66
use App\Models\Account;
7+
use Illuminate\Support\Facades\Gate;
78

89
class EditEmployeeController extends Controller
910
{
1011
public function __invoke(Account $account, User $employee)
1112
{
13+
if (Gate::denies('view', $account)) {
14+
abort(403);
15+
}
1216
return view('employees.edit',['employee' => $employee]);
1317
}
1418
}

app/Http/Controllers/ShowEmployeesForAccountController.php

+4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
namespace App\Http\Controllers;
44

55
use App\Models\Account;
6+
use Illuminate\Support\Facades\Gate;
67

78
class ShowEmployeesForAccountController extends Controller
89
{
910
public function __invoke(Account $account)
1011
{
12+
if (Gate::denies('view', $account)) {
13+
abort(403);
14+
}
1115
return view('employees.index', compact('account'));
1216
}
1317
}

app/Http/Controllers/ShowLocationsForAccountController.php

+5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
use App\Models\Account;
66
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Gate;
78

89
class ShowLocationsForAccountController extends Controller
910
{
1011

1112
public function __invoke(Account $account, Request $request)
1213
{
14+
if (Gate::denies('view', $account)) {
15+
abort(403);
16+
}
17+
1318
return view('locations.index', [
1419
'account' => $account,
1520
'user' => $request->user()

app/Http/Livewire/Employees/EditUserProfile.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ class EditUserProfile extends Component
6363
public $editUserProfileForm = [
6464
'name' => null,
6565
'date_of_employment' => null,
66-
'opening_overtime_balance' => null
66+
'opening_overtime_balance' => null,
67+
'is_account_admin' => false
68+
6769
];
6870

6971
public $days = [
@@ -226,6 +228,7 @@ public function mount(User $employee)
226228
$this->employee->date_of_employment_for_humans,
227229
'opening_overtime_balance' =>
228230
$this->employee->opening_overtime_balance,
231+
'is_account_admin' => $this->employee->is_account_admin
229232
], fn() => $this->fillPayrollFormFields($employee), Daybreak::hasEmployeePayrollFeature());
230233
}
231234

app/Policies/AccountPolicy.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function viewAny(User $user)
3030
*/
3131
public function view(User $user, Account $account)
3232
{
33-
return $user->ownsAccount($account);
33+
return $user->isAccountAdmin($account);
3434
}
3535

3636
/**
@@ -53,7 +53,7 @@ public function create(User $user)
5353
*/
5454
public function update(User $user, Account $account)
5555
{
56-
return $user->ownsAccount($account);
56+
return $user->isAccountAdmin($account);
5757
}
5858

5959
/**

app/Traits/HasAccounts.php

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public function ownsAccount(Account $account)
2121
return $this->id == $account->owned_by;
2222
}
2323

24+
public function isAccountAdmin(Account $account)
25+
{
26+
return $this->ownsAccount($account)
27+
|| ($this->belongsToAccount($account) && $this->is_account_admin);
28+
}
29+
2430
/**
2531
* Switch the user's context to the given account.
2632
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddAccountAdminToUsersTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('users', function (Blueprint $table) {
17+
$table->boolean('is_account_admin')->default(false);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('users', function (Blueprint $table) {
29+
$table->dropColumn('is_account_admin');
30+
});
31+
}
32+
}

resources/views/account-navigation-menu.blade.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55
<div class="flex">
66
<!-- Logo -->
77
<div class="flex-shrink-0 flex items-center">
8-
<a href="{{ route('accounts.show', Auth::user()->ownedAccount) }}">
8+
<a href="{{ route('accounts.show', Auth::user()->account) }}">
99
<img src="/logo.svg" class="block h-12 w-auto">
1010
</a>
1111
</div>
1212

1313
<!-- Navigation Links -->
1414
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
15-
<x-account-nav-link href="{{ route('locations', Auth::user()->ownedAccount) }}" :active="request()->routeIs('locations')">
15+
<x-account-nav-link href="{{ route('locations', Auth::user()->account) }}" :active="request()->routeIs('locations')">
1616
{{ __('Locations') }}
1717
</x-account-nav-link>
1818
</div>
1919
@if(App\Daybreak::hasProjectBillingFeature())
2020
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
21-
<x-account-nav-link href="{{ route('projects', Auth::user()->ownedAccount) }}" :active="request()->routeIs('projects')">
21+
<x-account-nav-link href="{{ route('projects', Auth::user()->account) }}" :active="request()->routeIs('projects')">
2222
{{ __('Projects') }}
2323
</x-account-nav-link>
2424
</div>
2525
@endif
2626
@if(App\Daybreak::hasEmployeePayrollFeature())
2727
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
28-
<x-account-nav-link href="{{ route('payrolls', Auth::user()->ownedAccount) }}" :active="request()->routeIs('payrolls')">
28+
<x-account-nav-link href="{{ route('payrolls', Auth::user()->account) }}" :active="request()->routeIs('payrolls')">
2929
{{ __('Payroll') }}
3030
</x-account-nav-link>
3131
</div>
3232
@endif
3333
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
34-
<x-account-nav-link href="{{ route('employees', Auth::user()->ownedAccount) }}" :active="request()->routeIs('employees')">
34+
<x-account-nav-link href="{{ route('employees', Auth::user()->account) }}" :active="request()->routeIs('employees')">
3535
{{ __('Employees') }}
3636
</x-account-nav-link>
3737
</div>
@@ -77,12 +77,12 @@
7777
<div class="border-t border-gray-100"></div>
7878

7979
<!-- Account Management -->
80-
@can('view', Auth::user()->ownedAccount)
80+
@can('view', Auth::user()->account)
8181
<div class="block px-4 py-2 text-xs text-gray-400">
8282
{{ __('Manage Account') }}
8383
</div>
8484

85-
<x-jet-dropdown-link href="{{ route('accounts.show', Auth::user()->ownedAccount) }}">
85+
<x-jet-dropdown-link href="{{ route('accounts.show', Auth::user()->account) }}">
8686
{{ __('Account Settings') }}
8787
</x-jet-dropdown-link>
8888
@endcan
@@ -94,7 +94,7 @@
9494
{{ __('Manage Location') }}
9595
</div>
9696

97-
{{-- <x-jet-dropdown-link href="{{ route('locations.index', Auth::user()->ownedAccount->id) }}">
97+
{{-- <x-jet-dropdown-link href="{{ route('locations.index', Auth::user()->account->id) }}">
9898
{{ __('Account Settings') }}
9999
</x-jet-dropdown-link> --}}
100100

@@ -190,22 +190,22 @@
190190
</x-jet-responsive-nav-link>
191191
@endif
192192

193-
<x-jet-responsive-nav-link href="{{ route('locations', Auth::user()->ownedAccount) }}" :active="request()->routeIs('locations')">
193+
<x-jet-responsive-nav-link href="{{ route('locations', Auth::user()->account) }}" :active="request()->routeIs('locations')">
194194
{{ __('Locations') }}
195195
</x-jet-responsive-nav-link>
196196
@if(App\Daybreak::hasProjectBillingFeature())
197197

198-
<x-jet-responsive-nav-link href="{{ route('projects', Auth::user()->ownedAccount) }}" :active="request()->routeIs('projects')">
198+
<x-jet-responsive-nav-link href="{{ route('projects', Auth::user()->account) }}" :active="request()->routeIs('projects')">
199199
{{ __('Projects') }}
200200
</x-jet-responsive-nav-link>
201201
@endif
202202
@if(App\Daybreak::hasEmployeePayrollFeature())
203-
<x-jet-responsive-nav-link href="{{ route('payrolls', Auth::user()->ownedAccount) }}" :active="request()->routeIs('payrolls')">
203+
<x-jet-responsive-nav-link href="{{ route('payrolls', Auth::user()->account) }}" :active="request()->routeIs('payrolls')">
204204
{{ __('Payroll') }}
205205
</x-jet-responsive-nav-link>
206206
@endif
207207

208-
<x-jet-responsive-nav-link href="{{ route('employees', Auth::user()->ownedAccount) }}" :active="request()->routeIs('employees')">
208+
<x-jet-responsive-nav-link href="{{ route('employees', Auth::user()->account) }}" :active="request()->routeIs('employees')">
209209
{{ __('Employees') }}
210210
</x-jet-responsive-nav-link>
211211

resources/views/livewire/employees/edit-user-profile.blade.php

+7
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@
215215
@if(App\Daybreak::hasEmployeePayrollFeature())
216216
<x-dynamic-component component="employee-payroll-form" />
217217
@endif
218+
<div class="col-span-6 lg:col-span-4 mt-2">
219+
<div class="inline-flex">
220+
<input type="checkbox" id="is_account_admin" wire:model.defer="editUserProfileForm.is_account_admin" class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
221+
<x-jet-label for="is_account_admin" class="ml-2 block text-sm text-gray-900" value="{{ __('Account Admin') }}" />
222+
</div>
223+
<x-jet-input-error for="is_account_admin" class="mt-2" />
224+
</div>
218225
</div>
219226
</x-slot>
220227
<x-slot name="actions">

resources/views/navigation-menu.blade.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@
103103
<div class="border-t border-gray-100"></div>
104104

105105
<!-- Account Management -->
106-
@can('view', Auth::user()->ownedAccount)
106+
@can('view', Auth::user()->account)
107107
<div class="block px-4 py-2 text-xs text-gray-400">
108108
{{ __('Manage Account') }}
109109
</div>
110110

111-
<x-jet-dropdown-link href="{{ route('accounts.show', Auth::user()->ownedAccount->id) }}">
111+
<x-jet-dropdown-link href="{{ route('accounts.show', Auth::user()->account->id) }}">
112112
{{ __('Account Settings') }}
113113
</x-jet-dropdown-link>
114114
@endcan
@@ -180,8 +180,8 @@
180180
{{ __('Location Settings') }}
181181
</x-jet-responsive-nav-link>
182182
@endcan
183-
@can('view', Auth::user()->ownedAccount)
184-
<x-jet-responsive-nav-link href="{{ route('accounts.show', Auth::user()->ownedAccount->id) }}">
183+
@can('view', Auth::user()->account)
184+
<x-jet-responsive-nav-link href="{{ route('accounts.show', Auth::user()->account->id) }}">
185185
{{ __('Account Settings') }}
186186
</x-jet-responsive-nav-link>
187187
@endcan

0 commit comments

Comments
 (0)