Skip to content

Commit ddb626b

Browse files
committed
Require fork before submitting a challenge
Both submit and submitWithoutDeploy now return 422 if the user hasn't forked the repository. Prevents submissions without proper GitHub integration.
1 parent ed7d6fd commit ddb626b

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

app/Http/Controllers/ChallengeController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ public function submit(Request $request, $slug)
311311
abort(400, 'Você já submeteu esse Mini Projeto');
312312
}
313313

314+
if (! $challengeUser->pivot->fork_url) {
315+
abort(422, 'Você precisa fazer o fork do repositório antes de submeter.');
316+
}
317+
314318
// Check if the URL is not from a github repository
315319
if (Str::contains($validated['submission_url'], 'github.com')) {
316320
abort(
@@ -390,6 +394,11 @@ public function submitWithoutDeploy(Request $request, $slug)
390394
->where('user_id', $request->user()->id)
391395
->firstOrFail();
392396

397+
// Check if the user has forked
398+
if (! $challengeUser->pivot->fork_url) {
399+
abort(422, 'Você precisa fazer o fork do repositório antes de submeter.');
400+
}
401+
393402
// Check if the user has already submitted
394403
if ($challengeUser->pivot['submitted_at']) {
395404
abort(400, 'Você já submeteu esse Mini Projeto');

tests/Feature/ChallengeSubmissionTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,42 @@ public function it_allows_marking_complete_after_submission(): void
276276
$challenge->users()->where('user_id', $user->id)->first()->pivot->completed
277277
);
278278
}
279+
280+
/** @test */
281+
public function it_prevents_submit_without_fork(): void
282+
{
283+
Event::fake();
284+
Mail::fake();
285+
$this->mockAllExternalServices();
286+
287+
$user = User::factory()->create();
288+
$challenge = Challenge::factory()->create(['status' => 'published']);
289+
$challenge->users()->attach($user->id);
290+
291+
$response = $this->signIn($user)
292+
->postJson("/api/challenges/{$challenge->slug}/submit", [
293+
'submission_url' => 'https://example.com',
294+
]);
295+
296+
$response->assertStatus(422);
297+
}
298+
299+
/** @test */
300+
public function it_prevents_submit_without_deploy_without_fork(): void
301+
{
302+
Event::fake();
303+
Mail::fake();
304+
$this->mockAllExternalServices();
305+
306+
$user = User::factory()->create();
307+
$challenge = Challenge::factory()->create(['status' => 'published']);
308+
$challenge->users()->attach($user->id);
309+
310+
$response = $this->signIn($user)
311+
->postJson("/api/challenges/{$challenge->slug}/submit-without-deploy", [
312+
'submission_image' => \Illuminate\Http\UploadedFile::fake()->image('screenshot.png'),
313+
]);
314+
315+
$response->assertStatus(422);
316+
}
279317
}

0 commit comments

Comments
 (0)