Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/Console/Commands/LegacyBudgetGroupShift.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use Illuminate\Support\Facades\Schema;
use App\Models\Legacy\LegacyBudgetGroup;
use App\Models\Legacy\LegacyBudgetItem;
use App\Models\Legacy\LegacyBudgetPlan;
Expand All @@ -17,12 +18,12 @@ class LegacyBudgetGroupShift extends Command

public function handle(): int
{
return \DB::transaction(function (): int {
$latestPlan = LegacyBudgetPlan::orderBy('id', 'desc')->limit(1)->sole();
return DB::transaction(function (): int {
$latestPlan = LegacyBudgetPlan::orderByDesc('id')->limit(1)->sole();
$budgetGroups = LegacyBudgetGroup::where('hhp_id', $latestPlan->id)
->where('id', '>=', $this->argument('new_group_id'));
$this->info('The following amount of other groups will be shifted back: '.$budgetGroups->count());
\Schema::disableForeignKeyConstraints();
Schema::disableForeignKeyConstraints();
// this is so hacky ...
$budgetGroups->update(['id' => DB::raw('-(id + 1)')]);
LegacyBudgetGroup::where('id', '<', 0)->update(['id' => DB::raw('-id')]);
Expand All @@ -36,7 +37,7 @@ public function handle(): int
]);
$newGroup->id = $this->argument('new_group_id');
$newGroup->save();
\Schema::enableForeignKeyConstraints();
Schema::enableForeignKeyConstraints();

return self::SUCCESS;
});
Expand Down
8 changes: 5 additions & 3 deletions app/Console/Commands/LegacyBudgetItemBatchShift.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Console\Commands;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Illuminate\Console\Command;
use Spatie\Regex\Regex;

Expand Down Expand Up @@ -41,8 +43,8 @@ public function handle(): int

$this->info('Transforming '.count($switch).' Legacy Titles');

return \DB::transaction(function () use ($switch): int {
\Schema::disableForeignKeyConstraints();
return DB::transaction(function () use ($switch): int {
Schema::disableForeignKeyConstraints();
foreach ($switch as [$oldId, $newId]) {
$res = $this->call('legacy:budget-id-shift', [
'old_id' => $oldId,
Expand All @@ -54,7 +56,7 @@ public function handle(): int
$this->fail("Failed subprocess $oldId->$newId. Aborting & Roling back...");
}
}
\Schema::enableForeignKeyConstraints();
Schema::enableForeignKeyConstraints();

return self::SUCCESS;
});
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Commands/LegacyBudgetItemShift.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use Illuminate\Support\Facades\DB;
use App\Models\Legacy\Booking;
use App\Models\Legacy\LegacyBudgetItem;
use App\Models\Legacy\ProjectPost;
Expand Down Expand Up @@ -32,7 +33,7 @@ class LegacyBudgetItemShift extends Command
*/
public function handle(): int
{
return \DB::transaction(function (): int {
return DB::transaction(function (): int {
$old_id = $this->argument('old_id');
$new_id = $this->argument('new_id');

Expand Down
8 changes: 5 additions & 3 deletions app/Console/Commands/LegacyDeleteBudgetPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Console\Commands;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use App\Models\Legacy\LegacyBudgetItem;
use App\Models\Legacy\LegacyBudgetPlan;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -36,12 +38,12 @@ public function handle(): void
return;
}

\DB::transaction(function () use ($hhp, $groups, $title): void {
\Schema::disableForeignKeyConstraints();
DB::transaction(function () use ($hhp, $groups, $title): void {
Schema::disableForeignKeyConstraints();
$title->delete();
$groups->delete();
$hhp->delete();
\Schema::enableForeignKeyConstraints();
Schema::enableForeignKeyConstraints();
$this->info('Plan, Groups and Bugets are deleted successfully!');
});

Expand Down
12 changes: 7 additions & 5 deletions app/Console/Commands/LegacyMigrateEncryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Console\Commands;

use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Str;
use App\Models\Legacy\ChatMessage;
use App\Models\Legacy\Expense;
use Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException;
Expand Down Expand Up @@ -51,13 +53,13 @@ public function handle(): int
// old prefix
$text = substr($text, strlen('$enc$'));
$text = ChatHandler::legacyDecryptMessage($text, Env::get('CHAT_PRIVATE_KEY'));
$message->text = \Crypt::encryptString($text);
$message->text = Crypt::encryptString($text);
$message->save();
$count++;
} elseif ($message->type === -1) {
// not used productive anymore, was "private message"
$text = ChatHandler::legacyDecryptMessage($text, Env::get('CHAT_PRIVATE_KEY'));
$message->text = \Crypt::encryptString($text);
$message->text = Crypt::encryptString($text);
$message->save();
$count++;
}
Expand All @@ -72,11 +74,11 @@ public function handle(): int
Expense::all()->each(function ($expense) use (&$count): void {
$cryptIban = $expense->getAttribute('zahlung_iban');
try {
\Crypt::decryptString($cryptIban);
Crypt::decryptString($cryptIban);
} catch (DecryptException) {
$iban = AuslagenHandler2::legacyDecryptStr($cryptIban);
$expense->setAttribute('zahlung_iban', \Crypt::encryptString($iban));
$expense->etag = \Str::random(32);
$expense->setAttribute('zahlung_iban', Crypt::encryptString($iban));
$expense->etag = Str::random(32);
$expense->save();
$count++;
}
Expand Down
5 changes: 3 additions & 2 deletions app/Console/Commands/LegacyMigrateFilesToStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use Illuminate\Support\Facades\Storage;
use App\Models\Legacy\ExpenseReceipt;
use App\Models\Legacy\FileInfo;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -39,8 +40,8 @@ public function handle(): void
if (empty($data->diskpath)) {
$data->diskpath = $path;
}
if (! \Storage::has($path)) {
\Storage::put($path, $pdfData);
if (! Storage::has($path)) {
Storage::put($path, $pdfData);
}
if ($this->option('delete') === true) {
$data->data = null;
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Commands/StuFisHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use Illuminate\Support\Facades\DB;
use Illuminate\Console\Command;

class StuFisHealth extends Command
Expand All @@ -27,7 +28,7 @@ public function handle(): void
{
$output = collect([
'version' => config('stufis.version', ''),
'database-prefix' => \DB::connection()->getConfig('prefix'),
'database-prefix' => DB::connection()->getConfig('prefix'),
]);
if ($this->option('json')) {
$this->output->writeln(json_encode($output, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
Expand Down
2 changes: 1 addition & 1 deletion app/Exports/Datev/DatevExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Models\Legacy\Booking;
use App\Models\Legacy\Expense;
use App\Models\Legacy\FileInfo;
use Carbon\Carbon;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Date;
Expand Down
2 changes: 1 addition & 1 deletion app/Exports/Datev/DatevExportPreviewRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Exports\Datev;

use Carbon\Carbon;
use Illuminate\Support\Carbon;

/**
* A single expense row for the DATEV export preview table — one expense = one ledger entry.
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use Illuminate\Support\Facades\App;
use App\Models\User;
use App\Services\Auth\AuthService;
use Illuminate\Http\RedirectResponse;
Expand All @@ -19,7 +20,7 @@ public function login()

public function callback(Request $request): RedirectResponse
{
if (Auth::guest() && ! \App::runningUnitTests()) {
if (Auth::guest() && ! App::runningUnitTests()) {
[$identifiers, $userAttributes] = $this->authService->userFromCallback($request);

$user = User::updateOrCreate($identifiers, $userAttributes);
Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/Dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\App;
use App\Services\Auth\AuthService;

class Dev extends Controller
{
public function groups()
{
$groupsRaw = \App::get(AuthService::class)->userGroupsRaw();
$groupMapping = \App::get(AuthService::class)->groupMapping();
$groups = \Auth::user()?->getGroups();
$groupsRaw = App::get(AuthService::class)->userGroupsRaw();
$groupMapping = App::get(AuthService::class)->groupMapping();
$groups = Auth::user()?->getGroups();

return view('components.dump', ['dump' => [
'groups-raw' => $groupsRaw,
Expand Down
18 changes: 9 additions & 9 deletions app/Http/Controllers/Legacy/DeleteExpenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http\Controllers\Legacy;

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Models\Legacy\Expense;
use App\Models\Legacy\ExpenseReceipt;
Expand All @@ -18,17 +20,15 @@ public function __invoke(int $expense_id)

// authorize user
$userPerm =
\Auth::user()->can('budget-officer', User::class)
|| $project->creator->id === \Auth::user()->id
|| explode(';', (string) $expense->created)[1] === \Auth::user()->username;
Auth::user()->can('budget-officer', User::class)
|| $project->creator->id === Auth::user()->id
|| explode(';', (string) $expense->created)[1] === Auth::user()->username;
// authorize state
$deletableState = ! in_array(explode(';', (string) $expense->state)[0], ['instructed', 'booked'], true);

if ($userPerm === false || $deletableState === false) {
abort(403);
}
abort_if($userPerm === false || $deletableState === false, 403);
// to make sure to delete everything and not only parts
\DB::beginTransaction();
DB::beginTransaction();
$reciepts = $expense->receipts;
$reciepts->each(function (ExpenseReceipt $receipt): void {
// delete all posts
Expand All @@ -49,9 +49,9 @@ public function __invoke(int $expense_id)

// clean up storage if DB is successfully cleaned
DB::afterCommit(function () use ($expense_id): void {
\Storage::deleteDirectory("auslagen/{$expense_id}/");
Storage::deleteDirectory("auslagen/{$expense_id}/");
});
\DB::commit();
DB::commit();

return to_route('legacy.dashboard', ['sub' => 'mygremium']);
}
Expand Down
9 changes: 4 additions & 5 deletions app/Http/Controllers/Legacy/DeleteProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Legacy;

use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Models\Legacy\Project;
use App\Models\User;
Expand All @@ -13,13 +14,11 @@ public function __invoke(int $project_id)
$project = Project::findOrFail($project_id);

// authorize
$userPerm = \Auth::user()->can('budget-officer', User::class)
|| $project->creator->id === \Auth::user()->id;
$userPerm = Auth::user()->can('budget-officer', User::class)
|| $project->creator->id === Auth::user()->id;
$dataPerm = $project->expenses()->count() === 0;

if ($userPerm === false || $dataPerm === false) {
abort(403);
}
abort_if($userPerm === false || $dataPerm === false, 403);

// delete
$project->posts()->delete();
Expand Down
12 changes: 7 additions & 5 deletions app/Http/Controllers/Legacy/LegacyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http\Controllers\Legacy;

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Auth;
use App\Exceptions\LegacyJsonException;
use App\Exceptions\LegacyRedirectException;
use App\Http\Controllers\Controller;
Expand Down Expand Up @@ -83,7 +85,7 @@ private function resolveSectionTabs(Request $request): ?array
['Haushaltsverantwortliche*r', 'scale', 'legacy.todo.hv'],
['Kassenverantwortliche*r', 'calculator', 'legacy.todo.kv'],
];
if (\Auth::user()->can('finance', \Auth::user())) {
if (Auth::user()->can('finance', Auth::user())) {
$items[] = ['Überweisungen', 'banknotes', 'legacy.todo.kv.bank'];
}

Expand Down Expand Up @@ -172,7 +174,7 @@ public function belegePdf(int $project_id, int $auslagen_id, int $version, ?stri
{
// file was generated and requested by the iframe
if ($file_name !== null) {
return \Storage::response(
return Storage::response(
"auslagen/$auslagen_id/belege-pdf-v$version.pdf",
$file_name
);
Expand All @@ -199,7 +201,7 @@ public function zahlungsanweisungPdf(int $project_id, int $auslagen_id, int $ver
{
// file was generated and requested by the iframe call
if ($file_name !== null) {
return \Storage::response(
return Storage::response(
"/auslagen/$auslagen_id/zahlungsanweisung-v$version.pdf",
$file_name
);
Expand All @@ -225,8 +227,8 @@ public function zahlungsanweisungPdf(int $project_id, int $auslagen_id, int $ver
public function deliverFile($auslagen_id, $fileHash, $fileName): StreamedResponse
{
$path = "/auslagen/$auslagen_id/$fileHash.pdf";
if (\Storage::exists($path)) {
return \Storage::response($path, $fileName);
if (Storage::exists($path)) {
return Storage::response($path, $fileName);
}
throw new FileNotFoundException("Datei $path konnte nicht gefunden werden");
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Auth;
use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
Expand All @@ -17,7 +18,7 @@ public function handle($request, Closure $next, ...$guards): Response
$this->authenticate($request, $guards);

// adds to parent: only user with the login or admin group pass
$groups = \Auth::user()->getGroups();
$groups = Auth::user()->getGroups();
if ($groups->contains('login') || $groups->contains('admin')) {
return $next($request);
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/VersionChangeNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Auth;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
Expand All @@ -16,7 +17,7 @@ class VersionChangeNotification
*/
public function handle(Request $request, Closure $next): Response
{
if (($user = \Auth::user()) !== null) {
if (($user = Auth::user()) !== null) {
$lastVersion = $user->version;
if ($lastVersion !== config('stufis.version')) {
Session::put('message.text', __('general.version_notification.text'));
Expand Down
Loading
Loading