Skip to content

Commit

Permalink
roll of honor
Browse files Browse the repository at this point in the history
  • Loading branch information
fiste788 committed Sep 12, 2024
1 parent a74306b commit 4745022
Show file tree
Hide file tree
Showing 29 changed files with 1,193 additions and 1,241 deletions.
2 changes: 1 addition & 1 deletion .docker/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
COMPOSE_PROJECT_NAME=fantamanajer
PHP_VERSION=8.2.5
PHP_VERSION=8.3.8
MYSQL_VERSION=10.6.15
APACHE_VERSION=2.4.57

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "project",
"homepage": "https://fantamanajer.it",
"require": {
"php": ">=8.2",
"php": ">=8.3",
"burzum/cakephp-service-layer": "^3.0",
"cakephp/authentication": "^3.0",
"cakephp/authorization": "^3.0",
Expand All @@ -24,7 +24,7 @@
"symfony/serializer": "^7.0",
"symfony/uid": "^7.0",
"web-auth/webauthn-lib": "^4.7",
"web-token/jwt-library": "^3.3",
"web-token/jwt-library": "^4.0",
"whichbrowser/parser": "^2.1"
},
"require-dev": {
Expand Down Expand Up @@ -102,4 +102,4 @@
"test:typing": "@stan",
"test:unit": "@test"
}
}
}
2,007 changes: 818 additions & 1,189 deletions composer.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@
->setPass(['id']);
;

$routes->resources('Leagues', [
'only' => ['view'],
], function (RouteBuilder $routes): void {
$routes->connect('/roll-of-honor', [
'controller' => 'Championships',
'action' => 'index',
'prefix' => 'Leagues',
]);
});

$routes->resources('Championships', [
'only' => ['view', 'update'],
], function (RouteBuilder $routes): void {
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
parameters:
level: 8
treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: false
paths:
- src

Expand All @@ -12,6 +11,8 @@ parameters:
- src/Stream/*

ignoreErrors:
-
identifier: missingType.generics
- '#Access to an undefined property object::\$entity#'
- '#Access to an undefined property object::\$query#'
- '#Access to an undefined property object::\$entities#'
Expand Down
2 changes: 1 addition & 1 deletion plugins/StreamCake/src/StreamCakePlugin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace StreamCaked;
namespace StreamCake;

use Cake\Core\BasePlugin;
use Cake\Core\PluginApplicationInterface;
Expand Down
5 changes: 2 additions & 3 deletions src/Command/SendMissingLineupNotificationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Cake\Console\ConsoleOptionParser;
use Cake\Core\Configure;
use Cake\I18n\DateTime;
use Cake\I18n\FrozenTime;
use GetStream\Stream\Client;
use WebPush\Action;
use WebPush\Notification;
Expand Down Expand Up @@ -99,7 +98,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
foreach ($teams as $team) {
$action = [
'operation' => 'navigateLastFocusedOrOpen',
'url' => '/teams/' . $team->id . '/lineup/current',
'url' => "/teams/{$team->id}/lineup/current",
];
$body = sprintf(
'Ricordati di impostare la formazione per la giornata %d! Ti restano %s',
Expand All @@ -121,7 +120,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
->withPayload($message->toString());
$io->out($message->toString());
foreach ($team->user->push_subscriptions as $subscription) {
$io->out('Send push notification to ' . $subscription->endpoint);
$io->out("Send push notification to {$subscription->endpoint}");
$this->PushNotification->sendAndRemoveExpired($notification, $subscription);
}

Expand Down
12 changes: 3 additions & 9 deletions src/Command/StartSeasonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ private function createSeason(ConsoleIo $io, Arguments $_args): Season
'bonus_points' => true,
]
);
$firstAugust = Chronos::create($year, 8, 1);

/** @var \App\Model\Table\MatchdaysTable $matchdaysTable */
$matchdaysTable = $this->fetchTable('Matchdays');
$zeroMatchday = $matchdaysTable->newEntity([
'number' => 0,
'date' => Chronos::now()->endOfDay(),
'date' => $firstAugust,
]);
$season->matchdays = [$zeroMatchday];
$seasonsTable->saveOrFail($season);
Expand All @@ -131,16 +132,9 @@ private function createSeason(ConsoleIo $io, Arguments $_args): Season

$lastMatchday = $matchdaysTable->newEntity([
'number' => 39,
'date' => Chronos::create($year + 1, 7, 31, 23, 59, 59),
'date' => $firstAugust->addYears(1)->addSeconds(-1),
]);
$season->matchdays = [$lastMatchday];

/** @var \App\Model\Entity\Matchday $firstMatchday */
$firstMatchday = $matchdaysTable->find()->where(['number' => 1, 'season_id' => $season->id])->first();
/** @var \App\Model\Entity\Matchday $zeroMatchday */
$zeroMatchday = $matchdaysTable->find()->where(['number' => 0, 'season_id' => $season->id])->first();
$zeroMatchday->date = $firstMatchday->date->subDays(7)->startOfWeek()->startOfDay();
$matchdaysTable->saveOrFail($zeroMatchday);
$seasonsTable->saveOrFail($season);

return $season;
Expand Down
49 changes: 49 additions & 0 deletions src/Controller/Leagues/ChampionshipsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

namespace App\Controller\Leagues;

use App\Controller\AppController;
use Authorization\Exception\ForbiddenException;
use Cake\Event\EventInterface;
use Psr\Http\Message\ResponseInterface;

/**
* @property \App\Model\Table\ChampionshipsTable $Championships
*/
class ChampionshipsController extends AppController
{
/**
* {@inheritDoc}
*
* @throws \Authorization\Exception\ForbiddenException
*/
public function beforeFilter(EventInterface $event): void
{
parent::beforeFilter($event);
$leagueId = (int)$this->request->getParam('league_id');
/** @var \App\Model\Entity\User $identity */
$identity = $this->Authentication->getIdentity();
if (!$identity->isInLeague($leagueId)) {
throw new ForbiddenException();
}
}

/**
* Index
*
* @return \Psr\Http\Message\ResponseInterface
* @throws \Crud\Error\Exception\ActionNotConfiguredException
* @throws \Exception
*/
public function index(): ResponseInterface
{
/** @var \Crud\Action\IndexAction $action */
$action = $this->Crud->action();
$action->findMethod(['byLeagueId' => [
'league_id' => (int)$this->request->getParam('league_id'),
]]);

return $this->Crud->execute();
}
}
20 changes: 19 additions & 1 deletion src/Database/Type/AttestedCredentialDataType.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Database\Type;

use AllowDynamicProperties;
use Burzum\CakeServiceLayer\Service\ServiceAwareTrait;
use Cake\Database\Driver;
use Cake\Database\Type\BaseType;
use Webauthn\AttestedCredentialData;

/**
* AttestedCredential data type
*
* @property \App\Service\WebauthnService $Webauthn
*/
#[AllowDynamicProperties]
class AttestedCredentialDataType extends BaseType
{
use ServiceAwareTrait;

/**
* @inheritDoc
*/
Expand All @@ -32,7 +43,14 @@ public function toPHP(mixed $value, Driver $driver): mixed
/** @var array<string, mixed> $json */
$json = json_decode((string)$value, true);

return AttestedCredentialData::createFromArray($json);
$this->loadService('Webauthn');

return $this->Webauthn->serializer->deserialize(
$json,
AttestedCredentialData::class,
'json'
);
//return AttestedCredentialData::createFromArray($json);
}

/**
Expand Down
20 changes: 19 additions & 1 deletion src/Database/Type/PublicKeyCredentialDescriptorType.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Database\Type;

use AllowDynamicProperties;
use Burzum\CakeServiceLayer\Service\ServiceAwareTrait;
use Cake\Database\Driver;
use Cake\Database\Type\BaseType;
use Webauthn\PublicKeyCredentialDescriptor;

/**
* PublicKeyCredential data type
*
* @property \App\Service\WebauthnService $Webauthn
*/
#[AllowDynamicProperties]
class PublicKeyCredentialDescriptorType extends BaseType
{
use ServiceAwareTrait;

/**
* @inheritDoc
*/
Expand All @@ -30,7 +41,14 @@ public function toPHP(mixed $value, Driver $driver): mixed
return null;
}

return PublicKeyCredentialDescriptor::createFromString((string)$value);
$this->loadService('Webauthn');

return $this->Webauthn->serializer->deserialize(
$value,
PublicKeyCredentialDescriptor::class,
'json'
);
//return PublicKeyCredentialDescriptor::createFromString((string)$value);
}

/**
Expand Down
22 changes: 21 additions & 1 deletion src/Database/Type/TrustPathDataType.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Database\Type;

use AllowDynamicProperties;
use Burzum\CakeServiceLayer\Service\ServiceAwareTrait;
use Cake\Database\Driver;
use Cake\Database\Type\BaseType;
use Webauthn\TrustPath\TrustPathLoader;
use Webauthn\Denormalizer\WebauthnSerializerFactory;
use Webauthn\TrustPath\TrustPath;

/**
* TrustPath data type
*
* @property \App\Service\WebauthnService $Webauthn
*/
#[AllowDynamicProperties]
class TrustPathDataType extends BaseType
{
use ServiceAwareTrait;

/**
* @inheritDoc
*/
Expand All @@ -32,7 +45,14 @@ public function toPHP(mixed $value, Driver $driver): mixed
/** @var array<string, mixed> $json */
$json = json_decode((string)$value, true);

return TrustPathLoader::loadTrustPath($json);
$this->loadService('Webauthn');

return $this->Webauthn->serializer->deserialize(
$json,
TrustPath::class,
'json'
);
// return TrustPathLoader::loadTrustPath($json);
}

/**
Expand Down
33 changes: 33 additions & 0 deletions src/Model/Entity/RollOfHonor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);

namespace App\Model\Entity;

use Cake\ORM\Entity;

/**
* RollOfHonor Entity
*
* @property int $team_id
* @property int $championship_id
* @property int $league_id
* @property float|null $points
* @property int|null $rank
*
* @property \App\Model\Entity\Member $member
*/
class RollOfHonor extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @var array<string, bool>
*/
protected array $_accessible = [

];
}
14 changes: 14 additions & 0 deletions src/Model/Entity/User.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace App\Model\Entity;
Expand Down Expand Up @@ -95,6 +96,19 @@ public function isInChampionship(int $championshipId): bool
}));
}

/**
* In in league
*
* @param int $leagueId Id
* @return bool
*/
public function isInLeague(int $leagueId): bool
{
return !empty(Hash::filter($this->teams, function (Team $value) use ($leagueId): bool {
return $value->championship->league_id == $leagueId;
}));
}

/**
* Is championship admin
*
Expand Down
Loading

0 comments on commit 4745022

Please sign in to comment.