From 48bd1ffa240b80d63f76001d1d011d5fc29c85b6 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 13 Apr 2010 01:44:03 +0000 Subject: [PATCH] BUGFIX If a Group doesn't have any specific TRANSLATE_ edit rights, but has general CMS access (CMS_ACCESS_CMSMain, CMS_ACCESS_LeftAndMain, ADMIN), then assign TRANSLATE_ALL permissions as a default. Necessary to avoid locking out CMS editors from their default language (see #4940 and 4941) (from r97911) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102553 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Translatable.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/model/Translatable.php b/core/model/Translatable.php index 56d82acd8..156ef01c6 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -587,6 +587,22 @@ class Translatable extends DataObjectDecorator implements PermissionProvider { // @todo This relies on the Locale attribute being on the base data class, and not any subclasses if($this->owner->class != ClassInfo::baseDataClass($this->owner->class)) return false; + // Permissions: If a group doesn't have any specific TRANSLATE_ edit rights, + // but has CMS_ACCESS_CMSMain (general CMS access), then assign TRANSLATE_ALL permissions as a default. + // Auto-setting permissions based on these intransparent criteria is a bit hacky, + // but unavoidable until we can determine when a certain permission code was made available first + // (see http://open.silverstripe.org/ticket/4940) + $groups = Permission::get_groups_by_permission(array('CMS_ACCESS_CMSMain','CMS_ACCESS_LeftAndMain','ADMIN')); + if($groups) foreach($groups as $group) { + $codes = $group->Permissions()->column('Code'); + $hasTranslationCode = false; + foreach($codes as $code) { + if(preg_match('/^TRANSLATE_/', $code)) $hasTranslationCode = true; + } + // Only add the code if no more restrictive code exists + if(!$hasTranslationCode) Permission::grant($group->ID, 'TRANSLATE_ALL'); + } + // If the Translatable extension was added after the first records were already // created in the database, make sure to update the Locale property if // if wasn't set before