-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d14047
commit 95491e3
Showing
17 changed files
with
578 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Convoy\Http\Requests\Admin\Coterms; | ||
|
||
use Convoy\Http\Requests\BaseApiRequest; | ||
use Convoy\Models\Coterm; | ||
|
||
class DeleteCotermRequest extends BaseApiRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
return $this->user()->can('delete', $this->parameter('coterm', Coterm::class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Convoy\Models\Filters; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
|
||
class FiltersCoterm implements Filter | ||
{ | ||
public function __invoke(Builder $query, $value, string $property) | ||
{ | ||
$query->where('id', $value) | ||
->orWhereRaw('LOWER(name) LIKE ?', ["%$value%"]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Convoy\Policies; | ||
|
||
use Convoy\Models\Coterm; | ||
use Convoy\Models\User; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class CotermPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
public function delete(User $user, Coterm $coterm): bool | ||
{ | ||
$coterm->loadCount(['nodes']); | ||
|
||
if ($coterm->nodes_count > 0) { | ||
$this->deny('Cannot delete an instance of Coterm with nodes attached to it.'); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Convoy\Transformers\Admin; | ||
|
||
use Convoy\Models\Coterm; | ||
use League\Fractal\TransformerAbstract; | ||
|
||
class CotermTransformer extends TransformerAbstract | ||
{ | ||
protected array $availableIncludes = ['token']; | ||
|
||
public function transform(Coterm $coterm): array | ||
{ | ||
return [ | ||
'id' => (int)$coterm->id, | ||
'name' => $coterm->name, | ||
'is_tls_enabled' => (boolean)$coterm->is_tls_enabled, | ||
'fqdn' => $coterm->fqdn, | ||
'port' => (int)$coterm->port, | ||
'nodes_count' => (int)$coterm->nodes_count, | ||
]; | ||
} | ||
|
||
public function includeToken(Coterm $coterm): array | ||
{ | ||
return [ | ||
'token_id' => $coterm->token_id, | ||
'token' => $coterm->token, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { rawDataToCoterm } from '@/api/admin/coterms/getCoterms' | ||
import http from '@/api/http' | ||
|
||
interface CreateCotermParameters { | ||
name: string | ||
isTlsEnabled: boolean | ||
fqdn: string | ||
port: number | ||
nodeIds?: number[] | null | ||
} | ||
|
||
const createCoterm = async ({ | ||
name, | ||
isTlsEnabled, | ||
fqdn, | ||
port, | ||
nodeIds, | ||
}: CreateCotermParameters) => { | ||
const { | ||
data: { data }, | ||
} = await http.post('/api/admin/coterms', { | ||
name, | ||
is_tls_enabled: isTlsEnabled, | ||
fqdn, | ||
port, | ||
node_ids: nodeIds, | ||
}) | ||
|
||
return rawDataToCoterm(data) | ||
} | ||
|
||
export default createCoterm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import http from '@/api/http' | ||
|
||
const deleteCoterm = (id: string) => http.delete(`/admin/coterms/${id}`) | ||
|
||
export default deleteCoterm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { NodeResponse, rawDataToNode } from '@/api/admin/nodes/getNodes' | ||
import http, { getPaginationSet } from '@/api/http' | ||
|
||
|
||
export interface QueryParams { | ||
query?: string | null | ||
fqdn?: string | null | ||
locationId?: number | null | ||
page?: number | null | ||
perPage?: number | null | ||
} | ||
|
||
const getAttachedNodes = async ( | ||
id: number, | ||
{ query, fqdn, locationId, page, perPage = 50 }: QueryParams | ||
): Promise<NodeResponse> => { | ||
const { data } = await http.get(`/api/admin/coterms/${id}/nodes`, { | ||
params: { | ||
query, | ||
fqdn, | ||
location_id: locationId, | ||
page, | ||
per_page: perPage, | ||
}, | ||
}) | ||
|
||
return { | ||
items: data.data.map(rawDataToNode), | ||
pagination: getPaginationSet(data.meta.pagination), | ||
} | ||
} | ||
|
||
export default getAttachedNodes |
Oops, something went wrong.