8000 Fix redirection when viewing a page that requires login by Floppy · Pull Request #2697 · manyfold3d/manyfold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix redirection when viewing a page that requires login #2697

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 3 commits into from
Sep 17, 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
14 changes: 14 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class ApplicationController < ActionController::Base
before_action :check_scan_status
before_action :remember_ordering

unless Rails.env.test?
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
end

def index
raise NotImplementedError
end
Expand Down Expand Up @@ -86,4 +90,14 @@ def random_delay
# by adding a random 0-2 second delay into the response. There is probably a better way.
sleep Random.new.rand(2.0)
end

private

def user_not_authorized
if current_user
raise ActiveRecord::RecordNotFound
else
redirect_to new_session_path(:user)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_collection
authorize Collection
@title = t(".unknown")
else
@collection = Collection.includes(:links, :caber_relations).find_by(public_id: params[:id])
@collection = Collection.includes(:links, :caber_relations).find_by!(public_id: params[:id])
authorize @collection
@title = @collection.name
end
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/concerns/filterable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def filtered_models(filters)

# Filter by library
def filter_by_library(models, library)
l = Library.find_by(public_id: library)
l ? models.where(library: l) : models
library ? models.where(library: Library.find_by!(public_id: library)) : models
end

# Filter by collection
Expand All @@ -36,7 +35,7 @@ def filter_by_collection(models, collection)
when ""
models.where(collection_id: nil)
else
@collection = Collection.find_by(public_id: collection)
@collection = Collection.find_by!(public_id: collection)
models.where(collection: Collection.tree_down(@collection.id))
end
end
Expand All @@ -49,7 +48,7 @@ def filter_by_creator(models, creator)
when ""
models.where(creator_id: nil)
else
@creator = Creator.find_by(public_id: creator)
@creator = Creator.find_by!(public_id: creator)
models.where(creator: @creator)
end
end
Expand Down Expand Up @@ -97,7 +96,7 @@ def filter_by_missing_tag(models, missingtag, library)
# Missing tags (If specific tag is not specified, require library to be set)
if missingtag.presence || (missingtag && library)
tag_regex_build = []
regexes = ((missingtag != "") ? [missingtag] : Library.find_by(public_id: library).tag_regex)
regexes = ((missingtag != "") ? [missingtag] : Library.find_by!(public_id: library).tag_regex)
# Regexp match syntax - postgres is different from MySQL and SQLite
regact = ApplicationRecord.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) ? "~" : "REGEXP"
regexes.each do |reg|
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/creators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_creator
authorize Creator
@title = t(".unknown")
else
@creator = Creator.includes(:links, :caber_relations).find_by(public_id: params[:id])
@creator = Creator.includes(:links, :caber_relations).find_by!(public_id: params[:id])
authorize @creator
@title = @creator.name
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/libraries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def library_params
end

def get_library
@library = Library.find_by(public_id: params[:id])
@library = Library.find_by!(public_id: params[:id])
authorize @library
@title = @library.name
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/model_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def show
def create
authorize @model
if params[:convert]
file = ModelFile.find_by(public_id: params[:convert][:id])
file = ModelFile.find_by!(public_id: params[:convert][:id])
Analysis::FileConversionJob.perform_later(file.id, params[:convert][:to].to_sym)
redirect_back_or_to [@model, file], notice: t(".conversion_started")
elsif params[:uploads]
Expand Down Expand Up @@ -65,7 +65,7 @@ def bulk_update
hash = bulk_update_params
params[:model_files].each_pair do |id, selected|
if selected == "1"
file = @model.model_files.find_by(public_id: id)
file = @model.model_files.find_by!(public_id: id)
current_user.set_list_state(file, :printed, params[:printed] === "1")
if file.update(hash)
file.save
Expand Down Expand Up @@ -118,11 +118,11 @@ def file_params
end

def get_model
@model = Model.find_by(public_id: params[:model_id])
@model = Model.find_by!(public_id: params[:model_id])
end

def get_file
@file = @model.model_files.includes(:unsupported_version, :presupported_version).find_by(public_id: params[:id])
@file = @model.model_files.includes(:unsupported_version, :presupported_version).find_by!(public_id: params[:id])
authorize @file
@title = @file.name
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def edit

def create
authorize :model
library = Library.find_by(public_id: params[:library])
library = Library.find_by!(public_id: params[:library])
uploads = begin
JSON.parse(params[:uploads])[0]["successful"]
rescue
Expand Down Expand Up @@ -197,7 +197,7 @@ def model_params
end

def get_model
@model = Model.includes(:model_files, :creator, :preview_file, :library, :tags, :taggings, :links, :caber_relations).find_by(public_id: params[:id])
@model = Model.includes(:model_files, :creator, :preview_file, :library, :tags, :taggings, :links, :caber_relations).find_by!(public_id: params[:id])
authorize @model
@title = @model.name
end
Expand All @@ -209,8 +209,8 @@ def get_creators_and_collections

def set_returnable
session[:return_after_new] = request.fullpath.split("?")[0]
@new_collection = Collection.find_by(public_id: params[:new_collection]) if params[:new_collection]
@new_creator = Creator.find_by(public_id: params[:new_creator]) if params[:new_creator]
@new_collection = Collection.find_by!(public_id: params[:new_collection]) if params[:new_collection]
@new_creator = Creator.find_by!(public_id: params[:new_creator]) if params[:new_creator]
if @model
@model.collection = @new_collection if @new_collection
@model.collection = @new_creator if @new_creator
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def index
end

def update
@problem = Problem.unscoped.find_by(public_id: params[:id])
@problem = Problem.unscoped.find_by!(public_id: params[:id])
authorize @problem
@problem.update!(permitted_params)
notice = t(
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_filters_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% if @filters[:library] %>
<div class="row">
<div class="col-auto"><%= icon "boxes", Library.model_name.human %></div>
<div class="col" aria-label="<%= Library.model_name.human %>"><%= [*@filters[:library]].map { |l| Library.find_by(public_id: l).name }.join(", ") %></div>
<div class="col" aria-label="<%= Library.model_name.human %>"><%= [*@filters[:library]].map { |l| Library.find_by!(public_id: l).name }.join(", ") %></div>
<div class="col-auto"><%= link_to icon("trash", t(".remove_library_filter")), @filters.except(:library), {class: "text-danger"} %></div>
</div>
<% end %>
Expand Down
Loading
0