mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added Translatable->getAllowedLocalesForMember()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88125 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
703d602450
commit
2506816ad6
@ -372,6 +372,27 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all locales that a member can access
|
||||
* as defined by {@link $allowed_locales}
|
||||
* and {@link canTranslate()}.
|
||||
* If {@link $allowed_locales} is not set and
|
||||
* the user has the `TRANSLATE_ALL` permission,
|
||||
* the method will return all available locales in the system.
|
||||
*
|
||||
* @param Member $member
|
||||
* @return array Map of locales
|
||||
*/
|
||||
function getAllowedLocalesForMember($member) {
|
||||
$locales = self::get_allowed_locales();
|
||||
if(!$locales) $locales = i18n::get_common_locales();
|
||||
if($locales) foreach($locales as $k => $locale) {
|
||||
if(!$this->canTranslate($member, $locale)) unset($locales[$k]);
|
||||
}
|
||||
|
||||
return $locales;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of languages in which a given element has been translated.
|
||||
*
|
||||
|
@ -789,6 +789,28 @@ class TranslatableTest extends FunctionalTest {
|
||||
Translatable::set_allowed_locales($origAllowedLocales);
|
||||
}
|
||||
|
||||
function testLocalesForMember() {
|
||||
$origAllowedLocales = Translatable::get_allowed_locales();
|
||||
Translatable::set_allowed_locales(array('de_DE', 'ja_JP'));
|
||||
|
||||
$cmseditor = $this->objFromFixture('Member', 'cmseditor');
|
||||
$translator = $this->objFromFixture('Member', 'germantranslator');
|
||||
|
||||
$this->assertEquals(
|
||||
array('de_DE', 'ja_JP'),
|
||||
singleton('SiteTree')->getAllowedLocalesForMember($cmseditor),
|
||||
'Members with TRANSLATE_ALL permission can edit all locales'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array('de_DE'),
|
||||
singleton('SiteTree')->getAllowedLocalesForMember($translator),
|
||||
'Members with TRANSLATE_<locale> permission cant edit all locales'
|
||||
);
|
||||
|
||||
Translatable::set_allowed_locales($origAllowedLocales);
|
||||
}
|
||||
|
||||
function testSavePageInCMS() {
|
||||
$adminUser = $this->objFromFixture('Member', 'admin');
|
||||
$enPage = $this->objFromFixture('Page', 'testpage_en');
|
||||
|
Loading…
Reference in New Issue
Block a user