Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove cache_store support for sessions

Oliver Günther8cd6e1ef64db
diff --git a/app/models/sessions/sql_bypass.rb b/app/models/sessions/sql_bypass.rb
index 89a926cbdce..dd9147154c5 100644
--- a/app/models/sessions/sql_bypass.rb
+++ b/app/models/sessions/sql_bypass.rb
@@ -43,16 +43,7 @@ module Sessions
# @return [Hash] The saved session data (user_id, updated_at, etc.) or nil if no session was found.
def lookup_data(session_id)
rack_session = Rack::Session::SessionId.new(session_id)
- if Rails.application.config.session_store == ActionDispatch::Session::ActiveRecordStore
- find_by_session_id(rack_session.private_id)&.data
- else
- session_store = Rails.application.config.session_store.new nil, {}
- _id, data = session_store.instance_eval do
- find_session({}, rack_session)
- end
-
- data.presence
- end
+ find_by_session_id(rack_session.private_id)&.data
end
def connection_pool
diff --git a/app/services/sessions/base_service.rb b/app/services/sessions/base_service.rb
deleted file mode 100644
index 2462fccfb18..00000000000
--- a/app/services/sessions/base_service.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module Sessions
- class BaseService
- class << self
- protected
-
- ##
- # Can we work on SQL sessions?
- def active_record_sessions?
- OpenProject::Configuration.session_store.to_s == 'active_record_store'
- end
- end
- end
-end
diff --git a/app/services/sessions/drop_all_sessions_service.rb b/app/services/sessions/drop_all_sessions_service.rb
index 55babcedc80..7c0b133f391 100644
--- a/app/services/sessions/drop_all_sessions_service.rb
+++ b/app/services/sessions/drop_all_sessions_service.rb
@@ -25,16 +25,12 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
-require_relative './base_service'
-
module Sessions
- class DropAllSessionsService < BaseService
+ class DropAllSessionsService
class << self
##
# Drop all sessions for the given user
def call(user)
- return false unless active_record_sessions?
-
::Sessions::UserSession
.for_user(user)
.delete_all
diff --git a/app/services/sessions/drop_other_sessions_service.rb b/app/services/sessions/drop_other_sessions_service.rb
index 4cc48dc9ab5..d348dc8a88d 100644
--- a/app/services/sessions/drop_other_sessions_service.rb
+++ b/app/services/sessions/drop_other_sessions_service.rb
@@ -25,17 +25,13 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
-require_relative './base_service'
-
module Sessions
- class DropOtherSessionsService < BaseService
+ class DropOtherSessionsService
class << self
##
# Drop all other sessions for the current user.
# This can only be done when active record sessions are used.
def call(user, session)
- return false unless active_record_sessions?
-
::Sessions::UserSession
.for_user(user)
.where.not(session_id: session.id.private_id)
diff --git a/app/services/sessions/initialize_session_service.rb b/app/services/sessions/initialize_session_service.rb
index ce1ac1a3edd..69a49a004fe 100644
--- a/app/services/sessions/initialize_session_service.rb
+++ b/app/services/sessions/initialize_session_service.rb
@@ -25,10 +25,8 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
-require_relative './base_service'
-
module Sessions
- class InitializeSessionService < BaseService
+ class InitializeSessionService
class << self
##
# Initializes a new session for the given user.
@@ -52,7 +50,7 @@ module Sessions
# We can only drop old sessions if they're stored in the database
# and enabled by configuration.
def drop_old_sessions?
- active_record_sessions? && OpenProject::Configuration.drop_old_sessions_on_login?
+ OpenProject::Configuration.drop_old_sessions_on_login?
end
end
end
diff --git a/config/configuration.yml.example b/config/configuration.yml.example
index cdd90d2491c..3ea7186309d 100644
--- a/config/configuration.yml.example
+++ b/config/configuration.yml.example
@@ -238,17 +238,10 @@ default:
# use memcache for performance, memcached must be installed
# rails_cache_store: :memcache
- # defines where session data is stored
- # possible values are :cookie_store, :cache_store, :active_record_store
- session_store: :cache_store
-
# Default comment sorting for new users
# Note, does not change saved preferences of existing users
# default_comment_sort_order: 'asc'
- # If the session store is :active_record_store, the following configuration settings
- # are available
-
# Delete old sessions for the same user when logging in
# Disabled by default to allow multiple concurrent sessions.
# drop_old_sessions_on_login: false
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index f10fb78713d..10439cfed9a 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -830,11 +830,6 @@ module Settings
default: '_open_project_session',
writable: false
},
- session_store: {
- description: 'Where to store session data',
- default: :active_record_store,
- writable: false
- },
session_ttl_enabled: {
default: false
},
diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb
index 26de512d203..4426fc80260 100644
--- a/config/initializers/session_store.rb
+++ b/config/initializers/session_store.rb
@@ -27,53 +27,8 @@
#++
# Be sure to restart your server when you modify this file.
-
-module OpenProject
- ##
- # `expire_store_after` option specifically for the cache store.
- #
- # Prepend to ActionDispatch::Session::CacheStore to override `write_session`.
- #
- # We hook into there to override the `expire_after` option so that we can
- # customize it on the storage level. I.e. we want sessions to remain longer
- # in storage without affecting the session ID cookie's expiration which is
- # set one level higher up in the call chain in the rack session middleware.
- module ExpireStoreAfterOption
- def write_session(env, sid, session, options)
- if update_entry_ttl? session, options
- opts = options.to_hash
-
- return super env, sid, session, opts.merge(expire_after: new_expire_after(session, opts))
- end
-
- super
- end
-
- def new_expire_after(session, options)
- options[:expire_store_after].call session, options[:expire_after]
- rescue StandardError => e
- Rails.logger.error(
- "Failed to determine new `after_expire` value. " +
- "Falling back to original value. (#{e.message} at #{caller.first})"
- )
-
- options[:expire_after]
- end
-
- def update_entry_ttl?(session, options)
- session && options[:expire_store_after] && options[:expire_store_after].respond_to?(:call)
- end
- end
-end
-
config = OpenProject::Configuration
-# Enforce session storage for testing
-if Rails.env.test?
- config['session_store'] = :active_record_store
-end
-
-session_store = config['session_store'].to_sym
relative_url_root = config['rails_relative_url_root'].presence
session_options = {
@@ -83,36 +38,9 @@ session_options = {
path: relative_url_root
}
-if session_store == :cache_store
- # env OPENPROJECT_CACHE__STORE__SESSION__USER__TTL__DAYS
- session_ttl = config['cache_store_session_user_ttl_days']&.to_i&.days || 3.days
-
- # Extend session cache entry TTL so that they can stay logged in when their
- # session ID cookie's TTL is 'session' where usually the session entry in the
- # cache would expire before the session in the browser by default.
- session_options[:expire_store_after] = lambda do |session, expire_after|
- if session.include? "user_id" # logged-in user
- [session_ttl, expire_after].compact.max
- else
- expire_after # anonymous user
- end
- end
-end
-
-OpenProject::Application.config.session_store session_store, **session_options
+OpenProject::Application.config.session_store :active_record_store, **session_options
Rails.application.reloader.to_prepare do
- method = ActionDispatch::Session::CacheStore.instance_method(:write_session)
- unless method.to_s.include?("write_session(env, sid, session, options)")
- raise(
- "The signature for `ActionDispatch::Session::CacheStore.write_session` " +
- "seems to have changed. Please update the " +
- "`ExpireStoreAfterOption` module (and this check) in #{__FILE__}"
- )
- end
-
- ActionDispatch::Session::CacheStore.prepend OpenProject::ExpireStoreAfterOption
-
##
# We use our own decorated session model to note the user_id
# for each session.
diff --git a/docs/installation-and-operations/configuration/README.md b/docs/installation-and-operations/configuration/README.md
index 0265d576daf..8b3f598ef8a 100644
--- a/docs/installation-and-operations/configuration/README.md
+++ b/docs/installation-and-operations/configuration/README.md
@@ -171,7 +171,6 @@ Configuring OpenProject through environment variables is described in detail [in
* `scm_subversion_command` (default: 'svn')
* [`scm_local_checkout_path`](#local-checkout-path) (default: 'repositories')
* `force_help_link` (default: nil)
-* `session_store`: `active_record_store`, `cache_store`, or `cookie_store` (default: cache_store)
* `drop_old_sessions_on_logout` (default: true)
* `drop_old_sessions_on_login` (default: false)
* [`auth_source_sso`](#auth-source-sso) (default: nil)
@@ -194,29 +193,26 @@ Configuring OpenProject through environment variables is described in detail [in
## Setting session options
-Use `session_store` to define where session information is stored. In order to store sessions in the database and use the following options, set that configuration to `:active_record_store`.
-
**Delete old sessions for the same user when logging in**
-To enable, set the configuration option:
-
*default: false*
+To enable, set the configuration option:
+
```yaml
-OPENPROJECT_SESSION__STORE="{ :active_record_store: { drop_old_sessions_on_login: true } }"
+OPENPROJECT_DROP__OLD__SESSIONS__ON__LOGIN="true"
```
**Delete old sessions for the same user when logging out**
-To disable, set the configuration option:
-
*default: true*
+To disable, set the configuration option:
+
```yaml
-OPENPROJECT_SESSION__STORE="{ :active_record_store: { drop_old_sessions_on_logout: false } }"
+OPENPROJECT_DROP__OLD__SESSIONS__ON__LOGOUT="false"
```
-
### disable password login
If you enable this option you have to configure at least one omniauth authentication
diff --git a/docs/installation-and-operations/configuration/environment/README.md b/docs/installation-and-operations/configuration/environment/README.md
index cc6fc7f0d48..5e907f1d274 100644
--- a/docs/installation-and-operations/configuration/environment/README.md
+++ b/docs/installation-and-operations/configuration/environment/README.md
@@ -55,7 +55,7 @@ OPENPROJECT_STORAGE_TYPE=nfs
The configuration uses YAML to parse overrides from ENV. Using YAML inline syntax, you can:
-1. Pass a symbol as an override using `OPENPROJECT_SESSION_STORE=":active_record_store"`
+1. Pass a symbol as an override using `OPENPROJECT_ATTACHMENTS__STORAGE=":file"`
2. Pass arrays by wrapping values in brackets (e.g., `[val1, val2, val3]`).
diff --git a/spec/features/security/expire_sessions_spec.rb b/spec/features/security/expire_sessions_spec.rb
index d4058761176..bfd55d9437f 100644
--- a/spec/features/security/expire_sessions_spec.rb
+++ b/spec/features/security/expire_sessions_spec.rb
@@ -28,8 +28,7 @@
require 'spec_helper'
-describe 'Expire old user sessions',
- with_config: { session_store: :active_record_store } do
+describe 'Expire old user sessions' do
shared_let(:admin) { create(:admin) }
let(:admin_password) { 'adminADMIN!' }
diff --git a/spec/features/users/my_spec.rb b/spec/features/users/my_spec.rb
index d620924933a..e4c12fe01ad 100644
--- a/spec/features/users/my_spec.rb
+++ b/spec/features/users/my_spec.rb
@@ -28,8 +28,7 @@
require 'spec_helper'
-describe 'my',
- js: true, with_config: { session_store: :active_record_store } do
+describe 'my', js: true do
let(:user_password) { 'bob' * 4 }
let(:user) do
create(:user,
diff --git a/spec/features/users/password_change_spec.rb b/spec/features/users/password_change_spec.rb
index 031df3ff9ea..89628b3825c 100644
--- a/spec/features/users/password_change_spec.rb
+++ b/spec/features/users/password_change_spec.rb
@@ -28,8 +28,7 @@
require 'spec_helper'
-describe 'random password generation',
- js: true, with_config: { session_store: :active_record_store } do
+describe 'random password generation', js: true do
shared_let(:admin) { create(:admin) }
let(:auth_source) { build(:dummy_auth_source) }