9
9
namespace Magento \AdminAdobeIms \Console \Command ;
10
10
11
11
use Magento \AdminAdobeIms \Model \ImsConnection ;
12
- use Magento \AdminAdobeIms \Service \UpdateTokensService ;
13
12
use Magento \AdminAdobeIms \Service \ImsCommandOptionService ;
14
13
use Magento \AdminAdobeIms \Service \ImsConfig ;
14
+ use Magento \AdminAdobeIms \Service \UpdateTokensService ;
15
+ use Magento \Authorization \Model \ResourceModel \Role \CollectionFactory ;
16
+ use Magento \Authorization \Model \Role ;
17
+ use Magento \Authorization \Model \UserContextInterface ;
15
18
use Magento \Framework \App \Cache \Type \Config ;
16
19
use Magento \Framework \App \Cache \TypeListInterface ;
20
+ use Magento \Framework \App \ObjectManager ;
17
21
use Magento \Framework \Console \Cli ;
18
22
use Magento \Framework \Exception \InvalidArgumentException ;
19
23
use Magento \Framework \Exception \LocalizedException ;
@@ -73,26 +77,42 @@ class AdminAdobeImsEnableCommand extends Command
73
77
*/
74
78
private UpdateTokensService $ updateTokensService ;
75
79
80
+ /**
81
+ * @var Role|mixed
82
+ */
83
+ private Role $ role ;
84
+
85
+ /**
86
+ * @var CollectionFactory
87
+ */
88
+ private CollectionFactory $ roleCollection ;
89
+
76
90
/**
77
91
* @param ImsConfig $adminImsConfig
78
92
* @param ImsConnection $adminImsConnection
79
93
* @param ImsCommandOptionService $imsCommandOptionService
80
94
* @param TypeListInterface $cacheTypeList
81
95
* @param UpdateTokensService $updateTokensService
96
+ * @param Role $role
97
+ * @param CollectionFactory $roleCollection
82
98
*/
83
99
public function __construct (
84
100
ImsConfig $ adminImsConfig ,
85
101
ImsConnection $ adminImsConnection ,
86
102
ImsCommandOptionService $ imsCommandOptionService ,
87
103
TypeListInterface $ cacheTypeList ,
88
- UpdateTokensService $ updateTokensService
104
+ UpdateTokensService $ updateTokensService ,
105
+ Role $ role = null ,
106
+ CollectionFactory $ roleCollection = null
89
107
) {
90
108
parent ::__construct ();
91
109
$ this ->adminImsConfig = $ adminImsConfig ;
92
110
$ this ->adminImsConnection = $ adminImsConnection ;
93
111
$ this ->imsCommandOptionService = $ imsCommandOptionService ;
94
112
$ this ->cacheTypeList = $ cacheTypeList ;
95
113
$ this ->updateTokensService = $ updateTokensService ;
114
+ $ this ->role = $ role ?: ObjectManager::getInstance ()->get (Role::class);
115
+ $ this ->roleCollection = $ roleCollection ?: ObjectManager::getInstance ()->get (CollectionFactory::class);
96
116
97
117
$ this ->setName ('admin:adobe-ims:enable ' )
98
118
->setDescription ('Enable Adobe IMS Module. ' )
@@ -164,6 +184,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
164
184
if ($ clientId && $ clientSecret && $ organizationId && $ isTwoFactorAuthEnabled ) {
165
185
$ enabled = $ this ->enableModule ($ clientId , $ clientSecret , $ organizationId , $ isTwoFactorAuthEnabled );
166
186
if ($ enabled ) {
187
+ $ this ->saveIMSAuthorizationRole ();
167
188
$ output ->writeln (__ ('Admin Adobe IMS integration is enabled ' ));
168
189
return Cli::RETURN_SUCCESS ;
169
190
}
@@ -182,6 +203,22 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
182
203
}
183
204
}
184
205
206
+ private function saveIMSAuthorizationRole (): bool
207
+ {
208
+ $ roleCollection = $ this ->roleCollection ->create ()->addFieldToFilter ('role_name ' , 'AdobeImsRole ' );
209
+
210
+ if (!$ roleCollection ->getSize ()) {
211
+ $ this ->role ->setRoleName ('AdobeImsRole ' )
212
+ ->setUserType ((string )UserContextInterface::USER_TYPE_ADMIN )
213
+ ->setUserId (0 )
214
+ ->setRoleType (\Magento \Authorization \Model \Acl \Role \Group::ROLE_TYPE )
215
+ ->setParentId (0 )
216
+ ->save ();
217
+ return true ;
218
+ }
219
+ return true ;
220
+ }
221
+
185
222
/**
186
223
* Enable Admin Adobe IMS Module when testConnection was successfully
187
224
*
0 commit comments