@@ -103,40 +103,6 @@ public function __construct()
103103 self ::$ user = Auth::user ();
104104 }
105105
106- /**
107- * Returns array of all servers owned by the logged in user.
108- * Returns all users servers if user is a root admin.
109- *
110- * @return \Illuminate\Database\Eloquent\Collection
111- */
112- public static function getUserServers ($ paginate = null )
113- {
114- $ query = self ::select (
115- 'servers.* ' ,
116- 'nodes.name as nodeName ' ,
117- 'locations.short as a_locationShort ' ,
118- 'allocations.ip ' ,
119- 'allocations.ip_alias ' ,
120- 'allocations.port ' ,
121- 'services.name as a_serviceName ' ,
122- 'service_options.name as a_serviceOptionName '
123- )->join ('nodes ' , 'servers.node_id ' , '= ' , 'nodes.id ' )
124- ->join ('locations ' , 'nodes.location_id ' , '= ' , 'locations.id ' )
125- ->join ('services ' , 'servers.service_id ' , '= ' , 'services.id ' )
126- ->join ('service_options ' , 'servers.option_id ' , '= ' , 'service_options.id ' )
127- ->join ('allocations ' , 'servers.allocation_id ' , '= ' , 'allocations.id ' );
128-
129- if (self ::$ user ->root_admin !== 1 ) {
130- $ query ->whereIn ('servers.id ' , Subuser::accessServers ());
131- }
132-
133- if (is_numeric ($ paginate )) {
134- return $ query ->paginate ($ paginate );
135- }
136-
137- return $ query ->get ();
138- }
139-
140106 /**
141107 * Returns a single server specified by UUID.
142108 * DO NOT USE THIS TO MODIFY SERVER DETAILS OR SAVE THOSE DETAILS.
@@ -150,7 +116,7 @@ public static function byUuid($uuid)
150116 $ query = self ::with ('service ' , 'node ' )->where ('uuidShort ' , $ uuid )->orWhere ('uuid ' , $ uuid );
151117
152118 if (! Auth::user ()->isRootAdmin ()) {
153- $ query ->whereIn ('id ' , Subuser:: accessServers ());
119+ $ query ->whereIn ('id ' , Auth:: user ()-> serverAccessArray ());
154120 }
155121
156122 $ result = $ query ->first ();
@@ -228,6 +194,16 @@ public function user()
228194 return $ this ->belongsTo (User::class, 'owner_id ' );
229195 }
230196
197+ /**
198+ * Gets the default allocation for a server.
199+ *
200+ * @return \Illuminate\Database\Eloquent\Relations\HasOne
201+ */
202+ public function allocation ()
203+ {
204+ return $ this ->hasOne (Allocation::class, 'id ' , 'allocation_id ' );
205+ }
206+
231207 /**
232208 * Gets all allocations associated with this server.
233209 *
0 commit comments