Commit f559ff78 authored by xjm's avatar xjm

Issue #2347799 by andypost, almaudoh, znerol: Remove bugged session-related...

Issue #2347799 by andypost, almaudoh, znerol: Remove bugged session-related methods from AccountInterface
parent 60901852
......@@ -57,30 +57,6 @@ public function getRoles($exclude_locked_roles = FALSE);
*/
public function hasPermission($permission);
/**
* Returns the session ID.
*
* @return string|null
* The session ID or NULL if this user does not have an active session.
*/
public function getSessionId();
/**
* Returns the secure session ID.
*
* @return string|null
* The session ID or NULL if this user does not have an active secure session.
*/
public function getSecureSessionId();
/**
* Returns the session data.
*
* @return array
* Array with the session data that belongs to this object.
*/
public function getSessionData();
/**
* Returns TRUE if the account is authenticated.
*
......@@ -173,11 +149,4 @@ public function getTimeZone();
*/
public function getLastAccessedTime();
/**
* Returns the session hostname.
*
* @return string
*/
public function getHostname();
}
......@@ -80,13 +80,6 @@ public function getRoles($exclude_locked_roles = FALSE) {
return $this->getAccount()->getRoles($exclude_locked_roles);
}
/**
* {@inheritdoc}
*/
public function getHostname() {
return $this->getAccount()->getHostname();
}
/**
* {@inheritdoc}
*/
......@@ -94,27 +87,6 @@ public function hasPermission($permission) {
return $this->getAccount()->hasPermission($permission);
}
/**
* {@inheritdoc}
*/
public function getSessionId() {
return $this->getAccount()->getSessionId();
}
/**
* {@inheritdoc}
*/
public function getSecureSessionId() {
return $this->getAccount()->getSecureSessionId();
}
/**
* {@inheritdoc}
*/
public function getSessionData() {
return $this->getAccount()->getSessionData();
}
/**
* {@inheritdoc}
*/
......
......@@ -18,9 +18,6 @@ class AnonymousUserSession extends UserSession {
* Intentionally don't allow parameters to be passed in like UserSession.
*/
public function __construct() {
if (\Drupal::hasRequest()) {
$this->hostname = \Drupal::request()->getClientIp();
}
}
}
......@@ -31,32 +31,11 @@ class UserSession implements AccountInterface {
protected $roles = array(AccountInterface::ANONYMOUS_ROLE);
/**
* Session ID.
* The Unix timestamp when the user last accessed the site.
*
* @var string.
*/
public $sid;
/**
* Secure session ID.
*
* @var string.
*/
public $ssid;
/**
* Session data.
*
* @var array.
*/
public $session;
/**
* The Unix timestamp when this session last requested a page.
*
* @var string.
*/
protected $timestamp;
protected $access;
/**
* The name of this account.
......@@ -93,13 +72,6 @@ class UserSession implements AccountInterface {
*/
protected $timezone;
/**
* The hostname for this user session.
*
* @var string
*/
protected $hostname = '';
/**
* Constructs a new user session.
*
......@@ -144,27 +116,6 @@ public function hasPermission($permission) {
return $this->getRoleStorage()->isPermissionInRoles($permission, $this->getRoles());
}
/**
* {@inheritdoc}
*/
public function getSecureSessionId() {
return $this->ssid;
}
/**
* {@inheritdoc}
*/
public function getSessionData() {
return $this->session;
}
/**
* {@inheritdoc}
*/
public function getSessionId() {
return $this->sid;
}
/**
* {@inheritdoc}
*/
......@@ -232,14 +183,7 @@ public function getTimeZone() {
* {@inheritdoc}
*/
public function getLastAccessedTime() {
return $this->timestamp;
}
/**
* {@inheritdoc}
*/
public function getHostname() {
return $this->hostname;
return $this->access;
}
/**
......
......@@ -81,11 +81,6 @@ protected function getUserFromSession(SessionInterface $session) {
// Check if the user data was found and the user is active.
if (!empty($values) && $values['status'] == 1) {
// UserSession::getLastAccessedTime() returns session save timestamp,
// while User::getLastAccessedTime() returns the user 'access'
// timestamp. This ensures they are synchronized.
$values['timestamp'] = $values['access'];
// Add the user's roles.
$rids = $this->connection
->query('SELECT roles_target_id FROM {user__roles} WHERE entity_id = :uid', [':uid' => $values['uid']])
......
......@@ -69,13 +69,6 @@ class User extends ContentEntityBase implements UserInterface {
*/
protected static $anonymousUser;
/**
* The hostname for this user.
*
* @var string
*/
protected $hostname;
/**
* {@inheritdoc}
*/
......@@ -170,37 +163,6 @@ public function getRoles($exclude_locked_roles = FALSE) {
return $roles;
}
/**
* {@inheritdoc}
*/
public function getSecureSessionId() {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getSessionData() {
return array();
}
/**
* {@inheritdoc}
*/
public function getSessionId() {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getHostname() {
if (!isset($this->hostname) && \Drupal::hasRequest()) {
$this->hostname = \Drupal::request()->getClientIp();
}
return $this->hostname;
}
/**
* {@inheritdoc}
*/
......
......@@ -21,42 +21,6 @@
*/
class AnonymousUserSessionTest extends UnitTestCase {
/**
* Tests creating an AnonymousUserSession when the request is available.
*
* @covers ::__construct
*/
public function testAnonymousUserSessionWithRequest() {
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request->expects($this->once())
->method('getClientIp')
->will($this->returnValue('test'));
$container = new ContainerBuilder();
$requestStack = new RequestStack();
$requestStack->push($request);
$container->set('request_stack', $requestStack);
\Drupal::setContainer($container);
$anonymous_user = new AnonymousUserSession();
$this->assertSame('test', $anonymous_user->getHostname());
}
/**
* Tests creating an AnonymousUserSession when the request is not available.
*
* @covers ::__construct
*/
public function testAnonymousUserSessionWithNoRequest() {
$container = new ContainerBuilder();
\Drupal::setContainer($container);
$anonymous_user = new AnonymousUserSession();
$this->assertSame('', $anonymous_user->getHostname());
}
/**
* Tests the method getRoles exclude or include locked roles based in param.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment