2021-06-11 12:17:25 +00:00
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
class SessionTimeoutJob :: Session
attr_accessor :session , :user
def initialize ( session )
@session = session
@user = User . find_by ( id : session . data [ 'user_id' ] )
end
def user?
user . present?
end
def active?
return true if timeout < 1
return true if session . data [ 'ping' ] > timeout . seconds . ago
end
def frontend_timeout
return if ! user?
PushMessages . send_to ( user . id , { event : 'session_timeout' } )
end
def timeout
2021-07-02 06:22:43 +00:00
return - 1 if ! user?
timeout_user
end
def timeout_user
@timeout_user || = begin
2021-06-11 12:17:25 +00:00
permissions = Permission . where ( id : user . permissions_with_child_ids ) . pluck ( :name )
result = - 1
config . each do | key , value |
next if key == 'default'
next if permissions . exclude? ( key )
next if value . to_i < result
result = value . to_i
end
if result < 1
result = config [ 'default' ] . to_i
end
result
end
end
def config
Setting . get ( 'session_timeout' )
end
2021-07-02 06:22:43 +00:00
def destroy
session . destroy
Rails . logger . info " SessionTimeoutJob removed session ' #{ session . id } ' for user id ' #{ user & . id } ' (last ping: ' #{ session . data [ 'ping' ] } ', timeout: ' #{ timeout . seconds } ') "
end
2021-06-11 12:17:25 +00:00
end