Skip to content

Commit b044ac3

Browse files
committed
feat: Initial Commit
0 parents  commit b044ac3

File tree

34 files changed

+1826
-0
lines changed

34 files changed

+1826
-0
lines changed

.github/workflows/main.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: m2-test
2+
3+
on: [push]
4+
5+
env:
6+
MODULE: Sozo_Feedbucket
7+
8+
jobs:
9+
magento2-build:
10+
runs-on: ubuntu-latest
11+
container: ubuntu
12+
name: 'Magento 2 Build and Test'
13+
services:
14+
mysql:
15+
image: docker://mysql:8.0
16+
env:
17+
MYSQL_ROOT_PASSWORD: magento
18+
MYSQL_DATABASE: magento
19+
ports:
20+
- 3306:3306
21+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
22+
elasticsearch:
23+
image: docker://elasticsearch:7.1.0
24+
ports:
25+
- 9200:9200
26+
options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
path: ${{ env.MODULE }}
32+
33+
- name: 'Install fresh Magento instance'
34+
uses: MAD-I-T/magento-actions@master
35+
env:
36+
COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
37+
with:
38+
process: 'install-magento'
39+
magento_version: '2.4.6'
40+
no_push: 1 ## add this arg to not push to the repo ideal for quick test on specific version
41+
42+
- name: 'Launch Magento 2 Unit Test'
43+
if: always()
44+
uses: MAD-I-T/magento-actions@master
45+
env:
46+
COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
47+
with:
48+
process: 'unit-test'
49+
unit_test_config: 'dev/tests/unit/phpunit.xml.dist'
50+
unit_test_subset_path: "../${{ env.MODULE }}/"
51+
52+
- name: 'phpstan'
53+
if: always()
54+
uses: MAD-I-T/magento-actions@master
55+
env:
56+
COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
57+
with:
58+
process: 'phpstan'
59+
exec_path: "../${{ env.MODULE }}/"
60+
61+
- name: 'Mess Detector'
62+
if: always()
63+
uses: MAD-I-T/magento-actions@master
64+
env:
65+
COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
66+
with:
67+
process: 'mess-detector'
68+
md_src_path: "../${{ env.MODULE }}/"
69+
70+
- name: 'Magento coding standard checking'
71+
if: always()
72+
uses: MAD-I-T/magento-actions@master
73+
env:
74+
COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
75+
with:
76+
process: 'phpcs-test'
77+
extension: ${{ env.MODULE }}
78+
severity: 10
79+
standard: 'Magento2'

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
3+
### SublimeText template
4+
# cache files for sublime text
5+
*.tmlanguage.cache
6+
*.tmPreferences.cache
7+
*.stTheme.cache
8+
9+
# workspace files are user-specific
10+
*.sublime-workspace
11+
12+
# project files should be checked into the repository, unless a significant
13+
# proportion of contributors will probably not be using SublimeText
14+
# *.sublime-project
15+
16+
# sftp configuration file
17+
sftp-config.json
18+
19+
# Package control specific files
20+
Package Control.last-run
21+
Package Control.ca-list
22+
Package Control.ca-bundle
23+
Package Control.system-ca-bundle
24+
Package Control.cache/
25+
Package Control.ca-certs/
26+
Package Control.merged-ca-bundle
27+
Package Control.user-ca-bundle
28+
oscrypto-ca-bundle.crt
29+
bh_unicode_properties.cache
30+
31+
# Sublime-github package stores a github token in this file
32+
# https://packagecontrol.io/packages/sublime-github
33+
GitHub.sublime-settings
34+
35+
/.idea
36+
37+
/.github/workflows/secrets/

.scrutinizer.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
checks:
2+
php:
3+
code_rating: true
4+
duplication: true
5+
excluded_dependencies:
6+
- magento/framework
7+
8+
filter:
9+
excluded_paths:
10+
- "Test/"
11+
12+
build:
13+
dependencies:
14+
before:
15+
- 'echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_COMPOSER_USERNAME}\",\"password\":\"${MAGENTO_COMPOSER_PASSWORD}\"}}}" > auth.json'
16+
- 'composer config allow-plugins true'
17+
18+
environment:
19+
php:
20+
version: 7.4.33

.styleci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
risky: false
2+
version: 7.4
3+
preset: psr12
4+
tab-width: 4
5+
use-tabs: false
6+
finder:
7+
exclude:
8+
- "vendor"
9+
name: "*.php"
10+
not-name:
11+
- "*.phtml"

Block/Backend.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/*
3+
* SOZO Design Ltd
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Open Software License (OSL 3.0)
8+
* that is bundled with this package in the file LICENSE.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/osl-3.0.php
11+
*
12+
* @category SOZO Design Ltd
13+
* @package Sozo_Feedbucket
14+
* @copyright Copyright (c) SOZO Design Ltd (https://sozodesign.co.uk)
15+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
namespace Sozo\Feedbucket\Block;
21+
22+
use Sozo\Feedbucket\Model\ConfigProvider;
23+
use Sozo\Feedbucket\Service\IpCheckerService;
24+
use Magento\Backend\Model\Auth\Session;
25+
use Magento\Framework\App\State;
26+
use Magento\Framework\View\Element\Template\Context;
27+
28+
class Backend extends Display
29+
{
30+
/**
31+
* @var Session
32+
*/
33+
private $authSession;
34+
35+
/**
36+
* @param Context $context
37+
* @param ConfigProvider $configProvider
38+
* @param IpCheckerService $ipCheckerService
39+
* @param State $state
40+
* @param Session $authSession
41+
* @param array $data
42+
*/
43+
public function __construct(
44+
Context $context,
45+
ConfigProvider $configProvider,
46+
IpCheckerService $ipCheckerService,
47+
State $state,
48+
Session $authSession,
49+
array $data = []
50+
) {
51+
parent::__construct($context, $configProvider, $ipCheckerService, $state, $data);
52+
$this->authSession = $authSession;
53+
}
54+
55+
/**
56+
* Return current admin user information
57+
*
58+
* @return \Magento\User\Model\User|null
59+
*/
60+
protected function getCurrentUser(): ?\Magento\User\Model\User
61+
{
62+
return $this->authSession->getUser();
63+
}
64+
65+
/**
66+
* @inheritdoc
67+
*
68+
* @return array|array[]
69+
*/
70+
public function prepareConfig(): array
71+
{
72+
$config = parent::prepareConfig();
73+
if ($this->getCurrentUser() && $this->configProvider->isBackendCaptureUserData()) {
74+
$config['reporter'] = [
75+
'name' => $this->getCurrentUser()->getName(),
76+
'email' => $this->getCurrentUser()->getEmail(),
77+
];
78+
79+
$config['reporter']['token'] = $this->configProvider->getUserHash($config['reporter']);
80+
}
81+
82+
return $this->jsConfig = array_merge($this->jsConfig, $config);
83+
}
84+
85+
/**
86+
* @inheritdoc
87+
*
88+
* @return string
89+
*/
90+
public function _toHtml(): string
91+
{
92+
if ($this->configProvider->isBackendEnabled()) {
93+
return parent::_toHtml();
94+
}
95+
96+
return '';
97+
}
98+
}

Block/Display.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/*
3+
* SOZO Design Ltd
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Open Software License (OSL 3.0)
8+
* that is bundled with this package in the file LICENSE.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/osl-3.0.php
11+
*
12+
* @category SOZO Design Ltd
13+
* @package Sozo_Feedbucket
14+
* @copyright Copyright (c) SOZO Design Ltd (https://sozodesign.co.uk)
15+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
namespace Sozo\Feedbucket\Block;
21+
22+
use Sozo\Feedbucket\Model\ConfigProvider;
23+
use Sozo\Feedbucket\Service\IpCheckerService;
24+
use Magento\Framework\App\State;
25+
use Magento\Framework\View\Element\Template;
26+
use Magento\Framework\View\Element\Template\Context;
27+
28+
class Display extends Template
29+
{
30+
/**
31+
* @var ConfigProvider
32+
*/
33+
protected $configProvider;
34+
35+
/**
36+
* @var IpCheckerService
37+
*/
38+
protected $ipChecker;
39+
/**
40+
* @var State
41+
*/
42+
private $state;
43+
44+
/**
45+
* @var array
46+
*/
47+
protected $jsConfig = [];
48+
49+
/**
50+
* @param Context $context
51+
* @param ConfigProvider $configProvider
52+
* @param IpCheckerService $ipCheckerService
53+
* @param State $state
54+
* @param array $data
55+
*/
56+
public function __construct(
57+
Context $context,
58+
ConfigProvider $configProvider,
59+
IpCheckerService $ipCheckerService,
60+
State $state,
61+
array $data = []
62+
) {
63+
$this->configProvider = $configProvider;
64+
$this->ipChecker = $ipCheckerService;
65+
$this->state = $state;
66+
67+
parent::__construct($context, $data);
68+
}
69+
70+
/**
71+
* Get the Widget ID
72+
*
73+
* @return string|null
74+
*/
75+
public function getSecret(): ?string
76+
{
77+
return $this->configProvider->getSecret();
78+
}
79+
80+
/**
81+
* Prepare the api configuration
82+
*
83+
* @return array[]
84+
*/
85+
public function prepareConfig(): array
86+
{
87+
$config = [
88+
'custom' => [
89+
'capturedBy' => 'Magento 2 Feedbucket Module: ' . $this->configProvider->getExtensionVersion(),
90+
'magentoDeployMode' => $this->state->getMode()
91+
]
92+
];
93+
94+
return $this->jsConfig = $config;
95+
}
96+
97+
/**
98+
* Return the JSON encoded api configuration
99+
*
100+
* @return string
101+
*/
102+
public function getJsConfig(): string
103+
{
104+
$this->prepareConfig();
105+
return json_encode($this->jsConfig, JSON_FORCE_OBJECT);
106+
}
107+
108+
/**
109+
* Generate the Feedbucket output
110+
*
111+
* @return string
112+
*/
113+
public function _toHtml(): string
114+
{
115+
$enabled = $this->configProvider->isEnabled();
116+
$ipAllowed = $this->ipChecker->checkAllowed();
117+
118+
return ($enabled && $ipAllowed) ? parent::_toHtml() : '';
119+
}
120+
}

0 commit comments

Comments
 (0)