Skip to content

Commit

Permalink
Merge pull request #1196 from RotherOSS/issue-#734-reinstate-session-…
Browse files Browse the repository at this point in the history
…limit-notification

Issue #734 reinstate session limit notification
  • Loading branch information
bschmalhofer authored Aug 26, 2021
2 parents 51dc9dc + be40bf1 commit 041093a
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 19 deletions.
12 changes: 9 additions & 3 deletions Kernel/Config/Files/XML/Framework.xml
Original file line number Diff line number Diff line change
Expand Up @@ -825,16 +825,15 @@
</Hash>
</Value>
</Setting>
<!-- not properly implemented -->
<!-- <Setting Name="Frontend::NotifyModule###2500-AgentSessionLimit" Required="1" Valid="1">
<Setting Name="Frontend::NotifyModule###2500-AgentSessionLimit" Required="1" Valid="1">
<Description Translatable="1">Defines the module to display a notification in the agent interface, if the agent session limit prior warning is reached.</Description>
<Navigation>Frontend::Agent::FrontendNotification</Navigation>
<Value>
<Hash>
<Item Key="Module">Kernel::Output::HTML::Notification::AgentSessionLimit</Item>
</Hash>
</Value>
</Setting> -->
</Setting>
<Setting Name="Frontend::NotifyModule###3000-ShowAgentOnline" Required="0" Valid="0">
<Description Translatable="1">Defines the module that shows all the currently logged in agents in the agent interface.</Description>
<Navigation>Frontend::Agent::FrontendNotification</Navigation>
Expand Down Expand Up @@ -989,6 +988,13 @@
<Item ValueType="Checkbox">1</Item>
</Value>
</Setting>
<Setting Name="AgentSessionLimitPriorWarning" Required="0" Valid="0">
<Description Translatable="1">Sets the maximum number of active agents within the timespan defined in SessionActiveTime before a prior warning will be visible for the logged in agents.</Description>
<Navigation>Core::Session</Navigation>
<Value>
<Item ValueType="String" ValueRegex="^[0-9]{1,8}$">90</Item>
</Value>
</Setting>
<Setting Name="AgentSessionLimit" Required="0" Valid="1">
<Description Translatable="1">Sets the maximum number of active agents within the timespan defined in SessionMaxIdleTime.</Description>
<Navigation>Core::Session</Navigation>
Expand Down
13 changes: 12 additions & 1 deletion Kernel/Output/HTML/Notification/AgentSessionLimit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@ our @ObjectDependencies = (
sub Run {
my ( $Self, %Param ) = @_;

return '';
# Check if the agent session limit for the prior warning is reached
# and save the message for the translation and the output.
my $AgentSessionLimitPriorWarningMessage
= $Kernel::OM->Get('Kernel::System::AuthSession')->CheckAgentSessionLimitPriorWarning();

return '' unless $AgentSessionLimitPriorWarningMessage;

my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');

return $LayoutObject->Notify(
Data => $LayoutObject->{LanguageObject}->Translate($AgentSessionLimitPriorWarningMessage),
Priority => 'Warning',
);
}

1;
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<a href="#" class="Button SettingEnabled [% IF Setting.IsValid == 0 %]Hidden[% END %]" title="[% Translate("Disable this setting, so it is no longer effective") | html %]"><i class="fa fa-times"></i> [% Translate("Disable") | html %]</a>
<a href="#" class="Button SettingDisabled [% IF Setting.IsValid == 1 %]Hidden[% END %]" title="[% Translate("Enable this setting, so it becomes effective") | html %]"><i class="fa fa-check"></i> [% Translate("Enable") | html %]</a>
[% END %]
<a href="[% Env("Baselink") %]Action=AdminSystemConfigurationSettingHistory;Subaction=ShowSettingHistory;SettingName=[% Setting.Name | uri %]" class="OTRSBusinessRequired SettingHistory Button"><i class="fa fa-clock-o"></i> [% Translate("History") | html %]</a>
<a href="[% Env("Baselink") %]Action=AdminSystemConfigurationSettingHistory;Subaction=ShowSettingHistory;SettingName=[% Setting.Name | uri %]" class="SettingHistory Button"><i class="fa fa-clock-o"></i> [% Translate("History") | html %]</a>
<a href="#" class="ResetSetting Button" data-user-modification="[% Setting.UserModificationPossible %]" title="[% Translate("Reset this setting to its default state") | html %]">
<i class="fa fa-undo"></i>
[% Translate("Reset setting") | html %]
Expand Down
62 changes: 58 additions & 4 deletions Kernel/System/AuthSession.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ our @ObjectDependencies = (
'Kernel::System::Cache',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::SystemData',
'Kernel::System::SysConfig',
);

Expand All @@ -52,8 +51,7 @@ sub new {
my ( $Type, %Param ) = @_;

# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
my $Self = bless {}, $Type;

# get configured session backend
my $GenericModule = $Kernel::OM->Get('Kernel::Config')->Get('SessionModule');
Expand All @@ -72,7 +70,7 @@ sub new {
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

for my $SessionLimitConfigKey (
qw(AgentSessionLimit AgentSessionPerUserLimit CustomerSessionLimit CustomerSessionPerUserLimit)
qw(AgentSessionLimitPriorWarning AgentSessionLimit AgentSessionPerUserLimit CustomerSessionLimit CustomerSessionPerUserLimit)
)
{
$Self->{$SessionLimitConfigKey} = $ConfigObject->Get($SessionLimitConfigKey);
Expand All @@ -97,6 +95,51 @@ sub CheckSessionID {
return $Self->{Backend}->CheckSessionID(%Param);
}

=head2 CheckAgentSessionLimitPriorWarning()
Get the agent session limit prior warning message, if the limit is reached.
my $PriorMessage = $SessionObject->CheckAgentSessionLimitPriorWarning();
returns the prior warning message (AgentSessionLimitPriorWarning reached) or false (AgentSessionLimitPriorWarning not reached)
=cut

sub CheckAgentSessionLimitPriorWarning {
my ( $Self, %Param ) = @_;

my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
my $CachedMessage = $CacheObject->Get(
Type => 'AuthSession',
Key => 'AgentSessionLimitPriorWarningMessage',
);

return $CachedMessage if defined $CachedMessage;

my $SessionLimitPriorWarning = $Self->{AgentSessionLimitPriorWarning};

my $PriorWarningMessage = '';
if ($SessionLimitPriorWarning) {

my %ActiveSessions = $Self->GetActiveSessions(
UserType => 'User',
);

if ( defined $ActiveSessions{Total} && $ActiveSessions{Total} > $SessionLimitPriorWarning ) {
$PriorWarningMessage = Translatable('Please note that the session limit is almost reached.');
}
}

$CacheObject->Set(
Type => 'AuthSession',
TTL => 60 * 15,
Key => 'AgentSessionLimitPriorWarningMessage',
Value => $PriorWarningMessage,
);

return $PriorWarningMessage;
}

=head2 SessionIDErrorMessage()
returns an error in the session handling
Expand Down Expand Up @@ -231,6 +274,12 @@ session can't get deleted)
sub RemoveSessionID {
my ( $Self, %Param ) = @_;

my $CacheObject = $Kernel::OM->Get('Kernel::System::Cache');
$CacheObject->Delete(
Type => 'AuthSession',
Key => 'AgentSessionLimitPriorWarningMessage',
);

return $Self->{Backend}->RemoveSessionID(%Param);
}

Expand Down Expand Up @@ -393,6 +442,11 @@ clean-up of sessions in your system
sub CleanUp {
my ( $Self, %Param ) = @_;

$Kernel::OM->Get('Kernel::System::Cache')->Delete(
Type => 'AuthSession',
Key => 'AgentSessionLimitPriorWarningMessage',
);

return $Self->{Backend}->CleanUp(%Param);
}

Expand Down
23 changes: 22 additions & 1 deletion scripts/test/AuthSession.t
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ for my $ModuleFile (@BackendModuleFiles) {
"#$Module - SessionList() no sessions left",
);

# Some special tests for the possible agent session limits.
my $AgentSessionLimitPriorWarningMessage = $SessionObject->CheckAgentSessionLimitPriorWarning();

$Self->False(
$AgentSessionLimitPriorWarningMessage,
"#$Module - CheckAgentSessionLimitPriorWarning() - AgentSessionLimitPriorWarning not active",
);

for my $Count ( 1 .. 2 ) {

my %NewSessionData = (
Expand All @@ -482,10 +490,21 @@ for my $ModuleFile (@BackendModuleFiles) {
Key => 'AgentSessionPerUserLimit',
Value => 1,
);
$ConfigObject->Set(
Key => 'AgentSessionLimitPriorWarning',
Value => 1,
);

# Reset the session object, to get the new config settings.
$SessionObject = Kernel::System::AuthSession->new();

$AgentSessionLimitPriorWarningMessage = $SessionObject->CheckAgentSessionLimitPriorWarning();

$Self->True(
$AgentSessionLimitPriorWarningMessage,
"#$Module - CheckAgentSessionLimitPriorWarning() - AgentSessionLimitPriorWarning reached",
);

my $SessionID = $SessionObject->CreateSessionID(
UserLogin => 'root1',
UserType => 'User',
Expand Down Expand Up @@ -537,9 +556,11 @@ for my $ModuleFile (@BackendModuleFiles) {
"#$Module - CleanUp after session limit tests()",
);

# Test the speical otobo business values from the cloudservice.
# First reset the config and session object
# and generate some dummy data in the system data.
$ConfigObject->Set(
Key => 'AgentSessionLimitPriorWarning',
);
$ConfigObject->Set(
Key => 'AgentSessionLimit',
Value => 100,
Expand Down
13 changes: 4 additions & 9 deletions scripts/test/Selenium/Agent/Login.t
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,10 @@ $Selenium->RunTest(
$Selenium->find_element( '#LoginButton', 'css' )->VerifiedClick();

# Check for the prior warning.
my $PageSource = $Selenium->get_page_source();
{
my $ToDo = todo('no session limit in OTOBO, issue #734');

ok(
index( $PageSource, 'Please note that the session limit is almost reached.' ) > -1,
"AgentSessionLimitPriorWarning is reached.",
);
}
$Selenium->content_contains(
'Please note that the session limit is almost reached.',
'AgentSessionLimitPriorWarning is reached.',
);

# Try to expand the user profile sub menu by clicking the avatar.
$Selenium->find_element( '.UserAvatar > a', 'css' )->click();
Expand Down

0 comments on commit 041093a

Please sign in to comment.