Skip to content

Commit

Permalink
UHF-8526: Use api authorization service, fixed readme to work with vault
Browse files Browse the repository at this point in the history
  • Loading branch information
tuutti committed Sep 14, 2023
1 parent e244175 commit f47ccbf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ Only main-navigation has syncing option. Other navigations are created in Etusiv
- run `drush upwd helfi-admin 123` to update admin password. it is used as api key in other instances.
- Setup any other instance with helfi_navigation module enabled.
- Add following line to local.settings.php. Otherwise syncing global navigation won't work
- `$config['helfi_navigation.api']['key'] = base64_encode('helfi-admin:123');`
```php
$config['helfi_api_base.api_accounts']['vault'][] = [
'id' => 'helfi_navigation',
'plugin' => 'authorization_token',
'data' => base64_decode('helfi-admin:123'),
];
```

### Steps after both instances are up and running.
1. Edit and save menu on any instance with helfi_navigation module enabled.
Expand Down
2 changes: 1 addition & 1 deletion helfi_navigation.module
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function helfi_navigation_menu_link_content_delete(MenuLinkContentInterface $ent
* Create menu update queue item.
*/
function _helfi_navigation_queue_item(string $menuName, string $langcode, string $action) : void {
if (!\Drupal::config('helfi_navigation.api')->get('key')) {
if (!\Drupal::service('helfi_navigation.api_authorization')->getAuthorization()) {
return;
}
$queue = Drupal::queue('helfi_navigation_menu_queue');
Expand Down
10 changes: 5 additions & 5 deletions src/Menu/MenuTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class MenuTreeBuilder {
* @param \Drupal\helfi_api_base\Link\InternalDomainResolver $domainResolver
* The internal domain resolver.
* @param \Drupal\Core\Menu\MenuLinkTreeInterface $menuTree
* The menu link tree builder service.
* The 'menu link tree builder' service.
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager
* The menu link manager.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
Expand Down Expand Up @@ -157,7 +157,7 @@ private function transform(array $menuItems, string $langcode, string $rootId =

$urlObject = $link->getUrlObject();

// Make sure url object retains the language information.
// Make sure the url object retains the language information.
if (!$urlObject->getOption('language')) {
$urlObject->setOptions(['language' => $link->language()]);
}
Expand Down Expand Up @@ -269,9 +269,9 @@ private function getEntity(MenuLinkInterface $link, string $langcode): ? MenuLin
* The element to check entity access for.
*/
private function evaluateEntityAccess(MenuLinkTreeElement $element) : void {
// Attempt to fetch the entity type and id from link's route parameters.
// The route parameters should be an array containing entity type => id
// like: ['node' => '1'].
// Attempt to fetch the entity type, and id from link's route parameters.
// The route parameters should be an array containing an entity type => id
// key pairs, like: ['node' => '1'].
$routeParameters = $element->link->getRouteParameters();
$entityType = key($routeParameters);

Expand Down

0 comments on commit f47ccbf

Please sign in to comment.