Skip to content

Commit

Permalink
3161 - Owner login with no collection should go to 'Start a project'
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNigel23 committed Jul 24, 2024
1 parent a48a707 commit 06fa68c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def switch_locale(&action)
end

# append region to locale
related_locales = http_accept_language.user_preferred_languages.select do |loc|
related_locales = http_accept_language.user_preferred_languages.select do |loc|
loc.to_s.include?(locale.to_s) && # is related to the chosen locale (is the locale, or is a regional version of it)
I18n.available_locales.map{|e| e.to_s}.include?(loc.to_s) # is an available locale
end
Expand Down Expand Up @@ -84,7 +84,7 @@ def guest_user
def guest_transcription

return head(:forbidden) unless GUEST_TRANSCRIPTION_ENABLED

if check_recaptcha(model: @page, :attribute => :errors)
User.find(session[:guest_user_id].nil? ? session[:guest_user_id] = create_guest_user.id : session[:guest_user_id])
redirect_to :controller => 'transcribe', :action => 'display_page', :page_id => @page.id
Expand Down Expand Up @@ -198,7 +198,7 @@ def set_friendly_collection(id)
elsif !DocumentSet.find_by(slug: id).nil?
@collection = DocumentSet.find_by(slug: id)
elsif !Collection.find_by(slug: id).nil?
@collection = Collection.find_by(slug: id)
@collection = Collection.find_by(slug: id)
end

# check to make sure URLs haven't gotten scrambled
Expand Down Expand Up @@ -324,7 +324,11 @@ def after_sign_in_path_for(resource)
elsif !session[:user_return_to].blank? && session[:user_return_to] != '/' && !session[:user_return_to].include?('/landing')
session[:user_return_to]
elsif current_user.owner
dashboard_owner_path
if current_user.collections.any?
dashboard_owner_path
else
dashboard_startproject_path
end
else
dashboard_watchlist_path
end
Expand Down
10 changes: 9 additions & 1 deletion spec/features/devise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,15 @@
click_button('Sign In')
expect(page.current_path).to eq old_path
end
it "redirects owner back to user dashboard/watchlist if original path was nil" do
it "redirects owner back to user dashboard/watchlist if original path was nil and user has no collection" do
visit new_user_session_path
page.fill_in 'Login', with: owner.login
page.fill_in 'Password', with: owner.password
click_button('Sign In')
expect(page.current_path).to eq dashboard_startproject_path
end
it "redirects owner back to user dashboard/watchlist if original path was nil and user has collection" do
_collection = create(:collection, owner_user_id: owner.id)
visit new_user_session_path
page.fill_in 'Login', with: owner.login
page.fill_in 'Password', with: owner.password
Expand Down

0 comments on commit 06fa68c

Please sign in to comment.