Skip to content
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
2 changes: 2 additions & 0 deletions app/controllers/concerns/session_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def parse_oauth_referer(referer)
preferred = ref_params["preferred_auth_provider"].first
@preferred_auth_provider = preferred if preferred && Settings.key?(:"#{preferred}_auth_id")
@client_app_name = Oauth2Application.where(:uid => ref_params["client_id"].first).pick(:name)

@hide_signup = ref_params["allow_signup"].first == "false"
end

##
Expand Down
12 changes: 7 additions & 5 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# locals: () %>
<%# locals: (hide_signup:) %>

<header class="d-flex bg-body flex-column flex-md-row h-auto position-relative text-nowrap closed z-3">
<h1 class="d-flex m-0 align-items-center fw-semibold">
Expand Down Expand Up @@ -75,10 +75,12 @@
</div>
</div>
<% else %>
<div class="d-inline-flex btn-group login-menu">
<%= link_to t(".log_in"), login_path(:referer => request.fullpath), :class => "geolink btn btn-outline-secondary" %>
<%= link_to t(".sign_up"), new_user_path, :class => "btn btn-outline-secondary" %>
</div>
<% unless hide_signup %>
<div class="d-inline-flex btn-group login-menu">
<%= link_to t(".log_in"), login_path(:referer => request.fullpath), :class => "geolink btn btn-outline-secondary" %>
Comment thread
hlfan marked this conversation as resolved.
Comment thread
hlfan marked this conversation as resolved.
<%= link_to t(".sign_up"), new_user_path, :class => "btn btn-outline-secondary" %>
</div>
<% end %>
<% end %>
</nav>
</header>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/site.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= render "layouts/head", :title => @title, :opengraph_properties => @opengraph_properties %>
<%= tag.body :class => body_class,
:data => { :map_theme => current_user&.preferred_color_scheme(:map, :site) } do %>
<%= render :partial => "layouts/header" %>
<%= render :partial => "layouts/header", :locals => { :hide_signup => @hide_signup } %>
<%= render :partial => "layouts/content" %>
<% if defined?(Settings.matomo) -%>
<noscript><p><%= image_tag "#{request.protocol}#{Settings.matomo['location']}/matomo.php?idsite=#{Settings.matomo['site']}", :class => "matomo", :alt => "" %></p></noscript>
Expand Down
18 changes: 10 additions & 8 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
<% end %>

<div class="d-flex align-items-end">
<ul class="nav nav-tabs fs-6">
<li class="nav-item">
<%= link_to t("sessions.new.tab_title"), "#", :class => "nav-link active" %>
</li>
<li class="nav-item">
<%= link_to t("users.new.tab_title"), url_for(:action => :new, :controller => :users, :referer => params[:referer]), :class => "nav-link" %>
</li>
</ul>
<% unless @hide_signup %>
<ul class="nav nav-tabs fs-6">
<li class="nav-item">
<%= link_to t("sessions.new.tab_title"), "#", :class => "nav-link active" %>
</li>
<li class="nav-item">
<%= link_to t("users.new.tab_title"), url_for(:action => :new, :controller => :users, :referer => params[:referer]), :class => "nav-link" %>
</li>
</ul>
<% end %>
<div class="flex-grow-1 header-illustration new-user-main"></div>
</div>
<% end %>
Expand Down
39 changes: 39 additions & 0 deletions test/integration/oauth2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,45 @@ def test_openid_key
assert_equal Doorkeeper::OpenidConnect.signing_key.kid, key_info["keys"][0]["kid"]
end

def test_allow_signup_not_set
client = create(:oauth_application, :redirect_uri => "https://some.web.app.example.org/callback", :scopes => "read_prefs write_api read_gpx")

options = {
:client_id => client.uid,
:redirect_uri => client.redirect_uri,
:response_type => "code",
:scope => "read_prefs"
}

oauth_path = oauth_authorization_path(options)
login_for_oauth_path = login_path(:referer => oauth_path)
cookies["_osm_session"] = "reassure the backend that cookies are enabled"
get oauth_path
assert_redirected_to login_for_oauth_path
get login_for_oauth_path
assert_match "Sign Up", response.body
end

def test_allow_signup_false
client = create(:oauth_application, :redirect_uri => "https://some.web.app.example.org/callback", :scopes => "read_prefs write_api read_gpx")

options = {
:client_id => client.uid,
:redirect_uri => client.redirect_uri,
:response_type => "code",
:scope => "read_prefs",
:allow_signup => "false"
}

oauth_path = oauth_authorization_path(options)
login_for_oauth_path = login_path(:referer => oauth_path)
cookies["_osm_session"] = "reassure the backend that cookies are enabled"
get oauth_path
assert_redirected_to login_for_oauth_path
get login_for_oauth_path
assert_no_match "Sign Up", response.body
end

private

def authorize_client(user, client, options = {})
Expand Down