Skip to content

Commit

Permalink
Merge branch 'develop-v4' of https://github.com/nystudio107/craft-seo…
Browse files Browse the repository at this point in the history
…matic into develop-v4
  • Loading branch information
khalwat committed Feb 23, 2024
2 parents 4f4b931 + 0817dee commit c46b1e0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Fixed
* Fixed an issue where a trailing slash would be added to a paginated URL that uses URL parameters and `addTrailingSlashesToUrls` was `true` in the General config ([#1401](https://github.com/nystudio107/craft-seomatic/issues/1401))
* Fixed an issue where clicking the SEOmatic CP nav item would result in a 403 exception if the current user didn't have permission to view the SEOmatic dashboard ([#1410](https://github.com/nystudio107/craft-seomatic/issues/1410))

## 4.0.42 - 2024.02.20
### Fixed
Expand Down
10 changes: 9 additions & 1 deletion src/Seomatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ public function getCpNavItem(): ?array
'url' => 'seomatic/plugin',
];
}
// SEOmatic doesn't really have an index page, so if the user can't access any sub nav items, we probably shouldn't show the main sub nav item either
if (empty($subNavs)) {
return null;
}
// A single sub nav item is redundant
if (count($subNavs) === 1) {
$subNavs = [];
}

return array_merge($navItem, [
'subnav' => $subNavs,
Expand Down Expand Up @@ -878,7 +886,7 @@ protected function customAdminCpRoutes(): array
{
return [
'seomatic' =>
'seomatic/settings/dashboard',
'',
'seomatic/dashboard' =>
'seomatic/settings/dashboard',
'seomatic/dashboard/<siteHandle:{handle}>' =>
Expand Down
21 changes: 21 additions & 0 deletions src/templates/index.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{# @var currentUser \craft\elements\User #}

{% requirePermission 'accessPlugin-seomatic' %}

{# Redirect the user to the first sub page they can access #}
{% if currentUser.can('seomatic:dashboard') %}
{% redirect cpUrl('seomatic/dashboard') %}
{% elseif currentUser.can('seomatic:global-meta') %}
{% redirect cpUrl('seomatic/global/general') %}
{% elseif currentUser.can('seomatic:content-meta') %}
{% redirect cpUrl('seomatic/content') %}
{% elseif currentUser.can('seomatic:site-settings') %}
{% redirect cpUrl('seomatic/site/identity') %}
{% elseif currentUser.can('seomatic:tracking-scripts') %}
{% redirect cpUrl('seomatic/tracking/gtag') %}
{% elseif currentUser.can('seomatic:plugin-settings') %}
{% redirect cpUrl('seomatic/plugin') %}
{% else %}
{# ...or throw a 403 if they can't access anything at all #}
{% exit 403 %}
{% endif %}

0 comments on commit c46b1e0

Please sign in to comment.