From 844218a9243fa3e155522db7b756ab5c99d365b4 Mon Sep 17 00:00:00 2001 From: Sebastian Marcet Date: Wed, 3 Dec 2014 14:10:32 -0300 Subject: [PATCH] [smarcet] - #7793 * Option to upgrade/downgrade user member level Conflicts: deployment_utils/deployment.sh --- .../active_records/FoundationMember.php | 13 +- openstack/code/FeedbackForm.php | 1 + registration/code/AffiliationController.php | 23 +++- registration/code/EditProfilePage.php | 10 ++ registration/javascript/edit.profile.page.js | 2 + .../templates/Layout/EditProfilePage.ss | 3 +- .../Layout/EditProfilePage_Training.ss | 1 + .../EditProfilePage_TrainingAddCourse.ss | 1 + .../Layout/EditProfilePage_agreements.ss | 2 +- .../Layout/EditProfilePage_election.ss | 7 +- ...tProfilePage_marketplace_administration.ss | 1 + .../Layout/EditProfilePage_speaker.ss | 4 +- .../templates/Layout/Includes/ProfileNav.ss | 3 - .../javascript/current.user.infobox.jquery.js | 124 ++++++++++++++++++ .../Layout/Includes/CurrentUserInfoBox.ss | 45 +++++++ 15 files changed, 227 insertions(+), 13 deletions(-) create mode 100644 themes/openstack/javascript/current.user.infobox.jquery.js diff --git a/elections/code/infrastructure/active_records/FoundationMember.php b/elections/code/infrastructure/active_records/FoundationMember.php index e1f68f6..0000708 100644 --- a/elections/code/infrastructure/active_records/FoundationMember.php +++ b/elections/code/infrastructure/active_records/FoundationMember.php @@ -38,7 +38,6 @@ final class FoundationMember } public function isFoundationMember(){ - $res = false; $res = $this->owner->inGroup(IFoundationMember::FoundationMemberGroupSlug); $legal_agreements = DataObject::get("LegalAgreement", " LegalDocumentPageID=422 AND MemberID =" . $this->owner->ID); $res = $res && $legal_agreements->count() > 0; @@ -74,12 +73,12 @@ final class FoundationMember public function resign(){ // Remove member from Foundation group foreach($this->owner->Groups() as $g){ - $this->owner->Groups()->remove($g->ID); + $this->owner->Groups()->remove($g); } // Remove member mamaged companies foreach($this->owner->ManagedCompanies() as $c){ - $this->owner->ManagedCompanies()->remove($c->ID); + $this->owner->ManagedCompanies()->remove($c); } // Remove Member's Legal Agreements $legal_agreements = $this->owner->LegalAgreements(); @@ -105,4 +104,12 @@ final class FoundationMember $is_foundation_member = $this->isFoundationMember(); return $group || $is_speaker || $is_foundation_member; } + + /** + * @return bool + */ + public function isSpeaker() { + $is_speaker = DataObject::get_one('Speaker', 'MemberID = '. $this->owner->ID); + return $is_speaker; + } } \ No newline at end of file diff --git a/openstack/code/FeedbackForm.php b/openstack/code/FeedbackForm.php index de101d2..40710f6 100644 --- a/openstack/code/FeedbackForm.php +++ b/openstack/code/FeedbackForm.php @@ -56,6 +56,7 @@ class FeedbackForm extends Form { // Redirect back to the page with a success message $form->controller->setMessage('Success', 'Thanks for providing feedback to improve the OpenStack website!'); + $form->controller->redirectBack(); } else { diff --git a/registration/code/AffiliationController.php b/registration/code/AffiliationController.php index 5258d24..7f83598 100644 --- a/registration/code/AffiliationController.php +++ b/registration/code/AffiliationController.php @@ -21,7 +21,9 @@ class AffiliationController extends Page_Controller 'GetAffiliation', 'ListAffiliations', 'ListOrganizations', - 'AffiliationsCount' + 'AffiliationsCount', + 'Downgrade2CommunityMember', + 'Upgrade2FoundationMember', ); function init() @@ -198,4 +200,23 @@ class AffiliationController extends Page_Controller } echo json_encode('ERROR'); } + + public function Downgrade2CommunityMember(){ + if ($CurrentMember = Member::currentUser()) { + $CurrentMember->convert2SiteUser(); + echo json_encode('OK'); + exit(); + } + echo json_encode('ERROR'); + } + + + public function Upgrade2FoundationMember(){ + if ($CurrentMember = Member::currentUser()) { + $CurrentMember->upgradeToFoundationMember(); + echo json_encode('OK'); + exit(); + } + echo json_encode('ERROR'); + } } \ No newline at end of file diff --git a/registration/code/EditProfilePage.php b/registration/code/EditProfilePage.php index 66ef9b7..7092e8e 100755 --- a/registration/code/EditProfilePage.php +++ b/registration/code/EditProfilePage.php @@ -77,8 +77,10 @@ class EditProfilePage_Controller extends Page_Controller Requirements::javascript("themes/openstack/javascript/jquery.ui.datepicker.validation.package-1.0.1/jquery.ui.datepicker.validation.js"); Requirements::javascript("themes/openstack/javascript/jquery.validate.custom.methods.js"); Requirements::javascript("registration/javascript/affiliations.js"); + Requirements::javascript('themes/openstack/javascript/current.user.infobox.jquery.js'); Requirements::javascript('registration/javascript/edit.profile.page.js'); + $this->course_repository = new SapphireCourseRepository; $this->training_repository = new SapphireTrainingServiceRepository; @@ -666,4 +668,12 @@ class EditProfilePage_Controller extends Page_Controller $this->extend('getNavActionsExtensions',$html); return $html; } + + public function LogoutUrl(){ + return $this->Link('logout'); + } + + public function ResignUrl(){ + return $this->Link('resign'); + } } \ No newline at end of file diff --git a/registration/javascript/edit.profile.page.js b/registration/javascript/edit.profile.page.js index 2dfdbf7..2b0a007 100755 --- a/registration/javascript/edit.profile.page.js +++ b/registration/javascript/edit.profile.page.js @@ -256,4 +256,6 @@ jQuery(document).ready(function($) { }); } + + $('body').user_infobox(); }); \ No newline at end of file diff --git a/registration/templates/Layout/EditProfilePage.ss b/registration/templates/Layout/EditProfilePage.ss index 0d53dd9..4078436 100644 --- a/registration/templates/Layout/EditProfilePage.ss +++ b/registration/templates/Layout/EditProfilePage.ss @@ -33,6 +33,7 @@ $SetCurrentTab(1)

There was a problem saving your profile. Please look for errors below.

<% end_if %> + <% include CurrentUserInfoBox LogOutLink=$Top.LogoutUrl, ResignLink=$Top.ResignUrl %> <% include ProfileNav %>
See how your public profile appears.
$EditProfileForm @@ -46,4 +47,4 @@ $SetCurrentTab(1)

Login Join The Foundation

<% end_if %> <% end_if %> - + diff --git a/registration/templates/Layout/EditProfilePage_Training.ss b/registration/templates/Layout/EditProfilePage_Training.ss index 1bc98bc..bd2be04 100644 --- a/registration/templates/Layout/EditProfilePage_Training.ss +++ b/registration/templates/Layout/EditProfilePage_Training.ss @@ -3,6 +3,7 @@ <% require themedCSS(profile-section) %>

$Title

<% if CurrentMember %> + <% include CurrentUserInfoBox LogOutLink=$Top.LogoutUrl, ResignLink=$Top.ResignUrl %> <% include ProfileNav %> <% if CurrentMember.isTrainingAdmin %>
diff --git a/registration/templates/Layout/EditProfilePage_TrainingAddCourse.ss b/registration/templates/Layout/EditProfilePage_TrainingAddCourse.ss index b6e9fcf..0a22bda 100644 --- a/registration/templates/Layout/EditProfilePage_TrainingAddCourse.ss +++ b/registration/templates/Layout/EditProfilePage_TrainingAddCourse.ss @@ -3,6 +3,7 @@ <% require themedCSS(profile-section) %>

$Title

<% if CurrentMember %> + <% include CurrentUserInfoBox LogOutLink=$Top.LogoutUrl, ResignLink=$Top.ResignUrl %> <% include ProfileNav %> <% if CurrentMember.isTrainingAdmin %> $AddTrainingCourseForm diff --git a/registration/templates/Layout/EditProfilePage_agreements.ss b/registration/templates/Layout/EditProfilePage_agreements.ss index 37cad25..8b4c468 100644 --- a/registration/templates/Layout/EditProfilePage_agreements.ss +++ b/registration/templates/Layout/EditProfilePage_agreements.ss @@ -16,7 +16,7 @@ <% end_if %> - + <% include CurrentUserInfoBox LogOutLink=$Top.LogoutUrl, ResignLink=$Top.ResignUrl %> <% include ProfileNav %>
diff --git a/registration/templates/Layout/EditProfilePage_election.ss b/registration/templates/Layout/EditProfilePage_election.ss index 84d84cd..bcdab15 100644 --- a/registration/templates/Layout/EditProfilePage_election.ss +++ b/registration/templates/Layout/EditProfilePage_election.ss @@ -1,9 +1,10 @@
$SetCurrentTab(2) <% require themedCSS(profile-section) %> -

$Title

- <% if CurrentMember.isFoundationMember %> - +

$Title

+ <% if CurrentMember.isFoundationMember %> + <% include CurrentUserInfoBox LogOutLink=$Top.LogoutUrl, ResignLink=$Top.ResignUrl %> +> <% include ProfileNav %> <% if CurrentElection %> diff --git a/registration/templates/Layout/EditProfilePage_marketplace_administration.ss b/registration/templates/Layout/EditProfilePage_marketplace_administration.ss index 4b1bbaa..d328cba 100644 --- a/registration/templates/Layout/EditProfilePage_marketplace_administration.ss +++ b/registration/templates/Layout/EditProfilePage_marketplace_administration.ss @@ -3,6 +3,7 @@ <% require themedCSS(profile-section) %>

$Title

<% if CurrentMember %> + <% include CurrentUserInfoBox LogOutLink=$Top.LogoutUrl, ResignLink=$Top.ResignUrl %> <% include ProfileNav %> <% if CurrentMember.isMarketPlaceAdmin %>
diff --git a/registration/templates/Layout/EditProfilePage_speaker.ss b/registration/templates/Layout/EditProfilePage_speaker.ss index 835168c..28edbc1 100644 --- a/registration/templates/Layout/EditProfilePage_speaker.ss +++ b/registration/templates/Layout/EditProfilePage_speaker.ss @@ -1,4 +1,5 @@
+ <% require javascript(framework/thirdparty/tinymce/tiny_mce.js) %> <% require javascript(themes/openstack/javascript/simple-tinymce.js) %> $SetCurrentTab(7) @@ -11,6 +12,7 @@

Your Profile has been saved!

<% end_if %> + <% include CurrentUserInfoBox LogOutLink=$Top.LogoutUrl, ResignLink=$Top.ResignUrl %> <% include ProfileNav %> $EditSpeakerProfileForm <% else %> @@ -22,4 +24,4 @@ class="roundedButton">Join The Foundation

<% end_if %> -
\ No newline at end of file + diff --git a/registration/templates/Layout/Includes/ProfileNav.ss b/registration/templates/Layout/Includes/ProfileNav.ss index 3d9a184..2f24196 100644 --- a/registration/templates/Layout/Includes/ProfileNav.ss +++ b/registration/templates/Layout/Includes/ProfileNav.ss @@ -1,6 +1,3 @@ -
- You are logged in as: $CurrentMember.Name    Logout   Resign Membership -

class="active"<% end_if %> >Your Details <% if CurrentMember.isFoundationMember %> diff --git a/themes/openstack/javascript/current.user.infobox.jquery.js b/themes/openstack/javascript/current.user.infobox.jquery.js new file mode 100644 index 0000000..6fd3594 --- /dev/null +++ b/themes/openstack/javascript/current.user.infobox.jquery.js @@ -0,0 +1,124 @@ +/** + * Copyright 2014 Openstack Foundation + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +(function( $ ){ + + var settings = {}; + var downgrade_btn = null; + var upgrade_btn = null; + var confirm_downgrade_dialog = null; + var confirm_upgrade_dialog = null; + + var methods = { + init: function(options){ + + settings = $.extend({}, options ); + downgrade_btn = $('.downgrade-2-community-member'); + upgrade_btn = $('.upgrade-2-foundation-member'); + + downgrade_btn.click(function(event){ + event.preventDefault(); + event.stopPropagation(); + confirm_downgrade_dialog.dialog( "open"); + return false; + }); + + upgrade_btn.click(function(event){ + event.preventDefault(); + event.stopPropagation(); + confirm_upgrade_dialog.dialog( "open"); + return false; + }); + + confirm_upgrade_dialog = $('#dialog-confirm-upgrade').dialog({ + resizable: false, + autoOpen: false, + height:520, + width:620, + modal: true, + buttons: { + "Agree": function() { + $.ajax( + { + type: "GET", + url: 'userprofile/Upgrade2FoundationMember', + dataType: "json", + timeout:5000, + retryMax: 2, + complete: function (jqXHR,textStatus) { + window.location.reload(); + }, + error: function (jqXHR, textStatus, errorThrown) { + alert( "Request failed: " + textStatus ); + } + } + ); + $(this).dialog( "close" ); + }, + "Disagree": function() { + $( this ).dialog( "close" ); + } + } + }); + + confirm_downgrade_dialog = $('#dialog-confirm-downgrade').dialog({ + resizable: false, + autoOpen: false, + height:220, + width:520, + modal: true, + buttons: { + "Agree": function() { + $.ajax( + { + type: "GET", + url: 'userprofile/Downgrade2CommunityMember', + dataType: "json", + timeout:5000, + retryMax: 2, + complete: function (jqXHR,textStatus) { + window.location.reload(); + }, + error: function (jqXHR, textStatus, errorThrown) { + alert( "Request failed: " + textStatus ); + } + } + ); + $(this).dialog( "close" ); + }, + "Disagree": function() { + $( this ).dialog( "close" ); + } + } + }); + + + + } + + }; + + + $.fn.user_infobox = function(methodOrOptions) { + if ( methods[methodOrOptions] ) { + return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) { + // Default to "init" + return methods.init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.user_infobox' ); + } + }; + // End of closure. +}( jQuery )); + diff --git a/themes/openstack/templates/Layout/Includes/CurrentUserInfoBox.ss b/themes/openstack/templates/Layout/Includes/CurrentUserInfoBox.ss index e69de29..6f32b72 100644 --- a/themes/openstack/templates/Layout/Includes/CurrentUserInfoBox.ss +++ b/themes/openstack/templates/Layout/Includes/CurrentUserInfoBox.ss @@ -0,0 +1,45 @@ +
+
+
You are logged in as: $CurrentMember.Name
+ + +
+
+ <% if $CurrentMember.isFoundationMember %> +
+ Current Member Level: Foundation Member +
+ + <% else_if $CurrentMember.isSpeaker %> +
+ Current Member Level: Speaker +
+ <% else_if $CurrentMember.isCommunityMember %> +
+ Current Member Level: Community Member +
+ + <% end_if %> +
+
+ + + \ No newline at end of file