-
Notifications
You must be signed in to change notification settings - Fork 51
Group license 1244 #1268
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
base: dev
Are you sure you want to change the base?
Group license 1244 #1268
Changes from all commits
5513f20
5873e77
ac078ca
26497ca
c9734f2
0f9305a
786f60d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,9 @@ class GroupsController < ApplicationController | |
|
||
before_action :license_check, :only => [:show, :create, :switch, :edit, :update, :unregister, :destroy] | ||
|
||
# few license related attributes are updated here | ||
before_action :group_license_attributes, :only => [:show, :new_license, :add_license, :show_license, :sign_license] | ||
|
||
# GET /groups | ||
# GET /groups.xml | ||
def index #:nodoc: | ||
|
@@ -268,6 +271,114 @@ def license_redirect #:nodoc: | |
end | ||
end | ||
|
||
def new_license #:nodoc: | ||
cb_error "Only owner can set licensing", :redirect => { :action => :show } unless @can_add_license | ||
end | ||
|
||
def add_license #:nodoc: | ||
cb_error("Only owner can set licensing", :redirect => { :action => :show }) unless @can_add_license | ||
|
||
license_text = params[:license_text] | ||
cb_error 'Empty licenses are presently not allowed' if license_text.blank? | ||
|
||
timestamp = Time.zone.now.strftime("%Y-%m-%dT%H:%M:%S") | ||
group_name = @group.name.gsub(/[^\w]+/, "") | ||
file_name = "license_#{group_name}_#{timestamp}.txt" | ||
license = @group.register_custom_license(license_text, current_user, file_name) | ||
current_user.signs_license_for_project(license, @group, model='group') | ||
|
||
flash[:notice] = 'A license is added. You can force users to sign multiple license agreements if needed.' | ||
redirect_to :action => :show | ||
end | ||
|
||
def show_license #:nodoc: | ||
# @group = @current_user.visible_groups.where(id: params[id]).first | ||
|
||
unsigned_licenses = current_user.unsigned_custom_licenses(@group) | ||
|
||
if unsigned_licenses.empty? | ||
if @current_licenses.present? | ||
flash[:notice] = 'You already signed all licenses' | ||
else | ||
flash[:notice] = 'No licenses are defined for this project' | ||
redirect_to :action => :show | ||
return | ||
end | ||
end | ||
|
||
# What to show. If a license is given in params, | ||
# we make sure it's a registered one and we pick that. | ||
@license_id = false unless @current_licenses.include? @license_id | ||
# If no valid license was given and there are unsigned licenses, pick the first | ||
@license_id ||= unsigned_licenses.first.try(:to_i) | ||
# Otherwise, show the first license. | ||
@license_id ||= @current_licenses.first | ||
|
||
# Load the text of the license | ||
userfile = Userfile.find(@license_id) | ||
userfile.sync_to_cache | ||
@license_text = userfile.cache_readhandle { |fh| fh.read } | ||
|
||
# Identifies if the current user has already signed it, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be removed too ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you want to remove comment that's for class variables, verbatim copy of the same comment Pierre made (or merged in) in a Neurohub controller, but confirm if you find it redundand |
||
# and whether they are the author | ||
end | ||
|
||
def sign_license #:nodoc: | ||
|
||
unless @group.custom_license_agreements.include?(@license_id) | ||
flash[:error] = 'You are trying to access unrelated license. Try again or report the issue to the support.' | ||
redirect_to :action => :show | ||
return | ||
end | ||
|
||
if @is_signed | ||
flash[:error] = 'You have already signed this license.' | ||
redirect_to :action => :show | ||
return | ||
end | ||
|
||
unless params.has_key?(:agree) | ||
flash[:error] = "You cannot access that project without signing the License Agreement first." | ||
redirect_to :action => :index | ||
return | ||
end | ||
|
||
if params[:license_check].blank? || params[:license_check].to_i == 0 | ||
flash[:error] = "There was a problem with your submission. Please read the agreement and check the checkbox." | ||
redirect_to show_license_group_path(@group) | ||
return | ||
end | ||
|
||
license = Userfile.find(@license_id) | ||
current_user.signs_license_for_project(license, @group, model='group') | ||
|
||
if current_user.unsigned_custom_licenses(@group).empty? | ||
flash[:notice] = 'You signed all the project licenses' | ||
else | ||
flash[:notice] = 'This project has at least one other license agreement' | ||
end | ||
redirect_to :action => :show, :id => @group.id | ||
end | ||
|
||
# check license for project (group) with id pid, | ||
def license_check(pid=false) | ||
pid = pid || params[:id] | ||
|
||
|
||
return true if pid == 'all' ## to do && current_user.has_role(:admin) | ||
# if unexpected id - let the action method handle the error message | ||
begin | ||
@group = current_user.viewable_groups.find(pid) | ||
rescue ActiveRecord::RecordNotFound | ||
return true | ||
end | ||
if current_user.unsigned_custom_licenses(@group).present? | ||
flash[:error] = "Access to the project #{@group.name} is blocked due to licensing issues. Please sign the license" | ||
# license_redirect | ||
raise CbrainLicenseException | ||
end | ||
end | ||
|
||
private | ||
|
||
def group_params #:nodoc: | ||
|
@@ -285,19 +396,14 @@ def group_params #:nodoc: | |
end | ||
end | ||
|
||
def license_check | ||
return true if params[:id].blank? | ||
return true if params[:id] == 'all' | ||
# if unexpected id - let the action method handle the error message | ||
begin | ||
@group = current_user.viewable_groups.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound | ||
return true | ||
end | ||
if current_user.unsigned_custom_licenses(@group).present? | ||
flash[:error] = "Access to the project #{@group.name} is blocked due to licensing issues. Please consult with the project maintainer or support for details" | ||
license_redirect | ||
end | ||
def group_license_attributes # helper updates custom license attribute | ||
@group = @current_user.viewable_groups.find(params[:id]) | ||
@can_add_license = current_user.id == @group&.creator_id | ||
@current_licenses = @group.custom_license_agreements | ||
|
||
param_lic_id = params['license_id'].presence | ||
@license_id = param_lic_id && param_lic_id.to_i # nil if param is nil-like, otherwise cast to integer | ||
@is_signed = current_user.custom_licenses_signed.include?(@license_id) | ||
end | ||
|
||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
<%- | ||
# | ||
# 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"> | ||
<p class="card-label">Carefully read this license agreement.</p> | ||
<pre class="card-text license-text"><%= @license_text %></pre> | ||
<% if @is_signed %> | ||
<% if @is_author %> | ||
<div class="status success"><%= nh_icon_checkmark %>As the author of the license you have implicitely signed this agreement.</div> | ||
<% else %> | ||
<div class="status success"><%= nh_icon_checkmark %>You have already signed this license agreement. </div> | ||
<% end %> | ||
<% end %> | ||
<% if !@is_signed %> | ||
<div class="status error"><%= nh_icon_error %> This license agreement is not yet signed. </div> | ||
<div class="d-flex"> | ||
<%= check_box_tag :license_check, 1, nil, :class => "my-2" %> | ||
<%= label_tag(:license_check,"By clicking here, I agree with all the conditions above.", :class=>"ml-2 card-label") %> | ||
</div> | ||
<% end %> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
<%- | ||
# | ||
# CBRAIN 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/>. | ||
# | ||
-%> | ||
|
||
<% title "Add License", "" %> | ||
|
||
<h2>Add New Licence to Project <%= @group.name %> </h2> | ||
|
||
<div id="new_license" > | ||
<%= form_tag add_license_group_path(@group) do %> | ||
<div class="generalbox"> | ||
<div class="field_note"><b>Important:</b> | ||
All members of the project will be required to sign the agreement in order to access the project. | ||
You, as the author, will be be considered as having signed it implicitly. | ||
MontrealSergiy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</div> | ||
|
||
<p> | ||
<label>Enter license text: </label> | ||
</p> | ||
<p> | ||
<%= text_area_tag "license_text", "", :required => true, :rows => 20, :class => "whole_width" %> | ||
|
||
</p> | ||
<div> | ||
<%= submit_tag "Add License", :name => :add_license, :class => "button" %> | ||
<span class="field_note"> | ||
You can assign additional license agreements at any time. | ||
</span> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> | ||
|
Uh oh!
There was an error while loading. Please reload this page.