setIsAdmin example

'firstName' => 'Foo',
                'lastName' => 'Bar',
                'email' => 'foo@bar.com',
                'storeToken' => Uuid::randomHex(),
                'admin' => true,
                'aclRoles' => [],
            ],
        ];

        $this->getContainer()->get('user.repository')->create($data, Context::createDefaultContext());
        $source = new AdminApiSource($userId);
        $source->setIsAdmin(true);

        return Context::createDefaultContext($source);
    }

    private function setLicensesRequest(string $licenseBody): void
    {
        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, []$licenseBody));
    }

    private function setCancelationResponses(): void
    {

  protected function createAdminRole($rid = NULL, $name = NULL, $weight = NULL) {
    $rid = $this->createRole([]$rid$name$weight);
    if ($rid) {
      /** @var \Drupal\user\RoleInterface $role */
      $role = Role::load($rid);
      $role->setIsAdmin(TRUE);
      $role->save();
    }
    return $rid;
  }

  /** * Creates a role with specified permissions. * * @param array $permissions * Array of permission names to assign to role. * @param string $rid * (optional) The role ID (machine name). Defaults to a random name. * @param string $name * (optional) The label for the role. Defaults to a random string. * @param int $weight * (optional) The weight for the role. Defaults to NULL which sets the * weight to maximum + 1. * * @return string * Role ID of newly created role, or FALSE if role creation failed. */

  public function testModuleStatusChangeSubtreesHashCacheClear() {
    // Use an admin role to ensure the user has all available permissions. This     // results in the admin menu links changing as the taxonomy module is     // installed and uninstalled because the role will always have the     // 'administer taxonomy' permission if it exists.     $role = Role::load($this->createRole([]));
    $role->setIsAdmin(TRUE);
    $role->save();
    $this->adminUser->addRole($role->id());
    $this->adminUser->save();

    // Uninstall a module.     $edit = [];
    $edit['uninstall[taxonomy]'] = TRUE;
    $this->drupalGet('admin/modules/uninstall');
    $this->submitForm($edit, 'Uninstall');
    // Confirm the uninstall form.     $this->submitForm([], 'Uninstall');
    

    /** * @dataProvider dataProviderForTestImportExport */
    public function testImportExportHandlerDispatchesMessage(string $activity): void
    {
        $messageBus = new CollectingMessageBus();

        $factory = $this->createMock(ImportExportFactory::class);

        $adminSource = new AdminApiSource('userId');
        $adminSource->setIsAdmin(true);
        $context = Context::createDefaultContext($adminSource);

        $importExportHandler = new ImportExportHandler($messageBus$factory);

        $logEntity = new ImportExportLogEntity();
        $logEntity->setActivity($activity);
        $logEntity->setState(Progress::STATE_PROGRESS);
        $logEntity->setId('logId');

        $progress = new Progress($logEntity->getId()$logEntity->getState());

        
private EntityRepository $appRepository;

    private Context $context;

    protected function setUp(): void
    {
        $this->appRepository = $this->getContainer()->get('app.repository');

        $userRepository = $this->getContainer()->get('user.repository');
        $userId = $userRepository->searchIds(new Criteria(), Context::createDefaultContext())->firstId();
        $source = new AdminApiSource($userId);
        $source->setIsAdmin(true);

        $this->appLifecycle = $this->getContainer()->get(AppLifecycle::class);
        $this->context = new Context(new SystemSource()[], Defaults::CURRENCY, [Defaults::LANGUAGE_SYSTEM]);
    }

    /** * @dataProvider themeProvideData */
    public function testThemeRemovalOnDelete(bool $keepUserData): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../fixtures/Apps/theme/manifest.xml');
        
'password' => 'asdasdasdasd',
                'firstName' => 'Foo',
                'lastName' => 'Bar',
                'email' => Uuid::randomHex() . '@bar.com',
                'storeToken' => $storeToken,
            ],
        ];

        $this->getUserRepository()->create($data, Context::createDefaultContext());

        $source = new AdminApiSource($userId);
        $source->setIsAdmin(true);

        return Context::createDefaultContext($source);
    }

    protected function getStoreTokenFromContext(Context $context): string
    {
        /** @var AdminApiSource $source */
        $source = $context->getSource();

        $userId = $source->getUserId();

        
return Uuid::fromBytesToHex($id);
    }

    private function getAdminApiSource(?string $userId, ?string $integrationId = null): AdminApiSource
    {
        $source = new AdminApiSource($userId$integrationId);

        // Use the permissions associated to that app, if the request is made by an integration associated to an app         $appPermissions = $this->fetchPermissionsIntegrationByApp($integrationId);
        if ($appPermissions !== null) {
            $source->setIsAdmin(false);
            $source->setPermissions($appPermissions);

            return $source;
        }

        if ($userId !== null) {
            $source->setPermissions($this->fetchPermissions($userId));
            $source->setIsAdmin($this->isAdmin($userId));

            return $source;
        }

        
protected function setUp(): void
    {
        $this->appRepository = $this->getContainer()->get('app.repository');
        $this->actionButtonRepository = $this->getContainer()->get('app_action_button.repository');

        $this->appLifecycle = $this->getContainer()->get(AppLifecycle::class);

        $userRepository = $this->getContainer()->get('user.repository');
        $userId = $userRepository->searchIds(new Criteria(), Context::createDefaultContext())->firstId();
        $source = new AdminApiSource($userId);
        $source->setIsAdmin(true);
        $this->context = Context::createDefaultContext($source);

        $this->eventDispatcher = $this->getContainer()->get('event_dispatcher');

        $cache = $this->getContainer()->get('cache.object');
        $item = $cache->getItem(ScriptLoader::CACHE_KEY);
        $cache->save(CacheCompressor::compress($item[]));

        $this->connection = $this->getContainer()->get(Connection::class);
    }

    
$voucherA = $this->ids->create('voucherA');

        $writtenEvent = $this->createPromotion($voucherA$voucherA$promotionRepository$salesChannelContext);
        $promotionEvent = $writtenEvent->getEventByEntityName(PromotionDefinition::ENTITY_NAME);

        static::assertNotNull($promotionEvent);
        static::assertNotEmpty($promotionEvent->getWriteResults()[0]);
        $promotionId = $promotionEvent->getWriteResults()[0]->getPayload()['id'];

        $userId = Uuid::randomHex();
        $origin = new AdminApiSource($userId);
        $origin->setIsAdmin(true);
        $context = Context::createDefaultContext($origin);

        $event = $this->createIndividualCode($promotionId, 'CODE-1', $promotionIndividualRepository$context);

        $result = $indexer->update($event);

        static::assertNull($result);
    }

    public function testPromotionIndexerUpdateReturnPromotionIndexingMessage(): void
    {
        

    }

    private function getAppContextSource(ScriptAppInformation $scriptAppInformation): AdminApiSource
    {
        if (\array_key_exists($scriptAppInformation->getAppId()$this->appSources)) {
            return $this->appSources[$scriptAppInformation->getAppId()];
        }

        $privileges = $this->fetchPrivileges($scriptAppInformation->getAppId());
        $source = new AdminApiSource(null, $scriptAppInformation->getIntegrationId());
        $source->setIsAdmin(false);
        $source->setPermissions($privileges);

        return $this->appSources[$scriptAppInformation->getAppId()] = $source;
    }

    private function fetchPrivileges(string $appId): array
    {
        $privileges = $this->connection->fetchOne(' SELECT `acl_role`.`privileges` AS `privileges` FROM `acl_role` INNER JOIN `app` ON `app`.`acl_role_id` = `acl_role`.`id` WHERE `app`.`id` = :appId ',
$permission = 'administer permissions';
    $role = Role::create([
      'id' => 'admin',
      'label' => 'Test',
      'is_admin' => TRUE,
      'permissions' => [$permission],
    ]);
    $role->save();
    $permissions = user_role_permissions([$role->id()]);
    $this->assertSame([$role->id() => []]$permissions);
    $role
      ->setIsAdmin(FALSE)
      ->grantPermission($permission)
      ->save();
    $permissions = user_role_permissions([$role->id()]);
    $this->assertSame([$role->id() => [$permission]]$permissions);
  }

}


  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    if ($form_state->hasValue('user_admin_role')) {
      $admin_roles = $this->roleStorage->getQuery()
        ->condition('is_admin', TRUE)
        ->execute();
      foreach ($admin_roles as $rid) {
        $this->roleStorage->load($rid)->setIsAdmin(FALSE)->save();
      }
      $new_admin_role = $form_state->getValue('user_admin_role');
      if ($new_admin_role) {
        $this->roleStorage->load($new_admin_role)->setIsAdmin(TRUE)->save();
      }
    }
  }

}
'category' => $criteria,
        ]);

        $resultWithPermissions = $this->searcher->search($queries$this->context);

        static::assertCount(2, $resultWithPermissions);

        static::assertNotEmpty($resultWithPermissions['category']);
        static::assertNotEmpty($resultWithPermissions['product']);

        $adminSource = new AdminApiSource($this->userId);
        $adminSource->setIsAdmin(false);
        $adminSource->setPermissions(['category:read']);

        $this->context->assign([
            'source' => $adminSource,
        ]);

        $resultWithoutPermissions = $this->searcher->search($queries$this->context);

        static::assertCount(1, $resultWithoutPermissions);
        static::assertNotEmpty($resultWithoutPermissions['category']);
        static::assertArrayNotHasKey('product', $resultWithoutPermissions);
    }
Home | Imprint | This part of the site doesn't use cookies.