Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translated section names can cause data-loss in permissions form #7771

Closed
robbeman opened this issue Apr 7, 2021 · 1 comment
Closed

Translated section names can cause data-loss in permissions form #7771

robbeman opened this issue Apr 7, 2021 · 1 comment
Labels

Comments

@robbeman
Copy link
Contributor

robbeman commented Apr 7, 2021

Description

When translating section names in translations/[locale]/site.php and you (by chance or by choice) have two sections with the same name it can cause the permissions form to overwrite the first section with the second.

Steps to reproduce

  1. Create site.php translations file in your language
  2. Add two items with the same name like:
      'Jobs' => 'Jobs',
      'Jobs Index' => 'Jobs',
    image
  3. Edit permissions http://you-are-wonderful.local/admin/settings/users/groups/1
  4. Save permissions
  5. Check git differences
  6. See things go away

Cause

In my specific case this is happening here:

foreach ($sections as $section) {
$label = Craft::t('app', 'Section - {section}',
['section' => Craft::t('site', $section->name)]);
if ($section->type == Section::TYPE_SINGLE) {
$permissions[$label] = $this->_getSingleEntryPermissions($section);
} else {
$permissions[$label] = $this->_getEntryPermissions($section);
}
}

Fix?

        foreach ($sections as $section) {
            $label = Craft::t('app', 'Section - {section}',
                ['section' => Craft::t('site', $section->name)]);

            if ($section->type == Section::TYPE_SINGLE) {
-                $permissions[$label] = $this->_getSingleEntryPermissions($section);
+                $permissions[$section->handle] = $this->_getSingleEntryPermissions($section);
            } else {
-                $permissions[$label] = $this->_getEntryPermissions($section);
+                $permissions[$section->handle] = $this->_getEntryPermissions($section);
            }
        }

This fix may have unintended side-effects, I'm not very well acquainted with the source code, but at least it's a starting point.

Additional info

  • Craft version: 3.6.8
  • PHP version:
  • Database driver & version:
  • Plugins & versions:
@robbeman robbeman added the bug label Apr 7, 2021
@brandonkelly brandonkelly added bug and removed bug labels Apr 7, 2021
@brandonkelly brandonkelly added this to the 4.0 milestone Apr 7, 2021
brandonkelly added a commit that referenced this issue Apr 7, 2021
@brandonkelly
Copy link
Member

That’s a tricky one. Your proposed fix would certainly fix the underlying issue, but those array keys are the human-facing group headings, so the unintended side effect would be that the group headings would start showing the section handles rather than their titles, which isn’t desired.

The only good fix for this is to stop indexing the array by headings, and move the headings into a nested key. That’s a breaking change, though, so unfortunately can’t be done for 3.x. I’ve just made the change for Craft 4, though (d3d20ba). In the meantime, you’ll just have to avoid using identical section names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants