Pwirth has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/368407 )

Change subject: Added BSTestPermissions.php
......................................................................

Added BSTestPermissions.php

MaintenanceScript to test permissions from the command line

Change-Id: I9dc441cd63c17d6094c53c270047c8dce846532a
---
A maintenance/BSTestPermissions.php
1 file changed, 81 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation 
refs/changes/07/368407/1

diff --git a/maintenance/BSTestPermissions.php 
b/maintenance/BSTestPermissions.php
new file mode 100644
index 0000000..0aac3ae
--- /dev/null
+++ b/maintenance/BSTestPermissions.php
@@ -0,0 +1,81 @@
+<?php
+
+require_once( 'BSMaintenance.php' );
+
+class BSTestPermissions extends BSMaintenance {
+
+       /**
+        *
+        * @var User
+        */
+       protected $testUser = null;
+
+       /**
+        *
+        * @var Title
+        */
+       protected $testTitle = null;
+
+       public function __construct() {
+               parent::__construct();
+
+               $this->addOption( 'username', 'The user to test with', true, 
true );
+               $this->addOption( 'title', 'The page title to test against', 
false );
+               $this->addOption( 'permission', 'The permission to test with', 
false, false );
+       }
+
+       public function execute() {
+               $this->makeUser();
+               $this->makeTitle();
+               $this->outputTestParameters();
+               $this->testPermission();
+       }
+
+       protected function makeUser() {
+               $userName = $this->getOption( 'username' );
+               $this->testUser = User::newFromName( $userName );
+               if( $this->testUser instanceof User === false ) {
+                       throw new Exception( "Could not create valid user from 
'$userName'" );
+               }
+       }
+
+       protected function makeTitle() {
+               $title = $this->getOption( 'title' );
+               $this->testTitle = Title::newFromText( $title );
+               if( $this->testTitle instanceof Title === false ) {
+                       $this->testTitle = Title::newMainPage();
+               }
+       }
+
+       protected function outputTestParameters() {
+               $this->output( 
"--------------------------------------------------------------------------------"
 );
+               $this->output( sprintf(
+                       "User: %s (ID:%d) | Title: %s (ID:%d) | Permission: %s",
+                       $this->testUser->getName(),
+                       $this->testUser->getId(),
+                       $this->testTitle->getPrefixedDBkey(),
+                       $this->testTitle->getArticleId(),
+                       $title = $this->getOption( 'permission' )
+
+               ) );
+       }
+
+       protected function testPermission() {
+               RequestContext::getMain()->setUser( $this->testUser );
+               $this->output( 
"--------------------------------------------------------------------------------"
 );
+               $permission = $this->getOption( 'permission' );
+               $result = FormatJson::encode(
+                       $this->testTitle->userCan( $permission, $this->testUser 
)
+               );
+
+               $this->output( "Result: $result" );
+       }
+
+}
+
+$maintClass = 'BSTestPermissions';
+if (defined('RUN_MAINTENANCE_IF_MAIN')) {
+       require_once( RUN_MAINTENANCE_IF_MAIN );
+} else {
+       require_once( DO_MAINTENANCE ); # Make this work on versions before 1.17
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/368407
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9dc441cd63c17d6094c53c270047c8dce846532a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: REL1_27
Gerrit-Owner: Pwirth <[email protected]>
Gerrit-Reviewer: Robert Vogel <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to