Skip to content

Commit ff603b7

Browse files
init: create repository
0 parents  commit ff603b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1936
-0
lines changed

Api/Data/LogInterface.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/*
3+
* Copyright © Ghost Unicorns snc. All rights reserved.
4+
* See LICENSE for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace GhostUnicorns\WebapiLogs\Api\Data;
10+
11+
use DateTime;
12+
use Exception;
13+
use Magento\Framework\Api\ExtensibleDataInterface;
14+
use Magento\Framework\DataObject;
15+
16+
interface LogInterface extends ExtensibleDataInterface
17+
{
18+
19+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/*
3+
* Copyright © Ghost Unicorns snc. All rights reserved.
4+
* See LICENSE for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace GhostUnicorns\WebapiLogs\Controller\Adminhtml\Reports;
10+
11+
use GhostUnicorns\WebapiLogs\Model\ResourceModel\Entity\LogCollectionFactory;
12+
use Magento\Backend\App\Action;
13+
use Magento\Backend\App\Action\Context;
14+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
15+
use Magento\Framework\View\Result\PageFactory;
16+
17+
class Delete extends Action implements HttpGetActionInterface
18+
{
19+
/**
20+
* Authorization level of a basic admin session
21+
*/
22+
const ADMIN_RESOURCE = 'GhostUnicorns_WebapiLogs::reports_webapilogs';
23+
24+
/**
25+
* @var bool|PageFactory
26+
*/
27+
protected $resultPageFactory = false;
28+
29+
/**
30+
* @var LogCollectionFactory
31+
*/
32+
private $logCollectionFactory;
33+
34+
/**
35+
* @param Context $context
36+
* @param PageFactory $resultPageFactory
37+
* @param LogCollectionFactory $logCollectionFactory
38+
*/
39+
public function __construct(
40+
Context $context,
41+
PageFactory $resultPageFactory,
42+
LogCollectionFactory $logCollectionFactory
43+
) {
44+
parent::__construct($context);
45+
$this->resultPageFactory = $resultPageFactory;
46+
$this->logCollectionFactory = $logCollectionFactory;
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
*/
52+
public function execute()
53+
{
54+
try {
55+
$logs = $this->logCollectionFactory->create();
56+
foreach ($logs as $log) {
57+
$log->delete();
58+
}
59+
} catch (\Exception $exception) {
60+
unset($exception);
61+
}
62+
63+
$resultRedirect = $this->resultRedirectFactory->create();
64+
return $resultRedirect->setPath('*/*/index', ['_current' => true]);
65+
}
66+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/*
3+
* Copyright © Ghost Unicorns snc. All rights reserved.
4+
* See LICENSE for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace GhostUnicorns\WebapiLogs\Controller\Adminhtml\Reports;
10+
11+
use Magento\Backend\App\Action;
12+
use Magento\Backend\App\Action\Context;
13+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
14+
use Magento\Framework\Controller\ResultInterface;
15+
use Magento\Framework\View\Result\Page;
16+
use Magento\Framework\View\Result\PageFactory;
17+
18+
class Detail extends Action implements HttpGetActionInterface
19+
{
20+
/**
21+
* Authorization level of a basic admin session
22+
*/
23+
const ADMIN_RESOURCE = 'GhostUnicorns_WebapiLogs::reports_webapilogs';
24+
25+
/**
26+
* @var bool|PageFactory
27+
*/
28+
protected $resultPageFactory = false;
29+
30+
/**
31+
* @param Context $context
32+
* @param PageFactory $resultPageFactory
33+
*/
34+
public function __construct(
35+
Context $context,
36+
PageFactory $resultPageFactory
37+
) {
38+
parent::__construct($context);
39+
$this->resultPageFactory = $resultPageFactory;
40+
}
41+
42+
/**
43+
* @return Page|ResultInterface
44+
*/
45+
public function execute()
46+
{
47+
$resultPage = $this->resultPageFactory->create();
48+
$resultPage->setActiveMenu('GhostUnicorns_WebapiLogs::reports');
49+
$resultPage->getConfig()->getTitle()->prepend(__('Webapi REST api logs'));
50+
return $resultPage;
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/*
3+
* Copyright © Ghost Unicorns snc. All rights reserved.
4+
* See LICENSE for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace GhostUnicorns\WebapiLogs\Controller\Adminhtml\Reports;
10+
11+
use Magento\Backend\App\Action;
12+
use Magento\Backend\App\Action\Context;
13+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
14+
use Magento\Framework\Controller\ResultInterface;
15+
use Magento\Framework\View\Result\Page;
16+
use Magento\Framework\View\Result\PageFactory;
17+
18+
class Index extends Action implements HttpGetActionInterface
19+
{
20+
/**
21+
* Authorization level of a basic admin session
22+
*/
23+
const ADMIN_RESOURCE = 'GhostUnicorns_WebapiLogs::reports_webapilogs';
24+
25+
/**
26+
* @var bool|PageFactory
27+
*/
28+
protected $resultPageFactory = false;
29+
30+
/**
31+
* @param Context $context
32+
* @param PageFactory $resultPageFactory
33+
*/
34+
public function __construct(
35+
Context $context,
36+
PageFactory $resultPageFactory
37+
) {
38+
parent::__construct($context);
39+
$this->resultPageFactory = $resultPageFactory;
40+
}
41+
42+
/**
43+
* @return Page|ResultInterface
44+
*/
45+
public function execute()
46+
{
47+
$resultPage = $this->resultPageFactory->create();
48+
$resultPage->setActiveMenu('GhostUnicorns_WebapiLogs::reports');
49+
$resultPage->getConfig()->getTitle()->prepend(__('Webapi REST api logs'));
50+
return $resultPage;
51+
}
52+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Ghost Unicorns snc di Ugolini Riccardo e Argentiero Danilo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Model/Config.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/*
3+
* Copyright © Ghost Unicorns snc. All rights reserved.
4+
* See LICENSE for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace GhostUnicorns\WebapiLogs\Model;
10+
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Store\Model\ScopeInterface;
13+
14+
class Config
15+
{
16+
/**
17+
* string
18+
*/
19+
protected const WEBAPI_LOGS_IS_ENABLED_CONFIG_PATH = 'webapi_logs/log/enabled';
20+
21+
/**
22+
* @var ScopeConfigInterface
23+
*/
24+
private $scopeConfig;
25+
26+
/**
27+
* @param ScopeConfigInterface $scopeConfig
28+
*/
29+
public function __construct(
30+
ScopeConfigInterface $scopeConfig
31+
) {
32+
$this->scopeConfig = $scopeConfig;
33+
}
34+
35+
/**
36+
* @return bool
37+
*/
38+
public function isEnabled(): bool
39+
{
40+
return $this->scopeConfig->isSetFlag(
41+
self::WEBAPI_LOGS_IS_ENABLED_CONFIG_PATH,
42+
ScopeInterface::SCOPE_WEBSITE
43+
);
44+
}
45+
}

Model/Config/Source/Code.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/*
3+
* Copyright © Ghost Unicorns snc. All rights reserved.
4+
* See LICENSE for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace GhostUnicorns\WebapiLogs\Model\Config\Source;
10+
11+
use GhostUnicorns\WebapiLogs\Model\ResourceModel\Entity\LogCollection;
12+
use GhostUnicorns\WebapiLogs\Model\ResourceModel\Entity\LogCollectionFactory;
13+
use Magento\Framework\Data\OptionSourceInterface;
14+
15+
class Code implements OptionSourceInterface
16+
{
17+
private LogCollectionFactory $logCollectionFactory;
18+
19+
/**
20+
* @param LogCollectionFactory $logCollectionFactory
21+
*/
22+
public function __construct(
23+
LogCollectionFactory $logCollectionFactory
24+
) {
25+
$this->logCollectionFactory = $logCollectionFactory;
26+
}
27+
28+
public function toOptionArray(): array
29+
{
30+
$result = [];
31+
/** @var LogCollection $logsCollection */
32+
$logsCollection = $this->logCollectionFactory->create();
33+
$logsCollection->addFieldToSelect('response_code');
34+
$logsCollection->distinct(true);
35+
foreach ($logsCollection as $logs) {
36+
$result[] = [
37+
'value' => $logs->getResponseCode(),
38+
'label' => $logs->getResponseCode()
39+
];
40+
}
41+
return $result;
42+
}
43+
}

Model/Config/Source/Methods.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/*
3+
* Copyright © Ghost Unicorns snc. All rights reserved.
4+
* See LICENSE for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace GhostUnicorns\WebapiLogs\Model\Config\Source;
10+
11+
use GhostUnicorns\WebapiLogs\Model\ResourceModel\Entity\LogCollection;
12+
use GhostUnicorns\WebapiLogs\Model\ResourceModel\Entity\LogCollectionFactory;
13+
use Magento\Framework\Data\OptionSourceInterface;
14+
15+
class Methods implements OptionSourceInterface
16+
{
17+
private LogCollectionFactory $logCollectionFactory;
18+
19+
/**
20+
* @param LogCollectionFactory $logCollectionFactory
21+
*/
22+
public function __construct(
23+
LogCollectionFactory $logCollectionFactory
24+
) {
25+
$this->logCollectionFactory = $logCollectionFactory;
26+
}
27+
28+
public function toOptionArray(): array
29+
{
30+
$result = [];
31+
/** @var LogCollection $logsCollection */
32+
$logsCollection = $this->logCollectionFactory->create();
33+
$logsCollection->addFieldToSelect('request_method');
34+
$logsCollection->distinct(true);
35+
foreach ($logsCollection as $logs) {
36+
$result[] = [
37+
'value' => $logs->getRequestMethod(),
38+
'label' => $logs->getRequestMethod()
39+
];
40+
}
41+
return $result;
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/*
3+
* Copyright © Ghost Unicorns snc. All rights reserved.
4+
* See LICENSE for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace GhostUnicorns\WebapiLogs\Model\Config\Source;
10+
11+
use GhostUnicorns\WebapiLogs\Model\ResourceModel\Entity\LogCollection;
12+
use GhostUnicorns\WebapiLogs\Model\ResourceModel\Entity\LogCollectionFactory;
13+
use Magento\Framework\Data\OptionSourceInterface;
14+
15+
class RequestorIp implements OptionSourceInterface
16+
{
17+
private LogCollectionFactory $logCollectionFactory;
18+
19+
/**
20+
* @param LogCollectionFactory $logCollectionFactory
21+
*/
22+
public function __construct(
23+
LogCollectionFactory $logCollectionFactory
24+
) {
25+
$this->logCollectionFactory = $logCollectionFactory;
26+
}
27+
28+
public function toOptionArray(): array
29+
{
30+
$result = [];
31+
/** @var LogCollection $logsCollection */
32+
$logsCollection = $this->logCollectionFactory->create();
33+
$logsCollection->addFieldToSelect('requestor_ip');
34+
$logsCollection->distinct(true);
35+
foreach ($logsCollection as $logs) {
36+
$result[] = [
37+
'value' => $logs->getRequestorIp(),
38+
'label' => $logs->getRequestorIp()
39+
];
40+
}
41+
return $result;
42+
}
43+
}

0 commit comments

Comments
 (0)