Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.2] Allow to disable session metadata tracking for guest users #37459

Merged
merged 7 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions administrator/components/com_config/forms/application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,20 @@
<option value="1">JYES</option>
</field>

<field
name="session_metadata_for_guest"
type="radio"
label="COM_CONFIG_FIELD_SESSION_METADATA_GUEST_LABEL"
description="COM_CONFIG_FIELD_SESSION_METADATA_GUEST_DESC"
layout="joomla.form.field.radio.switcher"
default="1"
filter="boolean"
showon="session_metadata:1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

</fieldset>

<fieldset
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/com_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ COM_CONFIG_FIELD_SERVER_TIMEZONE_LABEL="Website Time Zone"
COM_CONFIG_FIELD_SESSION_HANDLER_LABEL="Session Handler"
COM_CONFIG_FIELD_SESSION_METADATA_DESC="If enabled, additional metadata about a user's session (including their username, user ID, and which application they are logged into) will be logged to the session database table.<br>If disabled, features dependent on this data will be unavailable."
COM_CONFIG_FIELD_SESSION_METADATA_LABEL="Track Session Metadata"
COM_CONFIG_FIELD_SESSION_METADATA_GUEST_DESC="If enabled, additional metadata about both registered and non registered user's session will be logged to the session database table. <br>If disabled, only data for registered user will be logged."
COM_CONFIG_FIELD_SESSION_METADATA_GUEST_LABEL="Track Session Metadata for non registered Users"
Fedik marked this conversation as resolved.
Show resolved Hide resolved
COM_CONFIG_FIELD_SESSION_TIME_LABEL="Session Lifetime (minutes)"
COM_CONFIG_FIELD_SHARED_SESSION_DESC="When enabled, a user's session is shared between the frontend and administrator sections of the site. Note that changing this value will invalidate all existing sessions on the site. This is not available when the \"Force HTTPS\" option is set to \"Administrator Only\"."
COM_CONFIG_FIELD_SHARED_SESSION_LABEL="Shared Sessions"
Expand Down
15 changes: 13 additions & 2 deletions libraries/src/Session/EventListener/MetadataManagerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,20 @@ public function __construct(MetadataManager $metadataManager, Registry $config)
*/
public function onAfterSessionStart(SessionEvent $event)
{
if ($this->config->get('session_metadata', true) && $event->getSession()->has('user'))
// Whether to track Session Metadata
if (!$this->config->get('session_metadata', true) || !$event->getSession()->has('user'))
{
$this->metadataManager->createOrUpdateRecord($event->getSession(), $event->getSession()->get('user'));
return;
}

$user = $event->getSession()->get('user');

// Whether to track Session Metadata for Guest user
if (!$this->config->get('session_metadata_for_guest', true) && !$user->id)
{
return;
}

$this->metadataManager->createOrUpdateRecord($event->getSession(), $user);
}
}