Skip to content

Commit d28fca0

Browse files
committed
Merge branch 'master' into #355-2fa
# Conflicts: # app/Http/Controllers/Api/SearchController.php # resources/js/select2.js # routes/web.php
2 parents 05d898a + f312208 commit d28fca0

File tree

71 files changed

+941
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+941
-490
lines changed

app/Console/Commands/Database/RefreshProceduresCommand.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function __construct()
3838
*/
3939
public function handle()
4040
{
41-
$pdo = DB::getPdo();
4241
$databaseName = DB::getDatabaseName();
4342
$databaseUsername = DB::getConfig('username');
4443
$hostname = gethostname();
@@ -55,21 +54,25 @@ public function handle()
5554

5655
foreach ($procedureSqlFiles as $procedureFile) {
5756
$this->info('Creating procedures: ' . $procedureFile);
58-
$sql = file_get_contents($proceduresDirectory . DIRECTORY_SEPARATOR . $procedureFile);
59-
60-
$sql = str_replace('DELIMITER //', '', $sql);
61-
$sql = str_replace(" //\nDELIMITER ;", '', $sql);
62-
63-
$pdo->exec($sql);
6457

6558
$spname = basename($procedureFile, '.sql');
6659
if (substr($spname, 0, 3) == 'fn_') {
67-
$query = "GRANT EXECUTE ON FUNCTION $spname TO '$databaseUsername'@'$hostname'";
60+
$this->info('Skipping FUNCTION');
61+
continue; // Bail on functions as they need SUPER
62+
$dropQuery = "DROP FUNCTION IF EXISTS $spname";
63+
$grantQuery = "GRANT EXECUTE ON FUNCTION $spname TO '$databaseUsername'@'$hostname'";
6864
} else {
69-
$query = "GRANT EXECUTE ON PROCEDURE $spname TO '$databaseUsername'@'$hostname'";
65+
$dropQuery = "DROP PROCEDURE IF EXISTS $spname";
66+
$grantQuery = "GRANT EXECUTE ON PROCEDURE $spname TO '$databaseUsername'@'$hostname'";
7067
}
7168

72-
DB::unprepared($query);
69+
$sql = file_get_contents($proceduresDirectory . DIRECTORY_SEPARATOR . $procedureFile);
70+
preg_match_all('/CREATE.*END/ms', $sql, $createArray);
71+
$createQuery = $createArray[0][0];
72+
73+
DB::unprepared($dropQuery);
74+
DB::unprepared($createQuery);
75+
DB::unprepared($grantQuery);
7376
}
7477
}
7578
}

app/Console/Commands/Database/RefreshViewsCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function handle()
6060
foreach ($viewSqlFiles as $viewFile) {
6161
$this->info('Creating view: ' . $viewFile);
6262
$sql = file_get_contents($viewsDirectory . DIRECTORY_SEPARATOR . $viewFile);
63-
// dump($sql);
63+
6464
DB::unprepared($sql);
6565
}
6666
}

app/HMS/Entities/Banking/Account.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Account
2222
protected $natwestRef;
2323

2424
/**
25-
* @var \HMS\Entities\User
25+
* @var \HMS\Entities\User[]
2626
*/
2727
protected $users;
2828

@@ -82,7 +82,7 @@ public function getNatwestRef(): ?string
8282
/**
8383
* Gets the value of users.
8484
*
85-
* @return \HMS\Entities\User
85+
* @return \HMS\Entities\User[]
8686
*/
8787
public function getUsers()
8888
{
@@ -92,7 +92,7 @@ public function getUsers()
9292
/**
9393
* Sets the value of users.
9494
*
95-
* @param \HMS\Entities\User $users the users
95+
* @param \HMS\Entities\User[] $users the users
9696
*
9797
* @return self
9898
*/

app/HMS/Repositories/Banking/AccountRepository.php

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ public function findOneByPaymentRef(string $paymentRef);
3232
*/
3333
public function findLikeByPaymentRef(string $paymentRef);
3434

35+
/**
36+
* @param int $perPage
37+
* @param string $pageName
38+
*
39+
* @return \Illuminate\Pagination\LengthAwarePaginator
40+
*/
41+
public function paginateAll($perPage = 15, $pageName = 'page');
42+
43+
/**
44+
* @param int $perPage
45+
* @param string $pageName
46+
*
47+
* @return \Illuminate\Pagination\LengthAwarePaginator
48+
*/
49+
public function paginateJointAccounts($perPage = 15, $pageName = 'page');
50+
3551
/**
3652
* Save Account to the DB.
3753
*

app/HMS/Repositories/Banking/Doctrine/DoctrineAccountRepository.php

+22
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
use HMS\Entities\Banking\Account;
66
use Doctrine\ORM\EntityRepository;
77
use HMS\Repositories\Banking\AccountRepository;
8+
use LaravelDoctrine\ORM\Pagination\PaginatesFromRequest;
89

910
class DoctrineAccountRepository extends EntityRepository implements AccountRepository
1011
{
12+
use PaginatesFromRequest;
13+
1114
/**
1215
* @param $id
1316
*
@@ -51,6 +54,25 @@ public function findLikeByPaymentRef(string $paymentRef)
5154
return $q->getResult();
5255
}
5356

57+
/**
58+
* @param int $perPage
59+
* @param string $pageName
60+
*
61+
* @return \Illuminate\Pagination\LengthAwarePaginator
62+
*/
63+
public function paginateJointAccounts($perPage = 15, $pageName = 'page')
64+
{
65+
$q = parent::createQueryBuilder('a')
66+
->leftJoin('a.users', 'user')
67+
->where('user.account IS NOT NULL')
68+
->groupBy('a.id, a.paymentRef')
69+
->having('COUNT(0) > 1');
70+
71+
$q = $q->getQuery();
72+
73+
return $this->paginate($q, $perPage, $pageName);
74+
}
75+
5476
/**
5577
* Save Account to the DB.
5678
*

app/HMS/Repositories/Tools/BookingRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface BookingRepository
1616
*
1717
* @return null|Booking
1818
*/
19-
public function currnetForTool(Tool $tool);
19+
public function currentForTool(Tool $tool);
2020

2121
/**
2222
* Get the next booking for a tool.

app/HMS/Repositories/Tools/Doctrine/DoctrineBookingRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DoctrineBookingRepository extends EntityRepository implements BookingRepos
2020
*
2121
* @return null|Booking
2222
*/
23-
public function currnetForTool(Tool $tool)
23+
public function currentForTool(Tool $tool)
2424
{
2525
$now = Carbon::now();
2626

app/Http/Controllers/Api/SearchController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function users(string $searchQuery = null, Request $request)
5353
'address1' => $user->getProfile() ? $user->getProfile()->getAddress1() : null,
5454
'addressPostcode' => $user->getProfile() ? $user->getProfile()->getAddressPostcode() : null,
5555
'accountId' => $user->getAccount() ? $user->getAccount()->getId() : null,
56-
'paymentRef' => $user->getAccount() ? $user->getAccount()->getPaymentRef() : null,
56+
'paymentRef' => $user->getAccount() ? $user->getAccount()->getPaymentRef() : '',
5757
'google2fa' => $user->isGoogle2faEnable(),
5858
];
5959
}));

app/Http/Controllers/Auth/RegisterController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RegisterController extends Controller
3030
*
3131
* @var string
3232
*/
33-
protected $redirectTo = '/home';
33+
protected $redirectTo = '/registration-complete';
3434

3535
/**
3636
* @var UserManager
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Banking;
4+
5+
use HMS\Entities\User;
6+
use Illuminate\Http\Request;
7+
use HMS\Entities\Banking\Account;
8+
use App\Http\Controllers\Controller;
9+
use HMS\Repositories\UserRepository;
10+
use HMS\Factories\Banking\AccountFactory;
11+
use HMS\Repositories\Banking\AccountRepository;
12+
13+
class AccountController extends Controller
14+
{
15+
/**
16+
* @var AccountRepository
17+
*/
18+
protected $accountRepository;
19+
20+
/**
21+
* @var AccountFactory
22+
*/
23+
protected $accountFactory;
24+
25+
/**
26+
* @var UserRepository
27+
*/
28+
private $userRepository;
29+
30+
/**
31+
* Create a new controller instance.
32+
*
33+
* @param AccountRepository $accountRepository
34+
* @param UserRepository $userRepository
35+
*/
36+
public function __construct(
37+
AccountRepository $accountRepository,
38+
AccountFactory $accountFactory,
39+
UserRepository $userRepository
40+
) {
41+
$this->accountRepository = $accountRepository;
42+
$this->accountFactory = $accountFactory;
43+
$this->userRepository = $userRepository;
44+
45+
$this->middleware('can:profile.view.all')->only(['listJoint', 'show']);
46+
$this->middleware('can:profile.edit.all')->only(['linkUser', 'unlinkUser']);
47+
}
48+
49+
/**
50+
* Display a listing of the join Acounts.
51+
*
52+
* @return \Illuminate\Http\Response
53+
*/
54+
public function listJoint()
55+
{
56+
$joinAccounts = $this->accountRepository->paginateJointAccounts();
57+
58+
return view('banking.accounts.joint')
59+
->with('jointAccounts', $joinAccounts);
60+
}
61+
62+
/**
63+
* Display the specified Acount.
64+
*
65+
* @param Account $account
66+
*
67+
* @return \Illuminate\Http\Response
68+
*/
69+
public function show(Account $account)
70+
{
71+
// $bankTransactions = $this->bankTransactionRepository->paginateByAccount($user->getAccount(), 10);
72+
73+
return view('banking.accounts.show')
74+
->with('account', $account);
75+
}
76+
77+
/**
78+
* Link a given User with this Account.
79+
*
80+
* @param Account $account
81+
* @param \Illuminate\Http\Request $request
82+
*
83+
* @return \Illuminate\Http\Response
84+
*/
85+
public function linkUser(Account $account, Request $request)
86+
{
87+
$valiidatedDate = $request->validate([
88+
'user_id' => [
89+
'required',
90+
'exists:HMS\Entities\User,id',
91+
],
92+
]);
93+
94+
$user = $this->userRepository->findOneById($valiidatedDate['user_id']);
95+
96+
// TODO: As this will changes a Users account_id, we will orphan the old Account ref
97+
// if there are no bank_transaction against the ref we should be safe to delete it?
98+
$oldAccount = $user->getAccount();
99+
100+
$user->setAccount($account);
101+
$this->userRepository->save($user);
102+
103+
// TODO: fire some user account changed event?
104+
105+
flash($user->getFullname() . ' linked to Account.')->success();
106+
107+
return redirect()->route('banking.accounts.show', $account->getId());
108+
}
109+
110+
/**
111+
* Unlink a given User with this Account.
112+
*
113+
* @param Account $account
114+
* @param \Illuminate\Http\Request $request
115+
*
116+
* @return \Illuminate\Http\Response
117+
*/
118+
public function unlinkUser(Account $account, Request $request)
119+
{
120+
$valiidatedDate = $request->validate([
121+
'user_id' => [
122+
'required',
123+
'exists:HMS\Entities\User,id',
124+
],
125+
'new-account' => 'required|boolean',
126+
'existing-account' => 'required_if:new-account,false|exists:HMS\Entities\Banking\Account,id',
127+
]);
128+
129+
$user = $this->userRepository->findOneById($valiidatedDate['user_id']);
130+
131+
if ($valiidatedDate['new-account']) {
132+
$newAccount = $this->accountFactory->createNewAccount();
133+
} else {
134+
$newAccount = $this->accountRepository->findOneById($valiidatedDate['existing-account']);
135+
}
136+
137+
$user->setAccount($newAccount);
138+
$this->userRepository->save($user);
139+
140+
// TODO: fire some user account changed event?
141+
142+
flash($user->getFullname() . ' un-linked from Account.')->success();
143+
144+
return redirect()->route('banking.accounts.show', $account->getId());
145+
}
146+
}

app/Http/Controllers/Banking/BankTransactionsController.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function index(Request $request)
9898

9999
$bankTransactions = $this->bankTransactionRepository->paginateByAccount($user->getAccount(), 10);
100100

101-
return view('bankTransactions.index')
101+
return view('banking.transactions.index')
102102
->with('user', $user)
103103
->with('bankTransactions', $bankTransactions)
104104
->with('accountNo', $this->accountNo)
@@ -115,7 +115,8 @@ public function index(Request $request)
115115
*/
116116
public function edit(BankTransaction $bankTransaction)
117117
{
118-
return view('bankTransactions.edit')->with(['bankTransaction' => $bankTransaction]);
118+
// TODO: bail if this transaction is all ready matched
119+
return view('banking.transactions.edit')->with(['bankTransaction' => $bankTransaction]);
119120
}
120121

121122
/**
@@ -146,6 +147,6 @@ public function listUnmatched()
146147
{
147148
$bankTransactions = $this->bankTransactionRepository->paginateByAccount(null);
148149

149-
return view('bankTransactions.listUnmatched')->with(['bankTransactions' => $bankTransactions]);
150+
return view('banking.transactions.listUnmatched')->with(['bankTransactions' => $bankTransactions]);
150151
}
151152
}

app/Http/Controllers/HomeController.php

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use HMS\Entities\Role;
56
use HMS\Repositories\MetaRepository;
67
use HMS\Repositories\Members\ProjectRepository;
78

@@ -24,6 +25,20 @@ public function __construct(ProjectRepository $projectRepository)
2425
$this->projectRepository = $projectRepository;
2526
}
2627

28+
/**
29+
* Show the application welcome screen.
30+
*
31+
* @return \Illuminate\Http\Response
32+
*/
33+
public function welcome()
34+
{
35+
if (\Auth::check()) {
36+
return redirect()->route('home');
37+
}
38+
39+
return view('welcome');
40+
}
41+
2742
/**
2843
* Show the application dashboard.
2944
*
@@ -33,6 +48,10 @@ public function index()
3348
{
3449
$user = \Auth::user();
3550

51+
if ($user->hasRoleByName(Role::MEMBER_APPROVAL)) {
52+
return view('pages.awaitingApproval');
53+
}
54+
3655
$projectCount = $this->projectRepository->countActiveByUser($user);
3756

3857
return view('home')->with([

0 commit comments

Comments
 (0)