2020-10-12 14:03:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2020-10-14 16:22:42 +01:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2020-10-14 16:28:16 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-10-12 14:03:15 +01:00
|
|
|
use LibreNMS\Interfaces\Models\Keyable;
|
2020-10-17 21:53:46 +01:00
|
|
|
use LibreNMS\Permissions;
|
2020-10-12 14:03:15 +01:00
|
|
|
|
2020-10-14 15:36:54 +01:00
|
|
|
class ServiceTemplate extends Model implements Keyable
|
2020-10-12 14:03:15 +01:00
|
|
|
{
|
|
|
|
|
public $timestamps = false;
|
2020-10-16 16:42:31 +01:00
|
|
|
protected $primaryKey = 'id';
|
2020-10-12 14:03:15 +01:00
|
|
|
protected $fillable = [
|
2020-10-16 16:42:31 +01:00
|
|
|
'id',
|
2020-10-12 14:03:15 +01:00
|
|
|
'device_group_id',
|
2020-10-16 16:42:31 +01:00
|
|
|
'ip',
|
|
|
|
|
'type',
|
|
|
|
|
'desc',
|
|
|
|
|
'param',
|
|
|
|
|
'ignore',
|
|
|
|
|
'status',
|
|
|
|
|
'changed',
|
|
|
|
|
'disabled',
|
|
|
|
|
'name',
|
2020-10-12 14:03:15 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// ---- Helper Functions ----
|
|
|
|
|
|
|
|
|
|
public function getCompositeKey()
|
|
|
|
|
{
|
2020-10-16 16:42:31 +01:00
|
|
|
return $this->id . '-' . $this->device_group_id;
|
2020-10-12 14:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-17 10:01:29 +01:00
|
|
|
public function scopeHasAccess($query, User $user)
|
|
|
|
|
{
|
|
|
|
|
if ($user->hasGlobalRead()) {
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $query->whereIn('id', Permissions::serviceTemplatesForUser($user));
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 14:03:15 +01:00
|
|
|
/**
|
|
|
|
|
* @param Builder $query
|
|
|
|
|
* @return Builder
|
|
|
|
|
*/
|
|
|
|
|
public function scopeIsDisabled($query)
|
|
|
|
|
{
|
2020-10-16 16:42:31 +01:00
|
|
|
return $query->where('disabled', 1);
|
2020-10-12 14:03:15 +01:00
|
|
|
}
|
|
|
|
|
}
|