-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Logs for sites #9047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Logs for sites #9047
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
77 changes: 77 additions & 0 deletions
77
src/Appwrite/Platform/Modules/Sites/Http/Logs/DeleteLog.php
This file contains hidden or 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,77 @@ | ||
<?php | ||
|
||
namespace Appwrite\Platform\Modules\Sites\Http\Logs; | ||
|
||
use Appwrite\Event\Event; | ||
use Appwrite\Extend\Exception; | ||
use Appwrite\Platform\Modules\Compute\Base; | ||
use Appwrite\Utopia\Response; | ||
use Utopia\Database\Database; | ||
use Utopia\Database\Validator\UID; | ||
use Utopia\Platform\Action; | ||
use Utopia\Platform\Scope\HTTP; | ||
|
||
class DeleteLog extends Base | ||
{ | ||
use HTTP; | ||
|
||
public static function getName() | ||
{ | ||
return 'deleteLog'; | ||
} | ||
|
||
public function __construct() | ||
{ | ||
$this | ||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_DELETE) | ||
->setHttpPath('/v1/sites/:siteId/logs/:logId') | ||
->desc('Delete log') | ||
->groups(['api', 'sites']) | ||
->label('scope', 'log.write') | ||
->label('resourceType', RESOURCE_TYPE_SITES) | ||
->label('event', 'sites.[siteId].logs.[logId].delete') | ||
->label('audits.event', 'logs.delete') | ||
->label('audits.resource', 'site/{request.siteId}') | ||
->label('sdk.auth', [APP_AUTH_TYPE_KEY]) | ||
->label('sdk.namespace', 'sites') | ||
->label('sdk.method', 'deleteLog') | ||
->label('sdk.description', '/docs/references/sites/delete-log.md') // TODO: add this file | ||
->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) | ||
->label('sdk.response.model', Response::MODEL_NONE) | ||
->param('siteId', '', new UID(), 'Site ID.') | ||
->param('logId', '', new UID(), 'Log ID.') | ||
->inject('response') | ||
->inject('dbForProject') | ||
->inject('queueForEvents') | ||
->callback([$this, 'action']); | ||
} | ||
|
||
public function action(string $siteId, string $logId, Response $response, Database $dbForProject, Event $queueForEvents) | ||
{ | ||
$site = $dbForProject->getDocument('sites', $siteId); | ||
|
||
if ($site->isEmpty()) { | ||
throw new Exception(Exception::SITE_NOT_FOUND); | ||
} | ||
|
||
$log = $dbForProject->getDocument('executions', $logId); | ||
if ($log->isEmpty()) { | ||
throw new Exception(Exception::LOG_NOT_FOUND); | ||
} | ||
|
||
if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceId') !== $site->getId()) { | ||
vermakhushboo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new Exception(Exception::LOG_NOT_FOUND); | ||
} | ||
|
||
if (!$dbForProject->deleteDocument('executions', $log->getId())) { | ||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove log from DB'); | ||
} | ||
|
||
$queueForEvents | ||
->setParam('siteId', $site->getId()) | ||
->setParam('logId', $log->getId()) | ||
->setPayload($response->output($log, Response::MODEL_EXECUTION)); // TODO: Update model | ||
|
||
$response->noContent(); | ||
} | ||
} |
This file contains hidden or 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,64 @@ | ||
<?php | ||
|
||
namespace Appwrite\Platform\Modules\Sites\Http\Logs; | ||
|
||
use Appwrite\Extend\Exception; | ||
use Appwrite\Platform\Modules\Compute\Base; | ||
use Appwrite\Utopia\Response; | ||
use Utopia\Database\Database; | ||
use Utopia\Database\Validator\UID; | ||
use Utopia\Platform\Action; | ||
use Utopia\Platform\Scope\HTTP; | ||
|
||
class GetLog extends Base | ||
{ | ||
use HTTP; | ||
|
||
public static function getName() | ||
{ | ||
return 'getLog'; | ||
} | ||
|
||
public function __construct() | ||
{ | ||
$this | ||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) | ||
->setHttpPath('/v1/sites/:siteId/logs/:logId') | ||
->desc('Get log') | ||
->groups(['api', 'sites']) | ||
->label('scope', 'log.read') | ||
->label('sdk.auth', [APP_AUTH_TYPE_KEY]) | ||
->label('sdk.namespace', 'sites') | ||
->label('sdk.method', 'getLog') | ||
->label('sdk.description', '/docs/references/sites/get-log.md') // TODO: add this file | ||
->label('sdk.response.code', Response::STATUS_CODE_OK) | ||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON) | ||
->label('sdk.response.model', Response::MODEL_EXECUTION) | ||
->param('siteId', '', new UID(), 'Site ID.') | ||
->param('logId', '', new UID(), 'Log ID.') | ||
->inject('response') | ||
->inject('dbForProject') | ||
->callback([$this, 'action']); | ||
} | ||
|
||
public function action(string $siteId, string $logId, Response $response, Database $dbForProject) | ||
{ | ||
$site = $dbForProject->getDocument('sites', $siteId); | ||
|
||
if ($site->isEmpty() || !$site->getAttribute('enabled')) { | ||
throw new Exception(Exception::SITE_NOT_FOUND); | ||
} | ||
|
||
$log = $dbForProject->getDocument('executions', $logId); | ||
|
||
if ($log->getAttribute('resourceType') !== 'sites' && $log->getAttribute('resourceId') !== $site->getId()) { | ||
throw new Exception(Exception::LOG_NOT_FOUND); | ||
} | ||
|
||
if ($log->isEmpty()) { | ||
throw new Exception(Exception::LOG_NOT_FOUND); | ||
} | ||
|
||
$response->dynamic($log, Response::MODEL_EXECUTION); //TODO: Change to model log, but model log already exists - decide what to do | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.