Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit 5d084e4

Browse files
author
Baptiste Prunot
committed
File upload okay
1 parent e8b60c0 commit 5d084e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+244
-27
lines changed

Diff for: app/Http/Controllers/ChallengeController.php

+25-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Auth;
77
use View;
88
use App\Models\Team;
9-
use DB;
9+
use DB; use Storage;
1010
use App\Models\Challenge;
1111
use App\Http\Requests\ChallengeRequest;
1212

@@ -34,9 +34,22 @@ public function validationList() {
3434
* in order to validate a challenge
3535
*/
3636
public function submitToValidation(Request $request, int $challengeId, int $teamId) {
37+
38+
$this->validate($request, [
39+
"proof" => "required"
40+
]);
41+
42+
$file = fopen($request->file('proof')->getRealPath(), "r+");
43+
$filename = uniqid().".".$request->file("proof")->guessExtension();
44+
Storage::disk('validation-proofs')->put($filename, $file);
45+
fclose($file);
46+
47+
3748
$team = Team::find($teamId);
3849
$challenge = Challenge::find($challengeId);
39-
$team->challenges()->save($challenge, ["submittedOn"=> new \DateTime("now")]);
50+
$team->challenges()->save($challenge, ["submittedOn"=> new \DateTime("now"), "pic_url" => "proof/".$filename]);
51+
52+
4053
$request->flash("success", "La défis a bien été soumis à validation");
4154
return redirect(route("challenges.list"));
4255
}
@@ -80,7 +93,7 @@ public function add(ChallengeRequest $request) {
8093
/**
8194
* Used by team leader to submit a challenge to be validated
8295
*/
83-
public function submitChallenge(int $idChallenge) {
96+
public function submitChallengeForm(int $idChallenge) {
8497
$challenge = DB::table('challenges')->where("id", "=", $idChallenge)->first();
8598
return View::make("dashboard.challenges.submit", [
8699
"challenge" => $challenge
@@ -94,13 +107,19 @@ public function deleteChallenge(int $idChallenge) {
94107

95108
public function showChallengesList() {
96109
$challenges = DB::table("challenges")->get();
97-
return View::make('dashboard.challenges.list', [
98-
"challenges" => $challenges
99-
]);
110+
$team = Team::find(Auth()->user()->team_id);
111+
return View::make('dashboard.challenges.list', compact("challenges", "team"));
100112
}
101113

102114
public function showSentChallenges() {
103115
$challenges = Team::find(Auth::user()->team_id)->challenges()->get();
104116
return view("dashboard.challenges.challenges_sent", compact("challenges"));
105117
}
118+
119+
public function accept(int $challengeId, int $teamId) {
120+
$challenge = Team::find($teamId)->challenges()->where("id", "=", $challengeId)->first();
121+
$challenge->teams()->updateExistingPivot($teamId, ["validated" => true]);
122+
$challenge->save();
123+
return redirect(route("challenges.validationsList"));
124+
}
106125
}

Diff for: app/Http/Controllers/ValidationPic.php

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\Response;
7+
use Storage;
8+
9+
10+
class ValidationPic extends Controller
11+
{
12+
13+
14+
/**
15+
* Display a listing of the resource.
16+
*
17+
* @return \Illuminate\Http\Response
18+
*/
19+
public function index()
20+
{
21+
//
22+
}
23+
24+
/**
25+
* Show the form for creating a new resource.
26+
*
27+
* @return \Illuminate\Http\Response
28+
*/
29+
public function create()
30+
{
31+
//
32+
}
33+
34+
/**
35+
* Store a newly created resource in storage.
36+
*
37+
* @param \Illuminate\Http\Request $request
38+
* @return \Illuminate\Http\Response
39+
*/
40+
public function store(Request $request)
41+
{
42+
}
43+
44+
/**
45+
* Display the specified resource.
46+
*
47+
* @param int $id
48+
* @return \Illuminate\Http\Response
49+
*/
50+
public function show($name)
51+
{
52+
$pic = Storage::disk("validation-proofs")->get($name);
53+
return (new Response($pic, 200))
54+
->header("content-type", "image/*")
55+
->header("content-disposition", "inline")
56+
;
57+
58+
}
59+
60+
/**
61+
* Show the form for editing the specified resource.
62+
*
63+
* @param int $id
64+
* @return \Illuminate\Http\Response
65+
*/
66+
public function edit($id)
67+
{
68+
//
69+
}
70+
71+
/**
72+
* Update the specified resource in storage.
73+
*
74+
* @param \Illuminate\Http\Request $request
75+
* @param int $id
76+
* @return \Illuminate\Http\Response
77+
*/
78+
public function update(Request $request, $id)
79+
{
80+
//
81+
}
82+
83+
/**
84+
* Remove the specified resource from storage.
85+
*
86+
* @param int $id
87+
* @return \Illuminate\Http\Response
88+
*/
89+
public function destroy($id)
90+
{
91+
//
92+
}
93+
}

Diff for: app/Models/Challenge.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Challenge extends Model {
1919
* All the teams that asked validation for this challenge
2020
*/
2121
public function teams() {
22-
return $this->belongsToMany("App\Models\Team")->withPivot("submittedOn");
22+
return $this->belongsToMany("App\Models\Team", "challenge_validations")->withPivot(["submittedOn", "validated", "pic_url"]);
2323
}
2424

2525
}

Diff for: app/Models/Team.php

+20-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,28 @@ class Team extends Model
2222
* All the challenges sent to validation by the team
2323
*/
2424
public function challenges() {
25-
return $this->belongsToMany("App\Models\Challenge")->withPivot("submittedOn")->where("team_id", "=", $this->id);
25+
return $this->belongsToMany("App\Models\Challenge", "challenge_validations")->withPivot(["submittedOn", "validated", "pic_url"])->where("team_id", "=", $this->id);
2626
}
2727

28-
public function hasPendingValidation() :bool {
28+
/**
29+
* Returns all the pending validation : all the challenges where
30+
* 'validated' attribute is null
31+
*/
32+
public function getPendingValidations() {
33+
return $this->challenges()->wherePivot("validated", null);
34+
}
35+
36+
/**
37+
* Check if a challenge (given by id) has already been validated
38+
*/
39+
public function hasAlreadyValidatedChallenge(int $challengeId) :bool{
40+
return count($this->challenges()->where("id", "=", $challengeId)->wherePivot("validated", true)->get())>0?true:false;
41+
}
42+
43+
/**
44+
* Returns true if there is pending validations, false otherwise
45+
*/
46+
public function hasPendingValidations() :bool {
2947
return count($this->challenges()->get())>0?true:false;
3048
}
3149

Diff for: config/filesystems.php

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
'visibility' => 'public',
5555
],
5656

57+
"validation-proofs" => [
58+
'driver' => 'local',
59+
'root' => storage_path('app/validation-proofs'),
60+
'visibility' => 'private'
61+
],
62+
5763
's3' => [
5864
'driver' => 's3',
5965
'key' => 'your-key',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class PrimaryKeyChallengeTeam extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('challenge_team', function (Blueprint $table) {
17+
$table->primary(["team_id", "challenge_id"]);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('challenge_team', function (Blueprint $table) {
29+
$table->dropPrimary(["team_id", "challenge_id"]);
30+
});
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class RenameChallengeTeamAddColumn extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::rename("challenge_team", "challenge_validations");
17+
Schema::table('challenge_validations', function(Blueprint $table) {
18+
$table->string("pic_url", 100);
19+
});
20+
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
//
31+
Schema::rename("challenge_validations", "challenge_team");
32+
Schema::table('challenge_team', function(Blueprint $table) {
33+
$table->dropColumn("pic_url");
34+
});
35+
36+
}
37+
}

Diff for: public/.htaccess

100644100755
File mode changed.

Diff for: public/css/student_autocomplete.css

100644100755
File mode changed.

Diff for: public/docs/autorisation.pdf

100644100755
File mode changed.

Diff for: public/docs/branches.pdf

100644100755
File mode changed.

Diff for: public/docs/cgv.pdf

100644100755
File mode changed.

Diff for: public/docs/masters.pdf

100644100755
File mode changed.

Diff for: public/docs/nutt.pdf

100644100755
File mode changed.

Diff for: public/docs/tc.pdf

100644100755
File mode changed.

Diff for: public/front/font-awesome/css/font-awesome.css

100644100755
File mode changed.

Diff for: public/front/font-awesome/css/font-awesome.min.css

100644100755
File mode changed.

Diff for: public/front/font-awesome/fonts/FontAwesome.otf

100644100755
File mode changed.

Diff for: public/front/font-awesome/fonts/fontawesome-webfont.eot

100644100755
File mode changed.

Diff for: public/front/font-awesome/fonts/fontawesome-webfont.svg

100644100755
File mode changed.

Diff for: public/front/font-awesome/fonts/fontawesome-webfont.ttf

100644100755
File mode changed.

Diff for: public/front/font-awesome/fonts/fontawesome-webfont.woff

100644100755
File mode changed.

Diff for: public/front/font-awesome/fonts/fontawesome-webfont.woff2

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/animated.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/bordered-pulled.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/core.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/fixed-width.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/font-awesome.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/icons.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/larger.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/list.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/mixins.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/path.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/rotated-flipped.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/screen-reader.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/stacked.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/less/variables.less

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_animated.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_bordered-pulled.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_core.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_fixed-width.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_icons.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_larger.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_list.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_mixins.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_path.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_rotated-flipped.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_screen-reader.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_stacked.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/_variables.scss

100644100755
File mode changed.

Diff for: public/front/font-awesome/scss/font-awesome.scss

100644100755
File mode changed.

Diff for: public/img/home-background.jpg

100644100755
File mode changed.

Diff for: public/img/letter/bg.png

100644100755
File mode changed.

Diff for: public/img/letter/oscar.png

100644100755
File mode changed.

Diff for: public/img/letter/top.png

100644100755
File mode changed.

Diff for: public/img/mails/godfather/logo.png

100644100755
File mode changed.

Diff for: public/img/mails/infos1/.gitkeep

100644100755
File mode changed.

Diff for: public/img/mails/infos1/image1.png

100644100755
File mode changed.

Diff for: public/img/mails/infos1/image2.png

100644100755
File mode changed.

Diff for: public/img/mails/infos1/image3.png

100644100755
File mode changed.

Diff for: public/img/sponsors/mgel.png

100644100755
File mode changed.

Diff for: public/js/student_autocomplete.js

100644100755
File mode changed.

Diff for: public/policy-privacy.html

100644100755
File mode changed.

Diff for: resources/views/dashboard/challenges/challenges_sent.blade.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
</thead>
1919
<tbody>
2020
@foreach($challenges as $challenge)
21-
<tr scope="row">
22-
<td>{{ $challenge->name }}</td>
23-
@if($challenge->pivot->validated == null )
24-
<td>Le défis n'a pas encore été traité</td>
25-
@elseif(!$challenge->pivot->validated)
26-
<p>Le défis a été refusé</p>
27-
@else
28-
<p>Le défis a été validé !</p>
29-
@endif
30-
</tr>
21+
<tr scope="row">
22+
<td>{{ $challenge->name }}</td>
23+
@if($challenge->pivot->validated == null )
24+
<td>Le défis n'a pas encore été traité</td>
25+
@elseif(!$challenge->pivot->validated)
26+
<td>le défis a été refusé</td>
27+
@else
28+
<td>le défis a été accepté</td>
29+
@endif
30+
</tr>
3131
@endforeach
3232
</tbody>
3333
</table>

Diff for: resources/views/dashboard/challenges/list.blade.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
</form>
3838
<div class="btn-group" role="group">
3939
<a href={{ route("challenges.modifyForm", ["challengeId" => $challenge->id]) }}><button class="btn btn-primary">Modifier</button></a>
40-
@if(Auth::user()->ce)
40+
{{--I check wether the user is a team leader, and also if the team has already validated this challenge, in that case, the "valider un défis" button doesn't appear--}}
41+
@if(Auth::user()->ce && !$team->hasAlreadyValidatedChallenge($challenge->id))
4142
<a href={{ route("challenges.submitForm", ["id" => $challenge->id]) }}><button class="btn btn-primary">valider un défis</button></a>
4243
@endif
4344
</div>

Diff for: resources/views/dashboard/challenges/submissions.blade.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
</thead>
2626
<tbody>
2727
@forelse($teams as $team)
28-
@if($team->hasPendingValidation())
29-
@foreach($team->challenges()->get() as $challenge)
28+
@if($team->hasPendingValidations())
29+
@foreach($team->getPendingValidations()->get() as $challenge)
3030
<tr>
3131
<td>{{ $team->name }}</td>
3232
<td>{{ $challenge->name }}</td>
33-
<td> RIEN POUR LE MOMENT </td>
33+
<td> <img src="{{ $challenge->pivot->pic_url }}" class="img-fluid rounded" alt="Image de validation du défis"> </td>
3434
<td>
35-
<a href=""><button class="btn btn-primary">valider</button></a>
35+
<form method="post" action={{ route("challenges.accept", ["challengeId" => $challenge->id, "teamId" => $team->id]) }}><input class="btn btn-primary" type="submit" value="Valider"></form>
3636
<form action=""><input class="btn btn-danger" type="submit" value="Refuser"> </form>
3737
</td>
3838
</tr>

Diff for: resources/views/dashboard/challenges/submit.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<form action={{ route("challenge.submit",[
1818
"challengeId" => $challenge->id,
1919
"teamId" => Auth::user()->team_id,
20-
]) }} method="post">
20+
]) }} method="post" enctype="multipart/form-data">
2121
<div class="form-group">
2222
<label for="file">Preuve de la réussite</label>
23-
<input id="file" class="form-control-file" type="file" accept="image/*">
23+
<input id="file" name="proof" class="form-control-file" type="file" accept="image/*">
2424
</div>
2525
<input class="btn btn-primary form-control" type="submit" value="Envoyer">
2626
</form>

Diff for: routes/web.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@
663663
* Routes for challenges
664664
*/
665665
Route::group(["prefix" => "challenges"], function() {
666+
667+
/**
668+
* Admin authorization
669+
*/
666670
Route::group(["middleware" => "authorize:admin"], function() {
667671

668672
Route::get("add", [
@@ -686,12 +690,19 @@
686690

687691
Route::post("{challengeId}/modify", "ChallengeController@modify")->name("challenges.modify");
688692

693+
Route::post("{challengeId}/team/{teamId}/validate", "ChallengeController@accept")->name("challenges.accept");
694+
Route::resource("proof", "ValidationPic");
695+
689696
});
690697

698+
/**
699+
* Team leader authorization
700+
*/
691701
Route::group(["middleware" => "authorize:ce"], function() {
702+
692703
Route::get("{id}/submit", [
693704
"as" => "challenges.submitForm",
694-
"uses" => "ChallengeController@submitChallenge"
705+
"uses" => "ChallengeController@submitChallengeForm"
695706
]);
696707

697708
Route::post("team/{teamId}/challenge/{challengeId}/submit", "ChallengeController@submitToValidation")->name("challenge.submit");

0 commit comments

Comments
 (0)