Index: trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php |
— | — | @@ -303,11 +303,24 @@ |
304 | 304 | 'default' => wfMsg( 'openstackmanager-createinstancepuppetwarning' ), |
305 | 305 | ); |
306 | 306 | } |
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 ) { |
308 | 315 | foreach ( $puppetGroups as $puppetGroup ) { |
309 | 316 | $classes = array(); |
310 | 317 | $defaults = array(); |
311 | 318 | $puppetgroupname = $puppetGroup->getName(); |
| 319 | + $puppetgroupproject = $puppetGroup->getProject(); |
| 320 | + if ( $puppetgroupproject ) { |
| 321 | + $section = 'instance/puppetinfo/project'; |
| 322 | + } else { |
| 323 | + $section = 'instance/puppetinfo/global'; |
| 324 | + } |
312 | 325 | foreach ( $puppetGroup->getClasses() as $class ) { |
313 | 326 | $classname = $class["name"]; |
314 | 327 | $classes["$classname"] = $classname; |
— | — | @@ -317,12 +330,12 @@ |
318 | 331 | } |
319 | 332 | $instanceInfo["${puppetgroupname}"] = array( |
320 | 333 | 'type' => 'info', |
321 | | - 'section' => "instance/puppetinfo", |
| 334 | + 'section' => $section, |
322 | 335 | 'label' => Html::element( 'h3', array(), "$puppetgroupname:" ), |
323 | 336 | ); |
324 | 337 | $instanceInfo["${puppetgroupname}-puppetclasses"] = array( |
325 | 338 | 'type' => 'multiselect', |
326 | | - 'section' => "instance/puppetinfo", |
| 339 | + 'section' => $section, |
327 | 340 | 'options' => $classes, |
328 | 341 | 'default' => $defaults, |
329 | 342 | 'name' => "${puppetgroupname}-puppetclasses", |
— | — | @@ -335,7 +348,7 @@ |
336 | 349 | } |
337 | 350 | $instanceInfo["${puppetgroupname}-${variablename}"] = array( |
338 | 351 | 'type' => 'text', |
339 | | - 'section' => "instance/puppetinfo", |
| 352 | + 'section' => $section, |
340 | 353 | 'label' => $variablename, |
341 | 354 | 'default' => $default, |
342 | 355 | 'name' => "${puppetgroupname}-${variablename}", |
— | — | @@ -455,6 +468,7 @@ |
456 | 469 | */ |
457 | 470 | function listInstances() { |
458 | 471 | $this->setHeaders(); |
| 472 | + $this->getOutput()->addModuleStyles( 'ext.openstack' ); |
459 | 473 | $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-instancelist' ) ); |
460 | 474 | |
461 | 475 | $userProjects = $this->userLDAP->getProjects(); |
— | — | @@ -503,7 +517,6 @@ |
504 | 518 | $instanceOut .= Html::element( 'td', array(), $instance->getAvailabilityZone() ); |
505 | 519 | $instanceOut .= Html::element( 'td', array(), $instance->getImageId() ); |
506 | 520 | $instanceOut .= Html::element( 'td', array(), $instance->getLaunchTime() ); |
507 | | - |
508 | 521 | $actions = ''; |
509 | 522 | if ( $this->userLDAP->inRole( 'sysadmin', $project ) ) { |
510 | 523 | $msg = wfMsgHtml( 'openstackmanager-delete' ); |
— | — | @@ -540,15 +553,20 @@ |
541 | 554 | } |
542 | 555 | } |
543 | 556 | foreach ( $userProjects as $project ) { |
544 | | - $out .= Html::element( 'h2', array(), $project ); |
| 557 | + $action = ''; |
545 | 558 | 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]" ); |
547 | 561 | } |
| 562 | + $projectName = Html::rawElement( 'span', array( 'class' => 'mw-customtoggle-' . $project, 'id' => 'novaproject' ), $project ); |
| 563 | + $out .= Html::rawElement( 'h2', array(), "$projectName $action" ); |
| 564 | + $projectOut = ''; |
548 | 565 | if ( isset( $projectArr["$project"] ) ) { |
549 | | - $projectOut = $header; |
| 566 | + $projectOut .= $header; |
550 | 567 | $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 ); |
552 | 569 | } |
| 570 | + $out .= Html::rawElement( 'div', array( 'class' => 'mw-collapsible', 'id' => 'mw-customcollapsible-' . $project ), $projectOut ); |
553 | 571 | } |
554 | 572 | |
555 | 573 | $this->getOutput()->addHTML( $out ); |
— | — | @@ -676,24 +694,34 @@ |
677 | 695 | |
678 | 696 | $puppetinfo = array(); |
679 | 697 | if ( $wgOpenStackManagerPuppetOptions['enabled'] ) { |
| 698 | + $puppetGroups = OpenStackNovaPuppetGroup::getGroupList( $formData['project'] ); |
| 699 | + $this->getPuppetInfoByGroup( $puppetinfo, $puppetGroups, $formData ); |
680 | 700 | $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; |
686 | 714 | } |
687 | 715 | } |
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"]; |
693 | 721 | } |
694 | 722 | } |
695 | 723 | } |
696 | | - return $puppetinfo; |
697 | 724 | } |
| 725 | + |
698 | 726 | } |
699 | 727 | |
700 | 728 | class SpecialNovaInstanceForm extends HTMLForm { |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaSecurityGroup.php |
— | — | @@ -318,7 +318,8 @@ |
319 | 319 | array( 'action' => 'create', 'project' => $project ) ); |
320 | 320 | $action = Html::rawElement( 'span', array( 'id' => 'novaaction' ), "[$action]" ); |
321 | 321 | } |
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" ); |
323 | 324 | if ( isset( $projectArr["$project"] ) ) { |
324 | 325 | $projectOut = $groupheader; |
325 | 326 | $projectOut .= $projectArr["$project"]; |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaAddress.php |
— | — | @@ -429,7 +429,8 @@ |
430 | 430 | foreach ( $userProjects as $project ) { |
431 | 431 | $action = Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-allocateaddress' ), array(), array( 'action' => 'allocate', 'project' => $project ) ); |
432 | 432 | $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" ); |
434 | 435 | $projectOut = ''; |
435 | 436 | if ( isset( $projectArr["$project"] ) ) { |
436 | 437 | $projectOut = $header; |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaPuppetGroup.php |
— | — | @@ -6,12 +6,15 @@ |
7 | 7 | } |
8 | 8 | |
9 | 9 | function execute( $par ) { |
10 | | - |
11 | | - |
12 | 10 | if ( ! $this->getUser()->isLoggedIn() ) { |
13 | 11 | $this->notLoggedIn(); |
14 | 12 | return; |
15 | 13 | } |
| 14 | + $this->userLDAP = new OpenStackNovaUser(); |
| 15 | + if ( ! $this->userLDAP->exists() ) { |
| 16 | + $this->noCredentials(); |
| 17 | + return; |
| 18 | + } |
16 | 19 | $action = $this->getRequest()->getVal( 'action' ); |
17 | 20 | if ( $action == "create" ) { |
18 | 21 | $this->createPuppetGroup(); |
— | — | @@ -41,11 +44,21 @@ |
42 | 45 | */ |
43 | 46 | function createPuppetGroup() { |
44 | 47 | $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 | + } |
48 | 62 | } |
49 | | - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-createpuppetgroup' ) ); |
50 | 63 | |
51 | 64 | $puppetGroupInfo = array(); |
52 | 65 | $puppetGroupInfo['puppetgroupname'] = array( |
— | — | @@ -61,7 +74,11 @@ |
62 | 75 | 'default' => '', |
63 | 76 | 'name' => 'puppetgroupposition', |
64 | 77 | ); |
65 | | - |
| 78 | + $puppetGroupInfo['project'] = array( |
| 79 | + 'type' => 'hidden', |
| 80 | + 'default' => $project, |
| 81 | + 'name' => 'project', |
| 82 | + ); |
66 | 83 | $puppetGroupInfo['action'] = array( |
67 | 84 | 'type' => 'hidden', |
68 | 85 | 'default' => 'create', |
— | — | @@ -81,16 +98,29 @@ |
82 | 99 | * @return bool |
83 | 100 | */ |
84 | 101 | function addPuppetClass() { |
85 | | - |
86 | | - |
87 | 102 | $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' ); |
90 | 108 | return false; |
91 | 109 | } |
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 | + } |
93 | 124 | |
94 | | - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' ); |
95 | 125 | $puppetGroupInfo = array(); |
96 | 126 | $puppetGroupInfo['puppetclassname'] = array( |
97 | 127 | 'type' => 'text', |
— | — | @@ -103,6 +133,11 @@ |
104 | 134 | 'label-message' => 'openstackmanager-puppetclassposition', |
105 | 135 | 'name' => 'puppetclassposition', |
106 | 136 | ); |
| 137 | + $puppetGroupInfo['project'] = array( |
| 138 | + 'type' => 'hidden', |
| 139 | + 'default' => $project, |
| 140 | + 'name' => 'project', |
| 141 | + ); |
107 | 142 | $puppetGroupInfo['action'] = array( |
108 | 143 | 'type' => 'hidden', |
109 | 144 | 'default' => 'addclass', |
— | — | @@ -111,7 +146,7 @@ |
112 | 147 | $puppetGroupInfo['puppetgroupid'] = array( |
113 | 148 | 'type' => 'hidden', |
114 | 149 | 'default' => $puppetGroupId, |
115 | | - 'name' => 'puppetGroupId', |
| 150 | + 'name' => 'puppetgroupid', |
116 | 151 | ); |
117 | 152 | |
118 | 153 | $puppetGroupForm = new SpecialNovaPuppetGroupForm( $puppetGroupInfo, 'openstackmanager-novapuppetgroup' ); |
— | — | @@ -127,18 +162,31 @@ |
128 | 163 | * @return bool |
129 | 164 | */ |
130 | 165 | function deletePuppetClass() { |
131 | | - |
132 | | - |
133 | 166 | $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' ); |
136 | 172 | return false; |
137 | 173 | } |
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 | + } |
139 | 188 | if ( ! $this->getRequest()->wasPosted() ) { |
140 | 189 | $this->getOutput()->addWikiMsg( 'openstackmanager-removepuppetclassconfirm' ); |
141 | 190 | } |
142 | | - $puppetClassId = $this->getRequest()->getInt( 'puppetclassid' ); |
143 | 191 | $puppetGroupInfo = array(); |
144 | 192 | $puppetGroupInfo['puppetclassid'] = array( |
145 | 193 | 'type' => 'hidden', |
— | — | @@ -164,14 +212,28 @@ |
165 | 213 | * @return bool |
166 | 214 | */ |
167 | 215 | function addPuppetVar() { |
168 | | - |
169 | | - |
170 | 216 | $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' ); |
173 | 222 | return false; |
174 | 223 | } |
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 | + } |
176 | 238 | |
177 | 239 | $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' ); |
178 | 240 | $puppetGroupInfo = array(); |
— | — | @@ -186,16 +248,21 @@ |
187 | 249 | 'label-message' => 'openstackmanager-puppetvarposition', |
188 | 250 | 'name' => 'puppetvarposition', |
189 | 251 | ); |
| 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 | + ); |
190 | 262 | $puppetGroupInfo['action'] = array( |
191 | 263 | 'type' => 'hidden', |
192 | 264 | 'default' => 'addvar', |
193 | 265 | 'name' => 'action', |
194 | 266 | ); |
195 | | - $puppetGroupInfo['puppetgroupid'] = array( |
196 | | - 'type' => 'hidden', |
197 | | - 'default' => $puppetGroupId, |
198 | | - 'name' => 'puppetGroupId', |
199 | | - ); |
200 | 267 | |
201 | 268 | $puppetGroupForm = new SpecialNovaPuppetGroupForm( $puppetGroupInfo, 'openstackmanager-novapuppetgroup' ); |
202 | 269 | $puppetGroupForm->setTitle( SpecialPage::getTitleFor( 'NovaPuppetGroup' ) ); |
— | — | @@ -210,14 +277,28 @@ |
211 | 278 | * @return bool |
212 | 279 | */ |
213 | 280 | function deletePuppetVar() { |
214 | | - |
215 | | - |
216 | 281 | $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' ); |
219 | 287 | return false; |
220 | 288 | } |
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 | + } |
222 | 303 | |
223 | 304 | $puppetVarId = $this->getRequest()->getText( 'puppetvarid' ); |
224 | 305 | if ( ! $this->getRequest()->wasPosted() ) { |
— | — | @@ -248,16 +329,29 @@ |
249 | 330 | * @return bool |
250 | 331 | */ |
251 | 332 | function deletePuppetGroup() { |
252 | | - |
253 | | - |
254 | 333 | $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' ); |
257 | 339 | return false; |
258 | 340 | } |
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 | + } |
260 | 355 | |
261 | | - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' ); |
262 | 356 | if ( ! $this->getRequest()->wasPosted() ) { |
263 | 357 | $this->getOutput()->addWikiMsg( 'openstackmanager-removepuppetgroupconfirm' ); |
264 | 358 | } |
— | — | @@ -285,17 +379,44 @@ |
286 | 380 | * @return bool |
287 | 381 | */ |
288 | 382 | function modifyPuppetClass() { |
289 | | - |
290 | | - |
291 | 383 | $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' ); |
294 | 404 | return false; |
295 | 405 | } |
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 | + } |
297 | 420 | |
298 | | - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' ); |
299 | | - $puppetClassId = $this->getRequest()->getInt( 'puppetclassid' ); |
300 | 421 | $puppetClassPosition = $this->getRequest()->getInt( 'puppetclassposition' ); |
301 | 422 | $puppetGroupInfo = array(); |
302 | 423 | $puppetGroupInfo['puppetclassid'] = array( |
— | — | @@ -341,17 +462,45 @@ |
342 | 463 | * @return bool |
343 | 464 | */ |
344 | 465 | function modifyPuppetVar() { |
345 | | - |
346 | | - |
347 | 466 | $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' ); |
350 | 487 | return false; |
351 | 488 | } |
352 | | - $this->getOutput()->setPagetitle( wfMsg( 'openstackmanager-modifypuppetvar' ) ); |
| 489 | + $project = $group->getProject(); |
353 | 490 | |
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 | + |
356 | 505 | $puppetVarPosition = $this->getRequest()->getInt( 'puppetvarposition' ); |
357 | 506 | $puppetGroupInfo = array(); |
358 | 507 | $puppetGroupInfo['puppetvarid'] = array( |
— | — | @@ -398,13 +547,28 @@ |
399 | 548 | */ |
400 | 549 | function modifyPuppetGroup() { |
401 | 550 | $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' ); |
404 | 556 | return false; |
405 | 557 | } |
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 | + } |
407 | 572 | |
408 | | - $puppetGroupId = $this->getRequest()->getInt( 'puppetgroupid' ); |
409 | 573 | $puppetGroupPosition = $this->getRequest()->getInt( 'puppetgroupposition' ); |
410 | 574 | $puppetGroupInfo = array(); |
411 | 575 | $puppetGroupInfo['puppetgroupid'] = array( |
— | — | @@ -442,47 +606,96 @@ |
443 | 607 | $this->getOutput()->addModuleStyles( 'ext.openstack' ); |
444 | 608 | |
445 | 609 | $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 ) { |
446 | 625 | |
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 = ''; |
449 | 638 | foreach ( $puppetGroups as $puppetGroup ) { |
| 639 | + $puppetGroupProject = $puppetGroup->getProject(); |
| 640 | + //$puppetGroupProject can be null |
| 641 | + if ( !$puppetGroupProject ) { |
| 642 | + $puppetGroupProject = ''; |
| 643 | + } |
450 | 644 | $puppetGroupId = $puppetGroup->getId(); |
451 | 645 | $puppetGroupPosition = $puppetGroup->getPosition(); |
452 | 646 | $puppetGroupName = $puppetGroup->getName(); |
453 | 647 | $puppetGroupName = "[$puppetGroupPosition] " . htmlentities( $puppetGroupName ); |
454 | 648 | $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" ); |
460 | 662 | $puppetGroupClasses = $puppetGroup->getClasses(); |
461 | 663 | $puppetGroupVars = $puppetGroup->getVars(); |
462 | 664 | if ( $puppetGroupClasses ) { |
463 | 665 | $classesOut = ''; |
464 | 666 | 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' ) ); |
467 | 667 | $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 ); |
469 | 675 | } |
470 | 676 | $out .= Html::rawElement( 'ul', array(), $classesOut ); |
471 | 677 | } |
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" ); |
474 | 685 | if ( $puppetGroupVars ) { |
475 | 686 | $varsOut = ''; |
476 | 687 | 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' ) ); |
479 | 688 | $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 ); |
481 | 695 | } |
482 | 696 | $out .= Html::rawElement( 'ul', array(), $varsOut ); |
483 | 697 | } |
484 | 698 | } |
485 | | - |
486 | | - $this->getOutput()->addHTML( $out ); |
| 699 | + return $out; |
487 | 700 | } |
488 | 701 | |
489 | 702 | /** |
— | — | @@ -491,7 +704,7 @@ |
492 | 705 | * @return bool |
493 | 706 | */ |
494 | 707 | function tryCreateSubmit( $formData, $entryPoint = 'internal' ) { |
495 | | - $success = OpenStackNovaPuppetGroup::addGroup( $formData['puppetgroupname'], $formData['puppetgroupposition'] ); |
| 708 | + $success = OpenStackNovaPuppetGroup::addGroup( $formData['puppetgroupname'], $formData['puppetgroupposition'], $formData['project'] ); |
496 | 709 | if ( $success ) { |
497 | 710 | $this->getOutput()->addWikiMsg( 'openstackmanager-createdpuppetgroup' ); |
498 | 711 | } else { |
— | — | @@ -531,7 +744,7 @@ |
532 | 745 | * @return bool |
533 | 746 | */ |
534 | 747 | 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'] ); |
536 | 749 | if ( $success ) { |
537 | 750 | $this->getOutput()->addWikiMsg( 'openstackmanager-addedpuppetclass' ); |
538 | 751 | } else { |
— | — | @@ -571,7 +784,7 @@ |
572 | 785 | * @return bool |
573 | 786 | */ |
574 | 787 | 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'] ); |
576 | 789 | if ( $success ) { |
577 | 790 | $this->getOutput()->addWikiMsg( 'openstackmanager-addedpuppetvar' ); |
578 | 791 | } else { |
Index: trunk/extensions/OpenStackManager/OpenStackNovaPuppetGroup.php |
— | — | @@ -63,15 +63,16 @@ |
64 | 64 | * @param $name string |
65 | 65 | * @return OpenStackNovaPuppetGroup|null |
66 | 66 | */ |
67 | | - public static function newFromName( $name ) { |
| 67 | + public static function newFromName( $name, $project=null ) { |
68 | 68 | $dbr = wfGetDB( DB_SLAVE ); |
69 | 69 | $row = $dbr->selectRow( |
70 | 70 | 'openstack_puppet_groups', |
71 | | - array( |
72 | | - 'group_id', |
| 71 | + array( 'group_id', |
73 | 72 | '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 ), |
76 | 77 | __METHOD__ ); |
77 | 78 | |
78 | 79 | if ( $row ) { |
— | — | @@ -92,7 +93,8 @@ |
93 | 94 | array( |
94 | 95 | 'group_id', |
95 | 96 | 'group_name', |
96 | | - 'group_position' ), |
| 97 | + 'group_position', |
| 98 | + 'group_project' ), |
97 | 99 | array( 'group_id' => intval( $id ) ), |
98 | 100 | __METHOD__ ); |
99 | 101 | |
— | — | @@ -104,6 +106,42 @@ |
105 | 107 | } |
106 | 108 | |
107 | 109 | /** |
| 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 | + /** |
108 | 146 | * @param $row |
109 | 147 | * @return OpenStackNovaPuppetGroup |
110 | 148 | */ |
— | — | @@ -111,7 +149,8 @@ |
112 | 150 | return new OpenStackNovaPuppetGroup( |
113 | 151 | intval( $row->group_id ), |
114 | 152 | $row->group_name, |
115 | | - $row->group_position |
| 153 | + $row->group_position, |
| 154 | + $row->group_project |
116 | 155 | ); |
117 | 156 | } |
118 | 157 | |
— | — | @@ -119,23 +158,19 @@ |
120 | 159 | * @param $projects array Optionally get list for a set of projects |
121 | 160 | * @return array |
122 | 161 | */ |
123 | | - public static function getGroupList( $projects = array() ) { |
| 162 | + public static function getGroupList( $project='' ) { |
124 | 163 | $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'; |
132 | 168 | } |
133 | 169 | $rows = $dbr->select( |
134 | 170 | 'openstack_puppet_groups', |
135 | | - array( |
136 | | - 'group_id', |
| 171 | + array( 'group_id', |
137 | 172 | 'group_name', |
138 | | - 'group_position' |
139 | | - ), |
| 173 | + 'group_position', |
| 174 | + 'group_project', ), |
140 | 175 | $condition, |
141 | 176 | __METHOD__, |
142 | 177 | array( 'ORDER BY' => 'group_position ASC' ) // FIXME: Unindexed |
— | — | @@ -154,8 +189,7 @@ |
155 | 190 | $dbr = wfGetDB( DB_SLAVE ); |
156 | 191 | $rows = $dbr->select( |
157 | 192 | 'openstack_puppet_vars', |
158 | | - array( |
159 | | - 'var_id', |
| 193 | + array( 'var_id', |
160 | 194 | 'var_name', |
161 | 195 | 'var_position' ), |
162 | 196 | array( 'var_group_id' => $groupid ), // FIXME: Unindexed query |
— | — | @@ -182,8 +216,7 @@ |
183 | 217 | $dbr = wfGetDB( DB_SLAVE ); |
184 | 218 | $rows = $dbr->select( |
185 | 219 | 'openstack_puppet_classes', |
186 | | - array( |
187 | | - 'class_id', |
| 220 | + array( 'class_id', |
188 | 221 | 'class_name', |
189 | 222 | 'class_position' ), |
190 | 223 | array( 'class_group_id' => $groupid ), // FIXME: Unindexed query |
— | — | @@ -208,12 +241,13 @@ |
209 | 242 | * @param $position int |
210 | 243 | * @return bool |
211 | 244 | */ |
212 | | - public static function addGroup( $name, $position ) { |
| 245 | + public static function addGroup( $name, $position, $project=null ) { |
213 | 246 | $dbw = wfGetDB( DB_MASTER ); |
214 | 247 | return $dbw->insert( |
215 | 248 | 'openstack_puppet_groups', |
216 | 249 | array( 'group_name' => $name, |
217 | | - 'group_position' => $position |
| 250 | + 'group_position' => $position, |
| 251 | + 'group_project' => $project, |
218 | 252 | ), |
219 | 253 | __METHOD__ |
220 | 254 | ); |