phase 5
This commit is contained in:
@@ -24,6 +24,8 @@ class Issue extends Model
|
||||
'times_seen',
|
||||
'is_regression',
|
||||
'metadata',
|
||||
'first_release',
|
||||
'resolved_in_release',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -51,9 +53,13 @@ class Issue extends Model
|
||||
return $this->events()->latest('timestamp')->limit(1);
|
||||
}
|
||||
|
||||
public function resolve(): void
|
||||
public function resolve(?string $release = null): void
|
||||
{
|
||||
$this->update(['status' => 'resolved', 'is_regression' => false]);
|
||||
$this->update([
|
||||
'status' => 'resolved',
|
||||
'is_regression' => false,
|
||||
'resolved_in_release' => $release,
|
||||
]);
|
||||
}
|
||||
|
||||
public function ignore(): void
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
class PersonalAccessToken extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'token',
|
||||
'abilities',
|
||||
'last_used_at',
|
||||
'expires_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'abilities' => 'array',
|
||||
'last_used_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function tokenable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function can(string $ability): bool
|
||||
{
|
||||
return in_array('*', $this->abilities ?? []) || in_array($ability, $this->abilities ?? []);
|
||||
}
|
||||
|
||||
public function markAsUsed(): void
|
||||
{
|
||||
$this->update(['last_used_at' => now()]);
|
||||
}
|
||||
|
||||
public function isExpired(): bool
|
||||
{
|
||||
return $this->expires_at && $this->expires_at->isPast();
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,10 @@ use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
@@ -52,4 +54,21 @@ class User extends Authenticatable
|
||||
['email_enabled' => true, 'database_enabled' => true, 'muted' => false],
|
||||
);
|
||||
}
|
||||
|
||||
public function tokens(): MorphMany
|
||||
{
|
||||
return $this->morphMany(PersonalAccessToken::class, 'tokenable');
|
||||
}
|
||||
|
||||
public function createToken(string $name, array $abilities = ['*'], ?\DateTimeInterface $expiresAt = null): PersonalAccessToken
|
||||
{
|
||||
$token = Str::random(64);
|
||||
|
||||
return $this->tokens()->create([
|
||||
'name' => $name,
|
||||
'token' => hash('sha256', $token),
|
||||
'abilities' => $abilities,
|
||||
'expires_at' => $expiresAt,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user