Skip to content

infopages and licenses for neurohub resolves #1010, #1233 #1234

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

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions BrainPortal/app/assets/stylesheets/neurohub.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3220,6 +3220,7 @@ $DASHBOARD_CARD_MIN_WIDTH: 25;
border: 1px solid $DEFAULT_ALT;
border-radius: 2px;
overflow: scroll;
box-sizing: border-box;
}
.license-list {
background: $PRIMARY_WASH;
Expand Down Expand Up @@ -3265,6 +3266,42 @@ $DASHBOARD_CARD_MIN_WIDTH: 25;
}
}

#nh_portal_license {
.status {
@include text("xs");
svg {
@include mr(1);
width: 1rem;
}
&.success {
color: $SUCCESS_ALT;
svg {
fill: $SUCCESS_ALT;
stroke: $SUCCESS_ALT;
}
}
&.error {
color: $ERROR_BG;
svg {
fill: $ERROR_BG;
stroke: $ERROR_BG;
}
}
}


* , *:before, *:after {
box-sizing: border-box;
}
.license-text {
overflow: auto;
}
.btn-section {
align-self: flex-start;
flex: unset;
}
}

/*
=============================================================
| STORAGES
Expand Down
4 changes: 2 additions & 2 deletions BrainPortal/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def activate_user_time_zone #:nodoc:
# or sign license agreements.
def check_account_validity #:nodoc:
return false unless current_user
return true if params[:controller] == "sessions"
return true if params[:controller] =~ /sessions$/
return false unless check_mandatory_globus_id_linkage()
return false unless check_password_reset()
return false unless check_license_agreements()
Expand Down Expand Up @@ -149,7 +149,7 @@ def check_license_agreements #:nodoc:
return true if params[:controller] == "portal" && params[:action] =~ /license$/
return true if params[:controller] == "users" && (params[:action] == "change_password" || params[:action] == "update")

unsigned_agreements = current_user.unsigned_license_agreements
unsigned_agreements = current_user.cbrain_unsigned_license_agreements
unless unsigned_agreements.empty?
if File.exists?(Rails.root + "public/licenses/#{unsigned_agreements.first}.html")
respond_to do |format|
Expand Down
26 changes: 22 additions & 4 deletions BrainPortal/app/controllers/neurohub_application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,28 @@ def check_if_locked

end

# For the moment on the NeuroHub side, we bypass checking the site-wide
# licenses. They'll still be required if the user switch to CBRAIN.
def check_license_agreements
true
# overrides check_license_agreements, as list of NeuroHub licenses may differ from cbrains
def check_license_agreements #:nodoc:

current_user.meta.reload
return true if current_user.neurohub_licenses_signed.present?
return true if params[:controller] == "neurohub_portal" && params[:action] =~ /license$/
return true if params[:controller] == "nh_users" && (params[:action] == "change_password" || params[:action] == "update")

unsigned_agreements = current_user.neurohub_unsigned_license_agreements
unless unsigned_agreements.empty?
if File.exists?(Rails.root + "public/licenses/#{unsigned_agreements.first}.html")
respond_to do |format|
format.html { redirect_to :controller => :neurohub_portal, :action => :nh_show_license, :license => unsigned_agreements.first }
format.json { render :status => 403, :json => { "error" => "Some license agreements are not signed." } }
format.xml { render :status => 403, :xml => { "error" => "Some license agreements are not signed." } }
end
return false
end
end

current_user.neurohub_licenses_signed = "yes"
return true
end

########################################################################
Expand Down
35 changes: 34 additions & 1 deletion BrainPortal/app/controllers/neurohub_portal_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,38 @@ def search
@projects = report[:projects]
end

end
def nh_sign_license #:nodoc:
@license = params[:license]
unless params.has_key?(:agree) # no validation for info pages
flash[:error] = "#Neurohub cannot be used without signing the End User Licence Agreement."
redirect_to '/signout'
return
end
num_checkboxes = params[:num_checkboxes].to_i
if num_checkboxes > 0
num_checks = params.keys.grep(/\Alicense_check/).size
if num_checks < num_checkboxes
flash[:error] = "There was a problem with your submission. Please read the agreement and check all checkboxes."
redirect_to :action => :nh_show_license, :license => @license
return
end
end
current_user.accept_license_agreement @license
redirect_to :action => :welcome
end

def nh_show_license #:nodoc:
@license = params[:license].gsub(/[^\w-]+/, "")

# NeuroHub signed licenses to be shown in NeuroHub, CBRAIN signed licenses to be shown in CBRAIN
unless @license.start_with? 'nh-'
flash[:error] = 'Redirecting to CBRAIN, this license is best viewed via CBRAIN'
redirect_to :controller => :portal, :action => :show_license, :license => @license
return
end

@is_signed = current_user.custom_licenses_signed.include?(@license_id)
render :nh_show_infolicense if @license&.end_with? "_info" # info license does not require to accept it
end

end
16 changes: 12 additions & 4 deletions BrainPortal/app/controllers/portal_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,21 @@ def portal_log #:nodoc:

def show_license #:nodoc:
@license = params[:license].gsub(/[^\w-]+/, "")

# to reduce user confusion
# NeuroHub signed licenses are showed in NeuroHub, CBRAIN signed licenses are shown in CBRAIN
if @license.start_with? 'nh-'
flash[:notice] = 'You are redirected to NeuroHub, this license is best viewed via NeuroHub'
redirect_to :controller => :neurohub_portal, :action => :nh_show_license, :license => @license
return
end

render :show_infolicense if @license&.end_with? "_info" # info license does not require to accept it
end

def sign_license #:nodoc:
@license = params[:license]
#todo add @license.length check, max 4k perhaps?
unless params.has_key?(:agree)
flash[:error] = "CBRAIN cannot be used without signing the End User Licence Agreement."
redirect_to "/logout"
Expand All @@ -214,10 +225,7 @@ def sign_license #:nodoc:
return
end
end
signed_agreements = current_user.meta[:signed_license_agreements] || []
signed_agreements << @license
current_user.meta[:signed_license_agreements] = signed_agreements
current_user.addlog("Signed license agreement '#{@license}'.")
current_user.accept_license_agreement @license
redirect_to start_page_path
end

Expand Down
60 changes: 54 additions & 6 deletions BrainPortal/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,20 @@ def signed_license_agreements(license_agreement_set=self.license_agreement_set)
self.meta[:signed_license_agreements] || []
end

def unsigned_license_agreements #:nodoc:
license_agreement_set = self.license_agreement_set
def cbrain_unsigned_license_agreements #:nodoc:
# Difference between all cbrain license agreements and signed by the user
cbrain_license_agreement_set - (strip_prefix signed_license_agreements)
end

# Difference between all license agreements and whom signed by the user
license_agreement_set - self.signed_license_agreements(license_agreement_set)
def neurohub_unsigned_license_agreements #:nodoc:
neurohub_license_agreement_set - (add_prefix signed_license_agreements)
end

def license_agreement_set #:nodoc:
# all NeuroHub and cbrain agreements (on accessible objects)
def license_agreement_set
all_object_with_license = RemoteResource.find_all_accessible_by_user(self) +
Tool.find_all_accessible_by_user(self) +
DataProvider.find_all_accessible_by_user(self)

license_agreements = []
# List all license_agreements
all_object_with_license.each do |o|
Expand All @@ -170,6 +172,17 @@ def license_agreement_set #:nodoc:
RemoteResource.current_resource.license_agreements + license_agreements
end

# cbrain required licenses
def cbrain_license_agreement_set
license_agreement_set.reject {|l| l.start_with?('nh-')}
end

# neurohub license agreement set
def neurohub_license_agreement_set
RemoteResource.current_resource.license_agreements.select {|l| l.start_with?('nh-')}
end

# a flag that all required cbrain licenses are signed
def all_licenses_signed #:nodoc:
self.meta.reload
self.meta[:all_licenses_signed]
Expand All @@ -180,6 +193,25 @@ def all_licenses_signed=(x) #:nodoc:
self.meta[:all_licenses_signed] = x
end

# neurohub specific licenses are signed flag
def neurohub_licenses_signed #:nodoc:
self.meta.reload
self.meta['neurohub_licenses_signed']
end

# neurohub specific licenses are signed flag setter
def neurohub_licenses_signed=(x) #:nodoc:
self.meta.reload
self.meta['neurohub_licenses_signed'] = x
end

def accept_license_agreement(license) # logs and saves signed agreement id (either on cbrain or neurohub side)
signed_agreements = self.meta[:signed_license_agreements] || []
signed_agreements << license
self.meta[:signed_license_agreements] = signed_agreements
self.addlog("Signed license agreement '#{@license}'.")
end

#############################################################
#
# Custom, user-created licenses for misc objects
Expand Down Expand Up @@ -613,4 +645,20 @@ def add_system_groups #:nodoc:
true
end

# strips prefix in a string array
def strip_prefix(a, prefix='nh-')
a.map {|l| l.sub(/\A#{prefix}/, "")}
end

# add prefix to string array if missing
def add_prefix(a, prefix='nh-')
a.map do |l|
if l.start_with? prefix
l
else
prefix + l
end
end
end

end
5 changes: 4 additions & 1 deletion BrainPortal/app/views/bourreaux/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@
<% licenses = @bourreau.license_agreements.count == 0 ? "(None)": @bourreau.license_agreements.join("\n") %>
<% t.edit_cell(:license_agreements, :content => licenses) do |f| %>
<%= f.text_area :license_agreements, :value => @bourreau.license_agreements.join("\n"), :rows => 5, :cols => 40 %><br>
<div class="field_explanation">Enter one agreement name per line. Note that only alphanumeric characters, underscores (_) and dashes (-) are accepted.</div>
<div class="field_explanation">Enter one agreement name per line. Note that only alphanumeric characters, underscores (_) and dashes (-) are accepted.
the licenses starting with <i>nh-</i> prefix are reserved for NeuroHub. <i> _info </i> suffix indicates optional information
which does not oblige user to accept anything. It should be used to communicating important information.
</div>
<% end %>

<% if is_bourreau %>
Expand Down
44 changes: 44 additions & 0 deletions BrainPortal/app/views/neurohub_portal/_list_licenses.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<%-
#
# NeuroHub Project
#
# Copyright (C) 2020
# The Royal Institution for the Advancement of Learning
# McGill University
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-%>

<% if licenses.present? %>
<div class="card-row">
<div class="card-item">
<div>
<p class="card-label"> <%= heading %> | <%= licenses.count %></p>
<div class="card-text pt-2">
<% licenses.each do |license| %>
<%= link_to "#{license}",
{
:controller => :neurohub_portal,
:action => :nh_show_license,
:license => license
},
:class => "btn-text primary bg-primary-wash mt-1"
%>
<% end %>
</div>
</div>
</div>
</div>
<% end %>
40 changes: 40 additions & 0 deletions BrainPortal/app/views/neurohub_portal/_show_license_text.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<%-
#
# NeuroHub Project
#
# Copyright (C) 2020
# The Royal Institution for the Advancement of Learning
# McGill University
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-%>

<div class="card-item">

<% if ! is_signed %>
<p class="card-label">Carefully read this license agreement</p>
<% else %>
<p class="card-label">A license agreement (already signed by you)</p>
<% end %>

<br>

<div class="card-text license-text">
<% content = File.read(Rails.root + "public/licenses/#{@license}.html") rescue "(Error fetching license text)" %>
<% content.gsub!(/<input\s/i, "<INPUT DISABLED CHECKED ") if is_signed %>
<%= content.html_safe %>
</div>

</div>
Loading