Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement membership connection caps

  • Loading branch information...
commit 2011b6ee13675ab6a1281714cea9663431175896 1 parent 66fc1d4
@ginatrapani ginatrapani authored
View
39 tests/TestOfOwner.php
@@ -53,4 +53,43 @@ public function testConstructor() {
$this->assertFalse($owner->is_admin);
$this->assertTrue($owner->is_activated);
}
+
+ public function testIsMember() {
+ $owner_values = array('id'=>10, "full_name"=>"ThinkUp J. User", "email"=>'tu_user@example.com',
+ 'last_login'=>'1/1/2010', 'is_admin'=>0, 'is_activated'=>1, 'account_status'=>'', 'failed_logins'=>19,
+ 'email_notification_frequency' => 'both', 'membership_level'=>null );
+
+ $owner = new Owner($owner_values);
+ $this->assertFalse($owner->isMemberAtAnyLevel());
+
+ $owner->membership_level = 'Member';
+ $this->assertTrue($owner->isMemberAtAnyLevel());
+ $this->assertTrue($owner->isMemberLevel());
+ $this->assertFalse($owner->isProLevel());
+
+ $owner->membership_level = 'Early Bird';
+ $this->assertTrue($owner->isMemberAtAnyLevel());
+ $this->assertTrue($owner->isMemberLevel());
+ $this->assertFalse($owner->isProLevel());
+
+ $owner->membership_level = 'Late Bird';
+ $this->assertTrue($owner->isMemberAtAnyLevel());
+ $this->assertTrue($owner->isMemberLevel());
+ $this->assertFalse($owner->isProLevel());
+
+ $owner->membership_level = 'Pro';
+ $this->assertTrue($owner->isMemberAtAnyLevel());
+ $this->assertFalse($owner->isMemberLevel());
+ $this->assertTrue($owner->isProLevel());
+
+ $owner->membership_level = 'Exec';
+ $this->assertTrue($owner->isMemberAtAnyLevel());
+ $this->assertFalse($owner->isMemberLevel());
+ $this->assertFalse($owner->isProLevel());
+
+ $owner->membership_level = 'pajamas';
+ $this->assertFalse($owner->isMemberAtAnyLevel());
+ $this->assertFalse($owner->isMemberLevel());
+ $this->assertFalse($owner->isProLevel());
+ }
}
View
10 tests/TestOfOwnerInstanceMySQLDAO.php
@@ -92,6 +92,16 @@ public function testGetByInstance() {
$this->assertEqual(sizeof($owner_instances), 3);
}
+ public function testGetByOwner() {
+ $dao = new OwnerInstanceMySQLDAO();
+ $builder1 = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id'=>50) );
+ $builder2 = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id'=>51) );
+ $builder3 = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id'=>52) );
+ $owner_instances = $dao->getByOwner(50);
+ $this->assertIsA($owner_instances, 'Array');
+ $this->assertEqual(sizeof($owner_instances), 1);
+ }
+
public function testInsertOwnerInstance() {
$dao = new OwnerInstanceMySQLDAO();
$result = $dao->insert(10, 20, 'aaa', 'bbb');
View
4 tests/TestOfOwnerMySQLDAO.php
@@ -56,7 +56,7 @@ protected function buildData() {
'email'=>'ttuser@example.com', 'is_activated'=>0, 'pwd'=>$pwd1,
'pwd_salt'=>OwnerMySQLDAO::$default_salt, 'activation_code'=>'8888',
'account_status'=>'', 'api_key' => 'c9089f3c9adaf0186f6ffb1ee8d6501c',
- 'email_notification_frequency'=>'both', 'timezone'=>'UTC'));
+ 'email_notification_frequency'=>'both', 'timezone'=>'UTC', 'membership_level'=>'Member'));
$builders[] = FixtureBuilder::build('owners', array('full_name'=>'ThinkUp J. User1',
'email'=>'ttuser1@example.com', 'is_activated'=>1, 'pwd'=>$pwd2,
@@ -87,6 +87,8 @@ public function testGetByEmail() {
$this->assertEqual($existing_owner->account_status, '');
$this->assertEqual($existing_owner->api_key, 'c9089f3c9adaf0186f6ffb1ee8d6501c');
$this->assertEqual($existing_owner->email_notification_frequency, 'both');
+ $this->assertEqual($existing_owner->timezone, 'UTC');
+ $this->assertEqual($existing_owner->membership_level, 'Member');
//owner does not exist
$non_existing_owner = $this->DAO->getByEmail('idontexist@example.com');
View
17 webapp/_lib/controller/class.PluginConfigurationController.php
@@ -141,6 +141,12 @@
*/
var $options_hash = array();
+ /**
+ * Whether or not to show button to add user
+ * @var bool
+ */
+ var $do_show_add_button = true;
+
public function __construct($owner, $folder_name) {
parent::__construct(true);
$this->owner = $owner;
@@ -155,6 +161,17 @@ public function __construct($owner, $folder_name) {
$plugin_dao = DAOFactory::getDAO('PluginDAO');
$this->plugin_id = $plugin_dao->getPluginId($folder_name);
}
+ if (($owner instanceof Owner) && $owner != null && $owner->isProLevel()) {
+ // For Pro users, cap instances at 10
+ $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
+ $owner_instances = $owner_instance_dao->getByOwner($this->owner->id);
+ $total_instances = sizeof($owner_instances);
+ if ($total_instances >= 9) {
+ $this->do_show_add_button = false;
+ $this->addInfoMessage("You've connected ".$total_instances." of 10 accounts to ThinkUp.",
+ 'membership_cap');
+ }
+ }
}
/**
View
14 webapp/_lib/dao/class.OwnerInstanceMySQLDAO.php
@@ -153,6 +153,20 @@ public function getByInstance($instance_id) {
return $owner_instances;
}
+ public function getByOwner($owner_id) {
+ $q = "SELECT
+ id, owner_id, instance_id, oauth_access_token, oauth_access_token_secret, auth_error
+ FROM
+ #prefix#owner_instances
+ WHERE owner_id = :owner_id";
+
+ $vars = array(':owner_id' => $owner_id);
+ if ($this->profiler_enabled) { Profiler::setDAOMethod(__METHOD__); }
+ $stmt = $this->execute($q, $vars);
+ $owner_instances = $this->getDataRowsAsObjects($stmt, 'OwnerInstance');
+ return $owner_instances;
+ }
+
public function insert($owner_id, $instance_id, $oauth_token = '', $oauth_token_secret = '') {
$q = "INSERT INTO #prefix#owner_instances
(owner_id, instance_id, oauth_access_token, oauth_access_token_secret)
View
1  webapp/_lib/dao/class.OwnerMySQLDAO.php
@@ -48,6 +48,7 @@ public function getByEmail($email) {
failed_logins,
api_key,
email_notification_frequency,
+ membership_level,
timezone
FROM #prefix#owners AS o
WHERE email = :email;
View
8 webapp/_lib/dao/interface.OwnerInstanceDAO.php
@@ -53,12 +53,18 @@ public function doesOwnerHaveAccessToPost(Owner $owner, Post $post);
*/
public function get($owner_id, $instance_id);
/**
- * Get owner instances by an instance id
+ * Get owner instances by an instance ID
* @param int instance_id
* @return array OwnerInstance objects
*/
public function getByInstance($instance_id);
/**
+ * Get owner instances by an owner ID
+ * @param int owner_id
+ * @return array OwnerInstance objects
+ */
+ public function getByOwner($owner_id);
+ /**
* Inserts an owner instance record
* @param int owner_id
* @param int instance_id
View
31 webapp/_lib/model/class.Owner.php
@@ -88,6 +88,12 @@ class Owner {
* @var arr Non-persistent, used for UI, array of instances associated with owner.
*/
var $instances = null;
+ /**
+ * Valid values for membership level.
+ * @var array
+ */
+ static $valid_membership_values = array('Early Bird', 'Member', 'Late Bird', 'Pro', 'Exec');
+
public function __construct($row = false) {
if ($row) {
$this->id = $row['id'];
@@ -142,4 +148,29 @@ public function validateRecoveryToken($token) {
$data = explode('_', $this->password_token);
return ((time() - $data[1] <= 86400) && ($token == $data[0]));
}
+
+ /**
+ * Check if the owner is a ThinkUp.com member of any level.
+ * @return bool Whether or not the owner is a member
+ */
+ public function isMemberAtAnyLevel() {
+ return (in_array($this->membership_level, self::$valid_membership_values));
+ }
+
+ /**
+ * Check if the owner is Member level, i.e., Early Bird, Member, or Late Bird.
+ * @return bool Whether or not the owner is a member at member level
+ */
+ public function isMemberLevel() {
+ return ($this->membership_level == 'Member' || $this->membership_level == 'Early Bird'
+ || $this->membership_level == 'Late Bird');
+ }
+
+ /**
+ * Check if the owner is Pro member level.
+ * @return bool Whether or not the owner is a Pro level
+ */
+ public function isProLevel() {
+ return ($this->membership_level === 'Pro');
+ }
}
View
87 webapp/plugins/facebook/controller/class.FacebookPluginConfigurationController.php
@@ -28,20 +28,10 @@
*
*/
class FacebookPluginConfigurationController extends PluginConfigurationController {
- /**
- *
- * @var Owner
- */
- var $owner;
- /**
- * Constructor
- * @param Owner $owner
- * @return FacebookPluginConfigurationController
- */
+
public function __construct($owner) {
parent::__construct($owner, 'facebook');
$this->disableCaching();
- $this->owner = $owner;
}
public function authControl() {
@@ -116,17 +106,31 @@ protected function setUpFacebookInteractions($options) {
$fb_user_profile = null;
}
}
- //Plant unique token for CSRF protection during auth per https://developers.facebook.com/docs/authentication/
+ // Plant unique token for CSRF protection during auth per https://developers.facebook.com/docs/authentication/
if (SessionCache::get('facebook_auth_csrf') == null) {
SessionCache::put('facebook_auth_csrf', md5(uniqid(rand(), true)));
}
- $params = array('scope'=>'read_stream,user_likes,user_location,user_website,'.
- 'read_friendlists,friends_location,manage_pages,read_insights,manage_pages',
- 'state'=>SessionCache::get('facebook_auth_csrf'));
+ if (isset($this->owner) && $this->owner->isMemberAtAnyLevel()) {
+ if ($this->owner->isMemberLevel()) {
+ $instance_dao = DAOFactory::getDAO('InstanceDAO');
+ $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'facebook');
+ if (sizeof($owner_instances) > 0) {
+ $this->do_show_add_button = false;
+ $this->addInfoMessage("To connect another Facebook account to ThinkUp, upgrade your membership.",
+ 'membership_cap');
+ }
+ }
+ }
+
+ if ($this->do_show_add_button) {
+ $params = array('scope'=>'read_stream,user_likes,user_location,user_website,'.
+ 'read_friendlists,friends_location,manage_pages,read_insights,manage_pages',
+ 'state'=>SessionCache::get('facebook_auth_csrf'));
- $fbconnect_link = $facebook->getLoginUrl($params);
- $this->addToView('fbconnect_link', $fbconnect_link);
+ $fbconnect_link = $facebook->getLoginUrl($params);
+ $this->addToView('fbconnect_link', $fbconnect_link);
+ }
self::processPageActions($options, $facebook);
@@ -136,35 +140,38 @@ protected function setUpFacebookInteractions($options) {
$instance_dao = DAOFactory::getDAO('InstanceDAO');
$instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'facebook');
- $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
- foreach ($instances as $instance) {
- // TODO: figure out if the scope has changed since this instance last got its tokens,
- // and we need to get re-request permission with the new scope
- $tokens = $owner_instance_dao->getOAuthTokens($instance->id);
- $access_token = $tokens['oauth_access_token'];
- if ($instance->network == 'facebook') { //not a page
- $pages = FacebookGraphAPIAccessor::apiRequest('/'.$instance->network_user_id.'/likes', $access_token);
- if (@$pages->data) {
- $user_pages[$instance->network_user_id] = $pages->data;
- }
+ if ($this->do_show_add_button) {
+ $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
+ foreach ($instances as $instance) {
+ // TODO: figure out if the scope has changed since this instance last got its tokens,
+ // and we need to get re-request permission with the new scope
+ $tokens = $owner_instance_dao->getOAuthTokens($instance->id);
+ $access_token = $tokens['oauth_access_token'];
+ if ($instance->network == 'facebook') { //not a page
+ $pages = FacebookGraphAPIAccessor::apiRequest('/'.$instance->network_user_id.'/likes',
+ $access_token);
+ if (@$pages->data) {
+ $user_pages[$instance->network_user_id] = $pages->data;
+ }
- $sub_accounts = FacebookGraphAPIAccessor::apiRequest('/'.$instance->network_user_id.'/accounts',
- $access_token);
- if (!empty($sub_accounts->data)) {
- $user_admin_pages[$instance->network_user_id] = array();
- foreach ($sub_accounts->data as $act) {
- if (self::isAccountPage($act->id, $access_token)) {
- $user_admin_pages[$instance->network_user_id][] = $act;
+ $sub_accounts = FacebookGraphAPIAccessor::apiRequest('/'.$instance->network_user_id.'/accounts',
+ $access_token);
+ if (!empty($sub_accounts->data)) {
+ $user_admin_pages[$instance->network_user_id] = array();
+ foreach ($sub_accounts->data as $act) {
+ if (self::isAccountPage($act->id, $access_token)) {
+ $user_admin_pages[$instance->network_user_id][] = $act;
+ }
}
}
}
+ if (isset($tokens['auth_error']) && $tokens['auth_error'] != '') {
+ $instance->auth_error = $tokens['auth_error'];
+ }
}
- if (isset($tokens['auth_error']) && $tokens['auth_error'] != '') {
- $instance->auth_error = $tokens['auth_error'];
- }
+ $this->addToView('user_pages', $user_pages);
+ $this->addToView('user_admin_pages', $user_admin_pages);
}
- $this->addToView('user_pages', $user_pages);
- $this->addToView('user_admin_pages', $user_admin_pages);
$owner_instance_pages = $instance_dao->getByOwnerAndNetwork($this->owner, 'facebook page');
if (count($owner_instance_pages) > 0) {
View
53 webapp/plugins/facebook/tests/TestOfFacebookPluginConfigurationController.php
@@ -603,4 +603,57 @@ public function testForDeleteCSRFToken() {
$this->assertPattern('/name="csrf_token" value="'. self::CSRF_TOKEN .
'" \/><!\-\- delete page csrf token \-\->/', $output);
}
+
+ public function testOwnerMemberLevelWithAccountConnected() {
+ // build options data
+ $options_array = $this->buildPluginOptions();
+ //Add a connected Facebook account
+ $builders[] = FixtureBuilder::build('instances', array('id'=>2, 'network_user_id'=>14,
+ 'network_username'=>'zuck', 'is_public'=>1, 'network'=>'facebook'));
+ $builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>2));
+
+ $this->simulateLogin('me@example.com');
+ $owner_dao = DAOFactory::getDAO('OwnerDAO');
+ $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
+ //Set membership_level to Member
+ $owner->membership_level = "Member";
+
+ $controller = new FacebookPluginConfigurationController($owner, 'facebook');
+ $output = $controller->go();
+ $this->debug($output);
+
+ // Assert that the Add User button isn't there
+ $this->assertNoPattern('/Add a Facebook Account/', $output);
+ // Assert that the message about upgradiing is there
+ $this->assertPattern('/To connect another Facebook account to ThinkUp, upgrade your membership/', $output);
+ }
+
+ public function testOwnerProLevelWith9AccountsConnected() {
+ self::buildInstanceData();
+ // build options data
+ $options_array = $this->buildPluginOptions();
+ //Add 9 connected Facebok accounts
+ $i = 9;
+ while ($i > 0) {
+ $builders[] = FixtureBuilder::build('instances', array('id'=>(10+$i), 'network_user_id'=>14,
+ 'network_username'=>'zuck', 'is_public'=>1, 'network'=>'facebook'));
+ $builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>2, 'instance_id'=>(10+$i)));
+ $i--;
+ }
+
+ $this->simulateLogin('me2@example.com', true);
+ $owner_dao = DAOFactory::getDAO('OwnerDAO');
+ $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
+ //Set membership_level to Pro
+ $owner->membership_level = "Pro";
+ $controller = new FacebookPluginConfigurationController($owner, 'facebook');
+ $output = $controller->go();
+
+ $this->debug($output);
+
+ // Assert that the Add User button isn't there
+ $this->assertNoPattern('/Add a Facebook Account/', $output);
+ // Assert that the message about the membership cap is there
+ $this->assertPattern('/You&#39;ve connected 10 of 10 accounts to ThinkUp./', $output);
+ }
}
View
11 webapp/plugins/facebook/view/facebook.account.index.tpl
@@ -42,6 +42,7 @@
</div>
{/foreach}
</div>
+ {include file="_usermessage.tpl" field="membership_cap"}
{if isset($owner_instance_pages) && count($owner_instance_pages) > 0 }{include file="_usermessage.tpl" field="page_add"}{/if}
@@ -74,11 +75,11 @@
</div>
{/if}
-<div>
-<h2>Add a Facebook Page</h2>
{foreach from=$instances key=iid item=i name=foo}
{assign var='facebook_user_id' value=$i->network_user_id}
{if $user_pages.$facebook_user_id or $user_admin_pages.$facebook_user_id}
+<div>
+<h2>Add a Facebook Page</h2>
<div class="row-fluid">
<div class="span6">
<form name="addpage" action="index.php?p=facebook">
@@ -105,14 +106,10 @@
<span id="divaddpage{$i->network_username}"><input type="submit" name="action" class="btn addPage" id="{$i->network_username}" value="add page" /></span>
</div>
</div>
- {else}
- <div class="article">
- To add a Facebook page to ThinkUp, create a new page on Facebook.com or "like" an existing one, and refresh this page.
- </div>
+</div>
{/if}
{/foreach}
-</div>
{/if}
View
2  webapp/plugins/foursquare/tests/TestOfFoursquarePluginConfigurationController.php
@@ -109,7 +109,7 @@ private function buildPluginOptions() {
public function testConstructor() {
// Create a new controller
- $controller = new FoursquarePluginConfigurationController("me@example.com");
+ $controller = new FoursquarePluginConfigurationController(null);
// Check the controller was created
$this->assertNotNull($controller);
// Check the controller is of type foursquare
View
2  .../plugins/insightsgenerator/tests/TestOfInsightsGeneratorPluginConfigurationController.php
@@ -88,7 +88,7 @@ private function getController($logged_in, $is_admin=false) {
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$controller = new InsightsGeneratorPluginConfigurationController($owner);
} else {
- $controller = new InsightsGeneratorPluginConfigurationController(true);
+ $controller = new InsightsGeneratorPluginConfigurationController(null);
}
return $controller;
}
View
172 webapp/plugins/twitter/controller/class.TwitterPluginConfigurationController.php
@@ -31,11 +31,6 @@
*
*/
class TwitterPluginConfigurationController extends PluginConfigurationController {
- /**
- *
- * @var Owner
- */
- var $owner;
public function authControl() {
$config = Config::getInstance();
@@ -57,32 +52,45 @@ public function authControl() {
$plugin = new TwitterPlugin();
if ($plugin->isConfigured()) {
- $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
- /* Request tokens from twitter */
- $token_array = $twitter_oauth->getRequestToken(Utils::getApplicationURL(true)."account/?p=twitter");
-
- if (isset($token_array['oauth_token'])
- || (isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS") { //testing
- $token = $token_array['oauth_token'];
- SessionCache::put('oauth_request_token_secret', $token_array['oauth_token_secret']);
-
- self::addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors);
-
- /* Build the authorization URL */
- $oauthorize_link = $twitter_oauth->getAuthorizeURL($token);
-
- $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'twitter');
-
- $this->addToView('owner_instances', $owner_instances);
- $this->addToView('oauthorize_link', $oauthorize_link);
- $this->addToView('is_configured', true);
- } else {
- //set error message here
- $this->addErrorMessage(
- "Unable to obtain OAuth tokens from Twitter. Please double-check the consumer key and secret ".
- "are correct.", "setup");
- $oauthorize_link = '';
- $this->addToView('is_configured', false);
+ $this->addToView('is_configured', true);
+ $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'twitter');
+ $this->addToView('owner_instances', $owner_instances);
+ if (isset($this->owner) && $this->owner->isMemberAtAnyLevel()) {
+ if ($this->owner->isMemberLevel()) {
+ if (sizeof($owner_instances) > 0) {
+ $this->do_show_add_button = false;
+ $this->addInfoMessage("To connect another Twitter account to ThinkUp, upgrade your membership.",
+ 'membership_cap');
+ }
+ }
+ }
+ if (isset($_GET['oauth_token']) || $this->do_show_add_button ) {
+ $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
+ /* Request tokens from twitter */
+ $token_array = $twitter_oauth->getRequestToken(Utils::getApplicationURL(true)."account/?p=twitter");
+
+ if (isset($token_array['oauth_token'])
+ || (isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS") { //testing
+ $token = $token_array['oauth_token'];
+ SessionCache::put('oauth_request_token_secret', $token_array['oauth_token_secret']);
+
+ if (isset($_GET['oauth_token'])) {
+ self::addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors);
+ }
+
+ if ($this->do_show_add_button) {
+ /* Build the authorization URL */
+ $oauthorize_link = $twitter_oauth->getAuthorizeURL($token);
+ $this->addToView('oauthorize_link', $oauthorize_link);
+ }
+ } else {
+ //set error message here
+ $this->addErrorMessage(
+ "Unable to obtain OAuth tokens from Twitter. Please double-check the consumer key and secret ".
+ "are correct.", "setup");
+ $oauthorize_link = '';
+ $this->addToView('is_configured', false);
+ }
}
} else {
$this->addInfoMessage('Please complete plugin setup to start using it.', 'setup');
@@ -130,69 +138,65 @@ private function addOptionForm() {
* @return void
*/
private function addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors) {
- if (isset($_GET['oauth_token']) && SessionCache::isKeySet('oauth_request_token_secret')) {
- $request_token = $_GET['oauth_token'];
- $request_token_secret = SessionCache::get('oauth_request_token_secret');
-
- $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret, $request_token,
- $request_token_secret);
- if (isset($_GET['oauth_verifier'])) {
- $token_array = $twitter_oauth->getAccessToken($_GET['oauth_verifier']);
- } else {
- $token_array = null;
- }
+ $request_token = $_GET['oauth_token'];
+ $request_token_secret = SessionCache::get('oauth_request_token_secret');
- if (isset($token_array['oauth_token']) && isset($token_array['oauth_token_secret'])) {
- $api = new TwitterAPIAccessorOAuth($token_array['oauth_token'], $token_array['oauth_token_secret'],
- $oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors, false);
-
- $authed_twitter_user = $api->verifyCredentials();
- // echo "User ID: ". $authed_twitter_user['user_id']."<br>";
- // echo "User name: ". $authed_twitter_user['user_name']."<br>";
-
- $owner_dao = DAOFactory::getDAO('OwnerDAO');
- $owner = $owner_dao->getByEmail($this->getLoggedInUser());
-
- if ( isset($authed_twitter_user) && isset($authed_twitter_user['user_name'])
- && isset($authed_twitter_user['user_id'])) {
- $instance_dao = DAOFactory::getDAO('TwitterInstanceDAO');
- $instance = $instance_dao->getByUsername($authed_twitter_user['user_name'], 'twitter');
- $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
- if (isset($instance)) {
- $owner_instance = $owner_instance_dao->get($owner->id, $instance->id);
- if ($owner_instance != null) {
- $owner_instance_dao->updateTokens($owner->id, $instance->id, $token_array['oauth_token'],
- $token_array['oauth_token_secret']);
- $this->addSuccessMessage($authed_twitter_user['user_name'].
- " on Twitter is already set up in ThinkUp! To add a different Twitter account, ".
- "log out of Twitter.com in your browser and authorize ThinkUp again.", 'user_add');
- } else {
- if ($owner_instance_dao->insert($owner->id, $instance->id, $token_array['oauth_token'],
- $token_array['oauth_token_secret'])) {
- $this->addSuccessMessage("Success! ".$authed_twitter_user['user_name'].
- " on Twitter has been added to ThinkUp!", "user_add");
- } else {
- $this->addErrorMessage("Error: Could not create an owner instance.", "user_add");
- }
- }
+ $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret, $request_token,
+ $request_token_secret);
+ if (isset($_GET['oauth_verifier'])) {
+ $token_array = $twitter_oauth->getAccessToken($_GET['oauth_verifier']);
+ } else {
+ $token_array = null;
+ }
+
+ if (isset($token_array['oauth_token']) && isset($token_array['oauth_token_secret'])) {
+ $api = new TwitterAPIAccessorOAuth($token_array['oauth_token'], $token_array['oauth_token_secret'],
+ $oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors, false);
+
+ $authed_twitter_user = $api->verifyCredentials();
+ // echo "User ID: ". $authed_twitter_user['user_id']."<br>";
+ // echo "User name: ". $authed_twitter_user['user_name']."<br>";
+
+ if ( isset($authed_twitter_user) && isset($authed_twitter_user['user_name'])
+ && isset($authed_twitter_user['user_id'])) {
+ $instance_dao = DAOFactory::getDAO('TwitterInstanceDAO');
+ $instance = $instance_dao->getByUsername($authed_twitter_user['user_name'], 'twitter');
+ $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
+ if (isset($instance)) {
+ $owner_instance = $owner_instance_dao->get($this->owner->id, $instance->id);
+ if ($owner_instance != null) {
+ $owner_instance_dao->updateTokens($this->owner->id, $instance->id,
+ $token_array['oauth_token'], $token_array['oauth_token_secret']);
+ $this->addSuccessMessage($authed_twitter_user['user_name'].
+ " on Twitter is already set up in ThinkUp! To add a different Twitter account, ".
+ "log out of Twitter.com in your browser and authorize ThinkUp again.", 'user_add');
} else {
- $instance_dao->insert($authed_twitter_user['user_id'], $authed_twitter_user['user_name']);
- $instance = $instance_dao->getByUsername($authed_twitter_user['user_name']);
- if ($owner_instance_dao->insert( $owner->id, $instance->id, $token_array['oauth_token'],
- $token_array['oauth_token_secret'])) {
+ print_r($this->owner);
+ if ($owner_instance_dao->insert($this->owner->id, $instance->id,
+ $token_array['oauth_token'], $token_array['oauth_token_secret'])) {
$this->addSuccessMessage("Success! ".$authed_twitter_user['user_name'].
" on Twitter has been added to ThinkUp!", "user_add");
} else {
$this->addErrorMessage("Error: Could not create an owner instance.", "user_add");
}
}
+ } else {
+ $instance_dao->insert($authed_twitter_user['user_id'], $authed_twitter_user['user_name']);
+ $instance = $instance_dao->getByUsername($authed_twitter_user['user_name']);
+ if ($owner_instance_dao->insert( $this->owner->id, $instance->id, $token_array['oauth_token'],
+ $token_array['oauth_token_secret'])) {
+ $this->addSuccessMessage("Success! ".$authed_twitter_user['user_name'].
+ " on Twitter has been added to ThinkUp!", "user_add");
+ } else {
+ $this->addErrorMessage("Error: Could not create an owner instance.", "user_add");
+ }
}
- } else {
- $msg = "Error: Twitter authorization did not complete successfully. Check if your account already ".
- " exists. If not, please try again.";
- $this->addErrorMessage($msg, "user_add");
}
- $this->view_mgr->clear_all_cache();
+ } else {
+ $msg = "Error: Twitter authorization did not complete successfully. Check if your account already ".
+ " exists. If not, please try again.";
+ $this->addErrorMessage($msg, "user_add");
}
+ $this->view_mgr->clear_all_cache();
}
}
View
74 webapp/plugins/twitter/tests/TestOfTwitterPluginConfigurationController.php
@@ -50,7 +50,7 @@ protected function buildData(){
//Add owner
$builders[] = FixtureBuilder::build('owners', array('id'=>1, 'full_name'=>'ThinkUp J. User',
- 'email'=>'me@example.com', 'is_activated'=>1, 'pwd'=>'XXX', 'activation_code'=>8888));
+ 'email'=>'me@example.com', 'is_activated'=>1, 'pwd'=>'XXX', 'activation_code'=>8888, 'membership_level'=>null));
//Add instance_owner
$builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>1));
@@ -98,7 +98,7 @@ public function testConstructor() {
*/
public function testOutputNoParams() {
// build some options data
- $options_arry = $this->buildPluginOptions();
+ $options_array = $this->buildPluginOptions();
//not logged in, no owner set
$controller = new TwitterPluginConfigurationController(null, 'twitter');
@@ -124,7 +124,7 @@ public function testOutputNoParams() {
*/
public function testConfigOptionsNotAdmin() {
// build some options data
- $options_arry = $this->buildPluginOptions();
+ $options_array = $this->buildPluginOptions();
$this->simulateLogin('me@example.com');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
@@ -146,7 +146,7 @@ public function testConfigOptionsNotAdmin() {
public function testConfigOptionsIsAdmin() {
$_SERVER['SERVER_NAME'] = 'mytestthinkup';
// build some options data
- $options_arry = $this->buildPluginOptions();
+ $options_array = $this->buildPluginOptions();
$this->simulateLogin('me@example.com', true);
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
@@ -171,7 +171,7 @@ public function testConfigOptionsIsAdminWithSSL() {
$_SERVER['HTTPS'] = true;
$_SERVER['SERVER_NAME'] = 'mytestthinkup';
// build some options data
- $options_arry = $this->buildPluginOptions();
+ $options_array = $this->buildPluginOptions();
$this->simulateLogin('me@example.com', true);
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
@@ -190,7 +190,7 @@ public function testLocalhostConversionTo1270001() {
$_SERVER['HTTPS'] = null;
$_SERVER['SERVER_NAME'] = 'localhost';
// build some options data
- $options_arry = $this->buildPluginOptions();
+ $options_array = $this->buildPluginOptions();
$this->simulateLogin('me@example.com', true);
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
@@ -238,7 +238,7 @@ public function testConfigOptionsMissingRequiredValues() {
public function testForDeleteCSRFToken() {
$_SERVER['SERVER_NAME'] = 'mytestthinkup';
// build some options data
- $options_arry = $this->buildPluginOptions();
+ $options_array = $this->buildPluginOptions();
$this->simulateLogin('me@example.com', true, true);
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
@@ -300,7 +300,9 @@ public function testLoggedInAuthorizeUserAllParams() {
$plugn_opt_builder3 = FixtureBuilder::build('options', array('namespace'=>$namespace,
'option_name'=>'num_twitter_errors', 'option_value'=>'5'));
- $controller = new TwitterPluginConfigurationController(null, 'twitter');
+ $owner = new Owner(array('id'=>1, 'email'=>'me@example.com'));
+
+ $controller = new TwitterPluginConfigurationController($owner, 'twitter');
$this->debug('Controller has been instantiated');
$results = $controller->go();
@@ -331,7 +333,9 @@ public function testLoggedInAuthorizeExistingUserAllParams() {
//Add instance_owner
$builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>2));
- $controller = new TwitterPluginConfigurationController(null, 'twitter');
+ $owner = new Owner(array('id'=>1, 'email'=>'me@example.com'));
+
+ $controller = new TwitterPluginConfigurationController($owner, 'twitter');
$results = $controller->go();
$v_mgr = $controller->getViewManager();
@@ -341,4 +345,56 @@ public function testLoggedInAuthorizeExistingUserAllParams() {
'log out of Twitter.com in your browser and authorize ThinkUp again.', $msgs['user_add']);
$this->assertEqual('', $v_mgr->getTemplateDataItem('error_msg'));
}
+
+ public function testOwnerMemberLevelWithAccountConnected() {
+ // build options data
+ $options_array = $this->buildPluginOptions();
+ //Add a connected Twitter account
+ $builders[] = FixtureBuilder::build('instances', array('id'=>2, 'network_user_id'=>14,
+ 'network_username'=>'biz', 'is_public'=>1, 'network'=>'twitter'));
+ $builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>2));
+
+ $this->simulateLogin('me@example.com');
+ $owner_dao = DAOFactory::getDAO('OwnerDAO');
+ $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
+ //Set membership_level to Member
+ $owner->membership_level = "Member";
+
+ $controller = new TwitterPluginConfigurationController($owner, 'twitter');
+ $output = $controller->go();
+ $this->debug($output);
+
+ // Assert that the Add User button isn't there
+ $this->assertNoPattern('/Add a Twitter Account/', $output);
+ // Assert that the message about upgradiing is there
+ $this->assertPattern('/To connect another Twitter account to ThinkUp, upgrade your membership/', $output);
+ }
+
+ public function testOwnerProLevelWith9AccountsConnected() {
+ // build options data
+ $options_array = $this->buildPluginOptions();
+ //Add 9 connected Twitter accounts
+ $i = 9;
+ while ($i > 0) {
+ $builders[] = FixtureBuilder::build('instances', array('id'=>(1+$i), 'network_user_id'=>14,
+ 'network_username'=>'biz', 'is_public'=>1, 'network'=>'twitter'));
+ $builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>(1+$i)));
+ $i--;
+ }
+
+ $this->simulateLogin('me@example.com');
+ $owner_dao = DAOFactory::getDAO('OwnerDAO');
+ $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
+ //Set membership_level to Member
+ $owner->membership_level = "Pro";
+
+ $controller = new TwitterPluginConfigurationController($owner, 'twitter');
+ $output = $controller->go();
+ $this->debug($output);
+
+ // Assert that the Add User button isn't there
+ $this->assertNoPattern('/Add a Twitter Account/', $output);
+ // Assert that the message about the membership cap is there
+ $this->assertPattern('/You&#39;ve connected 10 of 10 accounts to ThinkUp./', $output);
+ }
}
View
2  webapp/plugins/twitter/view/twitter.account.index.tpl
@@ -54,6 +54,8 @@
</table>
{/if}
+{include file="_usermessage.tpl" field="membership_cap"}
+
{if $oauthorize_link}
<a href="{$oauthorize_link}" class="btn btn-success add-account"><i class="icon-plus icon-white"></i> Add a Twitter account</a>
Please sign in to comment.
Something went wrong with that request. Please try again.