<NME> UserTest.php
<BEF> <?php
class UserTest extends PHPUnit_Framework_TestCase
{
  protected $user;

  public function setUp()
  {
    // to test the write methods
    $this->user = new User();
    $this->credential = $this->getMock('cred', array('isOAuthRequest', 'getConsumer', 'checkRequest','getErrorAsString','getEmailFromOAuth'));
    $this->credential->expects($this->any())
      ->method('getConsumer')
      ->will($this->returnValue(array('foo')));
  }

  public function testGetAvatarFromEmailFromLibrary()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc', 'attrprofilePhoto' => 'http://foo/bar')));
    $themeObj = $this->getMock('ThemeObj', array('asset'));
    $themeObj->expects($this->any())
      ->method('asset')
      ->will($this->returnValue('/path/to/asset'));
    $this->user->inject('db', $db);
    $this->user->inject('themeObj', $themeObj);

    $_SERVER['HTTP_HOST'] = 'foo';

    $res = $this->user->getAvatarFromEmail(50, 'test@example.com');
    $this->assertEquals('http://foo/bar', $res);
  }

  public function testGetAvatarFromEmailGravatar()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc')));
    $themeObj = $this->getMock('ThemeObj', array('asset'));
    $themeObj->expects($this->any())
      ->method('asset')
      ->will($this->returnValue('/path/to/asset'));
    $config = new stdClass;
    $config->site = new stdClass;
    $config->site->useGravatar = 1;

    $this->user->inject('themeObj', $themeObj);
    $this->user->inject('db', $db);
    $this->user->inject('config', $config);

    $_SERVER['HTTP_HOST'] = 'foo';

    $res = $this->user->getAvatarFromEmail(50, 'test@example.com');
    $this->assertEquals('http://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=50&d=http%3A%2F%2Ffoo%2Fpath%2Fto%2Fasset', $res);
  }

  public function testGetAvatarFromEmailNoGravatar()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc')));
    $themeObj = $this->getMock('ThemeObj', array('asset'));
    $themeObj->expects($this->any())
      ->method('asset')
      ->will($this->returnValue('/path/to/asset'));
    $config = new stdClass;
    $config->site = new stdClass;
    $config->site->useGravatar = 0;

    $this->user->inject('themeObj', $themeObj);
    $this->user->inject('db', $db);
    $this->user->inject('config', $config);

    $_SERVER['HTTP_HOST'] = 'foo';

    $res = $this->user->getAvatarFromEmail(50, 'test@example.com');
    $this->assertEquals('http://foo/path/to/asset', $res);
  }

  public function testGetEmailAddressNonOAuth()
  {
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('test@example.com'));
    $this->user->inject('session', $session);
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $this->user->inject('credential', $this->credential);
    
    $res = $this->user->getEmailAddress();
    $this->assertEquals('test@example.com', $res);
  }

  public function testGetEmailAddressOAuth()
  {
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->any())
      ->method('getEmailFromOAuth')
      ->will($this->returnValue('test@example.com'));
    $this->user->inject('credential', $this->credential);
    
    $res = $this->user->getEmailAddress();
    $this->assertEquals('test@example.com', $res);
  }

  public function testGetEmailAddressNull()
  {
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue(null));
    $this->user->inject('session', $session);
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $this->user->inject('credential', $this->credential);
    
    $res = $this->user->getEmailAddress();
    $this->assertNull($res);
  }

  public function testGetUserByEmailFirstCallShouldCacheSuccess()
  {
    $db = $this->getMock('Db', array('getUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->onConsecutiveCalls(
        array('id' => 'test@example.com', 'seq' => 1),
        array('id' => 'test@example.com', 'seq' => 2)
      ));
    $this->user->inject('db', $db);
    $res = $this->user->getUserByEmail('foo@bar.com');
    $this->assertEquals(1, $res['seq']);

    $res = $this->user->getUserByEmail('foo@bar.com');
    $this->assertEquals(1, $res['seq']);
  }

  public function testGetUserByEmailSkipCacheSuccess()
  {
    $db = $this->getMock('Db', array('getUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->onConsecutiveCalls(
        array('id' => 'test@example.com', 'seq' => 1),
        array('id' => 'test@example.com', 'seq' => 2)
      ));
    $this->user->inject('db', $db);
    $res = $this->user->getUserByEmail('foo@bar.com');
    $this->assertEquals(1, $res['seq']);

    $res = $this->user->getUserByEmail('foo@bar.com', false);
    $this->assertEquals(2, $res['seq']);
  }

  public function testGetUserByEmailVerifyCacheByHandleSuccess()
  {
    $db = $this->getMock('Db', array('getUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->onConsecutiveCalls(
        array('id' => 'test1@example.com', 'seq' => 1),
        array('id' => 'test2@example.com', 'seq' => 2)
      ));
    $this->user->inject('db', $db);
    $res = $this->user->getUserByEmail('foo1@bar.com');
    $this->assertEquals(1, $res['seq']);

    $res = $this->user->getUserByEmail('foo2@bar.com');
    $this->assertEquals(2, $res['seq']);
  }

  public function testGetUserByEmailCachedSuccess()
  {
    $this->user->inject('userArray', array('foo@bar.com' => '123'));
    $res = $this->user->getUserByEmail('foo@bar.com');
    $this->assertEquals('123', $res);
  }

  public function testGetNextIdPhoto()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->onConsecutiveCalls(
        array('id' => 'test@example.com', 'lastPhotoId' => 'abc'),
        array('id' => 'test@example.com', 'lastPhotoId' => '0'),
        array('id' => 'test@example.com', 'lastPhotoId' => 'a1'),
        array('id' => 'test@example.com', 'lastPhotoId' => '9'),
        array('id' => 'test@example.com', 'lastPhotoId' => 'u')
      ));
    $db->expects($this->any())
      ->method('postUser')
      ->will($this->returnValue(true));
    $db->expects($this->any())
      ->method('putUser')
      ->will($this->returnValue(true));
    $this->user->inject('db', $db);

    // abc
    $res = $this->user->getNextId('photo');
    $this->assertEquals('abd', $res);
    // 0
    $res = $this->user->getNextId('photo');
    $this->assertEquals('1', $res);
    // a1
    $res = $this->user->getNextId('photo');
    $this->assertEquals('a2', $res);
    // 9
    $res = $this->user->getNextId('photo');
    $this->assertEquals('a', $res);
    // u
    $res = $this->user->getNextId('photo');
    $this->assertEquals('10', $res);
  }

  public function testGetNextIdPhotoFirstId()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(array('id' => 'test@example.com')));
    $db->expects($this->any())
      ->method('postUser')
      ->will($this->returnValue(true));
    $this->user->inject('db', $db);

    $res = $this->user->getNextId('photo');
    $this->assertEquals('1', $res);
  }

  public function testGetNextIdPhotoKeyNotExistYet()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(array('id' => 'test@example.com', 'lastActionId' => 'def')));
    $db->expects($this->any())
      ->method('postUser')
      ->will($this->returnValue(true));
    $this->user->inject('db', $db);

    $res = $this->user->getNextId('photo');
    $this->assertEquals('1', $res);
  }

  public function testGetNextIdFailure()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(false));
    $this->user->inject('db', $db);

    $res = $this->user->getNextId('photo');
    $this->assertFalse($res);
  }

  public function testGetNextIdUpdateFailure()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->onConsecutiveCalls(
        array('id' => 'test@example.com', 'lastPhotoId' => 'abc'),
        array('id' => '', 'lastPhotoId' => '')
      ));
    $db->expects($this->any())
      ->method('postUser')
      ->will($this->returnValue(false));
    $this->user->inject('db', $db);

    // abc
    $res = $this->user->getNextId('photo');
    $this->assertEquals(false, $res);
  }


  public function testGetAttributeNameSuccess()
  {
    $res = $this->user->getAttributeName('foobar');
    $this->assertEquals('attrfoobar', $res);
  }

  public function testGetAttributeSuccess()
  {
    $this->user->inject('user', array('attrfoobar' => '1234'));
    $res = $this->user->getAttribute('foobar');
    $this->assertEquals('1234', $res);
  }

  public function testGetAttributeFailure()
  {
    $this->user->inject('user', array('attrfoobar' => '1234'));
    $res = $this->user->getAttribute('foobarx');
    $this->assertEquals(false, $res);
  }

  public function testGetUserRecordFromRuntimeCache()
  {
    $this->user->inject('user', '1');
    $res = $this->user->getUserRecord();
    $this->assertEquals('1', $res);
  }

  public function testGetUserRecordOverridingRuntimeCache()
  {
    $this->user->inject('user', '1');

    $db = $this->getMock('Db', array('getUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue('2'));
    $this->user->inject('db', $db);

    $this->user->clearUserCache();
    $res = $this->user->getUserRecord();
    $this->assertEquals('2', $res);
  }

  public function testGetUserRecordWhenNullAndFailsToCreate()
  {
    $db = $this->getMock('Db', array('getUser', 'putUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(null));
    $db->expects($this->any())
      ->method('putUser')
      ->will($this->returnValue(false));
    $this->user->inject('db', $db);

    $res = $this->user->getUserRecord();
    $this->assertFalse($res);
  }

  public function testGetUserRecordWhenNull()
  {
    $db = $this->getMock('Db', array('getUser', 'putUser'));
    $db->expects($this->at(1))
      ->method('getUser')
      ->will($this->returnValue(null));
    $db->expects($this->at(2))
      ->method('getUser')
      ->will($this->returnValue('1'));
    $db->expects($this->any())
      ->method('putUser')
      ->will($this->returnValue(true));
    $this->user->inject('db', $db);

    $res = $this->user->getUserRecord();
    $this->assertEquals('1', $res);
  }

  public function testGetUserRecordWhenError()
  {
    $db = $this->getMock('Db', array('getUser'));
    $db->expects($this->once())
      ->method('getUser')
      ->will($this->returnValue(false));
    $this->user->inject('db', $db);

    $res = $this->user->getUserRecord();
    $this->assertFalse($res);
  }
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertTrue($res);
  }

    $this->user->inject('session', $session);
    $this->user->inject('credential', $this->credential);

    $res = $this->user->isLoggedIn();
    $this->assertFalse($res);
  }

  public function testIsLoggedInFalseWithOAuth()
  {
    $this->credential->expects($this->once())
      ->method('isOAuthRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('checkRequest')
      ->will($this->returnValue(false));
    $this->user->inject('credential', $this->credential);

    $res = $this->user->isLoggedIn();
    $this->assertFalse($res);
  }

  public function testIsLoggedInTrue()
  {
    $this->credential->expects($this->once())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('test@example.com'));
    $this->user->inject('session', $session);
    $this->user->inject('credential', $this->credential);

    $res = $this->user->isLoggedIn();
    $this->assertTrue($res);
  }

  public function testIsLoggedInTrueWithOAuth()
  {
    $this->credential->expects($this->once())
      ->method('isOAuthRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('checkRequest')
      ->will($this->returnValue(true));
    $this->user->inject('credential', $this->credential);

    $res = $this->user->isLoggedIn();
    $this->assertTrue($res);
  }

  public function testIsOwnerFalse()
  {
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue(null));
    $this->user->inject('session', $session);
    $this->user->inject('credential', $this->credential);
    $this->user->inject('config', new FauxObject);

    $res = $this->user->isOwner();
    $this->assertFalse($res);
  }

  public function testIsOwnerFalseLoggedInAsSomeoneElse()
  {
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('someoneelse@example.com'));
    $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('test@example.com'));
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'test@example.com';
    $this->user->inject('session', $session);
    $this->user->inject('credential', $this->credential);
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertFalse($res);
  }

  public function testIsOwnerTrue()
  {
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('test@example.com'));
    $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('test@example.com'));
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'test@example.com';
    $this->user->inject('session', $session);
    $this->user->inject('credential', $this->credential);
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertTrue($res);
  }

  public function testIsOwnerTrueLoggedInAsAdmin()
  {
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('someoneelse@example.com'));
    $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('test@example.com'));
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'test@example.com';
    $config->user->admins = 'someoneelse@example.com';
    $this->user->inject('session', $session);
    $this->user->inject('credential', $this->credential);
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertFalse($res);
    $res = $this->user->isOwner(true);
    $this->assertTrue($res);
    $res = $this->user->isAdmin();
    $this->assertTrue($res);
  }

  public function testIsOwnerTrueLoggedInAsAdminIgnoreCase()
  {
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('someoneelse@example.com'));
    $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('test@example.com'));
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'test@example.com';
    $config->user->admins = 'SoMeOnEeLsE@ExAmPlE.CoM';
    $this->user->inject('session', $session);
    $this->user->inject('credential', $this->credential);
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertFalse($res);
    $res = $this->user->isOwner(true);
    $this->assertTrue($res);
    $res = $this->user->isAdmin();
    $this->assertTrue($res);
  }

  public function testIsOwnerOAuthInvalid()
  {
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('checkRequest')
      ->will($this->returnValue(false));
    $this->user->inject('credential', $this->credential);
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'doesnt matter';
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertFalse($res);
  }

  public function testIsOwnerOAuthValidNotOwner()
  {
    $this->credential->expects($this->once())
      ->method('isOAuthRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('checkRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('getEmailFromOAuth')
      ->will($this->returnValue('test@example.com'));
    $this->user->inject('credential', $this->credential);
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'different@example.com';
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertFalse($res);
  }

  public function testIsOwnerOAuthTrue()
  {
    $this->credential->expects($this->once())
      ->method('isOAuthRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('checkRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('getEmailFromOAuth')
      ->will($this->returnValue('test@example.com'));
    $this->user->inject('credential', $this->credential);
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'test@example.com';
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertTrue($res);
  }

  public function testIsOwnerIgnoreCase()
  {
    $this->credential->expects($this->any())
      ->method('isOAuthRequest')
      ->will($this->returnValue(false));
    $session = $this->getMock('session', array('get'));
    $session->expects($this->any())
      ->method('get')
      ->will($this->returnValue('TeSt@eXaMpLe.CoM'));
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'test@example.com';
    $this->user->inject('session', $session);
    $this->user->inject('credential', $this->credential);
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertTrue($res);
  }

  public function testIsOwnerOAuthIgnoreCase()
  {
    $this->credential->expects($this->once())
      ->method('isOAuthRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('checkRequest')
      ->will($this->returnValue(true));
    $this->credential->expects($this->once())
      ->method('getEmailFromOAuth')
      ->will($this->returnValue('TeSt@ExAmPlE.CoM'));
    $this->user->inject('credential', $this->credential);
    $config = new stdClass;
    $config->user = new stdClass;
    $config->user->email = 'test@example.com';
    $this->user->inject('config', $config);

    $res = $this->user->isOwner();
    $this->assertTrue($res);
  }

  public function testLogin()
  {
    $this->markTestIncomplete('This test has not been implemented yet.');
  }

  public function testSetEmail()
  {
    $session = $this->getMock('session', array('set'));
    $session->expects($this->any())
      ->method('set')
      ->will($this->returnValue('test@example.com'));
    $config = arrayToObject(array('secrets' => array('secret' => 'foo')));
    $this->user->inject('config', $config);
    $this->user->inject('session', $session);

    $res = $this->user->setEmail('foo');
    $this->assertNull($res);
  }

  public function testUpdateSuccess()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc', 'lastActionId' => 'def')));
    $db->expects($this->any())
      ->method('postUser')
      ->will($this->returnValue(true));
    $this->user->inject('db', $db);

    $res = $this->user->update(array('id' => '123'));
    $this->assertTrue($res);
  }

  public function testUpdateCacheIsUpdatedSuccess()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->onConsecutiveCalls(array(),2));
    $db->expects($this->any())
      ->method('postUser')
      ->will($this->returnValue(true));
    $this->user->inject('db', $db);

    $res = $this->user->update(array('id' => '123'));
    $this->assertTrue($res);

    $user = $this->user->getUserRecord();
    $this->assertEquals(2, $user);
  }

  public function testUpdateFailure()
  {
    $db = $this->getMock('Db', array('getUser', 'postUser'));
    $db->expects($this->any())
      ->method('getUser')
      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc', 'lastActionId' => 'def')));
    $db->expects($this->any())
      ->method('postUser')
      ->will($this->returnValue(false));
    $this->user->inject('db', $db);

    $res = $this->user->update(array('id' => '123'));
    $this->assertFalse($res);
  }
}

<MSG> Merge branch 'gh-731' of ../frontend into development

<DFF> @@ -372,6 +372,10 @@ class UserTest extends PHPUnit_Framework_TestCase
     $this->user->inject('config', $config);
 
     $res = $this->user->isOwner();
+    $this->assertFalse($res);
+    $res = $this->user->isOwner(true);
+    $this->assertTrue($res);
+    $res = $this->user->isAdmin();
     $this->assertTrue($res);
   }
 

{'commit': 'diff --git a/src/html/assets/themes/beisel/templates/error403.php b/src/html/assets/themes/beisel/templates/error403.php\nindex b164cc55..aedc9391 100644\n--- a/src/html/assets/themes/beisel/templates/error403.php\n+++ b/src/html/assets/themes/beisel/templates/error403.php\n@@ -1,5 +1,5 @@\n <img src="<?php echo $this->theme->asset(\'image\', \'error.png\'); ?>">\n-<?php if($this->user->isLoggedIn() && !$this->user->isOwner()) { ?>\n+<?php if($this->user->isLoggedIn() && !$this->user->isAdmin()) { ?>\n   <h1>Sorry, but you don\'t have permission to view this page.</h1>\n <?php } else { ?>\n   <h1>You need to be logged in to view this page.</h1>\ndiff --git a/src/html/assets/themes/beisel/templates/front.php b/src/html/assets/themes/beisel/templates/front.php\nindex 9e64dbba..8d8c6bd6 100644\n--- a/src/html/assets/themes/beisel/templates/front.php\n+++ b/src/html/assets/themes/beisel/templates/front.php\n@@ -13,7 +13,7 @@\n <?php */ ?>\n \n <?php if($photos[0][\'totalRows\'] == 0) { ?>\n-  <?php if($this->user->isOwner()) { ?>\n+  <?php if($this->user->isAdmin()) { ?>\n     <a href="<?php $this->url->photoUpload(); ?>" class="link" title="Start uploading now!"><img src="<?php $this->theme->asset(\'image\', \'front.png\'); ?>" class="front" /></a>\n     <h1>Oh no, you haven\'t uploaded any photos yet. <a href="<?php $this->url->photoUpload(); ?>" class="link">Start Now</h1>\n   <?php } else { ?>\ndiff --git a/src/html/assets/themes/beisel/templates/partials/navigation.php b/src/html/assets/themes/beisel/templates/partials/navigation.php\nindex 8aa2f52a..14f5b511 100644\n--- a/src/html/assets/themes/beisel/templates/partials/navigation.php\n+++ b/src/html/assets/themes/beisel/templates/partials/navigation.php\n@@ -5,7 +5,7 @@\n \t<li id="nav-tags" <?php if($this->utility->isActiveTab(\'tags\')) { ?> class="active" <?php } ?>>\n \t\t<a href="<?php $this->url->tagsView(); ?>">Tags</a>\n \t</li>\n-<?php if($this->user->isOwner()) { ?>\n+<?php if($this->user->isAdmin()) { ?>\n \t<li id="nav-upload" <?php if($this->utility->isActiveTab(\'upload\')) { ?> class="active" <?php } ?>>\n \t\t<a href="<?php $this->url->photosUpload(); ?>">Upload</a>\n \t</li>\ndiff --git a/src/html/assets/themes/beisel/templates/photo-details.php b/src/html/assets/themes/beisel/templates/photo-details.php\nindex 91aa9bc1..efa5bb9e 100644\n--- a/src/html/assets/themes/beisel/templates/photo-details.php\n+++ b/src/html/assets/themes/beisel/templates/photo-details.php\n@@ -22,7 +22,7 @@\n               <span>Marked this photo as a favorite.</span>\n             <?php } ?>\n             <span class="date">\n-              <?php if($this->user->isOwner()) { ?>\n+              <?php if($this->user->isAdmin()) { ?>\n                 <form method="post" action="<?php $this->url->actionDelete($action[\'id\']); ?>">\n                   <input type="hidden" name="crumb" value="<?php echo $crumb; ?>">\n                   <a href="<?php $this->url->actionDelete($action[\'id\']); ?>" data-id="<?php $this->utility->safe($action[\'id\']); ?>" class="action-delete-click"><span></span>Delete comment</a>\ndiff --git a/src/html/assets/themes/beisel/templates/photos.php b/src/html/assets/themes/beisel/templates/photos.php\nindex 396eb5f6..96e859cf 100644\n--- a/src/html/assets/themes/beisel/templates/photos.php\n+++ b/src/html/assets/themes/beisel/templates/photos.php\n@@ -20,7 +20,7 @@\n   <br clear="all">\n   <span class="paginationbottom"><?php $this->theme->display(\'partials/pagination.php\', array_merge($pages, array(\'labelPosition\' => \'bottom\'))); ?></span>\n <?php } else { ?>\n-  <?php if($this->user->isOwner()) { ?>\n+  <?php if($this->user->isAdmin()) { ?>\n     <a href="<?php $this->url->photoUpload(); ?>" class="link" title="Start uploading now!"><img src="<?php $this->theme->asset(\'image\', \'front.png\'); ?>" class="front" /></a>\n     <h1>There don\'t seem to be any photos. You should <a href="<?php $this->url->photosUpload(); ?>" class="link">upload</a> some.</h1>\n     <p>\ndiff --git a/src/html/assets/themes/beisel/templates/template.php b/src/html/assets/themes/beisel/templates/template.php\nindex 5ae84a66..e2c02066 100644\n--- a/src/html/assets/themes/beisel/templates/template.php\n+++ b/src/html/assets/themes/beisel/templates/template.php\n@@ -15,7 +15,7 @@\n       <link rel="stylesheet" href="<?php $this->theme->asset(\'stylesheet\', \'bootstrap.min.css\'); ?>">\n       <link rel="stylesheet" href="/assets/stylesheets/upload.css">\n       <link rel="stylesheet" href="<?php $this->theme->asset(\'stylesheet\', \'main.css\'); ?>">\n-      <?php if(true || $this->user->isOwner()) { ?>\n+      <?php if(true || $this->user->isAdmin()) { ?>\n         <link rel="stylesheet" href="<?php $this->theme->asset(\'stylesheet\', \'owner.css\'); ?>">\n       <?php } ?>\n     <?php } else { ?>\n@@ -23,7 +23,7 @@\n                                                                   addCss("/assets/stylesheets/upload.css")->\n                                                                   addCss($this->theme->asset(\'stylesheet\', \'main.css\', false))->\n                                                                   getUrl(AssetPipeline::css, \'i\'); ?>">\n-      <?php if(true || $this->user->isOwner()) { ?>\n+      <?php if(true || $this->user->isAdmin()) { ?>\n         <link rel="stylesheet" href="<?php echo getAssetPipeline(true)->addCss($this->theme->asset(\'stylesheet\', \'owner.css\', false))->\n                                                                   getUrl(AssetPipeline::css, \'d\'); ?>">\n       <?php } ?>\n@@ -99,7 +99,7 @@\n             \'upload-start-click\':\'click:upload-start\',\n             \'webhook-delete-click\':\'click:webhook-delete\'\n         },\n-        <?php if($this->user->isOwner()) { ?>\n+        <?php if($this->user->isAdmin()) { ?>\n           \'change\': {\n               \'batch-field-change\':\'change:batch-field\'\n           },\ndiff --git a/src/html/assets/themes/beisel2.0/templates/partials/navigation.php b/src/html/assets/themes/beisel2.0/templates/partials/navigation.php\nindex 7d17921b..65f78ea4 100644\n--- a/src/html/assets/themes/beisel2.0/templates/partials/navigation.php\n+++ b/src/html/assets/themes/beisel2.0/templates/partials/navigation.php\n@@ -12,7 +12,7 @@\n           <li class="photos"><a href="<?php $this->url->photosView(); ?>"><i class="icon-picture icon-large"></i> Gallery</a></li>\n           <li class="albums"><a href="<?php $this->url->albumsView(); ?>"><i class="icon-th icon-large"></i> Albums</a></li>\n           <li class="tags"><a href="<?php $this->url->tagsView(); ?>"><i class="icon-tags icon-large"></i> Tags</a></li>\n-          <?php if($this->user->isOwner()) { ?>\n+          <?php if($this->user->isAdmin()) { ?>\n             <li class="upload"><a href="<?php $this->url->photosUpload(); ?>"><i class="icon-upload-alt icon-large"></i> Upload</a></li>\n             <li class="manage">\n               <ul class="nav pull-right">\ndiff --git a/src/html/assets/themes/beisel2.0/templates/partials/no-content.php b/src/html/assets/themes/beisel2.0/templates/partials/no-content.php\nindex 9feaab51..be672e9f 100644\n--- a/src/html/assets/themes/beisel2.0/templates/partials/no-content.php\n+++ b/src/html/assets/themes/beisel2.0/templates/partials/no-content.php\n@@ -26,11 +26,11 @@\n       <p>Start by clicking the <a href="#" class="login-modal-click"><i class="icon-signin icon-large"></i> sign in</a> or <a href="https://openphoto.me"><i class="icon-plus icon-large"></i> register</a> button.</p>\n     <?php } ?>\n   <?php } else { // user is logged in ?>\n-    <?php if($this->user->isOwner() && $type == \'upload\') { // message to upload photos ?>\n+    <?php if($this->user->isAdmin() && $type == \'upload\') { // message to upload photos ?>\n       <strong class="bigtext"><i class="icon-upload-alt icon-large"></i></strong><br/>\n       <h1>Either you haven\'t uploaded photos yet or none matched your search.</h1>\n       <p>Start now by clicking the <a href="<?php $this->url->photosUpload(); ?>"><i class="icon-upload-alt icon-large"></i> upload button</a>!</p>\n-    <?php } else if($this->user->isOwner() && $type == \'albums\') { // message to create albums ?>\n+    <?php } else if($this->user->isAdmin() && $type == \'albums\') { // message to create albums ?>\n       <strong class="bigtext"><i class="icon-th icon-large"></i></strong><br/>\n       <h1>You haven\'t created an albums on OpenPhoto yet.</h1>\n       <p>Start now by clicking the <a href="<?php $this->url->manageAlbums(); ?>"><i class="icon-th icon-large"></i> manage albums button</a>!</p>\n@@ -42,7 +42,7 @@\n     <?php } else { // default with message appropriate for owner/visitor ?>\n       <strong class="bigtext">:-(</strong><br/>\n       <h1>Sorry, nothing to see here.</h1>\n-      <?php if($this->user->isOwner()) { ?>\n+      <?php if($this->user->isAdmin()) { ?>\n         <p>You can <a href="<?php $this->url->photosUpload(); ?>"><i class="icon-upload-alt icon-large"></i> upload photos</a> or <a href="<?php $this->url->manage(); ?>"><i class="icon-upload-alt icon-large"></i> manage your account</a>.</p>\n       <?php } else { ?>\n         <p>You can <a href="https://openphoto.me"><i class="icon-plus icon-large"></i> register</a> for your own account.</p>\ndiff --git a/src/html/assets/themes/beisel2.0/templates/photo-details.php b/src/html/assets/themes/beisel2.0/templates/photo-details.php\nindex 1084cf33..5a6e341f 100644\n--- a/src/html/assets/themes/beisel2.0/templates/photo-details.php\n+++ b/src/html/assets/themes/beisel2.0/templates/photo-details.php\n@@ -126,10 +126,10 @@\n         <div class="iconbox">\n           <a href="#" class="invert"><i class="icon-comment"></i> <?php echo count($photo[\'actions\']); ?> comments &amp; favorites</a>\n           <a href="#" class="invert"><i class="icon-eye-open"></i> <?php $this->utility->licenseName($photo[\'license\']); ?></a>\n-          <?php if($this->user->isOwner() || $this->config->site->allowOriginalDownload == 1) { ?>\n+          <?php if($this->user->isAdmin() || $this->config->site->allowOriginalDownload == 1) { ?>\n             <a href="<?php $this->url->photoDownload($photo); ?>" class="invert"><i class="icon-download"></i> Download original</a>\n           <?php } ?>\n-          <?php if($this->user->isOwner()) { ?>\n+          <?php if($this->user->isAdmin()) { ?>\n             <a href="#" class="photo-edit-click invert" data-id="<?php $this->utility->safe($photo[\'id\']); ?>"><i class="icon-edit"></i> Edit details</a>\n           <?php } ?>\n         </div>\ndiff --git a/src/html/assets/themes/beisel2.0/templates/template.php b/src/html/assets/themes/beisel2.0/templates/template.php\nindex e6dce50b..61f2b186 100644\n--- a/src/html/assets/themes/beisel2.0/templates/template.php\n+++ b/src/html/assets/themes/beisel2.0/templates/template.php\n@@ -137,7 +137,7 @@\n               \'plugin-update-submit\':\'submit:plugin-update\',\n               \'search-submit\':\'submit:search\'\n           },\n-          <?php if($this->user->isOwner()) { ?>\n+          <?php if($this->user->isAdmin()) { ?>\n             \'change\': {\n                 \'batch-field-change\':\'change:batch-field\'\n             },\ndiff --git a/src/html/assets/themes/default/templates/error403.php b/src/html/assets/themes/default/templates/error403.php\nindex 913b0858..c62989cf 100644\n--- a/src/html/assets/themes/default/templates/error403.php\n+++ b/src/html/assets/themes/default/templates/error403.php\n@@ -1,4 +1,4 @@\n-<?php if($this->user->isLoggedIn() && !$this->user->isOwner()) { ?>\n+<?php if($this->user->isLoggedIn() && !$this->user->isAdmin()) { ?>\n   <h1>Sorry, but you don\'t have permission to view this page.</h1>\n <?php } else { ?>\n   <h1>You need to be logged in to view this page.</h1>\ndiff --git a/src/html/assets/themes/default/templates/front.php b/src/html/assets/themes/default/templates/front.php\nindex e56e439d..c0ad6185 100644\n--- a/src/html/assets/themes/default/templates/front.php\n+++ b/src/html/assets/themes/default/templates/front.php\n@@ -1,7 +1,7 @@\n <div class="front">\n   <p>\n     <?php if($photos[0][\'totalRows\'] == 0) { ?>\n-      <?php if($this->user->isOwner()) { ?>\n+      <?php if($this->user->isAdmin()) { ?>\n         <h1>Oh no, you haven\'t uploaded any photos yet. <a href="<?php $this->url->photoUpload(); ?>" class="button">Start Now</a>\n         <img src="<?php $this->theme->asset(\'image\', \'front.jpg\'); ?>" class="front">\n       <?php } else { ?>\ndiff --git a/src/html/assets/themes/default/templates/partials/navigation.php b/src/html/assets/themes/default/templates/partials/navigation.php\nindex f5c0924d..1c69d991 100644\n--- a/src/html/assets/themes/default/templates/partials/navigation.php\n+++ b/src/html/assets/themes/default/templates/partials/navigation.php\n@@ -16,7 +16,7 @@\n       </form>\n     </div>\n   </li>\n-  <?php if($this->user->isOwner()) { ?>\n+  <?php if($this->user->isAdmin()) { ?>\n     <li id="nav-upload" <?php if($this->utility->isActiveTab(\'search\')) { ?> class="on" <?php } ?>>\n       <a href="<?php $this->url->photosUpload(); ?>"><i class="icon-upload-alt"></i>Upload</a>\n     </li>\ndiff --git a/src/html/assets/themes/default/templates/photo-details.php b/src/html/assets/themes/default/templates/photo-details.php\nindex ebe4b905..73653c7d 100644\n--- a/src/html/assets/themes/default/templates/photo-details.php\n+++ b/src/html/assets/themes/default/templates/photo-details.php\n@@ -73,7 +73,7 @@\n         <?php } ?>\n         <div class="date">\n           <?php echo $this->utility->dateLong($action[\'datePosted\']); ?>\n-          <?php if($this->user->isOwner()) { ?>\n+          <?php if($this->user->isAdmin()) { ?>\n             <form method="post" action="<?php $this->url->actionDelete($action[\'id\']); ?>">\n               <input type="hidden" name="crumb" value="<?php echo $crumb; ?>">\n               (<a href="<?php $this->url->actionDelete($action[\'id\']); ?>" class="action-delete-click" data-id="<?php $this->utility->safe($action[\'id\']); ?>">delete</a>)\ndiff --git a/src/html/assets/themes/default/templates/photos.php b/src/html/assets/themes/default/templates/photos.php\nindex 931f79ea..fc35e8af 100644\n--- a/src/html/assets/themes/default/templates/photos.php\n+++ b/src/html/assets/themes/default/templates/photos.php\n@@ -16,7 +16,7 @@\n   <br clear="all">\n   <?php $this->theme->display(\'partials/pagination.php\', array_merge($pages, array(\'labelPosition\' => \'bottom\'))); ?>\n <?php } else { ?>\n-  <?php if($this->user->isOwner()) { ?>\n+  <?php if($this->user->isAdmin()) { ?>\n     <h1>There don\'t seem to be any photos. You should <a href="<?php $this->url->photosUpload(); ?>">upload</a> some.</h1>\n     <p>\n       If you\'re searching for photos then there aren\'t any which match your query.\ndiff --git a/src/html/assets/themes/fabrizio1.0/templates/partials/navigation.php b/src/html/assets/themes/fabrizio1.0/templates/partials/navigation.php\nindex 7d17921b..65f78ea4 100644\n--- a/src/html/assets/themes/fabrizio1.0/templates/partials/navigation.php\n+++ b/src/html/assets/themes/fabrizio1.0/templates/partials/navigation.php\n@@ -12,7 +12,7 @@\n           <li class="photos"><a href="<?php $this->url->photosView(); ?>"><i class="icon-picture icon-large"></i> Gallery</a></li>\n           <li class="albums"><a href="<?php $this->url->albumsView(); ?>"><i class="icon-th icon-large"></i> Albums</a></li>\n           <li class="tags"><a href="<?php $this->url->tagsView(); ?>"><i class="icon-tags icon-large"></i> Tags</a></li>\n-          <?php if($this->user->isOwner()) { ?>\n+          <?php if($this->user->isAdmin()) { ?>\n             <li class="upload"><a href="<?php $this->url->photosUpload(); ?>"><i class="icon-upload-alt icon-large"></i> Upload</a></li>\n             <li class="manage">\n               <ul class="nav pull-right">\ndiff --git a/src/html/assets/themes/fabrizio1.0/templates/partials/no-content.php b/src/html/assets/themes/fabrizio1.0/templates/partials/no-content.php\nindex 9feaab51..be672e9f 100644\n--- a/src/html/assets/themes/fabrizio1.0/templates/partials/no-content.php\n+++ b/src/html/assets/themes/fabrizio1.0/templates/partials/no-content.php\n@@ -26,11 +26,11 @@\n       <p>Start by clicking the <a href="#" class="login-modal-click"><i class="icon-signin icon-large"></i> sign in</a> or <a href="https://openphoto.me"><i class="icon-plus icon-large"></i> register</a> button.</p>\n     <?php } ?>\n   <?php } else { // user is logged in ?>\n-    <?php if($this->user->isOwner() && $type == \'upload\') { // message to upload photos ?>\n+    <?php if($this->user->isAdmin() && $type == \'upload\') { // message to upload photos ?>\n       <strong class="bigtext"><i class="icon-upload-alt icon-large"></i></strong><br/>\n       <h1>Either you haven\'t uploaded photos yet or none matched your search.</h1>\n       <p>Start now by clicking the <a href="<?php $this->url->photosUpload(); ?>"><i class="icon-upload-alt icon-large"></i> upload button</a>!</p>\n-    <?php } else if($this->user->isOwner() && $type == \'albums\') { // message to create albums ?>\n+    <?php } else if($this->user->isAdmin() && $type == \'albums\') { // message to create albums ?>\n       <strong class="bigtext"><i class="icon-th icon-large"></i></strong><br/>\n       <h1>You haven\'t created an albums on OpenPhoto yet.</h1>\n       <p>Start now by clicking the <a href="<?php $this->url->manageAlbums(); ?>"><i class="icon-th icon-large"></i> manage albums button</a>!</p>\n@@ -42,7 +42,7 @@\n     <?php } else { // default with message appropriate for owner/visitor ?>\n       <strong class="bigtext">:-(</strong><br/>\n       <h1>Sorry, nothing to see here.</h1>\n-      <?php if($this->user->isOwner()) { ?>\n+      <?php if($this->user->isAdmin()) { ?>\n         <p>You can <a href="<?php $this->url->photosUpload(); ?>"><i class="icon-upload-alt icon-large"></i> upload photos</a> or <a href="<?php $this->url->manage(); ?>"><i class="icon-upload-alt icon-large"></i> manage your account</a>.</p>\n       <?php } else { ?>\n         <p>You can <a href="https://openphoto.me"><i class="icon-plus icon-large"></i> register</a> for your own account.</p>\ndiff --git a/src/html/assets/themes/fabrizio1.0/templates/photo-details.php b/src/html/assets/themes/fabrizio1.0/templates/photo-details.php\nindex 58ca88fb..ff1f714f 100644\n--- a/src/html/assets/themes/fabrizio1.0/templates/photo-details.php\n+++ b/src/html/assets/themes/fabrizio1.0/templates/photo-details.php\n@@ -126,10 +126,10 @@\n         <div class="iconbox">\n           <a href="#" class="invert"><i class="icon-comment"></i> <?php echo count($photo[\'actions\']); ?> comments &amp; favorites</a>\n           <a href="#" class="invert"><i class="icon-eye-open"></i> <?php $this->utility->licenseName($photo[\'license\']); ?></a>\n-          <?php if($this->user->isOwner() || $this->config->site->allowOriginalDownload == 1) { ?>\n+          <?php if($this->user->isAdmin() || $this->config->site->allowOriginalDownload == 1) { ?>\n             <a href="<?php $this->url->photoDownload($photo); ?>" class="invert"><i class="icon-download"></i> Download original</a>\n           <?php } ?>\n-          <?php if($this->user->isOwner()) { ?>\n+          <?php if($this->user->isAdmin()) { ?>\n             <a href="#" class="photo-edit-click invert" data-id="<?php $this->utility->safe($photo[\'id\']); ?>"><i class="icon-edit"></i> Edit details</a>\n           <?php } ?>\n         </div>\ndiff --git a/src/html/assets/themes/fabrizio1.0/templates/template.php b/src/html/assets/themes/fabrizio1.0/templates/template.php\nindex e6dce50b..61f2b186 100644\n--- a/src/html/assets/themes/fabrizio1.0/templates/template.php\n+++ b/src/html/assets/themes/fabrizio1.0/templates/template.php\n@@ -137,7 +137,7 @@\n               \'plugin-update-submit\':\'submit:plugin-update\',\n               \'search-submit\':\'submit:search\'\n           },\n-          <?php if($this->user->isOwner()) { ?>\n+          <?php if($this->user->isAdmin()) { ?>\n             \'change\': {\n                 \'batch-field-change\':\'change:batch-field\'\n             },\ndiff --git a/src/libraries/adapters/DatabaseMySql.php b/src/libraries/adapters/DatabaseMySql.php\nindex 451f8908..e859aa29 100644\n--- a/src/libraries/adapters/DatabaseMySql.php\n+++ b/src/libraries/adapters/DatabaseMySql.php\n@@ -12,7 +12,7 @@ class DatabaseMySql implements DatabaseInterface\n     * Member variables holding the names to the SimpleDb domains needed and the database object itself.\n     * @access private\n     */\n-  private $actor, $config, $errors = array(), $owner, $mySqlDb, $mySqlHost, $mySqlUser, $mySqlPassword, $mySqlTablePrefix;\n+  private $actor, $config, $errors = array(), $isOwner, $isAdmin, $owner, $mySqlDb, $mySqlHost, $mySqlUser, $mySqlPassword, $mySqlTablePrefix;\n \n   /**\n     * Constructor\n@@ -1413,10 +1413,15 @@ class DatabaseMySql implements DatabaseInterface\n     $where = "WHERE `{$this->mySqlTablePrefix}{$table}`.`owner`=\'{$this->owner}\'";\n     if($table === \'activity\')\n     {\n-      $ids = array($this->getActor());\n-      $queryForFollows = $this->db->all("SELECT `follows` FROM `{$this->mySqlTablePrefix}relationship` WHERE `actor`=:actor", array(\':actor\' => $this->getActor()));\n-      foreach($queryForFollows as $followRes)\n-        $ids[] = $this->_($followRes[\'follows\']);\n+      // for owners and admins we get social feed\n+      // for everyone else just get activity for this site\n+      $ids = array($this->owner);\n+      if($this->isAdmin())\n+      {\n+        $queryForFollows = $this->db->all("SELECT `follows` FROM `{$this->mySqlTablePrefix}relationship` WHERE `actor`=:actor", array(\':actor\' => $this->getActor()));\n+        foreach($queryForFollows as $followRes)\n+          $ids[] = $this->_($followRes[\'follows\']);\n+      }\n       $ids = sprintf("\'%s\'", implode("\',\'", $ids));\n       $where = "WHERE `{$this->mySqlTablePrefix}{$table}`.`owner` IN({$ids})";\n     }\n@@ -1600,6 +1605,15 @@ class DatabaseMySql implements DatabaseInterface\n     return $this->actor;\n   }\n \n+  private function isAdmin()\n+  {\n+    if($this->isAdmin !== null)\n+      return $this->isAdmin;\n+\n+    $user = new User;\n+    return $user->isAdmin();\n+  }\n+\n   /**\n     * Get all the versions of a given photo\n     * TODO this can be eliminated once versions are in the json field\ndiff --git a/src/libraries/controllers/ApiGroupController.php b/src/libraries/controllers/ApiGroupController.php\nindex 7d8de684..98dcd1af 100644\n--- a/src/libraries/controllers/ApiGroupController.php\n+++ b/src/libraries/controllers/ApiGroupController.php\n@@ -97,7 +97,7 @@ class ApiGroupController extends ApiBaseController\n     getAuthentication()->requireAuthentication();\n \n     $userObj = new User;\n-    if(!$userObj->isOwner())\n+    if(!$userObj->isAdmin())\n       return $this->forbidden(\'You do not have permission to access this API.\', false);\n \n     $groups = $this->group->getGroups();\ndiff --git a/src/libraries/controllers/ApiPhotoController.php b/src/libraries/controllers/ApiPhotoController.php\nindex bf636f73..9f510f76 100644\n--- a/src/libraries/controllers/ApiPhotoController.php\n+++ b/src/libraries/controllers/ApiPhotoController.php\n@@ -696,7 +696,7 @@ class ApiPhotoController extends ApiBaseController\n     {\n       return $this->notFound("Photo {$id} not found", false);\n     }\n-    elseif(!$this->user->isOwner())\n+    elseif(!$this->user->isAdmin())\n     {\n       if($photo[\'permission\'] == 0)\n       {\n@@ -800,7 +800,7 @@ class ApiPhotoController extends ApiBaseController\n     $groupsObj = new Group;\n     // If the user is logged in then we can display photos based on group membership\n     $permission = 0;\n-    if($this->user->isOwner())\n+    if($this->user->isAdmin())\n     {\n       $permission = 1;\n     }\ndiff --git a/src/libraries/controllers/ApiTagController.php b/src/libraries/controllers/ApiTagController.php\nindex 98b6c188..d969595e 100644\n--- a/src/libraries/controllers/ApiTagController.php\n+++ b/src/libraries/controllers/ApiTagController.php\n@@ -104,10 +104,10 @@ class ApiTagController extends ApiBaseController\n     unset($filters[\'__route__\']);\n \n     $userObj = new User;\n-    if($userObj->isOwner())\n+    if($userObj->isAdmin())\n       $filters[\'permission\'] = 0;\n \n-    $tagField = $userObj->isOwner() ? \'countPrivate\' : \'countPublic\';\n+    $tagField = $userObj->isAdmin() ? \'countPrivate\' : \'countPublic\';\n     $tagsFromDb = $this->tag->getTags($filters);\n     $tags = array(); // see issue #795 why we don\'t operate directly on $tagsFromDb\n \ndiff --git a/src/libraries/controllers/ApiWebhookController.php b/src/libraries/controllers/ApiWebhookController.php\nindex 74eb3e8d..d54ff833 100644\n--- a/src/libraries/controllers/ApiWebhookController.php\n+++ b/src/libraries/controllers/ApiWebhookController.php\n@@ -42,7 +42,7 @@ class ApiWebhookController extends ApiBaseController\n     */\n   public function delete($id)\n   {\n-    //getAuthentication()->requireAuthentication();\n+    getAuthentication()->requireAuthentication();\n     $status = $this->webhook->delete($id);\n     if($status)\n       return $this->noContent(\'Webhook deleted successfully\', true);\n@@ -58,7 +58,7 @@ class ApiWebhookController extends ApiBaseController\n     */\n   public function update($id)\n   {\n-    //getAuthentication()->requireAuthentication();\n+    getAuthentication()->requireAuthentication();\n     $params = $_POST;\n     $id = $this->webhook->update($id, $params);\n     if($id)\n@@ -75,7 +75,7 @@ class ApiWebhookController extends ApiBaseController\n     */\n   public function view($id)\n   {\n-    //getAuthentication()->requireAuthentication();\n+    getAuthentication()->requireAuthentication();\n     $webhook = $this->webhook->getById($id);\n     if($webhook)\n       return $this->success("Successfully retrieved webhook ({$id})", $webhook);\ndiff --git a/src/libraries/controllers/OAuthController.php b/src/libraries/controllers/OAuthController.php\nindex 0af09593..be1d099d 100644\n--- a/src/libraries/controllers/OAuthController.php\n+++ b/src/libraries/controllers/OAuthController.php\n@@ -40,7 +40,7 @@ class OAuthController extends BaseController\n   public function authorizePost()\n   {\n     $userObj = new User;\n-    if(!$userObj->isOwner())\n+    if(!$userObj->isAdmin())\n     {\n       $this->route->run(\'/error/403\', EpiRoute::httpGet);\n       die();\ndiff --git a/src/libraries/controllers/PhotoController.php b/src/libraries/controllers/PhotoController.php\nindex 0310a658..852b9f33 100644\n--- a/src/libraries/controllers/PhotoController.php\n+++ b/src/libraries/controllers/PhotoController.php\n@@ -89,7 +89,7 @@ class PhotoController extends BaseController\n     $isAttachment = !isset($_GET[\'stream\']) || $_GET[\'stream\'] != \'1\';\n     $userObj = new User;\n     // the API enforces permissions, we just have to check for download privileges\n-    if($userObj->isOwner() || $this->config->site->allowOriginalDownload == 1)\n+    if($userObj->isAdmin() || $this->config->site->allowOriginalDownload == 1)\n     {\n       $photoResp = $this->api->invoke("/{$this->apiVersion}/photo/{$id}/view.json", EpiRoute::httpGet);\n       $photo = $photoResp[\'result\'];\n@@ -197,7 +197,7 @@ class PhotoController extends BaseController\n   {\n     getAuthentication()->requireAuthentication();\n     $userObj = new User;\n-    if(!$userObj->isOwner())\n+    if(!$userObj->isAdmin())\n     {\n       $this->route->run(\'/error/403\');\n       return;\ndiff --git a/src/libraries/models/Activity.php b/src/libraries/models/Activity.php\nindex 3882779f..11374924 100644\n--- a/src/libraries/models/Activity.php\n+++ b/src/libraries/models/Activity.php\n@@ -44,7 +44,7 @@ class Activity extends BaseModel\n   public function list_($filters, $pageSize)\n   {\n     $filters[\'pageSize\'] = $pageSize;\n-    if(!$this->user->isOwner())\n+    if(!$this->user->isAdmin())\n       $filters[\'permission\'] = \'1\';\n     return $this->db->getActivities($filters);\n   }\ndiff --git a/src/libraries/models/Album.php b/src/libraries/models/Album.php\nindex 5ae9a1cc..a538641b 100644\n--- a/src/libraries/models/Album.php\n+++ b/src/libraries/models/Album.php\n@@ -58,7 +58,7 @@ class Album extends BaseModel\n     if(!$album)\n       return false;\n \n-    if(!$this->user->isOwner())\n+    if(!$this->user->isAdmin())\n     {\n       if(!$this->isAlbumCoverVisible($album))\n         $album[\'cover\'] = null;\n@@ -79,7 +79,7 @@ class Album extends BaseModel\n     if($albums === false)\n       return false;\n     \n-    if(!$this->user->isOwner())\n+    if(!$this->user->isAdmin())\n     {\n       foreach($albums as $key => $alb)\n       {\ndiff --git a/src/libraries/models/Authentication.php b/src/libraries/models/Authentication.php\nindex 10000fe3..c3432590 100644\n--- a/src/libraries/models/Authentication.php\n+++ b/src/libraries/models/Authentication.php\n@@ -58,7 +58,7 @@ class Authentication\n         OPException::raise(new OPAuthorizationOAuthException($this->credential->getErrorAsString()));\n       }\n     }\n-    elseif(!$this->user->isLoggedIn() || ($requireOwner && !$this->user->isOwner()))\n+    elseif(!$this->user->isLoggedIn() || ($requireOwner && !$this->user->isAdmin()))\n     {\n       OPException::raise(new OPAuthorizationSessionException());\n     }\ndiff --git a/src/libraries/models/Photo.php b/src/libraries/models/Photo.php\nindex 5e7a6e7d..0c694797 100644\n--- a/src/libraries/models/Photo.php\n+++ b/src/libraries/models/Photo.php\n@@ -69,7 +69,7 @@ class Photo extends BaseModel\n \n     $photo[\'pathBase\'] = $this->generateUrlBaseOrOriginal($photo, \'base\');\n     // the original needs to be conditionally included\n-    if($this->config->site->allowOriginalDownload == 1 || $this->user->isOwner())\n+    if($this->config->site->allowOriginalDownload == 1 || $this->user->isAdmin())\n     {\n       $photo[\'pathOriginal\'] = $this->generateUrlBaseOrOriginal($photo, \'original\');\n       $photo[\'pathDownload\'] = $this->generateUrlDownload($photo);\ndiff --git a/src/libraries/models/Tag.php b/src/libraries/models/Tag.php\nindex c34ed535..ad66e8fb 100644\n--- a/src/libraries/models/Tag.php\n+++ b/src/libraries/models/Tag.php\n@@ -35,7 +35,7 @@ class Tag extends BaseModel\n   public function getTag($tag = null)\n   {\n     $userObj = new User;\n-    $tagField = $userObj->isOwner() ? \'countPrivate\' : \'countPublic\';\n+    $tagField = $userObj->isAdmin() ? \'countPrivate\' : \'countPublic\';\n     $tag = $this->db->getTag($tag);\n     if(!$tag || $tag[$tagField] == 0)\n       return false;\ndiff --git a/src/libraries/models/User.php b/src/libraries/models/User.php\nindex d3a694bf..554ed80e 100644\n--- a/src/libraries/models/User.php\n+++ b/src/libraries/models/User.php\n@@ -150,7 +150,12 @@ class User extends BaseModel\n       return $this->session->get(\'email\') != \'\';\n   }\n \n-  public function isOwner()\n+  public function isAdmin()\n+  {\n+    return $this->isOwner(true);\n+  }\n+\n+  public function isOwner($includeAdmin = false)\n   {\n     if(!isset($this->config->user))\n       return false;\n@@ -175,7 +180,7 @@ class User extends BaseModel\n       if($isOwner)\n         return true;\n \n-      if(isset($user->admins))\n+      if($includeAdmin && isset($user->admins))\n       {\n         $admins = (array)explode(\',\', $user->admins);\n         if(array_search(strtolower($loggedInEmail), array_map(\'strtolower\', $admins)) !== false)\n@@ -233,7 +238,7 @@ class User extends BaseModel\n   {\n     $this->session->set(\'email\', $email);\n     $this->session->set(\'crumb\', md5($this->config->secrets->secret . time()));\n-    if($this->isOwner())\n+    if($this->isAdmin())\n       $this->session->set(\'site\', $_SERVER[\'HTTP_HOST\']);\n   }\n \ndiff --git a/src/tests/libraries/models/UserTest.php b/src/tests/libraries/models/UserTest.php\nindex caff2100..b8a2a62a 100644\n--- a/src/tests/libraries/models/UserTest.php\n+++ b/src/tests/libraries/models/UserTest.php\n@@ -372,6 +372,10 @@ class UserTest extends PHPUnit_Framework_TestCase\n     $this->user->inject(\'config\', $config);\n \n     $res = $this->user->isOwner();\n+    $this->assertFalse($res);\n+    $res = $this->user->isOwner(true);\n+    $this->assertTrue($res);\n+    $res = $this->user->isAdmin();\n     $this->assertTrue($res);\n   }\n \n', 'commit_subject': "Merge branch 'gh-731' of ../frontend into development", 'repo_name': 'photo/frontend', 'committer': {'name': 'Jaisen Mathai', 'email': '6f8c39689dd529cc34d5afb72b4666f3c1788f24@jmathai.com', 'time_sec': '1354603055', 'tz_offset': '-480', 'date': {'seconds': '1354603055'}}, 'commit_tree': 'fe81c35e81509aa742800285afa35e892e816544', 'commit_message': "Merge branch 'gh-731' of ../frontend into development\n", 'language_name': 'PHP', 'license': 'apache-2.0', 'hunks': "@@ -372,6 +372,10 @@ class UserTest extends PHPUnit_Framework_TestCase\n     $this->user->inject('config', $config);\n \n     $res = $this->user->isOwner();\n+    $this->assertFalse($res);\n+    $res = $this->user->isOwner(true);\n+    $this->assertTrue($res);\n+    $res = $this->user->isAdmin();\n     $this->assertTrue($res);\n   }\n \n", 'addition_count': 4, 'deletion_count': 0, 'src_file': 'a/src/tests/libraries/models/UserTest.php', 'tgt_file': 'b/src/tests/libraries/models/UserTest.php', 'file_extension': '.php', 'before_file': "<?php\nclass UserTest extends PHPUnit_Framework_TestCase\n{\n  protected $user;\n\n  public function setUp()\n  {\n    // to test the write methods\n    $this->user = new User();\n    $this->credential = $this->getMock('cred', array('isOAuthRequest', 'getConsumer', 'checkRequest','getErrorAsString','getEmailFromOAuth'));\n    $this->credential->expects($this->any())\n      ->method('getConsumer')\n      ->will($this->returnValue(array('foo')));\n  }\n\n  public function testGetAvatarFromEmailFromLibrary()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc', 'attrprofilePhoto' => 'http://foo/bar')));\n    $themeObj = $this->getMock('ThemeObj', array('asset'));\n    $themeObj->expects($this->any())\n      ->method('asset')\n      ->will($this->returnValue('/path/to/asset'));\n    $this->user->inject('db', $db);\n    $this->user->inject('themeObj', $themeObj);\n\n    $_SERVER['HTTP_HOST'] = 'foo';\n\n    $res = $this->user->getAvatarFromEmail(50, 'test@example.com');\n    $this->assertEquals('http://foo/bar', $res);\n  }\n\n  public function testGetAvatarFromEmailGravatar()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc')));\n    $themeObj = $this->getMock('ThemeObj', array('asset'));\n    $themeObj->expects($this->any())\n      ->method('asset')\n      ->will($this->returnValue('/path/to/asset'));\n    $config = new stdClass;\n    $config->site = new stdClass;\n    $config->site->useGravatar = 1;\n\n    $this->user->inject('themeObj', $themeObj);\n    $this->user->inject('db', $db);\n    $this->user->inject('config', $config);\n\n    $_SERVER['HTTP_HOST'] = 'foo';\n\n    $res = $this->user->getAvatarFromEmail(50, 'test@example.com');\n    $this->assertEquals('http://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=50&d=http%3A%2F%2Ffoo%2Fpath%2Fto%2Fasset', $res);\n  }\n\n  public function testGetAvatarFromEmailNoGravatar()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc')));\n    $themeObj = $this->getMock('ThemeObj', array('asset'));\n    $themeObj->expects($this->any())\n      ->method('asset')\n      ->will($this->returnValue('/path/to/asset'));\n    $config = new stdClass;\n    $config->site = new stdClass;\n    $config->site->useGravatar = 0;\n\n    $this->user->inject('themeObj', $themeObj);\n    $this->user->inject('db', $db);\n    $this->user->inject('config', $config);\n\n    $_SERVER['HTTP_HOST'] = 'foo';\n\n    $res = $this->user->getAvatarFromEmail(50, 'test@example.com');\n    $this->assertEquals('http://foo/path/to/asset', $res);\n  }\n\n  public function testGetEmailAddressNonOAuth()\n  {\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('test@example.com'));\n    $this->user->inject('session', $session);\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $this->user->inject('credential', $this->credential);\n    \n    $res = $this->user->getEmailAddress();\n    $this->assertEquals('test@example.com', $res);\n  }\n\n  public function testGetEmailAddressOAuth()\n  {\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->any())\n      ->method('getEmailFromOAuth')\n      ->will($this->returnValue('test@example.com'));\n    $this->user->inject('credential', $this->credential);\n    \n    $res = $this->user->getEmailAddress();\n    $this->assertEquals('test@example.com', $res);\n  }\n\n  public function testGetEmailAddressNull()\n  {\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue(null));\n    $this->user->inject('session', $session);\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $this->user->inject('credential', $this->credential);\n    \n    $res = $this->user->getEmailAddress();\n    $this->assertNull($res);\n  }\n\n  public function testGetUserByEmailFirstCallShouldCacheSuccess()\n  {\n    $db = $this->getMock('Db', array('getUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->onConsecutiveCalls(\n        array('id' => 'test@example.com', 'seq' => 1),\n        array('id' => 'test@example.com', 'seq' => 2)\n      ));\n    $this->user->inject('db', $db);\n    $res = $this->user->getUserByEmail('foo@bar.com');\n    $this->assertEquals(1, $res['seq']);\n\n    $res = $this->user->getUserByEmail('foo@bar.com');\n    $this->assertEquals(1, $res['seq']);\n  }\n\n  public function testGetUserByEmailSkipCacheSuccess()\n  {\n    $db = $this->getMock('Db', array('getUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->onConsecutiveCalls(\n        array('id' => 'test@example.com', 'seq' => 1),\n        array('id' => 'test@example.com', 'seq' => 2)\n      ));\n    $this->user->inject('db', $db);\n    $res = $this->user->getUserByEmail('foo@bar.com');\n    $this->assertEquals(1, $res['seq']);\n\n    $res = $this->user->getUserByEmail('foo@bar.com', false);\n    $this->assertEquals(2, $res['seq']);\n  }\n\n  public function testGetUserByEmailVerifyCacheByHandleSuccess()\n  {\n    $db = $this->getMock('Db', array('getUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->onConsecutiveCalls(\n        array('id' => 'test1@example.com', 'seq' => 1),\n        array('id' => 'test2@example.com', 'seq' => 2)\n      ));\n    $this->user->inject('db', $db);\n    $res = $this->user->getUserByEmail('foo1@bar.com');\n    $this->assertEquals(1, $res['seq']);\n\n    $res = $this->user->getUserByEmail('foo2@bar.com');\n    $this->assertEquals(2, $res['seq']);\n  }\n\n  public function testGetUserByEmailCachedSuccess()\n  {\n    $this->user->inject('userArray', array('foo@bar.com' => '123'));\n    $res = $this->user->getUserByEmail('foo@bar.com');\n    $this->assertEquals('123', $res);\n  }\n\n  public function testGetNextIdPhoto()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->onConsecutiveCalls(\n        array('id' => 'test@example.com', 'lastPhotoId' => 'abc'),\n        array('id' => 'test@example.com', 'lastPhotoId' => '0'),\n        array('id' => 'test@example.com', 'lastPhotoId' => 'a1'),\n        array('id' => 'test@example.com', 'lastPhotoId' => '9'),\n        array('id' => 'test@example.com', 'lastPhotoId' => 'u')\n      ));\n    $db->expects($this->any())\n      ->method('postUser')\n      ->will($this->returnValue(true));\n    $db->expects($this->any())\n      ->method('putUser')\n      ->will($this->returnValue(true));\n    $this->user->inject('db', $db);\n\n    // abc\n    $res = $this->user->getNextId('photo');\n    $this->assertEquals('abd', $res);\n    // 0\n    $res = $this->user->getNextId('photo');\n    $this->assertEquals('1', $res);\n    // a1\n    $res = $this->user->getNextId('photo');\n    $this->assertEquals('a2', $res);\n    // 9\n    $res = $this->user->getNextId('photo');\n    $this->assertEquals('a', $res);\n    // u\n    $res = $this->user->getNextId('photo');\n    $this->assertEquals('10', $res);\n  }\n\n  public function testGetNextIdPhotoFirstId()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(array('id' => 'test@example.com')));\n    $db->expects($this->any())\n      ->method('postUser')\n      ->will($this->returnValue(true));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->getNextId('photo');\n    $this->assertEquals('1', $res);\n  }\n\n  public function testGetNextIdPhotoKeyNotExistYet()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(array('id' => 'test@example.com', 'lastActionId' => 'def')));\n    $db->expects($this->any())\n      ->method('postUser')\n      ->will($this->returnValue(true));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->getNextId('photo');\n    $this->assertEquals('1', $res);\n  }\n\n  public function testGetNextIdFailure()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(false));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->getNextId('photo');\n    $this->assertFalse($res);\n  }\n\n  public function testGetNextIdUpdateFailure()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->onConsecutiveCalls(\n        array('id' => 'test@example.com', 'lastPhotoId' => 'abc'),\n        array('id' => '', 'lastPhotoId' => '')\n      ));\n    $db->expects($this->any())\n      ->method('postUser')\n      ->will($this->returnValue(false));\n    $this->user->inject('db', $db);\n\n    // abc\n    $res = $this->user->getNextId('photo');\n    $this->assertEquals(false, $res);\n  }\n\n\n  public function testGetAttributeNameSuccess()\n  {\n    $res = $this->user->getAttributeName('foobar');\n    $this->assertEquals('attrfoobar', $res);\n  }\n\n  public function testGetAttributeSuccess()\n  {\n    $this->user->inject('user', array('attrfoobar' => '1234'));\n    $res = $this->user->getAttribute('foobar');\n    $this->assertEquals('1234', $res);\n  }\n\n  public function testGetAttributeFailure()\n  {\n    $this->user->inject('user', array('attrfoobar' => '1234'));\n    $res = $this->user->getAttribute('foobarx');\n    $this->assertEquals(false, $res);\n  }\n\n  public function testGetUserRecordFromRuntimeCache()\n  {\n    $this->user->inject('user', '1');\n    $res = $this->user->getUserRecord();\n    $this->assertEquals('1', $res);\n  }\n\n  public function testGetUserRecordOverridingRuntimeCache()\n  {\n    $this->user->inject('user', '1');\n\n    $db = $this->getMock('Db', array('getUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue('2'));\n    $this->user->inject('db', $db);\n\n    $this->user->clearUserCache();\n    $res = $this->user->getUserRecord();\n    $this->assertEquals('2', $res);\n  }\n\n  public function testGetUserRecordWhenNullAndFailsToCreate()\n  {\n    $db = $this->getMock('Db', array('getUser', 'putUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(null));\n    $db->expects($this->any())\n      ->method('putUser')\n      ->will($this->returnValue(false));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->getUserRecord();\n    $this->assertFalse($res);\n  }\n\n  public function testGetUserRecordWhenNull()\n  {\n    $db = $this->getMock('Db', array('getUser', 'putUser'));\n    $db->expects($this->at(1))\n      ->method('getUser')\n      ->will($this->returnValue(null));\n    $db->expects($this->at(2))\n      ->method('getUser')\n      ->will($this->returnValue('1'));\n    $db->expects($this->any())\n      ->method('putUser')\n      ->will($this->returnValue(true));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->getUserRecord();\n    $this->assertEquals('1', $res);\n  }\n\n  public function testGetUserRecordWhenError()\n  {\n    $db = $this->getMock('Db', array('getUser'));\n    $db->expects($this->once())\n      ->method('getUser')\n      ->will($this->returnValue(false));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->getUserRecord();\n    $this->assertFalse($res);\n  }\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertTrue($res);\n  }\n\n    $this->user->inject('session', $session);\n    $this->user->inject('credential', $this->credential);\n\n    $res = $this->user->isLoggedIn();\n    $this->assertFalse($res);\n  }\n\n  public function testIsLoggedInFalseWithOAuth()\n  {\n    $this->credential->expects($this->once())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('checkRequest')\n      ->will($this->returnValue(false));\n    $this->user->inject('credential', $this->credential);\n\n    $res = $this->user->isLoggedIn();\n    $this->assertFalse($res);\n  }\n\n  public function testIsLoggedInTrue()\n  {\n    $this->credential->expects($this->once())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('test@example.com'));\n    $this->user->inject('session', $session);\n    $this->user->inject('credential', $this->credential);\n\n    $res = $this->user->isLoggedIn();\n    $this->assertTrue($res);\n  }\n\n  public function testIsLoggedInTrueWithOAuth()\n  {\n    $this->credential->expects($this->once())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('checkRequest')\n      ->will($this->returnValue(true));\n    $this->user->inject('credential', $this->credential);\n\n    $res = $this->user->isLoggedIn();\n    $this->assertTrue($res);\n  }\n\n  public function testIsOwnerFalse()\n  {\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue(null));\n    $this->user->inject('session', $session);\n    $this->user->inject('credential', $this->credential);\n    $this->user->inject('config', new FauxObject);\n\n    $res = $this->user->isOwner();\n    $this->assertFalse($res);\n  }\n\n  public function testIsOwnerFalseLoggedInAsSomeoneElse()\n  {\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('someoneelse@example.com'));\n    $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('test@example.com'));\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'test@example.com';\n    $this->user->inject('session', $session);\n    $this->user->inject('credential', $this->credential);\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertFalse($res);\n  }\n\n  public function testIsOwnerTrue()\n  {\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('test@example.com'));\n    $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('test@example.com'));\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'test@example.com';\n    $this->user->inject('session', $session);\n    $this->user->inject('credential', $this->credential);\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertTrue($res);\n  }\n\n  public function testIsOwnerTrueLoggedInAsAdmin()\n  {\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('someoneelse@example.com'));\n    $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('test@example.com'));\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'test@example.com';\n    $config->user->admins = 'someoneelse@example.com';\n    $this->user->inject('session', $session);\n    $this->user->inject('credential', $this->credential);\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertFalse($res);\n    $res = $this->user->isOwner(true);\n    $this->assertTrue($res);\n    $res = $this->user->isAdmin();\n    $this->assertTrue($res);\n  }\n\n  public function testIsOwnerTrueLoggedInAsAdminIgnoreCase()\n  {\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('someoneelse@example.com'));\n    $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('test@example.com'));\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'test@example.com';\n    $config->user->admins = 'SoMeOnEeLsE@ExAmPlE.CoM';\n    $this->user->inject('session', $session);\n    $this->user->inject('credential', $this->credential);\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertFalse($res);\n    $res = $this->user->isOwner(true);\n    $this->assertTrue($res);\n    $res = $this->user->isAdmin();\n    $this->assertTrue($res);\n  }\n\n  public function testIsOwnerOAuthInvalid()\n  {\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('checkRequest')\n      ->will($this->returnValue(false));\n    $this->user->inject('credential', $this->credential);\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'doesnt matter';\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertFalse($res);\n  }\n\n  public function testIsOwnerOAuthValidNotOwner()\n  {\n    $this->credential->expects($this->once())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('checkRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('getEmailFromOAuth')\n      ->will($this->returnValue('test@example.com'));\n    $this->user->inject('credential', $this->credential);\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'different@example.com';\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertFalse($res);\n  }\n\n  public function testIsOwnerOAuthTrue()\n  {\n    $this->credential->expects($this->once())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('checkRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('getEmailFromOAuth')\n      ->will($this->returnValue('test@example.com'));\n    $this->user->inject('credential', $this->credential);\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'test@example.com';\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertTrue($res);\n  }\n\n  public function testIsOwnerIgnoreCase()\n  {\n    $this->credential->expects($this->any())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(false));\n    $session = $this->getMock('session', array('get'));\n    $session->expects($this->any())\n      ->method('get')\n      ->will($this->returnValue('TeSt@eXaMpLe.CoM'));\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'test@example.com';\n    $this->user->inject('session', $session);\n    $this->user->inject('credential', $this->credential);\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertTrue($res);\n  }\n\n  public function testIsOwnerOAuthIgnoreCase()\n  {\n    $this->credential->expects($this->once())\n      ->method('isOAuthRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('checkRequest')\n      ->will($this->returnValue(true));\n    $this->credential->expects($this->once())\n      ->method('getEmailFromOAuth')\n      ->will($this->returnValue('TeSt@ExAmPlE.CoM'));\n    $this->user->inject('credential', $this->credential);\n    $config = new stdClass;\n    $config->user = new stdClass;\n    $config->user->email = 'test@example.com';\n    $this->user->inject('config', $config);\n\n    $res = $this->user->isOwner();\n    $this->assertTrue($res);\n  }\n\n  public function testLogin()\n  {\n    $this->markTestIncomplete('This test has not been implemented yet.');\n  }\n\n  public function testSetEmail()\n  {\n    $session = $this->getMock('session', array('set'));\n    $session->expects($this->any())\n      ->method('set')\n      ->will($this->returnValue('test@example.com'));\n    $config = arrayToObject(array('secrets' => array('secret' => 'foo')));\n    $this->user->inject('config', $config);\n    $this->user->inject('session', $session);\n\n    $res = $this->user->setEmail('foo');\n    $this->assertNull($res);\n  }\n\n  public function testUpdateSuccess()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc', 'lastActionId' => 'def')));\n    $db->expects($this->any())\n      ->method('postUser')\n      ->will($this->returnValue(true));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->update(array('id' => '123'));\n    $this->assertTrue($res);\n  }\n\n  public function testUpdateCacheIsUpdatedSuccess()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->onConsecutiveCalls(array(),2));\n    $db->expects($this->any())\n      ->method('postUser')\n      ->will($this->returnValue(true));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->update(array('id' => '123'));\n    $this->assertTrue($res);\n\n    $user = $this->user->getUserRecord();\n    $this->assertEquals(2, $user);\n  }\n\n  public function testUpdateFailure()\n  {\n    $db = $this->getMock('Db', array('getUser', 'postUser'));\n    $db->expects($this->any())\n      ->method('getUser')\n      ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc', 'lastActionId' => 'def')));\n    $db->expects($this->any())\n      ->method('postUser')\n      ->will($this->returnValue(false));\n    $this->user->inject('db', $db);\n\n    $res = $this->user->update(array('id' => '123'));\n    $this->assertFalse($res);\n  }\n}\n", 'message': "Merge branch 'gh-731' of ../frontend into development\n", 'author_name': 'Jaisen Mathai', 'lang': 'php'}