Skip to content
This repository
Browse code

API CHANGE: Add Security::ignore_disallowed_actions() to allow site f…

…eatures to be disabled when permissions have failed, rather than redirecting to the log-in form. (Trac #7097)
  • Loading branch information...
commit 3f0136749b10781d93ea8f13e478a37089e93b70 1 parent 09e821e
Sam Minnée authored June 15, 2012
16  security/Security.php
@@ -158,6 +158,8 @@ static function set_default_message_set($messageSet) {
158 158
 	 * to log in.
159 159
 	 */
160 160
 	static function permissionFailure($controller = null, $messageSet = null) {
  161
+		self::set_ignore_disallowed_actions(true);
  162
+		
161 163
 		if(!$controller) $controller = Controller::curr();
162 164
 		
163 165
 		if(Director::is_ajax()) {
@@ -864,4 +866,18 @@ public static function default_login_dest() {
864 866
 		return self::$default_login_dest;
865 867
 	}
866 868
 
  869
+	protected static $ignore_disallowed_actions = false;
  870
+	
  871
+	/**
  872
+	 * Set to true to ignore access to disallowed actions, rather than returning permission failure
  873
+	 * Note that this is just a flag that other code needs to check with Security::ignore_disallowed_actions()
  874
+	 * @param $flag True or false
  875
+	 */
  876
+	public static function set_ignore_disallowed_actions($flag) {
  877
+		self::$ignore_disallowed_actions = $flag;
  878
+	}
  879
+	public static function ignore_disallowed_actions() {
  880
+		return self::$ignore_disallowed_actions;
  881
+	}
  882
+
867 883
 }
4  view/SSViewer.php
@@ -612,7 +612,9 @@ public function __construct($templateList) {
612 612
 			if(Director::isDev() || Director::is_cli() || Permission::check('ADMIN')) {
613 613
 				self::flush_template_cache();
614 614
 			} else {
615  
-				return Security::permissionFailure(null, 'Please log in as an administrator to flush the template cache.');
  615
+				if(!Security::ignore_disallowed_actions()) {
  616
+					return Security::permissionFailure(null, 'Please log in as an administrator to flush the template cache.');
  617
+				}
616 618
 			}
617 619
 		}
618 620
 		

0 notes on commit 3f01367

Please sign in to comment.
Something went wrong with that request. Please try again.