r112962 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112961‎ | r112962 | r112963 >
Date:21:08, 3 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
add handling for when someone tries to enlist an already enlisted user
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiEnlist.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRoleObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.api.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.enlist.js (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialDisenroll.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -552,6 +552,9 @@
553553 'ep-instructor-addittion-self-success',
554554 'ep-online-addittion-self-success',
555555 'ep-campus-addittion-self-success',
 556+ 'ep-instructor-addittion-null',
 557+ 'ep-online-addittion-null',
 558+ 'ep-campus-addittion-null',
556559 'ep-instructor-add-close-button',
557560 'ep-online-add-close-button',
558561 'ep-campus-add-close-button',
Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
@@ -172,7 +172,7 @@
173173 'student',
174174 true,
175175 $revAction
176 - );
 176+ ) !== false;
177177
178178 if ( $success ) {
179179 $this->showSuccess( wfMessage( 'ep-disenroll-success' ) );
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php
@@ -149,7 +149,7 @@
150150 foreach ( $courses as /* EPCourse */ $course ) {
151151 $courseIds[] = $course->getId();
152152 $course->setUpdateSummaries( false );
153 - $success = $course->enlistUsers( $this->getField( 'user_id' ), $this->getRoleName() ) && $success;
 153+ $success = $course->enlistUsers( $this->getField( 'user_id' ), $this->getRoleName() ) !== false && $success;
154154 $course->setUpdateSummaries( true );
155155 }
156156
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -565,7 +565,7 @@
566566 * @param boolean $save
567567 * @param EPRevisionAction|null $revAction
568568 *
569 - * @return boolean Success indicator
 569+ * @return integer|false The amount of enlisted users or false on failiure
570570 */
571571 public function enlistUsers( $newUsers, $role, $save = true, EPRevisionAction $revAction = null ) {
572572 $roleMap = array(
@@ -595,10 +595,10 @@
596596 $this->logRoleChange( $action, $role, $addedUsers, $revAction->getComment() );
597597 }
598598
599 - return $success;
 599+ return $success ? count( $addedUsers ) : false;
600600 }
601601 else {
602 - return true;
 602+ return 0;
603603 }
604604 }
605605
@@ -614,7 +614,7 @@
615615 * @param boolean $save
616616 * @param EPRevisionAction|null $revAction
617617 *
618 - * @return boolean Success indicator
 618+ * @return integer|false The amount of unenlisted users or false on failiure
619619 */
620620 public function unenlistUsers( $sadUsers, $role, $save = true, EPRevisionAction $revAction = null ) {
621621 $sadUsers = (array)$sadUsers;
@@ -656,10 +656,10 @@
657657 $this->logRoleChange( $action, $role, $removedUsers, $revAction->getComment() );
658658 }
659659
660 - return $success;
 660+ return $success ? count( $removedUsers ) : false;
661661 }
662662 else {
663 - return true;
 663+ return 0;
664664 }
665665 }
666666
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -626,6 +626,7 @@
627627 'ep-instructor-adding' => 'Adding...',
628628 'ep-instructor-addittion-success' => '$1 has been successfully added as {{GENDER:$1|instructor}} for course $2!',
629629 'ep-instructor-addittion-self-success' => 'You have been successfully added as {{GENDER:$1|instructor}} for course $2!',
 630+ 'ep-instructor-addittion-null' => '$1 has already been added as {{GENDER:$1|instructor}} to course $2',
630631 'ep-instructor-add-close-button' => 'Close',
631632 'ep-instructor-add-retry' => 'Retry',
632633 'ep-instructor-addittion-failed' => 'Something went wrong - could not add the instructor to the course.',
@@ -652,6 +653,7 @@
653654 'ep-online-adding' => 'Adding...',
654655 'ep-online-addittion-success' => '$1 has been successfully added as {{GENDER:$1|Online Ambassador}} for course $2!',
655656 'ep-online-addittion-self-success' => 'You have been successfully added as {{GENDER:$1|Online Ambassador}} for course $2!',
 657+ 'ep-online-addittion-null' => '$1 has already been added as {{GENDER:$1|Online Ambassador}} to course $2',
656658 'ep-online-add-close-button' => 'Close',
657659 'ep-online-add-retry' => 'Retry',
658660 'ep-online-addittion-failed' => 'Something went wrong - could not add the Online Ambassador to the course.',
@@ -678,6 +680,7 @@
679681 'ep-campus-adding' => 'Adding...',
680682 'ep-campus-addittion-success' => '$1 has been successfully added as {{GENDER:$1|Campus Ambassador}} for course $2!',
681683 'ep-campus-addittion-self-success' => 'You have been successfully added as {{GENDER:$1|Campus Ambassador}} for course $2!',
 684+ 'ep-campus-addittion-null' => '$1 has already been added as {{GENDER:$1|Campus Ambassador}} to course $2',
682685 'ep-campus-add-close-button' => 'Close',
683686 'ep-campus-add-retry' => 'Retry',
684687 'ep-campus-addittion-failed' => 'Something went wrong - could not add the Campus Ambassador to the course.',
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php
@@ -52,26 +52,32 @@
5353 $this->dieUsage( wfMsg( 'ep-enlist-invalid-course' ), 'invalid-course' );
5454 }
5555
56 - $success = false;
57 -
5856 $revAction = new EPRevisionAction();
5957 $revAction->setUser( $this->getUser() );
6058 $revAction->setComment( $params['reason'] );
6159
6260 switch ( $params['subaction'] ) {
6361 case 'add':
64 - $success = $course->enlistUsers( array( $userId ), $params['role'], true, $revAction );
 62+ $enlistmentResult = $course->enlistUsers( array( $userId ), $params['role'], true, $revAction );
6563 break;
6664 case 'remove':
67 - $success = $course->unenlistUsers( array( $userId ), $params['role'], true, $revAction );
 65+ $enlistmentResult = $course->unenlistUsers( array( $userId ), $params['role'], true, $revAction );
6866 break;
6967 }
7068
7169 $this->getResult()->addValue(
7270 null,
7371 'success',
74 - $success
 72+ $success = $enlistmentResult !== false
7573 );
 74+
 75+ if ( $enlistmentResult !== false ) {
 76+ $this->getResult()->addValue(
 77+ null,
 78+ 'count',
 79+ $enlistmentResult
 80+ );
 81+ }
7682 }
7783
7884 /**
Index: trunk/extensions/EducationProgram/resources/ep.api.js
@@ -24,10 +24,10 @@
2525 requestArgs,
2626 function( data ) {
2727 if ( data.hasOwnProperty( 'success' ) && data.success ) {
28 - deferred.resolve();
 28+ deferred.resolve( data );
2929 }
3030 else {
31 - deferred.reject();
 31+ deferred.reject( data );
3232 }
3333 }
3434 );
Index: trunk/extensions/EducationProgram/resources/ep.enlist.js
@@ -136,8 +136,8 @@
137137 };
138138
139139 this.doAdd = function() {
140 - var $add = $( '#ep-' + role + '-add-button' );
141 - var $cancel = $( '#ep-' + role + '-add-cancel-button' );
 140+ var $add = $( '#ep-' + role + '-add-button' ),
 141+ $cancel = $( '#ep-' + role + '-add-cancel-button' );
142142
143143 $add.button( 'option', 'disabled', true );
144144 $add.button( 'option', 'label', ep.msg( 'ep-' + role + '-adding' ) );
@@ -147,9 +147,18 @@
148148 'username': _this.getName(),
149149 'reason': _this.summaryInput.val(),
150150 'role': role
151 - } ).done( function() {
 151+ } ).done( function( data ) {
 152+ var messageKey = null;
 153+
 154+ if ( data.count === 0 ) {
 155+ messageKey = 'ep-' + role + '-addittion-null';
 156+ }
 157+ else {
 158+ messageKey = this.selfMode ? 'ep-' + role + '-addittion-self-success' : 'ep-' + role + '-addittion-success';
 159+ }
 160+
152161 _this.$dialog.text( ep.msg(
153 - _this.selfMode ? 'ep-' + role + '-addittion-self-success' : 'ep-' + role + '-addittion-success',
 162+ messageKey,
154163 _this.getName(),
155164 _this.courseName
156165 ) );
@@ -158,16 +167,18 @@
159168 $cancel.button( 'option', 'label', ep.msg( 'ep-' + role + '-add-close-button' ) );
160169 $cancel.focus();
161170
162 - // TODO: link name to user page and show control links
163 - $ul = $( '#ep-course-' + role ).find( 'ul' );
 171+ if ( data.count > 0 ) {
 172+ // TODO: link name to user page and show control links
 173+ $ul = $( '#ep-course-' + role ).find( 'ul' );
164174
165 - if ( $ul.length < 1 ) {
166 - $ul = $( '<ul>' );
167 - $( '#ep-course-' + role ).html( $ul );
 175+ if ( $ul.length < 1 ) {
 176+ $ul = $( '<ul>' );
 177+ $( '#ep-course-' + role ).html( $ul );
 178+ }
 179+
 180+ $ul.append( $( '<li>' ).text( _this.getName() ) );
168181 }
169 -
170 - $ul.append( $( '<li>' ).text( _this.getName() ) )
171 - } ).fail( function() {
 182+ } ).fail( function( data ) {
172183 // TODO: implement nicer handling for fails caused by invalid user name
173184
174185 $add.button( 'option', 'disabled', false );

Sign-offs

UserFlagDate
Rob Schnautz (WMF)tested19:30, 7 March 2012

Status & tagging log