Skip to content

Commit

Permalink
Fix: Redirect to the login page when accessing private ontology while…
Browse files Browse the repository at this point in the history
… being not authenticated (#673)
  • Loading branch information
Bilelkihal authored Jun 21, 2024
1 parent 0d6dd48 commit a332b32
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 121 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/login.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.login-form{
margin-top: 30px;
margin-top: 10px;
padding: 37px 41px;
box-shadow: rgba(0, 0, 0, 0.08) 0px 20px 50px;
border-radius: 14px;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/ontologies.scss
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ $widget-table-border-color: #EFEFEF;
#bd_content .sidebar {
overflow-x: auto;
white-space: nowrap;
min-width: 35%;
min-width: 29%;
}

#search_box:focus {
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,16 @@ def show
return
end


# Note: find_by_acronym includes ontology views
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
ontology_not_found(params[:ontology]) if @ontology.nil? || @ontology.errors

if @ontology.nil? || @ontology.errors
if ontology_access_denied?
redirect_to "/login?redirect=/ontologies/#{params[:ontology]}", alert: t('login.private_ontology')
return
else
ontology_not_found(params[:ontology])
end
end

# Handle the case where an ontology is converted to summary only.
# See: https://github.com/ncbo/bioportal_web_ui/issues/133.
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module OntologiesHelper
API_KEY = $API_KEY
LANGUAGE_FILTERABLE_SECTIONS = %w[classes schemes collections instances properties].freeze

def ontology_access_denied?
@ontology&.errors&.include?('Access denied for this resource')
end

def concept_search_input(placeholder)
content_tag(:div, class: 'search-inputs p-1') do
text_input(placeholder: placeholder, label: '', name: "search", value: '', data: { action: "input->browse-filters#dispatchInputEvent" })
Expand Down
105 changes: 0 additions & 105 deletions app/javascript/controllers/content_finder_controller.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/javascript/controllers/label_ajax_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class extends Controller {
success: this.#ajaxSuccess.bind(this),
error: this.#ajaxError.bind(this)
});
},0)
},1)
}

abort() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class extends Controller {
ontology_name: key.split('/').pop(),
ontology_mappings: value,
}))

this.bubblesTarget.innerHTML = ''
useMappingsDrawBubbles(data, width, height, margin, this.bubblesTarget, normalization_ratio, logScaleFactor)

this.#centerScroll(this.frameTarget)
Expand Down
2 changes: 1 addition & 1 deletion app/views/instances/_details.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

= render ConceptDetailsComponent.new(id:'instance-details', acronym: ontology_acronym, concept_id: @instance["@id"]) do |c|
- c.header(stripped: true) do |t|
- t.add_row({th: t("instances.id")}, {td: link_to_with_actions(@instance["@id"]) })
- t.add_row({th: t("instances.id")}, {td: link_to_with_actions(@instance["@id"], acronym: @ontology.acronym) })

- label = @instance['label'] || @instance['prefLabel']
- unless label.blank?
Expand Down
9 changes: 4 additions & 5 deletions app/views/login/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
- @title = t('login.title')
- unless @errors.nil?
%div{:style => "color:red;"}
= t('login.invalid_login')
%ul
.d-flex.justify-content-center.mt-4
- unless @errors.nil?
= render Display::AlertComponent.new(type: "danger", closable: false) do
- for error in @errors
%li= error
%div=error
.d-flex.justify-content-center
.login-form
= form_for(:user, :url => {:controller => 'login',:action=>'create'}) do |f|
Expand Down
3 changes: 2 additions & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Load the Rails application.
require_relative "application"
require_relative 'application'


# Remove this after migrating to Rails 7.1 (https://github.com/rails/rails/issues/32947#issuecomment-1356391185)
class Rails::Application
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ en:
enter_email: Enter your username
enter_password: Enter your password
forgot_password: Forgot password?
invalid_login: Errors on the form
private_ontology: This ontology is private. Please login.
no_account: Do not have an account?
password: Password
register: Register
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ fr:
enter_email: Entrez votre nom d'utilisateur
enter_password: Entrez votre mot de passe
forgot_password: Mot de passe oublié ?
invalid_login: Erreurs sur le formulaire
private_ontology: Cette ontologie est privée. Veuillez vous connecter.
no_account: Vous n'avez pas de compte ?
password: Mot de passe
register: S'inscrire
Expand Down

0 comments on commit a332b32

Please sign in to comment.