function activateState($state) { // We always just set the $_GET variable rather than store in Session - this always works, has highest priority // in Subsite::currentSubsiteID() and doesn't persist unlike Subsite::changeSubsite $_GET['SubsiteID'] = $state; Permission::flush_permission_cache(); }
function testFrontendBlogPostRequiresPermission() { // get valid SecurityID (from comments form, would usually be copy/pasted) $blogEntry = $this->objFromFixture('BlogEntry', 'entry1'); $response = $this->get($blogEntry->RelativeLink()); $securityID = Session::get('SecurityID'); // without login $data = array('Title' => 'Disallowed', 'Author' => 'Disallowed', 'BlogPost' => 'Disallowed', 'action_postblog' => 'Post blog entry', 'SecurityID' => $securityID); $response = $this->post('blog/BlogEntryForm', $data); $this->assertFalse(DataObject::get_one('BlogEntry', sprintf("\"Title\" = 'Disallowed'"))); // with login $blogEditor = $this->objFromFixture('Member', 'blog_editor'); $this->session()->inst_set('loggedInAs', $blogEditor->ID); Permission::flush_permission_cache(); $data = array('Title' => 'Allowed', 'Author' => 'Allowed', 'BlogPost' => 'Allowed', 'action_postblog' => 'Post blog entry', 'SecurityID' => $securityID); $response = $this->post('blog/BlogEntryForm', $data); $this->assertType('BlogEntry', DataObject::get_one('BlogEntry', sprintf("\"Title\" = 'Allowed'"))); }
public function onBeforeWrite() { parent::onBeforeWrite(); // Just in case we've altered someone's permissions Permission::flush_permission_cache(); }
public function onAfterWrite() { parent::onAfterWrite(); Permission::flush_permission_cache(); if ($this->isChanged('Password')) { MemberPassword::log($this); } }
public function tearDown() { Security::setDefaultAdmin($this->defaultUsername, $this->defaultPassword); Permission::flush_permission_cache(); parent::tearDown(); }
/** * Switch to another subsite. * * @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself */ static function changeSubsite($subsite) { if (is_object($subsite)) { $subsiteID = $subsite->ID; } else { $subsiteID = $subsite; } Session::set('SubsiteID', (int) $subsiteID); // Set locale if (is_object($subsite) && $subsite->Language != '') { if (isset(i18n::$likely_subtags[$subsite->Language])) { i18n::set_locale(i18n::$likely_subtags[$subsite->Language]); } } // Only bother flushing caches if we've actually changed if ($subsiteID != self::currentSubsiteID()) { Permission::flush_permission_cache(); } }
/** * Switch to another subsite through storing the subsite identifier in the current PHP session. * Only takes effect when {@link Subsite::$use_session_subsiteid} is set to TRUE. * * @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself */ public static function changeSubsite($subsite) { // Session subsite change only meaningful if the session is active. // Otherwise we risk setting it to wrong value, e.g. if we rely on currentSubsiteID. if (!Subsite::$use_session_subsiteid) { return; } if (is_object($subsite)) { $subsiteID = $subsite->ID; } else { $subsiteID = $subsite; } Session::set('SubsiteID', (int) $subsiteID); // Set locale if (is_object($subsite) && $subsite->Language != '') { $locale = i18n::get_locale_from_lang($subsite->Language); if ($locale) { i18n::set_locale($locale); } } Permission::flush_permission_cache(); }