r107801 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107800‎ | r107801 | r107802 >
Date:06:59, 2 January 2012
Author:laner
Status:ok
Tags:openstack 
Comment:
* Fix collapsible headings, only make the project name catch the click, not the action links
* Add support for per-project puppet groups
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackNovaPuppetGroup.php (modified) (history)
  • /trunk/extensions/OpenStackManager/special/SpecialNovaAddress.php (modified) (history)
  • /trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php (modified) (history)
  • /trunk/extensions/OpenStackManager/special/SpecialNovaPuppetGroup.php (modified) (history)
  • /trunk/extensions/OpenStackManager/special/SpecialNovaSecurityGroup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php
@@ -303,11 +303,24 @@
304304 'default' => wfMsg( 'openstackmanager-createinstancepuppetwarning' ),
305305 );
306306 }
307 - $puppetGroups = OpenStackNovaPuppetGroup::getGroupList();
 307+ $project = $instanceInfo['project']['default'];
 308+ $projectGroups = OpenStackNovaPuppetGroup::getGroupList( $project );
 309+ $this->setPuppetInfoByGroups( $instanceInfo, $puppetinfo, $projectGroups );
 310+ $globalGroups = OpenStackNovaPuppetGroup::getGroupList();
 311+ $this->setPuppetInfoByGroups( $instanceInfo, $puppetinfo, $globalGroups );
 312+ }
 313+
 314+ function setPuppetInfoByGroups( &$instanceInfo, $puppetinfo, $puppetGroups ) {
308315 foreach ( $puppetGroups as $puppetGroup ) {
309316 $classes = array();
310317 $defaults = array();
311318 $puppetgroupname = $puppetGroup->getName();
 319+ $puppetgroupproject = $puppetGroup->getProject();
 320+ if ( $puppetgroupproject ) {
 321+ $section = 'instance/puppetinfo/project';
 322+ } else {
 323+ $section = 'instance/puppetinfo/global';
 324+ }
312325 foreach ( $puppetGroup->getClasses() as $class ) {
313326 $classname = $class["name"];
314327 $classes["$classname"] = $classname;
@@ -317,12 +330,12 @@
318331 }
319332 $instanceInfo["${puppetgroupname}"] = array(
320333 'type' => 'info',
321 - 'section' => "instance/puppetinfo",
 334+ 'section' => $section,
322335 'label' => Html::element( 'h3', array(), "$puppetgroupname:" ),
323336 );
324337 $instanceInfo["${puppetgroupname}-puppetclasses"] = array(
325338 'type' => 'multiselect',
326 - 'section' => "instance/puppetinfo",
 339+ 'section' => $section,
327340 'options' => $classes,
328341 'default' => $defaults,
329342 'name' => "${puppetgroupname}-puppetclasses",
@@ -335,7 +348,7 @@
336349 }
337350 $instanceInfo["${puppetgroupname}-${variablename}"] = array(
338351 'type' => 'text',
339 - 'section' => "instance/puppetinfo",
 352+ 'section' => $section,
340353 'label' => $variablename,
341354 'default' => $default,
342355 'name' => "${puppetgroupname}-${variablename}",
@@ -455,6 +468,7 @@
456469 */
457470 function listInstances() {
458471 $this->setHeaders();
 472+ $this->getOutput()->addModuleStyles( 'ext.openstack' );
459473 $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-instancelist' ) );
460474
461475 $userProjects = $this->userLDAP->getProjects();
@@ -503,7 +517,6 @@
504518 $instanceOut .= Html::element( 'td', array(), $instance->getAvailabilityZone() );
505519 $instanceOut .= Html::element( 'td', array(), $instance->getImageId() );
506520 $instanceOut .= Html::element( 'td', array(), $instance->getLaunchTime() );
507 -
508521 $actions = '';
509522 if ( $this->userLDAP->inRole( 'sysadmin', $project ) ) {
510523 $msg = wfMsgHtml( 'openstackmanager-delete' );
@@ -540,15 +553,20 @@
541554 }
542555 }
543556 foreach ( $userProjects as $project ) {
544 - $out .= Html::element( 'h2', array(), $project );
 557+ $action = '';
545558 if ( $this->userLDAP->inRole( 'sysadmin', $project ) ) {
546 - $out .= Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-createinstance' ), array(), array( 'action' => 'create', 'project' => $project ) );
 559+ $action = Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-createinstance' ), array(), array( 'action' => 'create', 'project' => $project ) );
 560+ $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$action]" );
547561 }
 562+ $projectName = Html::rawElement( 'span', array( 'class' => 'mw-customtoggle-' . $project, 'id' => 'novaproject' ), $project );
 563+ $out .= Html::rawElement( 'h2', array(), "$projectName $action" );
 564+ $projectOut = '';
548565 if ( isset( $projectArr["$project"] ) ) {
549 - $projectOut = $header;
 566+ $projectOut .= $header;
550567 $projectOut .= $projectArr["$project"];
551 - $out .= Html::rawElement( 'table', array( 'id' => 'novainstancelist', 'class' => 'wikitable sortable collapsible' ), $projectOut );
 568+ $projectOut = Html::rawElement( 'table', array( 'id' => 'novainstancelist', 'class' => 'wikitable sortable' ), $projectOut );
552569 }
 570+ $out .= Html::rawElement( 'div', array( 'class' => 'mw-collapsible', 'id' => 'mw-customcollapsible-' . $project ), $projectOut );
553571 }
554572
555573 $this->getOutput()->addHTML( $out );
@@ -676,24 +694,34 @@
677695
678696 $puppetinfo = array();
679697 if ( $wgOpenStackManagerPuppetOptions['enabled'] ) {
 698+ $puppetGroups = OpenStackNovaPuppetGroup::getGroupList( $formData['project'] );
 699+ $this->getPuppetInfoByGroup( $puppetinfo, $puppetGroups, $formData );
680700 $puppetGroups = OpenStackNovaPuppetGroup::getGroupList();
681 - foreach ( $puppetGroups as $puppetGroup ) {
682 - $puppetgroupname = $puppetGroup->getName();
683 - foreach ( $puppetGroup->getClasses() as $class ) {
684 - if ( in_array( $class["name"], $formData["$puppetgroupname-puppetclasses"] ) ) {
685 - $puppetinfo['classes'][] = $class["name"];
 701+ $this->getPuppetInfoByGroup( $puppetinfo, $puppetGroups, $formData );
 702+ }
 703+ return $puppetinfo;
 704+ }
 705+
 706+ function getPuppetInfoByGroup( &$puppetinfo, $puppetGroups, $formData ) {
 707+ foreach ( $puppetGroups as $puppetGroup ) {
 708+ $puppetgroupname = $puppetGroup->getName();
 709+ foreach ( $puppetGroup->getClasses() as $class ) {
 710+ if ( in_array( $class["name"], $formData["$puppetgroupname-puppetclasses"] ) ) {
 711+ $classname = $class["name"];
 712+ if ( !in_array( $classname, $puppetinfo['classes'] ) ) {
 713+ $puppetinfo['classes'][] = $classname;
686714 }
687715 }
688 - foreach ( $puppetGroup->getVars() as $variable ) {
689 - $variablename = $variable["name"];
690 - if ( isset ( $formData["$puppetgroupname-$variablename"] ) && trim( $formData["$puppetgroupname-$variablename"] ) ) {
691 - $puppetinfo['variables']["$variablename"] = $formData["$puppetgroupname-$variablename"];
692 - }
 716+ }
 717+ foreach ( $puppetGroup->getVars() as $variable ) {
 718+ $variablename = $variable["name"];
 719+ if ( isset ( $formData["$puppetgroupname-$variablename"] ) && trim( $formData["$puppetgroupname-$variablename"] ) ) {
 720+ $puppetinfo['variables']["$variablename"] = $formData["$puppetgroupname-$variablename"];
693721 }
694722 }
695723 }
696 - return $puppetinfo;
697724 }
 725+
698726 }
699727
700728 class SpecialNovaInstanceForm extends HTMLForm {
Index: trunk/extensions/OpenStackManager/special/SpecialNovaSecurityGroup.php
@@ -318,7 +318,8 @@
319319 array( 'action' => 'create', 'project' => $project ) );
320320 $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$action]" );
321321 }
322 - $out .= Html::rawElement( 'h2', array( 'class' => 'mw-customtoggle-' . $project, 'id' => 'novaproject' ), "$project $action" );
 322+ $projectName = Html::rawElement( 'span', array( 'class' => 'mw-customtoggle-' . $project, 'id' => 'novaproject' ), $project );
 323+ $out .= Html::rawElement( 'h2', array(), "$projectName $action" );
323324 if ( isset( $projectArr["$project"] ) ) {
324325 $projectOut = $groupheader;
325326 $projectOut .= $projectArr["$project"];
Index: trunk/extensions/OpenStackManager/special/SpecialNovaAddress.php
@@ -429,7 +429,8 @@
430430 foreach ( $userProjects as $project ) {
431431 $action = Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-allocateaddress' ), array(), array( 'action' => 'allocate', 'project' => $project ) );
432432 $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$action]" );
433 - $out .= Html::rawElement( 'h2', array( 'class' => 'mw-customtoggle-' . $project, 'id' => 'novaproject' ), "$project $action" );
 433+ $projectName = Html::rawElement( 'span', array( 'class' => 'mw-customtoggle-' . $project, 'id' => 'novaproject' ), $project );
 434+ $out .= Html::rawElement( 'h2', array(), "$projectName $action" );
434435 $projectOut = '';
435436 if ( isset( $projectArr["$project"] ) ) {
436437 $projectOut = $header;
Index: trunk/extensions/OpenStackManager/special/SpecialNovaPuppetGroup.php
@@ -6,12 +6,15 @@
77 }
88
99 function execute( $par ) {
10 -
11 -
1210 if ( ! $this->getUser()->isLoggedIn() ) {
1311 $this->notLoggedIn();
1412 return;
1513 }
 14+ $this->userLDAP = new OpenStackNovaUser();
 15+ if ( ! $this->userLDAP->exists() ) {
 16+ $this->noCredentials();
 17+ return;
 18+ }
1619 $action = $this->getRequest()->getVal( 'action' );
1720 if ( $action == "create" ) {
1821 $this->createPuppetGroup();
@@ -41,11 +44,21 @@
4245 */
4346 function createPuppetGroup() {
4447 $this->setHeaders();
45 - if ( !$this->userCanExecute( $this->getUser() ) ) {
46 - $this->displayRestrictionError();
47 - return false;
 48+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-createpuppetgroup' ) );
 49+ $project = $this->getRequest()->getText( 'project' );
 50+ if ( $project ) {
 51+ // Project specific
 52+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 53+ $this->notInRole( 'sysadmin' );
 54+ return false;
 55+ }
 56+ } else {
 57+ // Global project - requires manageproject
 58+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 59+ $this->displayRestrictionError();
 60+ return false;
 61+ }
4862 }
49 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-createpuppetgroup' ) );
5063
5164 $puppetGroupInfo = array();
5265 $puppetGroupInfo['puppetgroupname'] = array(
@@ -61,7 +74,11 @@
6275 'default' => '',
6376 'name' => 'puppetgroupposition',
6477 );
65 -
 78+ $puppetGroupInfo['project'] = array(
 79+ 'type' => 'hidden',
 80+ 'default' => $project,
 81+ 'name' => 'project',
 82+ );
6683 $puppetGroupInfo['action'] = array(
6784 'type' => 'hidden',
6885 'default' => 'create',
@@ -81,16 +98,29 @@
8299 * @return bool
83100 */
84101 function addPuppetClass() {
85 -
86 -
87102 $this->setHeaders();
88 - if ( !$this->userCanExecute( $this->getUser() ) ) {
89 - $this->displayRestrictionError();
 103+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-addpuppetclass' ) );
 104+ $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
 105+ $group = OpenStackNovaPuppetGroup::newFromId( $puppetGroupId );
 106+ if ( !$group ) {
 107+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
90108 return false;
91109 }
92 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-addpuppetclass' ) );
 110+ $project = $group->getProject();
 111+ if ( $project ) {
 112+ // Project specific
 113+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 114+ $this->notInRole( 'sysadmin' );
 115+ return false;
 116+ }
 117+ } else {
 118+ // Global project - requires manageproject
 119+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 120+ $this->displayRestrictionError();
 121+ return false;
 122+ }
 123+ }
93124
94 - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
95125 $puppetGroupInfo = array();
96126 $puppetGroupInfo['puppetclassname'] = array(
97127 'type' => 'text',
@@ -103,6 +133,11 @@
104134 'label-message' => 'openstackmanager-puppetclassposition',
105135 'name' => 'puppetclassposition',
106136 );
 137+ $puppetGroupInfo['project'] = array(
 138+ 'type' => 'hidden',
 139+ 'default' => $project,
 140+ 'name' => 'project',
 141+ );
107142 $puppetGroupInfo['action'] = array(
108143 'type' => 'hidden',
109144 'default' => 'addclass',
@@ -111,7 +146,7 @@
112147 $puppetGroupInfo['puppetgroupid'] = array(
113148 'type' => 'hidden',
114149 'default' => $puppetGroupId,
115 - 'name' => 'puppetGroupId',
 150+ 'name' => 'puppetgroupid',
116151 );
117152
118153 $puppetGroupForm = new SpecialNovaPuppetGroupForm( $puppetGroupInfo, 'openstackmanager-novapuppetgroup' );
@@ -127,18 +162,31 @@
128163 * @return bool
129164 */
130165 function deletePuppetClass() {
131 -
132 -
133166 $this->setHeaders();
134 - if ( !$this->userCanExecute( $this->getUser() ) ) {
135 - $this->displayRestrictionError();
 167+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-removepuppetclass' ) );
 168+ $puppetClassId = $this->getRequest()->getInt( 'puppetclassid' );
 169+ $group = OpenStackNovaPuppetGroup::newFromClassId( $puppetClassId );
 170+ if ( !$group ) {
 171+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
136172 return false;
137173 }
138 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-removepuppetclass' ) );
 174+ $project = $group->getProject();
 175+ if ( $project ) {
 176+ // Project specific
 177+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 178+ $this->notInRole( 'sysadmin' );
 179+ return false;
 180+ }
 181+ } else {
 182+ // Global project - requires manageproject
 183+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 184+ $this->displayRestrictionError();
 185+ return false;
 186+ }
 187+ }
139188 if ( ! $this->getRequest()->wasPosted() ) {
140189 $this->getOutput()->addWikiMsg( 'openstackmanager-removepuppetclassconfirm' );
141190 }
142 - $puppetClassId = $this->getRequest()->getInt( 'puppetclassid' );
143191 $puppetGroupInfo = array();
144192 $puppetGroupInfo['puppetclassid'] = array(
145193 'type' => 'hidden',
@@ -164,14 +212,28 @@
165213 * @return bool
166214 */
167215 function addPuppetVar() {
168 -
169 -
170216 $this->setHeaders();
171 - if ( !$this->userCanExecute( $this->getUser() ) ) {
172 - $this->displayRestrictionError();
 217+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-addpuppetvar' ) );
 218+ $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
 219+ $group = OpenStackNovaPuppetGroup::newFromId( $puppetGroupId );
 220+ if ( !$group ) {
 221+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
173222 return false;
174223 }
175 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-addpuppetvar' ) );
 224+ $project = $group->getProject();
 225+ if ( $project ) {
 226+ // Project specific
 227+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 228+ $this->notInRole( 'sysadmin' );
 229+ return false;
 230+ }
 231+ } else {
 232+ // Global project - requires manageproject
 233+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 234+ $this->displayRestrictionError();
 235+ return false;
 236+ }
 237+ }
176238
177239 $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
178240 $puppetGroupInfo = array();
@@ -186,16 +248,21 @@
187249 'label-message' => 'openstackmanager-puppetvarposition',
188250 'name' => 'puppetvarposition',
189251 );
 252+ $puppetGroupInfo['puppetgroupid'] = array(
 253+ 'type' => 'hidden',
 254+ 'default' => $puppetGroupId,
 255+ 'name' => 'puppetgroupid',
 256+ );
 257+ $puppetGroupInfo['project'] = array(
 258+ 'type' => 'hidden',
 259+ 'default' => $project,
 260+ 'name' => 'project',
 261+ );
190262 $puppetGroupInfo['action'] = array(
191263 'type' => 'hidden',
192264 'default' => 'addvar',
193265 'name' => 'action',
194266 );
195 - $puppetGroupInfo['puppetgroupid'] = array(
196 - 'type' => 'hidden',
197 - 'default' => $puppetGroupId,
198 - 'name' => 'puppetGroupId',
199 - );
200267
201268 $puppetGroupForm = new SpecialNovaPuppetGroupForm( $puppetGroupInfo, 'openstackmanager-novapuppetgroup' );
202269 $puppetGroupForm->setTitle( SpecialPage::getTitleFor( 'NovaPuppetGroup' ) );
@@ -210,14 +277,28 @@
211278 * @return bool
212279 */
213280 function deletePuppetVar() {
214 -
215 -
216281 $this->setHeaders();
217 - if ( !$this->userCanExecute( $this->getUser() ) ) {
218 - $this->displayRestrictionError();
 282+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-removepuppetvar' ) );
 283+ $puppetVarId = $this->getRequest()->getText( 'puppetvarid' );
 284+ $group = OpenStackNovaPuppetGroup::newFromVarId( $puppetVarId );
 285+ if ( !$group ) {
 286+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
219287 return false;
220288 }
221 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-removepuppetvar' ) );
 289+ $project = $group->getProject();
 290+ if ( $project ) {
 291+ // Project specific
 292+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 293+ $this->notInRole( 'sysadmin' );
 294+ return false;
 295+ }
 296+ } else {
 297+ // Global project - requires manageproject
 298+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 299+ $this->displayRestrictionError();
 300+ return false;
 301+ }
 302+ }
222303
223304 $puppetVarId = $this->getRequest()->getText( 'puppetvarid' );
224305 if ( ! $this->getRequest()->wasPosted() ) {
@@ -248,16 +329,29 @@
249330 * @return bool
250331 */
251332 function deletePuppetGroup() {
252 -
253 -
254333 $this->setHeaders();
255 - if ( !$this->userCanExecute( $this->getUser() ) ) {
256 - $this->displayRestrictionError();
 334+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-deletepuppetgroup' ) );
 335+ $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
 336+ $group = OpenStackNovaPuppetGroup::newFromId( $puppetGroupId );
 337+ if ( !$group ) {
 338+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
257339 return false;
258340 }
259 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-deletepuppetgroup' ) );
 341+ $project = $group->getProject();
 342+ if ( $project ) {
 343+ // Project specific
 344+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 345+ $this->notInRole( 'sysadmin' );
 346+ return false;
 347+ }
 348+ } else {
 349+ // Global project - requires manageproject
 350+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 351+ $this->displayRestrictionError();
 352+ return false;
 353+ }
 354+ }
260355
261 - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
262356 if ( ! $this->getRequest()->wasPosted() ) {
263357 $this->getOutput()->addWikiMsg( 'openstackmanager-removepuppetgroupconfirm' );
264358 }
@@ -285,17 +379,44 @@
286380 * @return bool
287381 */
288382 function modifyPuppetClass() {
289 -
290 -
291383 $this->setHeaders();
292 - if ( !$this->userCanExecute( $this->getUser() ) ) {
293 - $this->displayRestrictionError();
 384+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-modifypuppetclass' ) );
 385+ $puppetClassId = $this->getRequest()->getInt( 'puppetclassid' );
 386+ $group = OpenStackNovaPuppetGroup::newFromClassId( $puppetClassId );
 387+ $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
 388+ // Check to ensure a user is a sysadmin in both the from and to
 389+ // groups.
 390+ if ( $puppetGroupId != $group->getId() ) {
 391+ $newgroup = OpenStackNovaPuppetGroup::newFromId( $puppetGroupId );
 392+ if ( !$newgroup ) {
 393+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
 394+ return false;
 395+ }
 396+ $project = $newgroup->getProject();
 397+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 398+ $this->notInRole( 'sysadmin' );
 399+ return false;
 400+ }
 401+ }
 402+ if ( !$group ) {
 403+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
294404 return false;
295405 }
296 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-modifypuppetclass' ) );
 406+ $project = $group->getProject();
 407+ if ( $project ) {
 408+ // Project specific
 409+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 410+ $this->notInRole( 'sysadmin' );
 411+ return false;
 412+ }
 413+ } else {
 414+ // Global project - requires manageproject
 415+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 416+ $this->displayRestrictionError();
 417+ return false;
 418+ }
 419+ }
297420
298 - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
299 - $puppetClassId = $this->getRequest()->getInt( 'puppetclassid' );
300421 $puppetClassPosition = $this->getRequest()->getInt( 'puppetclassposition' );
301422 $puppetGroupInfo = array();
302423 $puppetGroupInfo['puppetclassid'] = array(
@@ -341,17 +462,45 @@
342463 * @return bool
343464 */
344465 function modifyPuppetVar() {
345 -
346 -
347466 $this->setHeaders();
348 - if ( !$this->userCanExecute( $this->getUser() ) ) {
349 - $this->displayRestrictionError();
 467+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-modifypuppetvar' ) );
 468+ $puppetVarId = $this->getRequest()->getInt( 'puppetvarid' );
 469+ $group = OpenStackNovaPuppetGroup::newFromVarId( $puppetVarId );
 470+ $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
 471+ // Check to ensure a user is a sysadmin in both the from and to
 472+ // groups.
 473+ if ( $puppetGroupId != $group->getId() ) {
 474+ $newgroup = OpenStackNovaPuppetGroup::newFromId( $puppetGroupId );
 475+ if ( !$newgroup ) {
 476+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
 477+ return false;
 478+ }
 479+ $project = $newgroup->getProject();
 480+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 481+ $this->notInRole( 'sysadmin' );
 482+ return false;
 483+ }
 484+ }
 485+ if ( !$group ) {
 486+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
350487 return false;
351488 }
352 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-modifypuppetvar' ) );
 489+ $project = $group->getProject();
353490
354 - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
355 - $puppetVarId = $this->getRequest()->getInt( 'puppetvarid' );
 491+ if ( $project ) {
 492+ // Project specific
 493+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 494+ $this->notInRole( 'sysadmin' );
 495+ return false;
 496+ }
 497+ } else {
 498+ // Global project - requires manageproject
 499+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 500+ $this->displayRestrictionError();
 501+ return false;
 502+ }
 503+ }
 504+
356505 $puppetVarPosition = $this->getRequest()->getInt( 'puppetvarposition' );
357506 $puppetGroupInfo = array();
358507 $puppetGroupInfo['puppetvarid'] = array(
@@ -398,13 +547,28 @@
399548 */
400549 function modifyPuppetGroup() {
401550 $this->setHeaders();
402 - if ( !$this->userCanExecute( $this->getUser() ) ) {
403 - $this->displayRestrictionError();
 551+ $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-modifypuppetgroup' ) );
 552+ $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
 553+ $group = OpenStackNovaPuppetGroup::newFromId( $puppetGroupId );
 554+ if ( !$group ) {
 555+ $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistentresource' );
404556 return false;
405557 }
406 - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-modifypuppetgroup' ) );
 558+ $project = $group->getProject();
 559+ if ( $project ) {
 560+ // Project specific
 561+ if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
 562+ $this->notInRole( 'sysadmin' );
 563+ return false;
 564+ }
 565+ } else {
 566+ // Global project - requires manageproject
 567+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 568+ $this->displayRestrictionError();
 569+ return false;
 570+ }
 571+ }
407572
408 - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' );
409573 $puppetGroupPosition = $this->getRequest()->getInt( 'puppetgroupposition' );
410574 $puppetGroupInfo = array();
411575 $puppetGroupInfo['puppetgroupid'] = array(
@@ -442,47 +606,96 @@
443607 $this->getOutput()->addModuleStyles( 'ext.openstack' );
444608
445609 $out = '';
 610+ $projects = $this->userLDAP->getProjects();
 611+ foreach ( $projects as $project ) {
 612+ if ( !$this->userLDAP->inRole( 'sysadmin', $project ) ) {
 613+ continue;
 614+ }
 615+ $action = Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-createpuppetgroup' ), array(), array( 'action' => 'create', 'project' => $project ) );
 616+ $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$action]" );
 617+ $projectName = Html::rawElement( 'span', array( 'class' => 'mw-customtoggle-' . $project, 'id' => 'novaproject' ), $project );
 618+ $out .= Html::rawElement( 'h2', array(), "$projectName $action" );
 619+ $groupsOut = $this->getPuppetGroupOutput( OpenStackNovaPuppetGroup::getGroupList( $project ) );
 620+ $out .= Html::rawElement( 'div', array( 'class' => 'mw-collapsible', 'id' => 'mw-customcollapsible-' . $project ), $groupsOut );
 621+ }
 622+ $action = '';
 623+ $showlinks = $this->userCanExecute( $this->getUser() );
 624+ if ( $showlinks ) {
446625
447 - $out .= Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-createpuppetgroup' ), array(), array( 'action' => 'create' ) );
448 - $puppetGroups = OpenStackNovaPuppetGroup::getGroupList();
 626+ $action = Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-createpuppetgroup' ), array(), array( 'action' => 'create' ) );
 627+ $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$action]" );
 628+ }
 629+ $allProjectsMsg = Html::rawElement( 'span', array( 'class' => 'mw-customtoggle-allprojects', 'id' => 'novaproject' ), wfMsgHtml( 'openstackmanager-puppetallprojects' ) );
 630+ $out .= Html::rawElement( 'h2', array(), "$allProjectsMsg $action" );
 631+ $groupsOut = $this->getPuppetGroupOutput( OpenStackNovaPuppetGroup::getGroupList(), $showlinks );
 632+ $out .= Html::rawElement( 'div', array( 'class' => 'mw-collapsible', 'id' => 'mw-customcollapsible-allprojects' ), $groupsOut );
 633+ $this->getOutput()->addHTML( $out );
 634+ }
 635+
 636+ function getPuppetGroupOutput( $puppetGroups, $showlinks=true ) {
 637+ $out = '';
449638 foreach ( $puppetGroups as $puppetGroup ) {
 639+ $puppetGroupProject = $puppetGroup->getProject();
 640+ //$puppetGroupProject can be null
 641+ if ( !$puppetGroupProject ) {
 642+ $puppetGroupProject = '';
 643+ }
450644 $puppetGroupId = $puppetGroup->getId();
451645 $puppetGroupPosition = $puppetGroup->getPosition();
452646 $puppetGroupName = $puppetGroup->getName();
453647 $puppetGroupName = "[$puppetGroupPosition] " . htmlentities( $puppetGroupName );
454648 $specialPuppetGroupTitle = Title::newFromText( 'Special:NovaPuppetGroup' );
455 - $modify = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-modify' ), array(), array( 'action' => 'modify', 'puppetgroupid' => $puppetGroupId, 'puppetgroupposition' => $puppetGroupPosition, 'returnto' => 'Special:NovaPuppetGroup' ) );
456 - $delete = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-delete' ), array(), array( 'action' => 'delete', 'puppetgroupid' => $puppetGroupId, 'returnto' => 'Special:NovaPuppetGroup' ) );
457 - $out .= Html::rawElement( 'h2', array(), "$puppetGroupName ($modify, $delete)" );
458 - $out .= Html::element( 'h3', array(), wfMsg( 'openstackmanager-puppetclasses' ) );
459 - $out .= Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-addpuppetclass' ), array(), array( 'action' => 'addclass', 'puppetgroupid' => $puppetGroupId, 'returnto' => 'Special:NovaPuppetGroup' ) );
 649+ if ( $showlinks ) {
 650+ $modify = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-modify' ), array(), array( 'action' => 'modify', 'puppetgroupid' => $puppetGroupId, 'puppetgroupposition' => $puppetGroupPosition, 'returnto' => 'Special:NovaPuppetGroup' ) );
 651+ $delete = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-delete' ), array(), array( 'action' => 'delete', 'puppetgroupid' => $puppetGroupId, 'returnto' => 'Special:NovaPuppetGroup' ) );
 652+ $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$modify, $delete]" );
 653+ $out .= Html::rawElement( 'h3', array(), "$puppetGroupName $action" );
 654+ }
 655+ $action = '';
 656+ if ( $showlinks ) {
 657+ $action = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-addpuppetclass' ), array(), array( 'action' => 'addclass', 'puppetgroupid' => $puppetGroupId, 'project' => $puppetGroupProject, 'returnto' => 'Special:NovaPuppetGroup' ) );
 658+ $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$action]" );
 659+ }
 660+ $classesMsg = wfMsgHtml( 'openstackmanager-puppetclasses' );
 661+ $out .= Html::rawElement( 'h4', array(), "$classesMsg $action" );
460662 $puppetGroupClasses = $puppetGroup->getClasses();
461663 $puppetGroupVars = $puppetGroup->getVars();
462664 if ( $puppetGroupClasses ) {
463665 $classesOut = '';
464666 foreach ( $puppetGroupClasses as $puppetGroupClass ) {
465 - $modify = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-modify' ), array(), array( 'action' => 'modifyclass', 'puppetclassid' => $puppetGroupClass["id"], 'puppetclassposition' => $puppetGroupClass["position"], 'puppetgroupid' => $puppetGroupId, 'returnto' => 'Special:NovaPuppetGroup' ) );
466 - $delete = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-delete' ), array(), array( 'action' => 'deleteclass', 'puppetclassid' => $puppetGroupClass["id"], 'returnto' => 'Special:NovaPuppetGroup' ) );
467667 $classname = '[' . $puppetGroupClass["position"] . '] ' . htmlentities( $puppetGroupClass["name"] );
468 - $classesOut .= Html::rawElement( 'li', array(), "$classname ($modify, $delete)" );
 668+ if ( $showlinks ) {
 669+ $modify = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-modify' ), array(), array( 'action' => 'modifyclass', 'puppetclassid' => $puppetGroupClass["id"], 'puppetclassposition' => $puppetGroupClass["position"], 'puppetgroupid' => $puppetGroupId, 'returnto' => 'Special:NovaPuppetGroup' ) );
 670+ $delete = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-delete' ), array(), array( 'action' => 'deleteclass', 'puppetclassid' => $puppetGroupClass["id"], 'returnto' => 'Special:NovaPuppetGroup' ) );
 671+ $classname .= Html::rawElement( 'span', array( 'id' => 'novaaction' ), " [$modify, $delete]" );
 672+ }
 673+
 674+ $classesOut .= Html::rawElement( 'li', array(), $classname );
469675 }
470676 $out .= Html::rawElement( 'ul', array(), $classesOut );
471677 }
472 - $out .= Html::element( 'h3', array(), wfMsg( 'openstackmanager-puppetvars' ) );
473 - $out .= Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-addpuppetvar' ), array(), array( 'action' => 'addvar', 'puppetgroupid' => $puppetGroupId, 'returnto' => 'Special:NovaPuppetGroup' ) );
 678+ $action = '';
 679+ if ( $showlinks ) {
 680+ $action = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-addpuppetvar' ), array(), array( 'action' => 'addvar', 'puppetgroupid' => $puppetGroupId, 'project' => $puppetGroupProject, 'returnto' => 'Special:NovaPuppetGroup' ) );
 681+ $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$action]" );
 682+ }
 683+ $varsMsg = wfMsgHtml( 'openstackmanager-puppetvars' );
 684+ $out .= Html::rawElement( 'h4', array(), "$varsMsg $action" );
474685 if ( $puppetGroupVars ) {
475686 $varsOut = '';
476687 foreach ( $puppetGroupVars as $puppetGroupVar ) {
477 - $modify = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-modify' ), array(), array( 'action' => 'modifyvar', 'puppetvarid' => $puppetGroupVar["id"], 'puppetvarposition' => $puppetGroupVar["position"], 'puppetgroupid' => $puppetGroupId, 'returnto' => 'Special:NovaPuppetGroup' ) );
478 - $delete = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-delete' ), array(), array( 'action' => 'deletevar', 'puppetvarid' => $puppetGroupVar["id"], 'returnto' => 'Special:NovaPuppetGroup' ) );
479688 $varname = '[' . $puppetGroupVar["position"] . '] ' . htmlentities( $puppetGroupVar["name"] );
480 - $varsOut .= Html::rawElement( 'li', array(), "$varname ($modify, $delete)" );
 689+ if ( $showlinks ) {
 690+ $modify = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-modify' ), array(), array( 'action' => 'modifyvar', 'puppetvarid' => $puppetGroupVar["id"], 'puppetvarposition' => $puppetGroupVar["position"], 'puppetgroupid' => $puppetGroupId, 'returnto' => 'Special:NovaPuppetGroup' ) );
 691+ $delete = Linker::link( $specialPuppetGroupTitle, wfMsgHtml( 'openstackmanager-delete' ), array(), array( 'action' => 'deletevar', 'puppetvarid' => $puppetGroupVar["id"], 'returnto' => 'Special:NovaPuppetGroup' ) );
 692+ $varname .= Html::rawElement( 'span', array( 'id' => 'novaaction' ), " [$modify, $delete]" );
 693+ }
 694+ $varsOut .= Html::rawElement( 'li', array(), $varname );
481695 }
482696 $out .= Html::rawElement( 'ul', array(), $varsOut );
483697 }
484698 }
485 -
486 - $this->getOutput()->addHTML( $out );
 699+ return $out;
487700 }
488701
489702 /**
@@ -491,7 +704,7 @@
492705 * @return bool
493706 */
494707 function tryCreateSubmit( $formData, $entryPoint = 'internal' ) {
495 - $success = OpenStackNovaPuppetGroup::addGroup( $formData['puppetgroupname'], $formData['puppetgroupposition'] );
 708+ $success = OpenStackNovaPuppetGroup::addGroup( $formData['puppetgroupname'], $formData['puppetgroupposition'], $formData['project'] );
496709 if ( $success ) {
497710 $this->getOutput()->addWikiMsg( 'openstackmanager-createdpuppetgroup' );
498711 } else {
@@ -531,7 +744,7 @@
532745 * @return bool
533746 */
534747 function tryAddClassSubmit( $formData, $entryPoint = 'internal' ) {
535 - $success = OpenStackNovaPuppetGroup::addClass( $formData['puppetclassname'], $formData['puppetclassposition'], $formData['puppetgroupid'] );
 748+ $success = OpenStackNovaPuppetGroup::addClass( $formData['puppetclassname'], $formData['puppetclassposition'], $formData['puppetgroupid'], $formData['project'] );
536749 if ( $success ) {
537750 $this->getOutput()->addWikiMsg( 'openstackmanager-addedpuppetclass' );
538751 } else {
@@ -571,7 +784,7 @@
572785 * @return bool
573786 */
574787 function tryAddVarSubmit( $formData, $entryPoint = 'internal' ) {
575 - $success = OpenStackNovaPuppetGroup::addVar( $formData['puppetvarname'], $formData['puppetvarposition'], $formData['puppetgroupid'] );
 788+ $success = OpenStackNovaPuppetGroup::addVar( $formData['puppetvarname'], $formData['puppetvarposition'], $formData['puppetgroupid'], $formData['project'] );
576789 if ( $success ) {
577790 $this->getOutput()->addWikiMsg( 'openstackmanager-addedpuppetvar' );
578791 } else {
Index: trunk/extensions/OpenStackManager/OpenStackNovaPuppetGroup.php
@@ -63,15 +63,16 @@
6464 * @param $name string
6565 * @return OpenStackNovaPuppetGroup|null
6666 */
67 - public static function newFromName( $name ) {
 67+ public static function newFromName( $name, $project=null ) {
6868 $dbr = wfGetDB( DB_SLAVE );
6969 $row = $dbr->selectRow(
7070 'openstack_puppet_groups',
71 - array(
72 - 'group_id',
 71+ array( 'group_id',
7372 'group_name',
74 - 'group_position' ),
75 - array( 'group_name' => $name ),
 73+ 'group_position',
 74+ 'group_project' ),
 75+ array( 'group_name' => $name,
 76+ 'group_project' => $project ),
7677 __METHOD__ );
7778
7879 if ( $row ) {
@@ -92,7 +93,8 @@
9394 array(
9495 'group_id',
9596 'group_name',
96 - 'group_position' ),
 97+ 'group_position',
 98+ 'group_project' ),
9799 array( 'group_id' => intval( $id ) ),
98100 __METHOD__ );
99101
@@ -104,6 +106,42 @@
105107 }
106108
107109 /**
 110+ * @param $id int
 111+ * @return OpenStackNovaPuppetGroup|null
 112+ */
 113+ public static function newFromClassId( $id ) {
 114+ $dbr = wfGetDB( DB_SLAVE );
 115+ $row = $dbr->selectRow(
 116+ 'openstack_puppet_classes',
 117+ array( 'class_group_id' ),
 118+ array( 'class_id' => intval( $id ) ),
 119+ __METHOD__ );
 120+ if ( $row ) {
 121+ return self::newFromId( $row->class_group_id );
 122+ } else {
 123+ return null;
 124+ }
 125+ }
 126+
 127+ /**
 128+ * @param $id int
 129+ * @return OpenStackNovaPuppetGroup|null
 130+ */
 131+ public static function newFromVarId( $id ) {
 132+ $dbr = wfGetDB( DB_SLAVE );
 133+ $row = $dbr->selectRow(
 134+ 'openstack_puppet_vars',
 135+ array( 'var_group_id' ),
 136+ array( 'var_id' => intval( $id ) ),
 137+ __METHOD__ );
 138+ if ( $row ) {
 139+ return self::newFromId( $row->var_group_id );
 140+ } else {
 141+ return null;
 142+ }
 143+ }
 144+
 145+ /**
108146 * @param $row
109147 * @return OpenStackNovaPuppetGroup
110148 */
@@ -111,7 +149,8 @@
112150 return new OpenStackNovaPuppetGroup(
113151 intval( $row->group_id ),
114152 $row->group_name,
115 - $row->group_position
 153+ $row->group_position,
 154+ $row->group_project
116155 );
117156 }
118157
@@ -119,23 +158,19 @@
120159 * @param $projects array Optionally get list for a set of projects
121160 * @return array
122161 */
123 - public static function getGroupList( $projects = array() ) {
 162+ public static function getGroupList( $project='' ) {
124163 $dbr = wfGetDB( DB_SLAVE );
125 - $condition = '';
126 - if ( $projects ) {
127 - $conditions = array();
128 - foreach ( $projects as $project) {
129 - $conditions[] = 'group_project =' . $dbr->addQuotes( $project ); // FIXME: Unindexed query - No index on group_project
130 - }
131 - $condition = implode( ' || ', $conditions );
 164+ if ( $project ) {
 165+ $condition = 'group_project = ' . $dbr->addQuotes( $project );
 166+ } else {
 167+ $condition = 'group_project is NULL';
132168 }
133169 $rows = $dbr->select(
134170 'openstack_puppet_groups',
135 - array(
136 - 'group_id',
 171+ array( 'group_id',
137172 'group_name',
138 - 'group_position'
139 - ),
 173+ 'group_position',
 174+ 'group_project', ),
140175 $condition,
141176 __METHOD__,
142177 array( 'ORDER BY' => 'group_position ASC' ) // FIXME: Unindexed
@@ -154,8 +189,7 @@
155190 $dbr = wfGetDB( DB_SLAVE );
156191 $rows = $dbr->select(
157192 'openstack_puppet_vars',
158 - array(
159 - 'var_id',
 193+ array( 'var_id',
160194 'var_name',
161195 'var_position' ),
162196 array( 'var_group_id' => $groupid ), // FIXME: Unindexed query
@@ -182,8 +216,7 @@
183217 $dbr = wfGetDB( DB_SLAVE );
184218 $rows = $dbr->select(
185219 'openstack_puppet_classes',
186 - array(
187 - 'class_id',
 220+ array( 'class_id',
188221 'class_name',
189222 'class_position' ),
190223 array( 'class_group_id' => $groupid ), // FIXME: Unindexed query
@@ -208,12 +241,13 @@
209242 * @param $position int
210243 * @return bool
211244 */
212 - public static function addGroup( $name, $position ) {
 245+ public static function addGroup( $name, $position, $project=null ) {
213246 $dbw = wfGetDB( DB_MASTER );
214247 return $dbw->insert(
215248 'openstack_puppet_groups',
216249 array( 'group_name' => $name,
217 - 'group_position' => $position
 250+ 'group_position' => $position,
 251+ 'group_project' => $project,
218252 ),
219253 __METHOD__
220254 );

Sign-offs

UserFlagDate
Reedytested21:21, 27 January 2012

Status & tagging log