Skip to content

Commit

Permalink
Profile Links #52
Browse files Browse the repository at this point in the history
  • Loading branch information
chx2 committed Mar 4, 2021
1 parent e2f9981 commit d4ca1ff
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 1 deletion.
33 changes: 33 additions & 0 deletions database/factories/ProfileLinkFactory.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\Location;
use Tipoff\Locations\Models\ProfileLink;

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

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'link' => $this->faker->url,
'type' => $this->faker->text,
'location_id' => Location::factory()->create()->id
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Tipoff\Locations\Models\Location;

class CreateProfileLinkTable extends Migration
{
public function up()
{
Schema::create('profile_links', function (Blueprint $table) {
$table->id();
$table->string('link');
$table->string('type');

$table->foreignIdFor(Location::class);
$table->foreignIdFor(app('company'))->nullable();
$table->foreignIdFor(app('webpage'))->nullable();
$table->foreignIdFor(app('domain'))->nullable();
$table->timestamps();
});
}
}
3 changes: 3 additions & 0 deletions src/LocationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use Tipoff\Locations\Commands\SyncLocations;
use Tipoff\Locations\Models\Location;
use Tipoff\Locations\Models\Market;
use Tipoff\Locations\Models\ProfileLink;
use Tipoff\Locations\Policies\LocationPolicy;
use Tipoff\Locations\Policies\MarketPolicy;
use Tipoff\Locations\Policies\ProfileLinkPolicy;
use Tipoff\Support\TipoffPackage;
use Tipoff\Support\TipoffServiceProvider;

Expand All @@ -20,6 +22,7 @@ public function configureTipoffPackage(TipoffPackage $package): void
->hasPolicies([
Location::class => LocationPolicy::class,
Market::class => MarketPolicy::class,
ProfileLink::class => ProfileLinkPolicy::class,
])
->hasNovaResources([
\Tipoff\Locations\Nova\Location::class,
Expand Down
37 changes: 37 additions & 0 deletions src/Models/ProfileLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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 ProfileLink extends BaseModel
{
use HasPackageFactory;
use HasCreator;
use HasUpdater;

public function company()
{
return $this->belongsTo(app('company'));
}

public function domain()
{
return $this->belongsTo(app('domain'));
}

public function location()
{
return $this->belongsTo(Location::class);
}

public function webpage()
{
return $this->belongsTo(app('webpage'));
}
}
49 changes: 49 additions & 0 deletions src/Policies/ProfileLinkPolicy.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\ProfileLink;
use Tipoff\Support\Contracts\Models\UserInterface;

class ProfileLinkPolicy
{
use HandlesAuthorization;

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

public function view(UserInterface $user, ProfileLink $profile_link): bool
{
return $user->hasPermissionTo('view profile links') ? true : false;
}

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

public function update(UserInterface $user, ProfileLink $profile_link): bool
{
return $user->hasPermissionTo('update profile links');
}

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

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

public function forceDelete(UserInterface $user, ProfileLink $profile_link): bool
{
return false;
}
}
5 changes: 4 additions & 1 deletion tests/Unit/Migrations/PermissionsMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public function permissions_seeded()
'view markets',
'create markets',
'update markets',
'view profile links',
'create profile links',
'update profile links',
])->pluck('name');

$this->assertCount(6, $seededPermissions);
$this->assertCount(9, $seededPermissions);
}
}
21 changes: 21 additions & 0 deletions tests/Unit/Models/ProfileLinkTest.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\ProfileLink;
use Tipoff\Locations\Tests\TestCase;

class ProfileLinkTest extends TestCase
{
use DatabaseTransactions;

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

0 comments on commit d4ca1ff

Please sign in to comment.