<commit_before><?php

namespace App\Controllers;

use App\Auth;
use App\CoreUtils;
use App\DB;
use App\Exceptions\MismatchedProviderException;
use App\Exceptions\UnsupportedProviderException;
use App\ImageProvider;
use App\Input;
use App\Models\EventEntry;
use App\Models\EventEntryVote;
use App\Permission;
use App\Response;
use App\Time;

class EventEntryController extends EventController {

  /** @var EventEntry */
  private $entry;

  private function load_event_entry($params, string $action) {
    if (!Auth::$signed_in)
      Response::fail();

    if (!isset($params['entryid']))
      Response::fail('Entry ID is missing or invalid');

    $this->entry = EventEntry::find(\intval($params['entryid'], 10));
    if (empty($this->entry))
      Response::fail('The requested entry could not be found');
    if ($action === 'lazyload')
      return;

    if ($action === 'manage' && $this->entry->submitted_by !== Auth::$user->id && Permission::insufficient('staff'))
      Response::fail("You don't have permission to manage this entry");

    $this->load_event(['id' => $this->entry->event_id]);

    if ($action === 'vote'){
      if ($this->event->type !== 'contest')
        Response::fail('You can only vote on entries to contest events');
      if (!$this->event->hasEnded())
        Response::fail('This event has ended; entries can no longer be voted on');
      if (!$this->event->checkCanVote(Auth::$user))
        Response::fail('You are not allowed to vote on entries to this event');
      if ($this->entry->submitted_by === Auth::$user->id)
        Response::fail('You cannot vote on your own entries', ['disable' => true]);<commit_msg>Allow event entries to be lazy loaded without login<commit_after><?php

namespace App\Controllers;

use App\Auth;
use App\CoreUtils;
use App\DB;
use App\Exceptions\MismatchedProviderException;
use App\Exceptions\UnsupportedProviderException;
use App\ImageProvider;
use App\Input;
use App\Models\EventEntry;
use App\Models\EventEntryVote;
use App\Permission;
use App\Response;
use App\Time;

class EventEntryController extends EventController {

  /** @var EventEntry */
  private $entry;

  private function load_event_entry($params, string $action) {
    $lazy_loading = $action === 'lazyload';
    if (!Auth::$signed_in && !$lazy_loading)
      Response::fail();

    if (!isset($params['entryid']))
      Response::fail('Entry ID is missing or invalid');

    $this->entry = EventEntry::find((int)$params['entryid']);
    if (empty($this->entry))
      Response::fail('The requested entry could not be found');
    if ($lazy_loading)
      return;

    if ($action === 'manage' && $this->entry->submitted_by !== Auth::$user->id && Permission::insufficient('staff'))
      Response::fail("You don't have permission to manage this entry");

    $this->load_event(['id' => $this->entry->event_id]);

    if ($action === 'vote'){
      if ($this->event->type !== 'contest')
        Response::fail('You can only vote on entries to contest events');
      if (!$this->event->hasEnded())
        Response::fail('This event has ended; entries can no longer be voted on');
      if (!$this->event->checkCanVote(Auth::$user))
        Response::fail('You are not allowed to vote on entries to this event');
      if ($this->entry->submitted_by === Auth::$user->id)
        Response::fail('You cannot vote on your own entries', ['disable' => true]);
{'fraction_non_alphanumeric': 0.16073005593170445, 'fraction_numerical': 0.0005887547836326171, 'mean_word_length': 4.164133738601824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2259013', 'n_tokens_mistral': 989, 'n_tokens_neox': 988, 'n_words': 283}