r80672 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80671‎ | r80672 | r80673 >
Date:00:57, 21 January 2011
Author:laner
Status:deferred
Tags:
Comment:
* Added initial support for managing global and project roles
* Upped version to 0.8
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.i18n.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackManager.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaProject.php (modified) (history)
  • /trunk/extensions/OpenStackManager/special/SpecialNovaProject.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/special/SpecialNovaProject.php
@@ -176,6 +176,7 @@
177177 $out .= $sk->link( $this->getTitle(), wfMsg( 'openstackmanager-createproject' ), array(), array( 'action' => 'create' ), array() );
178178 $projectsOut = Html::element( 'th', array(), wfMsg( 'openstackmanager-projectname' ) );
179179 $projectsOut .= Html::element( 'th', array(), wfMsg( 'openstackmanager-members' ) );
 180+ $projectsOut .= Html::element( 'th', array(), wfMsg( 'openstackmanager-roles' ) );
180181 $projectsOut .= Html::element( 'th', array(), wfMsg( 'openstackmanager-actions' ) );
181182 $projects = OpenStackNovaProject::getAllProjects();
182183 if ( ! $projects ) {
@@ -196,6 +197,30 @@
197198 $memberOut = Html::rawElement( 'ul', array(), $memberOut );
198199 }
199200 $projectOut .= Html::rawElement( 'td', array(), $memberOut );
 201+ $rolesOut = Html::element( 'th', array(), wfMsg( 'openstackmanager-rolename' ) );
 202+ $rolesOut .= Html::element( 'th', array(), wfMsg( 'openstackmanager-members' ) );
 203+ $rolesOut .= Html::element( 'th', array(), wfMsg( 'openstackmanager-actions' ) );
 204+ foreach ( $project->getRoles() as $role ) {
 205+ $roleOut = Html::element( 'td', array(), $role->getRoleName() );
 206+ $roleMembers = '';
 207+ $specialRoleTitle = Title::newFromText( 'Special:NovaRole' );
 208+ foreach ( $role->getMembers() as $member ) {
 209+ $link = $sk->link( $specialRoleTitle, wfMsg( 'openstackmanager-removerolemember' ), array(),
 210+ array( 'action' => 'removemember', 'projectname' => $projectName, 'rolename' => $role->getRoleName(), 'member' => $member, 'referrer' => 'Special:NovaProject' ), array() );
 211+ $member = $member . ' (' . $link . ')';
 212+ $roleMembers .= Html::rawElement( 'li', array(), $member );
 213+ }
 214+ $roleMembers = Html::rawElement( 'ul', array(), $roleMembers );
 215+ $roleOut .= Html::rawElement( 'td', array(), $roleMembers );
 216+ $link = $sk->link( $specialRoleTitle, wfMsg( 'openstackmanager-addrolemember' ), array(),
 217+ array( 'action' => 'addmember', 'projectname' => $projectName, 'rolename' => $role->getRoleName(), 'referrer' => 'Special:NovaProject' ), array() );
 218+ $actions = Html::rawElement( 'li', array(), $link );
 219+ $actions = Html::rawElement( 'ul', array(), $actions );
 220+ $roleOut .= Html::rawElement( 'td', array(), $actions );
 221+ $rolesOut .= Html::rawElement( 'tr', array(), $roleOut );
 222+ }
 223+ $rolesOut = Html::rawElement( 'table', array( 'class' => 'wikitable' ), $rolesOut );
 224+ $projectOut .= Html::rawElement( 'td', array(), $rolesOut );
200225 $link = $sk->link( $this->getTitle(), wfMsg( 'openstackmanager-deleteproject' ), array(),
201226 array( 'action' => 'delete', 'projectname' => $projectName ), array() );
202227 $actions = Html::rawElement( 'li', array(), $link );
Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php
@@ -134,6 +134,10 @@
135135 'openstackmanager-badinstancename' => 'Bad instance name provided. Instance names must start with a-z, and can only contain a-z, 0-9, and - characters.',
136136 'openstackmanager-novaproject-project' => 'Project',
137137 'openstackmanager-novaproject-info' => 'Project Information',
 138+ 'openstackmanager-roles' => 'Roles',
 139+ 'openstackmanager-rolename' => 'Role Name',
 140+ 'openstackmanager-removerolemember' => 'Remove role member',
 141+ 'openstackmanager-addrolemember' => 'Add role member',
138142
139143 'openstackmanager-shellaccountname' => 'Instance Shell Account Name',
140144 'openstackmanager-shellaccountnamehelp' => 'The shell account name must start with a-z, and can only contain a-z, 0-9, -, and _ characters.',
Index: trunk/extensions/OpenStackManager/OpenStackNovaProject.php
@@ -5,7 +5,10 @@
66 var $projectname;
77 var $projectDN;
88 var $projectInfo;
 9+ var $roles;
910
 11+ static $rolenames = array( 'sysadmin', 'netadmin' );
 12+
1013 function __construct( $projectname ) {
1114 $this->projectname = $projectname;
1215 $this->connect();
@@ -32,12 +35,20 @@
3336 $this->projectInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
3437 wfRestoreWarnings();
3538 $this->projectDN = $this->projectInfo[0]['dn'];
 39+ $this->roles = array();
 40+ foreach ( self::$rolenames as $rolename ) {
 41+ $this->roles[] = OpenStackNovaRole::getProjectRoleByName( $rolename, $this );
 42+ }
3643 }
3744
3845 function getProjectName() {
3946 return $this->projectname;
4047 }
4148
 49+ function getRoles() {
 50+ return $this->roles;
 51+ }
 52+
4253 function getMembers() {
4354 $members = array();
4455 if ( isset( $this->projectInfo[0]['member'] ) ) {
@@ -170,12 +181,19 @@
171182 $project['cn'] = $projectname;
172183 $project['owner'] = $wgOpenStackManagerLDAPUser;
173184 $project['gidnumber'] = OpenStackNovaUser::getNextIdNumber( $wgAuth, 'gidnumber' );
174 - $dn = 'cn=' . $projectname . ',' . $wgOpenStackManagerLDAPProjectBaseDN;
 185+ $projectdn = 'cn=' . $projectname . ',' . $wgOpenStackManagerLDAPProjectBaseDN;
175186
176187 wfSuppressWarnings();
177 - $success = ldap_add( $wgAuth->ldapconn, $dn, $project );
 188+ $success = ldap_add( $wgAuth->ldapconn, $projectdn, $project );
178189 wfRestoreWarnings();
 190+ $project = OpenStackNovaProject( $projectname );
179191 if ( $success ) {
 192+ foreach ( self::$rolenames as $rolename ) {
 193+ $role = OpenStackNovaRole::createRole( $rolename, $project );
 194+ # TODO: If role addition fails, find a way to fail gracefully
 195+ # Though, if the project was added successfully, it is unlikely
 196+ # that role addition will fail.
 197+ }
180198 $wgAuth->printDebug( "Successfully added project $projectname", NONSENSITIVE );
181199 return true;
182200 } else {
@@ -189,7 +207,6 @@
190208 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
191209 global $wgOpenStackManagerLDAPDomain;
192210
193 -
194211 $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
195212 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
196213
@@ -199,20 +216,29 @@
200217 }
201218 $dn = $project->projectDN;
202219
203 - # Projects can have roles as sub entries, fail if they exist
204 - # It is a bad idea to rely on LDAP failure here, as some directories
205 - # may simply delete sub entries.
 220+ # Projects can have roles as sub-entries, we need to delete them first
206221 $result = ldap_list( $wgAuth->ldapconn, $dn, 'objectclass=*' );
207222 $roles = ldap_get_entries( $wgAuth->ldapconn, $result );
208 - if ( $roles['count'] != "0" ) {
209 - return false;
 223+ array_shift( $roles );
 224+ foreach ( $roles as $role ) {
 225+ $roledn = $role['dn'];
 226+ wfSuppressWarnings();
 227+ $success = ldap_delete( $wgAuth->ldapconn, $roledn );
 228+ wfRestoreWarnings();
 229+ if ( $success ){
 230+ $wgAuth->printDebug( "Successfully deleted role $roledn", NONSENSITIVE );
 231+ } else {
 232+ $wgAuth->printDebug( "Failed to delete role $roledn", NONSENSITIVE );
 233+ }
210234 }
211235 wfSuppressWarnings();
212236 $success = ldap_delete( $wgAuth->ldapconn, $dn );
213237 wfRestoreWarnings();
214238 if ( $success ) {
 239+ $wgAuth->printDebug( "Successfully deleted project $projectname", NONSENSITIVE );
215240 return true;
216241 } else {
 242+ $wgAuth->printDebug( "Failed to delete project $projectname", NONSENSITIVE );
217243 return false;
218244 }
219245 }
Index: trunk/extensions/OpenStackManager/OpenStackManager.php
@@ -21,7 +21,7 @@
2222 'path' => __FILE__,
2323 'name' => 'OpenStackManager',
2424 'author' => 'Ryan Lane',
25 - 'version' => '0.7',
 25+ 'version' => '0.8',
2626 'url' => 'http://mediawiki.org/wiki/Extension:OpenStackManager',
2727 'descriptionmsg' => 'openstackmanager-desc',
2828 );
@@ -75,6 +75,7 @@
7676 $wgAutoloadClasses['OpenStackNovaAddress'] = $dir . 'OpenStackNovaAddress.php';
7777 $wgAutoloadClasses['OpenStackNovaSecurityGroup'] = $dir . 'OpenStackNovaSecurityGroup.php';
7878 $wgAutoloadClasses['OpenStackNovaSecurityGroupRule'] = $dir . 'OpenStackNovaSecurityGroupRule.php';
 79+$wgAutoloadClasses['OpenStackNovaRole'] = $dir . 'OpenStackNovaRole.php';
7980 $wgAutoloadClasses['SpecialNovaInstance'] = $dir . 'special/SpecialNovaInstance.php';
8081 $wgAutoloadClasses['SpecialNovaKey'] = $dir . 'special/SpecialNovaKey.php';
8182 $wgAutoloadClasses['SpecialNovaProject'] = $dir . 'special/SpecialNovaProject.php';

Status & tagging log