Skip to content

Commit

Permalink
Timezones #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hackett committed Mar 1, 2021
1 parent 40c604a commit f1a6381
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 2 deletions.
33 changes: 33 additions & 0 deletions database/factories/TimezoneFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Tipoff\Locations\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Tipoff\Locations\Models\Timezone;

class TimezoneFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Timezone::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->timezone,
'title' => $this->faker->timezone,
'php' => $this->faker->timezone,
'is_daylight_saving' => $this->faker->boolean
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public function up()
'view markets',
'create markets',
'update markets',
'delete markets'
'delete markets',
'view timezones',
'create timezones',
'update timezones',
'delete timezones'
] as $name) {
app(Permission::class)::findOrCreate($name, null);
};
Expand Down
29 changes: 29 additions & 0 deletions src/Models/Timezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Tipoff\Locations\Models;

use Tipoff\Support\Models\BaseModel;
use Tipoff\Support\Traits\HasCreator;
use Tipoff\Support\Traits\HasPackageFactory;
use Tipoff\Support\Traits\HasUpdater;

class Timezone extends BaseModel
{
use HasPackageFactory;
use HasCreator;
use HasUpdater;

public $timestamps = false;

public function markets()
{
return $this->belongsToMany(app('market'));
}

public function locations()
{
return $this->belongsToMany(app('location'));
}
}
49 changes: 49 additions & 0 deletions src/Policies/TimezonePolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Tipoff\Locations\Policies;

use Illuminate\Auth\Access\HandlesAuthorization;
use Tipoff\Locations\Models\Timezone;
use Tipoff\Support\Contracts\Models\UserInterface;

class TimezonePolicy
{
use HandlesAuthorization;

public function viewAny(UserInterface $user): bool
{
return $user->hasPermissionTo('view timezones') ? true : false;
}

public function view(UserInterface $user, Timezone $timezone): bool
{
return $user->hasPermissionTo('view timezones') ? true : false;
}

public function create(UserInterface $user): bool
{
return $user->hasPermissionTo('create timezones') ? true : false;
}

public function update(UserInterface $user, Timezone $timezone): bool
{
return $user->hasPermissionTo('update timezones') ? true : false;
}

public function delete(UserInterface $user, Timezone $timezone): bool
{
return false;
}

public function restore(UserInterface $user, Timezone $timezone): bool
{
return false;
}

public function forceDelete(UserInterface $user, Timezone $timezone): bool
{
return false;
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Migrations/PermissionsMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class PermissionsMigrationTest extends TestCase
public function permissions_seeded()
{
$this->assertTrue(Schema::hasTable('permissions'));
$this->assertDatabaseCount('permissions', 8);
$this->assertDatabaseCount('permissions', 13);
}
}
21 changes: 21 additions & 0 deletions tests/Unit/Models/TimezoneModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Tipoff\Locations\Tests\Unit\Models;

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tipoff\Locations\Models\Timezone;
use Tipoff\Locations\Tests\TestCase;

class TimezoneModelTest extends TestCase
{
use DatabaseTransactions;

/** @test */
public function create()
{
$model = Timezone::factory()->create();
$this->assertNotNull($model);
}
}

0 comments on commit f1a6381

Please sign in to comment.