Tweichart has submitted this change and it was merged. Change subject: ResponsibleEditors: Fixed missing permissions in ajax context ......................................................................
ResponsibleEditors: Fixed missing permissions in ajax context Added hook handler for overwrite FRCRevisionReview RevisionAjaxReviewBeforeParams to apply possible temporary permissions in AjaxReview context Also used this method to the StateBarBeforeBodyViewAdd handler PatchSet 2: * Changed name of new method * Made new method public * Added some docs Change-Id: I2e95faff739c4544d0b3108cbb3d6b5c8695eb4f (cherry picked from commit 399e53f5e153d52a8fda53bf1d89d8d70c069267) --- M ResponsibleEditors/ResponsibleEditors.class.php 1 file changed, 87 insertions(+), 14 deletions(-) Approvals: Tweichart: Verified; Looks good to me, approved Pwirth: Checked; Looks good to me, but someone else must approve diff --git a/ResponsibleEditors/ResponsibleEditors.class.php b/ResponsibleEditors/ResponsibleEditors.class.php index 9975ee0..1d04230 100644 --- a/ResponsibleEditors/ResponsibleEditors.class.php +++ b/ResponsibleEditors/ResponsibleEditors.class.php @@ -88,7 +88,8 @@ $this->setHook( 'BSStateBarAddSortTopVars', 'onStatebarAddSortTopVars' ); $this->setHook( 'BSStateBarAddSortBodyVars', 'onStatebarAddSortBodyVars' ); $this->setHook( 'BSStateBarBeforeTopViewAdd', 'onStateBarBeforeTopViewAdd' ); - $this->setHook( 'BSStateBarBeforeBodyViewAdd', 'onStateBarBeforeBodyViewAdd' ); + $this->setHook( 'BSStateBarBeforeBodyViewAdd', 'onStateBarBeforeBodyViewAdd', true ); + $this->setHook( 'RevisionAjaxReviewBeforeParams' ); $this->setHook( 'BSPageAccessAddAdditionalAccessGroups', 'onPageAccessAddAdditionalAccessGroups' ); $this->setHook( 'BSDashboardsUserDashboardPortalConfig' ); $this->setHook( 'BSDashboardsUserDashboardPortalPortlets' ); @@ -185,6 +186,82 @@ } /** + * Add the given User to a temporary group if he is a responsible editor + * for the given Title. This group will have special permissions for the + * Title's namespace. The group assignment exists only during the current + * request. This method needs to be called before a permission check is + * performed on the Title. + * @param Title $oTitle + * @param User $oUser + * @return boolean + */ + public function applyTempPermissionsForRespEditor( Title $oTitle, User $oUser ) { + $iArticleID = $oTitle->getArticleID(); + $aResponsibleEditorsIDs = $this->getResponsibleEditorIdsByArticleId( $iArticleID ); + + if ( !in_array( $oUser->getId(), $aResponsibleEditorsIDs ) ){ + return false; + } + + $aAvailablePermissions = BsConfig::get( 'MW::ResponsibleEditors::AutoPermissions' ); + if ( empty( $aAvailablePermissions ) ) { + return false; + } + + BsGroupHelper::addTemporaryGroupToUser( + $oUser, + 'tmprespeditors', + $aAvailablePermissions, + $oTitle + ); + + return true; + } + + /** + * Hook handler for FlaggedRevs RevisionReview overwrite. + * ATTENTION: This is a handler for a custom hook in FlaggedRevsConnector! + * It will be removed in next version! + * @param FRCRevisionReview $oRevisionReview + * @param Title $oTitle + * @param type $aArgs + * @return boolean + * @deprecated since version 1.22 + */ + public function onRevisionAjaxReviewBeforeParams( $oRevisionReview, &$oTitle, &$aArgs ) { + //MW BeforeInitialize hook is not present in ajax calls, so apply + //possible permissions for responsible editors in this context + if( is_null($oTitle) ) { + foreach( $aArgs as $sArg ) { + $set = explode( '|', $sArg, 2 ); + if( count( $set ) != 2 ) { + continue; + } + + list( $sKey, $vVal ) = $set; + if( $sKey != 'target' ) { + continue; + } + + $oTitle = Title::newFromURL( $vVal ); + break; + } + } + if( is_null($oTitle) || !$oTitle->exists() ) { + return true; + } + + $aActivatedNamespaces = BsConfig::get('MW::ResponsibleEditors::ActivatedNamespaces'); + if ( !in_array($oTitle->getNamespace(), $aActivatedNamespaces) ) { + return true; + } + + global $wgUser; + $this->applyTempPermissionsForRespEditor( $oTitle, $wgUser ); + return true; + } + + /** * Hook-Handler for MediaWiki hook BeforeInitialize * @global array $wgGroupPermissions * @global User $wgUser @@ -197,21 +274,12 @@ * @return boolean Always true */ public function onBeforeInitialize( &$oTitle, $article, &$output, &$oUser, $request, $mediaWiki ) { - if ( !$oTitle->exists() ) return true; + if( is_null($oTitle) || !$oTitle->exists() ) return true; $aActivatedNamespaces = BsConfig::get('MW::ResponsibleEditors::ActivatedNamespaces'); - if ( !is_array( $aActivatedNamespaces ) ) return true; if ( !in_array($oTitle->getNamespace(), $aActivatedNamespaces) ) return true; - $iArticleID = $oTitle->getArticleID(); - $aResponsibleEditorsIDs = $this->getResponsibleEditorIdsByArticleId( $iArticleID ); - - if ( !in_array( $oUser->getId(), $aResponsibleEditorsIDs ) ) return true; - - $aAvailablePermissions = BsConfig::get( 'MW::ResponsibleEditors::AutoPermissions' ); - if ( empty( $aAvailablePermissions ) ) return true; - - BsGroupHelper::addTemporaryGroupToUser( $oUser, 'tmprespeditors', $aAvailablePermissions, $oTitle ); + $this->applyTempPermissionsForRespEditor( $oTitle, $oUser ); return true; } @@ -273,7 +341,7 @@ return $aPrefs; } - /** + /** * Hook Handler for BSDashboardsUserDashboardPortalPortlets * * @param array &$aPortlets reference to array portlets @@ -417,6 +485,11 @@ return true; if ($oTitle->exists() == false) return true; + + //MW BeforeInitialize hook is not present in ajax calls, so apply + //possible permissions for responsible editors in this context + $this->applyTempPermissionsForRespEditor( $oTitle, $oUser ); + $oResponsibleEditorsView = $this->makeStateBarBodyResponsibleEditorsEntries($oTitle->getArticleID()); if( !$oResponsibleEditorsView ) return true; @@ -1079,4 +1152,4 @@ public static function deleteResponsibleEditorsFromCache( $iArticleId ) { BsCacheHelper::invalidateCache( BsCacheHelper::getCacheKey( 'ResponsibleEditors', 'getResponsibleEditorsByArticleId', (int)$iArticleId ) ); } -} \ No newline at end of file +} -- To view, visit https://gerrit.wikimedia.org/r/189963 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2e95faff739c4544d0b3108cbb3d6b5c8695eb4f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions Gerrit-Branch: master Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz> Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz> Gerrit-Reviewer: Pigpen <reym...@hallowelt.biz> Gerrit-Reviewer: Pwirth <wi...@hallowelt.biz> Gerrit-Reviewer: Tweichart <weich...@hallowelt.biz> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits