diff --git a/Gemfile b/Gemfile index ccb3208..4b9b2fa 100644 --- a/Gemfile +++ b/Gemfile @@ -81,8 +81,8 @@ end gem 'ruby-openai', '~> 7.0' -gem "devise", "~> 4.9" -gem "devise-jwt", "~> 0.12.0" +gem 'devise', '~> 4.9' +gem 'devise-jwt', '~> 0.12.0' gem 'solid_queue', '~> 0.3.3' diff --git a/Gemfile.lock b/Gemfile.lock index 80ac5c8..6ad16ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -166,9 +166,9 @@ GEM jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) + json (2.7.2) jwt (2.8.2) base64 - json (2.7.2) language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c9a3ab3..b8546f7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class ApplicationController < ActionController::Base - protect_from_forgery with: :exception, if: Proc.new { |c| c.request.format != 'application/json' } - protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' } + protect_from_forgery with: :exception, if: proc { |c| c.request.format != 'application/json' } + protect_from_forgery with: :null_session, if: proc { |c| c.request.format == 'application/json' } before_action :authenticate_user! diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 5376fec..8003cad 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -97,7 +97,7 @@ # Notice that if you are skipping storage for all authentication paths, you # may want to disable generating routes to Devise's sessions controller by # passing skip: :sessions to `devise_for` in your config/routes.rb - config.skip_session_storage = [:http_auth, :params_auth] + config.skip_session_storage = %i[http_auth params_auth] # By default, Devise cleans up the CSRF token on authentication to # avoid CSRF token fixation attacks. This means that, when using AJAX @@ -313,6 +313,23 @@ # devise-jwt config config.jwt do |jwt| - jwt.secret = Rails.application.credentials.devise_jwt_secret_key! + credentials = Rails.application.credentials + + unless credentials.devise_jwt_secret_key.present? + encrypted = ActiveSupport::EncryptedConfiguration.new( + config_path: 'config/credentials.yml.enc', + key_path: 'config/master.key', + env_key: 'RAILS_MASTER_KEY', + raise_if_missing_key: true + ) + + current_credentials = YAML.load(encrypted.read) || {} + devise_jwt_secret_key = SecureRandom.hex(12) + updated_credentials = current_credentials.deep_merge({devise_jwt_secret_key: devise_jwt_secret_key}) + encrypted.write(updated_credentials.to_yaml) + jwt.secret = devise_jwt_secret_key + else + jwt.secret = credentials.devise_jwt_secret_key! + end end end diff --git a/db/migrate/20240605185921_create_messages.rb b/db/migrate/20240605185921_create_messages.rb deleted file mode 100644 index 69e49ba..0000000 --- a/db/migrate/20240605185921_create_messages.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class CreateMessages < ActiveRecord::Migration[7.1] - def change - create_table :messages do |t| - t.text :body - - t.timestamps - end - end -end diff --git a/db/migrate/20240605222045_add_from_to_message.rb b/db/migrate/20240605222045_add_from_to_message.rb deleted file mode 100644 index 96c830e..0000000 --- a/db/migrate/20240605222045_add_from_to_message.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class AddFromToMessage < ActiveRecord::Migration[7.1] - def change - add_column :messages, :from, :string, default: :user - end -end diff --git a/db/migrate/20240605222936_create_chats.rb b/db/migrate/20240605222936_create_chats.rb deleted file mode 100644 index 439b463..0000000 --- a/db/migrate/20240605222936_create_chats.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class CreateChats < ActiveRecord::Migration[7.1] - def change - create_table :chats do |t| - t.string :title - - t.timestamps - end - end -end diff --git a/db/migrate/20240609152859_create_participants.rb b/db/migrate/20240609152859_create_participants.rb deleted file mode 100644 index 752eb29..0000000 --- a/db/migrate/20240609152859_create_participants.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class CreateParticipants < ActiveRecord::Migration[7.1] - def change - create_table :participants do |t| - t.string :name - t.text :configuration - t.string :implementor - - t.timestamps - end - end -end diff --git a/db/migrate/20240609153938_add_chat_ref_to_messages.rb b/db/migrate/20240609153938_add_chat_ref_to_messages.rb deleted file mode 100644 index 58ed028..0000000 --- a/db/migrate/20240609153938_add_chat_ref_to_messages.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class AddChatRefToMessages < ActiveRecord::Migration[7.1] - def change - add_reference :messages, :chat, null: false, foreign_key: true - end -end diff --git a/db/migrate/20240715112948_drop_unused_tables.rb b/db/migrate/20240715112948_drop_unused_tables.rb deleted file mode 100644 index ffbba3b..0000000 --- a/db/migrate/20240715112948_drop_unused_tables.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class DropUnusedTables < ActiveRecord::Migration[7.1] - def up - drop_table :messages - drop_table :chats - drop_table :participants - end - - def down - create_table :chats do |t| - t.string :title - - t.timestamps - end - - create_table :messages do |t| - t.text :body - t.string :from - t.references :chat - - t.timestamps - end - - create_table :participants do |t| - t.string :name - t.text :configuration - t.string :implementor - - t.timestamps - end - end -end diff --git a/db/schema.rb b/db/schema.rb index b2ede0e..30a4ea3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 20_240_715_112_948) do +ActiveRecord::Schema[7.1].define(version: 20_240_712_102_033) do # These are extensions that must be enabled in order to support this database enable_extension 'plpgsql' diff --git a/rails b/rails deleted file mode 100644 index 9588986..0000000 --- a/rails +++ /dev/null @@ -1 +0,0 @@ -$(bin/rails db:encryption:init) credentials:edit