TabsPlugin.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * MageSpecialist
  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.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to info@magespecialist.it so we can send you a copy immediately.
  14. *
  15. * @category MSP
  16. * @package MSP_TwoFactorAuth
  17. * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. */
  20. namespace MSP\TwoFactorAuth\Plugin\Block\User\Edit;
  21. use Magento\Framework\AuthorizationInterface;
  22. use MSP\TwoFactorAuth\Api\TfaInterface;
  23. class TabsPlugin
  24. {
  25. /**
  26. * @var TfaInterface
  27. */
  28. private $tfa;
  29. /**
  30. * @var AuthorizationInterface
  31. */
  32. private $authorization;
  33. /**
  34. * TabsPlugin constructor.
  35. * @param TfaInterface $tfa
  36. * @param AuthorizationInterface $authorization
  37. */
  38. public function __construct(
  39. TfaInterface $tfa,
  40. AuthorizationInterface $authorization
  41. ) {
  42. $this->tfa = $tfa;
  43. $this->authorization = $authorization;
  44. }
  45. /**
  46. * @param \Magento\User\Block\User\Edit\Tabs $subject
  47. * @throws \Magento\Framework\Exception\LocalizedException
  48. */
  49. public function beforeToHtml(\Magento\User\Block\User\Edit\Tabs $subject)
  50. {
  51. if (empty($this->tfa->getAllEnabledProviders()) ||
  52. !$this->authorization->isAllowed('MSP_TwoFactorAuth::tfa')
  53. ) {
  54. return;
  55. }
  56. $tfaForm = $subject->getLayout()->renderElement('msp_twofactorauth_edit_user_form');
  57. $subject->addTabAfter(
  58. 'msp_twofactorauth',
  59. [
  60. 'label' => __('2FA'),
  61. 'title' => __('2FA'),
  62. 'content' => $tfaForm,
  63. 'active' => true
  64. ],
  65. 'roles_section'
  66. );
  67. }
  68. }