Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
use Log;
use Spatie\Activitylog\Traits\LogsActivity;
use Laravel\Nova\Actions\Actionable;

class Event extends Model
{
use LogsActivity, Actionable;



protected $table = 'events';
protected $fillable = [
'status', 'title', 'slug', 'organizer', 'description',
Expand Down Expand Up @@ -72,7 +72,7 @@ public function path()

public function picture_path()
{
if ($this->picture){
if ($this->picture) {
return env('AWS_URL') . $this->picture;
} else {
return 'https://s3-eu-west-1.amazonaws.com/codeweek-dev/events/pictures/event_default_picture.png';
Expand Down Expand Up @@ -146,13 +146,14 @@ public function getClosest()

}

public function notifyAmbassadors(){
public function notifyAmbassadors()
{

//Get the ambassador list based on the event country
$ambassadors = User::role('ambassador')->where('country_iso', $this->country_iso)->get();
if ($ambassadors->isEmpty()){
if ($ambassadors->isEmpty()) {
Mail::to('info@codeweek.eu')->queue(new \App\Mail\EventCreatedNoAmbassador($this));
}else {
} else {
//send emails
foreach ($ambassadors as $ambassador) {
Mail::to($ambassador->email)->queue(new \App\Mail\EventCreated($this, $ambassador));
Expand All @@ -161,16 +162,23 @@ public function notifyAmbassadors(){

}

public function approve(){
public function approve()
{


$data = ['status' => "APPROVED", 'approved_by' => auth()->user()->id];
$data = ['status' => "APPROVED", 'approved_by' => auth()->user()->id];



$this->update($data);

Mail::to($this->owner->email)->queue(new \App\Mail\EventApproved($this, $this->owner));

if (!empty($this->user_email)) {
Mail::to($this->user_email)->queue(new \App\Mail\EventApproved($this, $this->owner));
} else if (!is_null($this->owner) && (!is_null($this->owner->email))) {
Mail::to($this->owner->email)->queue(new \App\Mail\EventApproved($this, $this->owner));
}


return true;
}

Expand Down
10 changes: 9 additions & 1 deletion app/Http/Controllers/ScoreboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class ScoreboardController extends Controller
public function index()
{

$total = DB::table('events')
->where('status',"=","APPROVED")
->whereYear('end_date', '>=', Carbon::now('Europe/Brussels')->year)
->count();

$events = DB::table('events')
->join('countries', 'events.country_iso', '=', 'countries.iso')
->select('countries.iso', 'countries.name as country_name','countries.population as country_population', DB::raw('count(*) as total'), DB::raw('countries.population / count(*) as rank'))
Expand All @@ -21,6 +26,9 @@ public function index()
->orderBy('rank','asc')
->get();

return view('scoreboard', ['events'=>$events]);
return view('scoreboard', [
'events'=>$events,
'total'=>$total
]);
}
}
2 changes: 1 addition & 1 deletion app/Providers/NovaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function gate()
{
Gate::define('viewNova', function ($user) {
return in_array($user->email, [
"alainvd@gmail.com"
"alainvd@gmail.com","raphdom@gmail.com"
]);
});
}
Expand Down
10 changes: 10 additions & 0 deletions public/css/ext/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13127,4 +13127,14 @@ textarea.border-form-control {

.youtube-iframe{
width:100%;
}

.scoreboard-total{
text-align: center;
font-size: 24px;
padding: 15px;
}

.country-name.macedonia {
font-size: 10px;
}
2 changes: 1 addition & 1 deletion resources/views/ambassadors.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class="social-icon inline-block si-small si-light si-rounded si-gplus">
<img src="https://s3-eu-west-1.amazonaws.com/codeweek-s3/flags/{{strtolower($country->country_iso)}}.png"
alt="{{$country->country_iso}}">

<div class="country-name">
<div class="country-name {{strtolower($country->name)}}">
@lang('countries.'.$country->name) ({{$country->total}})
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/events.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<img src="https://s3-eu-west-1.amazonaws.com/codeweek-s3/flags/{{strtolower($country->iso)}}.png" alt="{{$country->name}}">

<div class="country-name">
<div class="country-name {{strtolower($country->name)}}">
@lang('countries.'.$country->name)
</div>
</div>
Expand Down
14 changes: 10 additions & 4 deletions resources/views/scoreboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<p>@lang('scoreboard.paragraph')</p>
</div>

<div class="scoreboard-total">
{{$total}} @lang('scoreboard.events')
</div>

<div class="sb-wrapper">
<ol class="one-row">
Expand All @@ -29,11 +32,14 @@
alt=" {{$event->country_name}}"/>


<div class="box-inner">
<span class="country-name">@lang('countries.'.$event->country_name)</span>
<p> @lang('scoreboard.parcipating_with') </p>
<div class="box-inner flex-row">
<div>
<span class="country-name">@lang('countries.'.$event->country_name)</span>
<p style="margin-bottom: 5px !important;"> @lang('scoreboard.parcipating_with') </p>
</div>
<a href="/search?country_iso={{$event->iso}}&past=no">
<span class="event-number">{{ $event->total }} @lang('scoreboard.events')</span></a>
<span class="event-number">{{ $event->total }} @lang('search.' . str_plural('event', $event->total))</span>
</a>
</div>

</li>
Expand Down
103 changes: 87 additions & 16 deletions tests/Feature/ApproveEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Tests\Feature;

use App\Mail\EventApproved;
use App\School;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
Expand All @@ -14,14 +16,12 @@ class ApproveEventTest extends TestCase
use DatabaseMigrations;



public function setup()
{
parent::setUp();
$this->seed('RolesAndPermissionsSeeder');



}

/** @test */
Expand All @@ -36,17 +36,92 @@ public function event_can_be_approved_by_admin()

$this->signIn($superadmin);

$event = create('App\Event', ['status'=>'PENDING']);
$event = create('App\Event', ['status' => 'PENDING']);

$this->assertEquals($event->fresh()->status, 'PENDING');

$this->post(route('event.approve', $event));

$this->assertEquals($event->fresh()->status, 'APPROVED');
$this->assertEquals($superadmin->id, $event->fresh()->approved_by );
$this->assertEquals($superadmin->id, $event->fresh()->approved_by);

}

/** @test */
public function email_should_be_sent_to_event_email_when_event_is_approved()
{

$this->withExceptionHandling();

Mail::fake();

$superadmin = create('App\User');
$superadmin->assignRole('super admin');

$this->signIn($superadmin);

$event = create('App\Event', ['status' => 'PENDING', 'user_email' => 'foo@bar.com']);


$event->approve();

// Assert a message was sent to the given users...
Mail::assertQueued(EventApproved::class, function ($mail) use ($event) {
return $mail->hasTo($event->user_email);
});

}

/** @test */
public function email_should_be_sent_to_creator_email_when_event_email_is_blank()
{

$this->withExceptionHandling();

Mail::fake();

$superadmin = create('App\User', ['email' => 'test@boo.com']);
$superadmin->assignRole('super admin');

$this->signIn($superadmin);

$event = create('App\Event', ['status' => 'PENDING', 'user_email' => '', 'creator_id' => $superadmin->id]);


$event->approve();


// Assert a message was sent to the given users...
Mail::assertQueued(EventApproved::class, function ($mail) use ($superadmin) {

return $mail->hasTo($superadmin->email);
});

}

/** @test */
public function email_should_not_be_sent_to_creator_email()
{

$this->withExceptionHandling();

Mail::fake();

$superadmin = create('App\User', ['email' => NULL]);
$superadmin->assignRole('super admin');

$this->signIn($superadmin);

$event = create('App\Event', ['status' => 'PENDING', 'user_email' => '', 'creator_id' => $superadmin->id]);


$event->approve();


// Assert a message was sent to the given users...
Mail::assertNotQueued(EventApproved::class);

}


/** @test */
Expand All @@ -56,12 +131,12 @@ public function event_cant_be_approved_by_ambassador_of_other_country()
$this->withExceptionHandling();


$ambassador = create('App\User',['country_iso'=>'FR']);
$ambassador = create('App\User', ['country_iso' => 'FR']);
$ambassador->assignRole('ambassador');

$this->signIn($ambassador);

$event = create('App\Event', ['status'=>'PENDING','country_iso'=>'BE']);
$event = create('App\Event', ['status' => 'PENDING', 'country_iso' => 'BE']);

$this->assertEquals($event->fresh()->status, 'PENDING');

Expand All @@ -79,12 +154,12 @@ public function event_can_be_approved_by_ambassador_of_same_country()
$this->withExceptionHandling();


$ambassador = create('App\User',['country_iso'=>'FR']);
$ambassador = create('App\User', ['country_iso' => 'FR']);
$ambassador->assignRole('ambassador');

$this->signIn($ambassador);

$event = create('App\Event', ['status'=>'PENDING','country_iso'=>'FR']);
$event = create('App\Event', ['status' => 'PENDING', 'country_iso' => 'FR']);

$this->assertEquals($event->fresh()->status, 'PENDING');

Expand All @@ -110,10 +185,10 @@ public function visitors_cant_see_the_approve_banner()
/** @test */
public function ambassadors_of_other_countries_cant_see_the_approve_banner()
{
$ambassador = create('App\User',['country_iso'=>'FR'])->assignRole('ambassador');
$ambassador = create('App\User', ['country_iso' => 'FR'])->assignRole('ambassador');
$this->signIn($ambassador);

$event = create('App\Event',['country_iso'=>'BE']);
$event = create('App\Event', ['country_iso' => 'BE']);

$this->get('/view/' . $event->id . '/random')
->assertDontSee('moderate-event');
Expand All @@ -123,21 +198,17 @@ public function ambassadors_of_other_countries_cant_see_the_approve_banner()
/** @test */
public function ambassadors_of_right_country_can_see_the_approve_banner()
{
$ambassador = create('App\User',['country_iso'=>'FR'])->assignRole('ambassador');
$ambassador = create('App\User', ['country_iso' => 'FR'])->assignRole('ambassador');
$this->signIn($ambassador);

$event = create('App\Event',['country_iso'=>'FR']);
$event = create('App\Event', ['country_iso' => 'FR']);

$this->get('/view/' . $event->id . '/random')
->assertSee('moderate-event');

}






}