Skip to content

Commit

Permalink
Merge pull request #1 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Dec 26, 2019
2 parents f681bbe + d09513e commit aa985c9
Show file tree
Hide file tree
Showing 38 changed files with 2,241 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG: https://www.mageplaza.com/releases/gift-card
89 changes: 89 additions & 0 deletions Helper/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_GiftCardGraphQl
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\GiftCardGraphQl\Helper;

use Magento\Framework\Authorization\PolicyInterface;
use Magento\Integration\Api\IntegrationServiceInterface;
use Magento\Integration\Model\Oauth\TokenFactory;

/**
* Class Auth
* @package Mageplaza\GiftCardGraphQl\Helper
*/
class Auth
{
/**
* @var PolicyInterface
*/
private $aclPolicy;

/**
* @var TokenFactory
*/
private $tokenFactory;

/**
* @var IntegrationServiceInterface
*/
private $integrationService;

/**
* Auth constructor.
*
* @param PolicyInterface $aclPolicy
* @param TokenFactory $tokenFactory
* @param IntegrationServiceInterface $integrationService
*/
public function __construct(
PolicyInterface $aclPolicy,
TokenFactory $tokenFactory,
IntegrationServiceInterface $integrationService
) {
$this->aclPolicy = $aclPolicy;
$this->tokenFactory = $tokenFactory;
$this->integrationService = $integrationService;
}

/**
* @param string $accessToken
*
* @return string
*/
private function getAclRoleId($accessToken)
{
$token = $this->tokenFactory->create()->loadByToken($accessToken);

return $this->integrationService->findByConsumerId($token->getConsumerId())->getId();
}

/**
* @param string $accessToken
* @param string $resource
* @param string $privilege
*
* @return bool
*/
public function isAllowed($accessToken, $resource, $privilege = null)
{
return $this->aclPolicy->isAllowed($this->getAclRoleId($accessToken), $resource, $privilege);
}
}
33 changes: 33 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Copyright © 2016-present Mageplaza Co. Ltd.

This License is entered by Mageplaza to govern the usage or redistribution of Mageplaza software. This is a legal agreement between you (either an individual or a single entity) and Mageplaza for Mageplaza software product(s) which may include extensions, templates and services.

By purchasing, installing, or otherwise using Mageplaza products, you acknowledge that you have read this License and agree to be bound by the terms of this Agreement. If you do not agree to the terms of this License, do not install or use Mageplaza products.

The Agreement becomes effective at the moment when you acquire software from our site or receive it through email or on data medium or by any other means. Mageplaza reserves the right to make reasonable changes to the terms of this license agreement and impose its clauses at any given time.

1. GRANT OF LICENSE: By purchasing a product of Mageplaza:

1. Customer will receive source code open 100%.

2. Customer will obtain a License Certificate which will remain valid until the Customer stops using the Product or until Mageplaza terminates this License because of Customer’s failure to comply with any of its Terms and Conditions. Each License Certificate includes a license serial which is valid for one live Magento installation only and unlimited test Magento installations.

3. You are allowed to customize our products to fit with your using purpose.

4. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS

5. Installation and Use

6. For each new Software installation, you are obliged to purchase a separate License. You are not permitted to use any part of the code in whole or part in any other software or product or website. You are legally bound to preserve the copyright information intact including the text/link at bottom.

2. Distribution: You are not allowed to distribute Mageplaza software to third parties. Any distribution without our permission, including non commercial distribution is considered as violation of this Agreement and entails liability, according to the current law. You may not place the Software onto a server that allows access to the Software via a public network or the Internet for distribution purposes.

3. Rental: You may not give, sell, sub-license, rent, lease or lend any portion of the Software to anyone.

4. Compliance with Applicable Laws: You must comply with all applicable laws regarding use of software products. Mageplaza software and a portion of it are protected by copyright laws and international copyright treaties, as well as other intellectual property laws and treaties. Accordingly, customer is required to treat the software like any other copyrighted material. Any activity violating copyright law will be prosecuted according to the current law. We retain the right to revoke the license of any user holding an invalid license.

5. TERMINATION: Without prejudice to any other rights, Mageplaza may terminate this License at any time if you fail to comply with the terms and conditions of this License. In such event, it constitutes a breach of the agreement, and your license to use the program is revoked and you must destroy all copies of Mageplaza products in your possession. After being notified of termination of your license, if you continue to use Mageplaza software, you hereby agree to accept an injunction to prevent you from its further use and to pay all costs (including but not limited to reasonable attorney fees) to enforce our revocation of your license and any damages suffered by us because of your misuse of the Software. We are not bound to return you the amount spent for purchase of the Software for the termination of this License.

6. LIMITATION OF LIABILITY: In no event shall Mageplaza be liable for any damages (including, without limitation, lost profits, business interruption, or lost information) rising out of ‘Authorized Users’ use of or inability to use the Mageplaza products, even if Mageplaza has been advised of the possibility of such damages. In no event will Mageplaza be liable for prosecution arising from use of the Software against law or for any illegal use.

The latest License: https://www.mageplaza.com/LICENSE.txt
104 changes: 104 additions & 0 deletions Model/Resolver/AbstractResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_GiftCardGraphQl
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

declare(strict_types=1);

namespace Mageplaza\GiftCardGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Mageplaza\GiftCard\Helper\Data;
use Mageplaza\GiftCardGraphQl\Helper\Auth;
use Mageplaza\GiftCardGraphQl\Model\Resolver\Filter\Query\Filter;

/**
* Class AbstractResolver
* @package Mageplaza\GiftCardGraphQl\Model\Resolver
*/
abstract class AbstractResolver implements ResolverInterface
{
/**
* @var string
*/
protected $_aclResource = '';

/**
* @var string
*/
protected $_type = '';

/**
* @var Filter
*/
protected $filter;

/**
* @var Data
*/
private $helper;

/**
* @var Auth
*/
private $auth;

/**
* AbstractResolver constructor.
*
* @param Filter $filter
* @param Data $helper
* @param Auth $auth
*/
public function __construct(
Filter $filter,
Data $helper,
Auth $auth
) {
$this->filter = $filter;
$this->helper = $helper;
$this->auth = $auth;
}

/**
* {@inheritDoc}
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!$this->helper->isEnabled()) {
throw new GraphQlInputException(__('The module is disabled'));
}

if (!$this->auth->isAllowed($args['accessToken'], $this->_aclResource)) {
throw new GraphQlInputException(__("The consumer isn't authorized to access %1", $this->_aclResource));
}

return $this->handleArgs($args);
}

/**
* @param array $args
*
* @return mixed
*/
abstract protected function handleArgs(array $args);
}
49 changes: 49 additions & 0 deletions Model/Resolver/Delete/AbstractResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_GiftCardGraphQl
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

declare(strict_types=1);

namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Delete;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;

/**
* Class AbstractResolver
* @package Mageplaza\GiftCardGraphQl\Model\Resolver\Delete
*/
class AbstractResolver extends \Mageplaza\GiftCardGraphQl\Model\Resolver\AbstractResolver
{
/**
* @param array $args
*
* @return bool
* @throws GraphQlInputException
*/
protected function handleArgs(array $args)
{
try {
return $this->filter->deleteEntity($args['id'], $this->_type);
} catch (NoSuchEntityException $e) {
throw new GraphQlInputException(__($e->getMessage()));
}
}
}
41 changes: 41 additions & 0 deletions Model/Resolver/Delete/GiftCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_GiftCardGraphQl
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

declare(strict_types=1);

namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Delete;

/**
* Class GiftCode
* @package Mageplaza\GiftCardGraphQl\Model\Resolver\Delete
*/
class GiftCode extends AbstractResolver
{
/**
* @var string
*/
protected $_aclResource = 'Mageplaza_GiftCard::code';

/**
* @var string
*/
protected $_type = 'mpGiftCode';
}
41 changes: 41 additions & 0 deletions Model/Resolver/Delete/GiftPool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_GiftCardGraphQl
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

declare(strict_types=1);

namespace Mageplaza\GiftCardGraphQl\Model\Resolver\Delete;

/**
* Class GiftPool
* @package Mageplaza\GiftCardGraphQl\Model\Resolver\Delete
*/
class GiftPool extends AbstractResolver
{
/**
* @var string
*/
protected $_aclResource = 'Mageplaza_GiftCard::pool';

/**
* @var string
*/
protected $_type = 'mpGiftPool';
}
Loading

0 comments on commit aa985c9

Please sign in to comment.