More model updates to more places than I anticipated.

This probably broke a lot of things.
This commit is contained in:
Dane Everitt 2017-02-09 17:43:54 -05:00
parent 0d61417814
commit 4f61637284
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
21 changed files with 339 additions and 433 deletions

View file

@ -63,4 +63,15 @@ class Allocation extends Model
{
return (is_null($this->ip_alias)) ? $this->ip : $this->ip_alias;
}
/**
* Accessor to quickly determine if this allocation has an alias.
*
* @param null|string $value
* @return boolean
*/
public function getHasAliasAttribute($value)
{
return (! is_null($this->ip_alias));
}
}

View file

@ -69,4 +69,14 @@ class DatabaseServer extends Model
{
return $this->belongsTo(Node::class, 'linked_node');
}
/**
* Gets the databases assocaited with this host.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function databases()
{
return $this->hasMany(Database::class, 'db_server');
}
}

View file

@ -122,6 +122,7 @@ class Node extends Model
/**
* Return an instance of the Guzzle client for this specific node.
*
* @param array $headers
* @return \GuzzleHttp\Client
*/
public function guzzleClient($headers = [])

View file

@ -276,4 +276,14 @@ class Server extends Model
{
return $this->hasMany(Task::class, 'server', 'id');
}
/**
* Gets all databases associated with a server.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function databases()
{
return $this->hasMany(Database::class);
}
}

View file

@ -51,4 +51,14 @@ class ServerVariables extends Model
'server_id' => 'integer',
'variable_id' => 'integer',
];
/**
* Returns information about a given variables parent.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function variable()
{
return $this->belongsTo(ServiceVariables::class, 'variable_id');
}
}

View file

@ -51,6 +51,28 @@ class ServiceOptions extends Model
'service_id' => 'integer',
];
/**
* Returns the display executable for the option and will use the parent
* service one if the option does not have one defined.
*
* @return string
*/
public function getDisplayExecutableAttribute($value)
{
return (is_null($this->executable)) ? $this->service->executable : $this->executable;
}
/**
* Returns the display startup string for the option and will use the parent
* service one if the option does not have one defined.
*
* @return string
*/
public function getDisplayStartupAttribute($value)
{
return (is_null($this->startup)) ? $this->service->startup : $this->startup;
}
/**
* Gets service associated with a service option.
*

View file

@ -59,4 +59,24 @@ class Subuser extends Model
'user_id' => 'integer',
'server_id' => 'integer',
];
/**
* Gets the server associated with a subuser.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function server()
{
return $this->belongsTo(Server::class);
}
/**
* Gets the user associated with a subuser.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
}

View file

@ -167,16 +167,6 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
return $subuser->daemonSecret;
}
/**
* Returns all permissions that a user has.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function permissions()
{
return $this->hasMany(Permission::class);
}
/**
* Returns an array of all servers a user is able to access.
* Note: does not account for user admin status.
@ -205,4 +195,24 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
return (is_numeric($paginate)) ? $query->paginate($paginate) : $query->get();
}
/**
* Returns all permissions that a user has.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function permissions()
{
return $this->hasMany(Permission::class);
}
/**
* Returns all servers that a user owns.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function servers()
{
return $this->hasMany(Server::class, 'owner_id');
}
}