Skip to content

Commit

Permalink
Add missing maintenance.access permission and fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Nov 15, 2020
1 parent 5053540 commit ee7e9b4
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->files()
->in(__DIR__.'/app')
->in(__DIR__.'/config')
->in(__DIR__.'/database')
->in(__DIR__.'/resources/lang')
->in(__DIR__.'/routes');
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Azuriom follows the [PSR-12 coding style](https://www.php-fig.org/psr/psr-12/).

You can also run [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) to automatically fix the code style with this command.

## Manual installation for development

1. Clone the [GitHub repository](https://github.com/Azuriom/Azuriom).
Expand Down
2 changes: 0 additions & 2 deletions app/Games/Minecraft/Servers/Ping.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use Azuriom\Games\Minecraft\Servers\Protocol\MinecraftPing;
use Azuriom\Games\ServerBridge;
use Azuriom\Models\User;
use Exception;
use Illuminate\Support\Arr;
use RuntimeException;

class Ping extends ServerBridge
{
Expand Down
5 changes: 3 additions & 2 deletions app/Games/ServerBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ abstract public function verifyLink();
* @param \Azuriom\Models\User|null $user
* @param bool $needConnected
*/
public function sendCommands(array $commands, User $user = null, bool $needConnected = false) {
public function sendCommands(array $commands, User $user = null, bool $needConnected = false)
{
if (! $this->canExecuteCommand()) {
report(new RuntimeException('Command cannot be executed with this link.'));

Expand All @@ -67,7 +68,7 @@ public function sendCommands(array $commands, User $user = null, bool $needConne
* @param array $commands
* @param string|null $playerName
* @param bool $needConnected
* @deprecated Use sendCommands() instead.
* @deprecated use sendCommands() instead
*/
public function executeCommands(array $commands, ?string $playerName, bool $needConnected = false)
{
Expand Down
1 change: 0 additions & 1 deletion app/Games/Steam/Servers/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Azuriom\Games\Steam\SteamID;
use Azuriom\Models\User;
use Exception;
use RuntimeException;
use xPaw\SourceQuery\SourceQuery;

class Query extends ServerBridge
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/Admin/BanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function store(BanRequest $request, User $user)
'reason' => $request->input('reason'),
]);

$user->update(['is_banned' => true]);

return redirect()->route('admin.users.edit', $user)->with('success', trans('admin.users.status.banned'));
}

Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ public function enableAdvancedCache()
return $redirect->with('error', trans('admin.settings.performances.boost.status.enable-error'));
}

return $redirect->with('success',
trans('admin.settings.performances.boost.status.'.($cacheStatus ? 'reloaded' : 'enabled')));
$message = trans('admin.settings.performances.boost.status.'.($cacheStatus ? 'reloaded' : 'enabled'));

return $redirect->with('success', $message);
}

public function disableAdvancedCache()
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Admin/ThemeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ public function config(Request $request, string $theme)

$this->themes->updateConfig($theme, $validated);

return redirect()->route('admin.themes.index')->with('success',
trans('admin.themes.status.config-updated'));
return redirect()->route('admin.themes.index')->with(
'success',
trans('admin.themes.status.config-updated')
);
} catch (FileNotFoundException $e) {
return redirect()->back()->with('error', 'Invalid theme configuration.');
}
Expand Down
11 changes: 9 additions & 2 deletions app/Models/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ class Ban extends Model
*/
protected $userKey = 'author_id';

protected static function booted()
{
foreach (['created', 'deleted'] as $event) {
static::registerModelEvent($event, function (self $ban) {
$ban->user->refreshActiveBan();
});
}
}

/**
* Get the banned user.
*/
Expand Down Expand Up @@ -92,7 +101,5 @@ public function removeBan(User $remover = null)
$this->save();

$this->delete();

$this->user->update(['is_banned' => false]);
}
}
2 changes: 1 addition & 1 deletion app/Models/NavbarElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class NavbarElement extends Model
protected static function booted()
{
foreach (['created', 'updated', 'deleted'] as $event) {
static::$event(function () {
static::registerModelEvent($event, function () {
static::clearCache();
});
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Permission extends Model
private static $permissions = [
'comments.create' => 'admin.permissions.create-comments',
'comments.delete.other' => 'admin.permissions.delete-other-comments',
'maintenance.access' => 'admin.permissions.maintenance-access',
'admin.access' => 'admin.permissions.admin-access',
'admin.logs' => 'admin.permissions.admin-logs',
'admin.images' => 'admin.permissions.admin-images',
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@
'source-query' => 'Source Query',
'source-rcon' => 'Source RCON',
'rust-rcon' => 'Rust RCON',
'flyff-server' => 'Flyff Server',
'flyff-server' => 'Flyff Server', // TODO make this dynamic
],
],

Expand Down Expand Up @@ -414,6 +414,7 @@
'permissions' => [
'create-comments' => 'Comment a post',
'delete-other-comments' => 'Delete a post comment from another user',
'maintenance-access' => 'Access the website during a maintenance',
'admin-access' => 'Access to the admin dashboard',
'admin-logs' => 'View and manage site logs',
'admin-images' => 'View and manage images',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/fr/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
'permissions' => [
'create-comments' => 'Commenter un article',
'delete-other-comments' => 'Supprimer un commentaire d\'un autre utilisateur',
'maintenance-access' => 'Accéder au site pendant une maintenance',
'admin-access' => 'Accéder au panel administrateur',
'admin-logs' => 'Voir et gérer les logs du site',
'admin-images' => 'Voir et gérer les images',
Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/ChartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class ChartsTest extends TestCase
public function testDailyChart()
{
$dates = [
today()->subMonths(2),
today()->subDays(5),
today()->subDays(3),
today()->subDays(3),
today()->subMonths(2)->addMinutes(20),
today()->subDays(5)->addMinutes(45),
today()->subDays(3)->addMinutes(10),
today()->subDays(3)->addMinutes(15),
today()->subDays(3),
today(),
];
Expand All @@ -35,13 +35,13 @@ public function testDailyChart()

public function testMonthlyChart()
{
$month = today()->startOfMonth()->toImmutable();
$month = today()->startOfMonth()->addHour()->toImmutable();

$dates = [
$month->subMonths(7),
$month->subMonths(5),
$month->subMonths(3),
$month->subMonths(3),
$month->subMonths(7)->addHours(10),
$month->subMonths(5)->addHours(12),
$month->subMonths(3)->addHours(16),
$month->subMonths(3)->addHours(15),
$month->subMonth(),
$month,
];
Expand All @@ -50,7 +50,7 @@ public function testMonthlyChart()
User::factory()->create(['created_at' => $date]);
}

$expected = collect([0, 0, 2, 0, 1, 1])->mapWithKeys(function (int $count, int $i) {
$expected = collect([1, 0, 2, 0, 1, 1])->mapWithKeys(function (int $count, int $i) {
return [today()->subMonths(5 - $i)->translatedFormat('F Y') => $count];
})->all();

Expand Down

0 comments on commit ee7e9b4

Please sign in to comment.