Skip to content

v3.7.0 #598

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

Merged
merged 2 commits into from
Mar 11, 2021
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
18 changes: 14 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class ApplicationController < ActionController::Base

append_before_action :check_for_terms_acceptance!, unless: :devise_controller?
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :set_locale
before_action :set_current_organization
before_action :set_locale,
:set_current_organization,
:store_user_location

rescue_from MissingTOSAcceptance, OutadedTOSAcceptance do
redirect_to terms_path
Expand Down Expand Up @@ -38,8 +39,18 @@ def set_current_organization
end
end

def store_user_location
if request.get? && !request.xhr? && is_navigational_format? && !devise_controller?
store_location_for(:user, request.fullpath)
end
end

def after_sign_in_path_for(user)
if user.members.present?
stored_location = stored_location_for(user)

if stored_location.present?
stored_location
elsif user.members.present?
users_path
else
page_path("about")
Expand Down Expand Up @@ -76,7 +87,6 @@ def admin?
def superadmin?
current_user.try :superuser?
end

alias :superuser? :superadmin?

def authenticate_superuser!
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
class SessionsController < Devise::SessionsController

# POST /resource/sign_in
def create
super
flash.delete(:notice)
end

# DELETE /resource/sign_out
def destroy
super
flash.delete(:notice)
end
end
end
1 change: 0 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def show_error_messages!(resource)
def markdown(content)
RDiscount.new(content || ''.freeze).to_html.html_safe
end

alias m markdown

# Green or red CSS class depending on whether
Expand Down
31 changes: 16 additions & 15 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
RSpec.describe SessionsController do
let(:user) do
Fabricate(:user, password: 'papapa22', password_confirmation: 'papapa22')
let(:user) { Fabricate(:user, password: 'papapa22', password_confirmation: 'papapa22') }

before do
request.env["devise.mapping"] = Devise.mappings[:user]
end

describe '#create' do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
end

it 'does not show a notice flash message' do
post :create, params: { user: {
email: user.email,
password: user.password
} }
post :create, params: { user: { email: user.email, password: user.password } }

expect(flash[:notice]).to be_nil
end

it 'redirects to the previous page' do
session["user_return_to"] = offers_path

post :create, params: { user: { email: user.email, password: user.password } }

expect(response).to redirect_to(offers_path)
end
end

describe '#destroy' do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
post :create, params: { user: {
email: user.email,
password: user.password
} }
post :create, params: { user: { email: user.email, password: user.password } }
end

it 'does not show a notice flash message' do
delete :destroy

expect(flash[:notice]).to be_nil
end
end
Expand Down