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
8 changes: 8 additions & 0 deletions app/controllers/contributors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def new
# GET /plans/:plan_id/contributors/:id/edit
def edit
authorize @plan
@all_orgs = Org.all

# choose which org partial to use for choosing org
@org_partial = if Rails.configuration.x.application.restrict_orgs
"shared/org_selectors/local_only"
else
"shared/org_selectors/combined"
end
end

# POST /plans/:plan_id/contributors
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ class HomeController < ApplicationController
# User's contact name is not filled in
# Is this the desired behavior?
def index
@all_orgs = Org.all

# choose which org patial to use for choosing org
@org_partial = if Rails.configuration.x.application.restrict_orgs
"shared/org_selectors/local_only"
else
"shared/org_selectors/combined"
end

if user_signed_in?
name = current_user.name(false)
# The RolesController defaults the firstname and surname (both required fields)
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ def show
else
Template.where(family_id: @plan.template.customization_of).first
end

@all_orgs = Org.all

# choose which org patial to use for choosing org
@org_partial = if Rails.configuration.x.application.restrict_orgs
"shared/org_selectors/local_only"
else
"shared/org_selectors/combined"
end

respond_to :html
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
Expand Down
53 changes: 29 additions & 24 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def edit
@identifier_schemes = IdentifierScheme.for_users.order(:name)
@default_org = current_user.org

# choose which org patial to use for choosing org
@org_partial = if Rails.configuration.x.application.restrict_orgs
"shared/org_selectors/local_only"
else
"shared/org_selectors/combined"
end

msg = "No default preferences found (should be in dmproadmap.rb initializer)."
flash[:alert] = msg unless @prefs
end
Expand All @@ -28,22 +35,20 @@ def new

@user = User.new

# rubocop:disable Style/GuardClause
unless oauth.nil?
# The OAuth provider could not be determined or there was no unique UID!
if !oauth["provider"].nil? && !oauth["uid"].nil?
# Connect the new user with the identifier sent back by the OAuth provider
# rubocop:disable Layout/LineLength
flash[:notice] = _("Please make a choice below. After linking your details to a %{application_name} account, you will be able to sign in directly with your institutional credentials.") % {
application_name: ApplicationService.application_name
}
end
end
# rubocop:enable Style/GuardClause
# no oath, no provider or no uid - bail out
return if oauth.nil? or oauth["provider"].nil? or oauth["uid"].nil?

# Connect the new user with the identifier sent back by the OAuth provider
flash[:notice] = _("Please make a choice below. After linking your
details to a %{application_name} account,
you will be able to sign in directly with your
institutional credentials.") % {
application_name: ApplicationService.application_name
}
end

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/BlockNesting, Layout/LineLength
# POST /resource
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockNesting
def create
oauth = { provider: nil, uid: nil }
IdentifierScheme.for_users.each do |scheme|
Expand All @@ -52,12 +57,18 @@ def create
end
end

blank_org = if Rails.configuration.x.application.restrict_orgs
sign_up_params[:org_id]["id"].blank?
else
sign_up_params[:org_id].blank?
end

if sign_up_params[:accept_terms].to_s == "0"
redirect_to after_sign_up_error_path_for(resource),
alert: _("You must accept the terms and conditions to register.")
elsif sign_up_params[:org_id].blank?
elsif blank_org
redirect_to after_sign_up_error_path_for(resource),
alert: _("Please select an organisation from the list, or enter your organisation's name.")
alert: _("Please select an organisation from the list, or choose Other.")
else
existing_user = User.where_case_insensitive("email", sign_up_params[:email]).first
if existing_user.present?
Expand Down Expand Up @@ -119,8 +130,7 @@ def create
end
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockNesting
# rubocop:enable
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/BlockNesting

def update
if user_signed_in?
Expand Down Expand Up @@ -149,7 +159,7 @@ def needs_password?(user)
user.email != update_params[:email] || update_params[:password].present?
end

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Layout/LineLength, Metrics/BlockNesting
def do_update(require_password = true, confirm = false)
mandatory_params = true
# added to by below, overwritten otherwise
Expand All @@ -169,9 +179,7 @@ def do_update(require_password = true, confirm = false)
mandatory_params &&= false
end
if update_params[:org_id].blank?
# rubocop:disable Layout/LineLength
message += _("Please select an organisation from the list, or enter your organisation's name.")
# rubocop:enable Layout/LineLength
mandatory_params &&= false
end
# has the user entered all the details
Expand All @@ -186,7 +194,6 @@ def do_update(require_password = true, confirm = false)
# if user is changing email
if current_user.email != attrs[:email]
# password needs to be present
# rubocop:disable Metrics/BlockNesting
if attrs[:password].blank?
message = _("Please enter your password to change email address.")
successfully_updated = false
Expand All @@ -200,7 +207,6 @@ def do_update(require_password = true, confirm = false)
else
message = _("Invalid password")
end
# rubocop:enable Metrics/BlockNesting
else
# remove the current_password because its not actuallyt part of the User record
attrs.delete(:current_password)
Expand Down Expand Up @@ -244,8 +250,7 @@ def do_update(require_password = true, confirm = false)
render "edit"
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Layout/LineLength, Metrics/BlockNesting

# rubocop:disable Metrics/AbcSize
def do_update_password(current_user, args)
Expand Down
22 changes: 22 additions & 0 deletions app/controllers/users/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ class Users::InvitationsController < Devise::InvitationsController
# to the Org after Devise does its thing
prepend_after_action :handle_org, only: [:update]

def edit
@all_orgs = Org.all
# choose which org patial to use for choosing org
@org_partial = if Rails.configuration.x.application.restrict_orgs
"shared/org_selectors/local_only"
else
"shared/org_selectors/combined"
end
super
end

def update
@all_orgs = Org.all
# choose which org patial to use for choosing org
@org_partial = if Rails.configuration.x.application.restrict_orgs
"shared/org_selectors/local_only"
else
"shared/org_selectors/combined"
end
super
end

protected

# Override require_no_authentication method defined at DeviseController
Expand Down
2 changes: 2 additions & 0 deletions app/presenters/org_selection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def crosswalk

def select_list
@crosswalk.map { |rec| rec[:name] }.to_json
rescue StandardError
nil
end

def crosswalk_entry_from_org_id(value:)
Expand Down
3 changes: 2 additions & 1 deletion app/views/contributors/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ roles_tooltip = _("Select each role that applies to the contributor.")

<div class="form-group row" id="contributor-org-controls"><!-- org -->
<div class="col-md-8">
<%= render partial: "shared/org_selectors/combined",
<%= render partial: org_partial,
locals: { form: form,
orgs: orgs,
default_org: contributor.org,
required: false,
label: _("Affiliation") } %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/contributors/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<%= form_for @contributor, url: plan_contributor_path(@plan, @contributor),
html: { method: :put } do |f| %>
<%= render partial: "contributors/form",
locals: { form: f, plan: @plan, contributor: @contributor } %>
locals: { form: f, plan: @plan, contributor: @contributor, orgs: @orgs, org_partial: @org_partial } %>
<% end %>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/devise/invitations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
<%= f.text_field(:surname, class: "form-control", "aria-required": true, value: @user.surname) %>
</div>
<div class="form-group" id="invite-org-controls">
<%= render partial: "shared/org_selectors/combined",
<%= render partial: @org_partial,
locals: {
form: f,
orgs: @all_orgs,
default_org: nil,
required: true
} %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/devise/registrations/_personal_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

<% org_admin = (current_user.can_org_admin? && !current_user.can_super_admin?) %>
<div class="form-group col-xs-8" id="profile-org-controls" <%= "data-toggle=\"tooltip\" title=\"#{_('Changing your organisation will result in the loss of your administrative privileges.')}\"" if org_admin %>>
<%= render partial: "shared/org_selectors/combined",
<%= render partial: org_partial,
locals: {
form: f,
orgs: orgs,
default_org: current_user.org,
required: true
} %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div id="personal-details" role="tabpanel" class="tab-pane active">
<div class="panel panel-default">
<div class="panel-body">
<%= render partial: 'devise/registrations/personal_details' %>
<%= render partial: 'devise/registrations/personal_details', locals: {orgs: @orgs, org_partial: @org_partial} %>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
</div>

<div class="col-md-4">
<%= render partial: 'shared/access_controls' %>
<%= render partial: 'shared/access_controls', locals: {orgs: @all_orgs, org_partial: @org_partial} %>
</div>
</div>
4 changes: 0 additions & 4 deletions app/views/layouts/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
<ul class="nav navbar-nav navbar-right">
<%= render "layouts/signin_signout" %>
</ul>

<% unless user_signed_in? || ((controller_name.eql? "home") && (action_name.eql? "index")) %>
<%= render partial: 'shared/access_controls', layout: 'shared/modal', locals: { id: "header-signin", title: _('Sign in')} %>
<% end %>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
2 changes: 1 addition & 1 deletion app/views/plans/_edit_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="row">
<div class="col-md-8">
<%= render partial: "plans/project_details",
locals: { form: f, plan: plan } %>
locals: { form: f, plan: plan, orgs: orgs, org_partial: org_partial } %>

<%= f.button(_('Save'), class: "btn btn-default", type: "submit") %>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/plans/_project_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@
<%# Otherwise display the Org typeahead for funders %>
<div class="col-md-8">
<%= fields_for :funder, plan.funder do |funder_fields| %>
<%= render partial: "shared/org_selectors/combined",
<%= render partial: org_partial,
locals: {
form: form,
orgs: orgs,
funder_only: true,
label: _("Funder"),
default_org: plan.funder,
Expand Down
2 changes: 1 addition & 1 deletion app/views/plans/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<div class="row">
<div class="col-md-12">
<%= render partial: partial, layout: 'navigation',
locals: { plan: @plan, visibility: @visibility } %>
locals: { plan: @plan, visibility: @visibility, orgs: @orgs, org_partial: @org_partial } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/shared/_access_controls.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<div id="create-account-form" role="tabpanel" class="tab-pane">
<div class="panel panel-default">
<div class="panel-body">
<%= render :partial => 'shared/create_account_form', locals: {extended: false} %>
<%= render :partial => 'shared/create_account_form', locals: {orgs: orgs, org_partial: org_partial} %>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/shared/_create_account_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
<%= f.email_field(:email, class: "form-control", "aria-required": true) %>
</div>
<div class="form-group" id="create-account-org-controls">
<%= render partial: "shared/org_selectors/combined",
<%= render partial: org_partial,
locals: {
form: f,
orgs: orgs,
default_org: resource&.org,
required: true
} %>
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/_dmproadmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class Application < Rails::Application
}
}
}
# Setting to only take orgs from local and not allow on-the-fly creation
config.x.application.restrict_orgs = false

# ------------------- #
# SHIBBOLETH SETTINGS #
Expand Down