--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Events\RoundChanged;
+use App\Models\Protocol;
+use App\Models\Round;
+use Illuminate\Console\Command;
+
+class UnlockRound extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'round:unlock {round}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Unlock the round';
+
+ /**
+ * Execute the console command.
+ *
+ * @return int
+ */
+ public function handle()
+ {
+ $round = Round::findOrFail($this->argument('round'));
+
+ if (!$round->locked) {
+ $this->line('already unlocked');
+ return 0;
+ }
+
+ $round->locked = false;
+ $round->save();
+
+ Protocol::roundUnlocked(
+ $round->tournament,
+ $round,
+ );
+
+ RoundChanged::dispatch($round);
+
+ return 0;
+ }
+}
{
$this->round = $round;
$this->round->setRelations([]);
+ if ($this->round->locked) {
+ $round->load(['results', 'results.user']);
+ }
}
/**
use App\Models\Round;
use App\Models\User;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Gate;
class ResultController extends Controller
{
$result->load('user');
+ if (!Gate::allows('seeResults', $round)) {
+ $result->hideResult($request->user());
+ }
+
return $result->toJson();
}
use App\Models\Tournament;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Gate;
class TournamentController extends Controller
{
$this->authorize('view', $tournament);
$rounds = $tournament->rounds()->with(['results', 'results.user'])->limit(25)->get();
foreach ($rounds as $round) {
- try {
- $this->authorize('seeResults', $round);
- } catch (AuthorizationException) {
+ if (!Gate::allows('seeResults', $round)) {
$round->hideResults($request->user());
}
}
->with(['results', 'results.user'])
->limit(25)->get();
foreach ($rounds as $round) {
- try {
- $this->authorize('seeResults', $round);
- } catch (AuthorizationException) {
+ if (!Gate::allows('seeResults', $round)) {
$round->hideResults($request->user());
}
}
}
+ public function hideResult(User $user = null) {
+ if (!$user || $this->user_id != $user->id) {
+ $this->makeHidden(['forfeit', 'placement', 'score', 'time']);
+ } else {
+ $this->makeHidden(['placement', 'score']);
+ }
+ }
+
+
public function round() {
return $this->belongsTo(Round::class);
}
public function hideResults(User $user = null) {
foreach ($this->results as $result) {
- if (!$user || $result->user_id != $user->id) {
- $result->makeHidden(['forfeit', 'placement', 'score', 'time']);
- }
+ $result->hideResult($user);
}
}
<span className="time">
{getTime(result, maySee)}
</span>
- {getIcon(result, maySee)}
+ {getIcon(result, maySeeResult(authUser, tournament, round))}
</Button>
{maySee && result && result.vod ?
<Button
}
return {
...round,
- results: round.results.map(r => r.id === result.id ? result : r),
+ results: round.results.map(r => r.id === result.id ? { ...r, ...result } : r),
};
};
const moreRounds = React.useCallback(async () => {
const last_round = getLastRound(tournament);
if (!last_round) return;
- console.log(last_round);
const last_known = last_round.number;
const rsp = await axios.get(
`/api/tournaments/${id}/more-rounds`,
}));
setShowContentDialog(false);
} catch (e) {
- toastr.error(t('content.saveError'));
+ toastr.error(t('content.saveError', e));
}
}, [tournament && tournament.description_id]);