Skip to content

Commit

Permalink
BUGFIX If a Group doesn't have any specific TRANSLATE_<locale> edit r…
Browse files Browse the repository at this point in the history
…ights, 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
  • Loading branch information
chillu committed Apr 13, 2010
1 parent 6fb2a2a commit 48bd1ff
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/model/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,22 @@ function requireDefaultRecords() {
// @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_<locale> 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
Expand Down

0 comments on commit 48bd1ff

Please sign in to comment.