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

Cookies #41

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def set_locale
session[:locale] || http_accept_language.preferred_language_from(I18n.available_locales)
end

def last_visited_page
redirect_to cookies[:last_visited_page] || root_path
end

private

def require_user
Expand Down
6 changes: 5 additions & 1 deletion app/models/featured_scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def localized_description(locale)
end

def as_json(options = {})
super.merge(version: version, end_year: end_year)
super.merge(
version: version,
end_year: end_year,
author: owner&.user&.name || "No author"
)
end
end
7 changes: 7 additions & 0 deletions app/models/featured_scenario_user.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class FeaturedScenarioUser < ApplicationRecord
# TODO user should be optional. Either User or Name.
# TODO form to create Featured scenario users from admin console!
belongs_to :user
has_many :featured_scenarios, foreign_key: :owner_id, dependent: :destroy

validates :name, presence: true
validates :user, presence: true
end
3 changes: 2 additions & 1 deletion app/views/layouts/_buttons.html.haml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.flex.py-5
.bg-gray-100.p-2.px-5.mr-0.ml-auto.rounded-md Continue working (in Classic/in Collections)
.bg-gray-100.p-2.px-5.mr-0.ml-auto.rounded-md
= link_to t('continue_working'), last_visited_page_path, class: 'continue-button'
2 changes: 1 addition & 1 deletion config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MyEtm::Application.config.session_store :active_record_store, key: "_idp_session"
MyEtm::Application.config.session_store :active_record_store, key: "_idp_session", domain: :all, tld_length: 2
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ en:
undo: Undo
more: More...
language: English
continue_working: "Back to work"

errors:
sorry: Oops! We're sorry
Expand Down
1 change: 1 addition & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
nl:
language: Nederlands
continue_working: Terug aan het werk
time:
formats:
short: "%-d %b %H:%M"
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
mount Sidekiq::Web => '/sidekiq'
end

get '/last_visited_page', to: 'application#last_visited_page', as: :last_visited_page

namespace :identity do
get '/', to: redirect('/identity/profile')
get 'profile', to: 'settings#index', as: :profile
Expand Down
6 changes: 5 additions & 1 deletion spec/factories/featured_scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
title_en { 'English title' }
title_nl { 'Dutch title' }

owner { association :featured_scenario_user }
transient do
with_owner { false }
end

owner { with_owner ? association(:featured_scenario_user) : nil }
end
end
6 changes: 3 additions & 3 deletions spec/requests/api/featured_scenarios_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

parsed_response['featured_scenarios'].each do |scenario|
expect(scenario.keys).to contain_exactly(
'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year'
'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year', 'author'
)
expect(scenario['version']).to eq('latest')
end
Expand All @@ -42,7 +42,7 @@

parsed_response['featured_scenarios'].each do |scenario|
expect(scenario.keys).to contain_exactly(
'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year'
'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year', 'author'
)
expect(scenario['version']).to eq('old')
end
Expand All @@ -58,7 +58,7 @@
expect(response).to have_http_status(:ok)
parsed_response = JSON.parse(response.body)
expect(parsed_response.keys).to contain_exactly(
'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year'
'id', 'saved_scenario_id', 'owner_id', 'group', 'title_en', 'title_nl', 'version', 'end_year', 'author'
)
expect(parsed_response['id']).to eq(featured_scenario_id)
expect(parsed_response['version']).to eq('latest')
Expand Down
Loading