-
Notifications
You must be signed in to change notification settings - Fork 13
Feature/publish events simple #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
demogorgonzola
wants to merge
4
commits into
master
Choose a base branch
from
feature/publish-events-simple
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f089c8d
[base] CheckPublished middleware made/integrated
demogorgonzola e19463e
[test] added tests and fixes for publish event
demogorgonzola aab5576
[ui] added publish button and view contexts
demogorgonzola 6891790
[fix] using post route for publish
demogorgonzola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Middleware; | ||
|
|
||
| use Closure; | ||
| use Illuminate\Contracts\Auth\Guard; | ||
| use App\Models\Slot; | ||
| use App\Models\Department; | ||
| use App\Models\Schedule; | ||
| use App\Models\Shift; | ||
|
|
||
| class CheckPublished | ||
| { | ||
| /** | ||
| * The Guard implementation. | ||
| * | ||
| * @var Guard | ||
| */ | ||
| protected $auth; | ||
|
|
||
| /** | ||
| * Create a new filter instance. | ||
| * | ||
| * @param Guard $auth | ||
| * @return void | ||
| */ | ||
| public function __construct(Guard $auth) | ||
| { | ||
| $this->auth = $auth; | ||
| } | ||
|
|
||
| /** | ||
| * Handle an incoming request. | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @param \Closure $next | ||
| * @return mixed | ||
| */ | ||
| public function handle($request, Closure $next, $model_name) | ||
| { | ||
| if($request->{$model_name}) | ||
| { | ||
| $event = $this->childModelToEvent($request->{$model_name}); | ||
|
|
||
| $is_published = ($event->published_at !== null); | ||
| $is_admin= $this->auth->user()->hasRole('admin'); | ||
| $is_department_lead = $this->auth->user()->hasRole('department-lead'); | ||
| if(!$is_published && !$is_admin && !$is_department_lead) | ||
| { | ||
| return response('Unauthorized.', 401); | ||
| } | ||
| } | ||
|
|
||
| return $next($request); | ||
| } | ||
|
|
||
| /** | ||
| * Get parent event of shift, slot, schedule, or department | ||
| * | ||
| * @param Model $model descendent model of Event | ||
| * @return Event Event or parent Event | ||
| */ | ||
| public static function childModelToEvent($model) | ||
| { | ||
|
|
||
| $model_class = get_class($model); | ||
| $event = $model; | ||
| if($model_class === Department::class) { | ||
| $event = $model->event; | ||
| } | ||
| if($model_class === Shift::class) { | ||
| $event = $model->event; | ||
| } | ||
| if($model_class === Schedule::class) { | ||
| $event = $model->shift->event; | ||
| } | ||
| if($model_class === Slot::class) { | ||
| $event = $model->schedule->shift->event; | ||
| } | ||
| return $event; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
laravel/database/migrations/2019_08_26_124054_add_published_at_to_events_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Support\Facades\Schema; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Database\Migrations\Migration; | ||
|
|
||
| class AddPublishedAtToEventsTable extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function up() | ||
| { | ||
| Schema::table('events', function (Blueprint $table) { | ||
| $table->timestamp('published_at')->nullable(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function down() | ||
| { | ||
| Schema::table('events', function (Blueprint $table) { | ||
| $table->drop('published_at'); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Feature; | ||
|
|
||
| use Tests\TestCase; | ||
| use Illuminate\Foundation\Testing\WithFaker; | ||
| use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
|
||
| use App\Models\User; | ||
| use App\Models\UserData; | ||
| use App\Models\Slot; | ||
|
|
||
| class CheckPublishedTest extends TestCase | ||
| { | ||
| use RefreshDatabase; | ||
|
|
||
| /** | ||
| * @test | ||
| * | ||
| * @return void | ||
| */ | ||
| public function unpublished_event_viewable_by_admin() | ||
| { | ||
| // Given | ||
| $admin = factory(User::class)->states('admin')->create(); | ||
|
|
||
| $admin->data()->save(factory(UserData::class)->make()); | ||
| $slot = factory(Slot::class)->create(); | ||
|
|
||
| // When | ||
| $response = $this->actingAs($admin)->get("/slot/{$slot->id}/view"); | ||
|
|
||
| // Then | ||
| $response->assertStatus(200); | ||
| } | ||
|
|
||
| /** | ||
| * @test | ||
| * | ||
| * @return void | ||
| */ | ||
| public function unpublished_event_not_viewable_by_volunteer() | ||
| { | ||
| // Given | ||
| $volunteer = factory(User::class)->create(); | ||
| $slot = factory(Slot::class)->create(); | ||
|
|
||
| // When | ||
| $response = $this->actingAs($volunteer)->get("/slot/{$slot->id}/view"); | ||
|
|
||
| // Then | ||
| $response->assertStatus(401); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
|
|
||
| class SlotControllerTest extends TestCase | ||
| { | ||
| use RefreshDatabase; | ||
|
|
||
| /** | ||
| * @test | ||
| * @return void | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Unit; | ||
|
|
||
| use Tests\TestCase; | ||
| use Illuminate\Foundation\Testing\WithFaker; | ||
| use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
|
||
| use App\Http\Middleware\CheckPublished; | ||
| use App\Models\Slot; | ||
| use App\Models\Event; | ||
|
|
||
| class CheckPublishedTest extends TestCase | ||
| { | ||
| use RefreshDatabase; | ||
|
|
||
| /** | ||
| * @test | ||
| * | ||
| * @return void | ||
| */ | ||
| public function handle_parses_model_name() | ||
| { | ||
| // Given | ||
| $slot = factory(Slot::class)->create(); | ||
|
|
||
| // When | ||
| $event = CheckPublished::childModelToEvent($slot); | ||
|
|
||
| // Then | ||
| $this->assertEquals(Event::class, get_class($event)); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.