Skip to content

Commit

Permalink
Merge pull request #493 from DMPRoadmap/development
Browse files Browse the repository at this point in the history
Merging for release v.0.3.0
  • Loading branch information
vyruss authored Jul 5, 2017
2 parents f894545 + 156fc6f commit 2d1ea52
Show file tree
Hide file tree
Showing 49 changed files with 289 additions and 409 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def set_locale_session
if FastGettext.default_available_locales.include?(params[:locale])
session[:locale] = params[:locale]
end
redirect_to root_path
redirect_to(request.referer || root_path) #redirects the user to URL where she/he was when the request to this resource was made or root if none is encountered
end

def store_location
Expand Down
13 changes: 2 additions & 11 deletions app/controllers/guidances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,11 @@ def admin_create
@guidance = Guidance.new(guidance_params)
authorize @guidance
@guidance.text = params["guidance-text"]

@guidance.themes = []
if !guidance_params[:theme_ids].nil?
guidance_params[:theme_ids].map{|t| @guidance.themes << Theme.find(t.to_i) unless t.empty? }
end

if @guidance.published == true then
@gg = GuidanceGroup.find(@guidance.guidance_group_id)
if @gg.published == false || @gg.published.nil? then
@gg.published = true
@gg.save
end
end

if @guidance.save
redirect_to admin_show_guidance_path(@guidance), notice: _('Guidance was successfully created.')
Expand All @@ -69,8 +61,7 @@ def admin_update
@guidance = Guidance.find(params[:id])
authorize @guidance
@guidance.text = params["guidance-text"]

if @guidance.save(guidance_params)
if @guidance.update_attributes(guidance_params)
redirect_to admin_show_guidance_path(params[:guidance]), notice: _('Guidance was successfully updated.')
else
flash[:notice] = failed_update_error(@guidance, _('guidance'))
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def admin_update
private
def org_params
params.require(:org).permit(:name, :abbreviation, :target_url, :is_other, :banner_text, :language_id,
:region_id, :logo, :contact_email)
:region_id, :logo, :contact_email, :remove_logo)
end
end
22 changes: 12 additions & 10 deletions app/controllers/phases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@ def edit
# get the ids of the dynamically selected guidance groups
# and keep a map of them so we can extract the names later
guidance_groups_ids = @plan.guidance_groups.map{|pgg| pgg.id}
guidance_groups = GuidanceGroup.includes({guidances: :themes}).find(guidance_groups_ids)
guidance_groups = GuidanceGroup.includes({guidances: :themes}).where(published: true, id: guidance_groups_ids)

# create a map from theme to array of guidances
# where guidance is a hash with the text and the org name
theme_guidance = {}

guidance_groups.each do |guidance_group|
guidance_groups.includes(guidances:[:themes]).each do |guidance_group|
guidance_group.guidances.each do |guidance|
guidance.themes.each do |theme|
title = theme.title
if !theme_guidance.has_key?(title)
theme_guidance[title] = Array.new
if guidance.published
guidance.themes.each do |theme|
title = theme.title
if !theme_guidance.has_key?(title)
theme_guidance[title] = Array.new
end
theme_guidance[title] << {
text: guidance.text,
org: guidance_group.name + ':'
}
end
theme_guidance[title] << {
text: guidance.text,
org: guidance_group.name + ':'
}
end
end
end
Expand Down
152 changes: 31 additions & 121 deletions app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def index
def new
@plan = Plan.new
authorize @plan

# Get all of the available funders and non-funder orgs
@funders = Org.funders.joins(:templates).where(templates: {published: true}).uniq.sort{|x,y| x.name <=> y.name }
@orgs = (Org.institutions + Org.managing_orgs).flatten.uniq.sort{|x,y| x.name <=> y.name }

# Get the current user's org
@default_org = current_user.org if @orgs.include?(current_user.org)

respond_to :html
end

Expand All @@ -32,48 +32,48 @@ def new
def create
@plan = Plan.new
authorize @plan

@plan.principal_investigator = current_user.surname.blank? ? nil : "#{current_user.firstname} #{current_user.surname}"
@plan.data_contact = current_user.email
@plan.funder_name = plan_params[:funder_name]

# If a template hasn't been identified look for the available templates
if plan_params[:template_id].blank?
template_options(plan_params[:org_id], plan_params[:funder_id])

# Return the 'Select a template' section
respond_to do |format|
format.js {}
format.js {}
end

# Otherwise create the plan
else
@plan.template = Template.find(plan_params[:template_id])

if plan_params[:title].blank?
@plan.title = current_user.firstname.blank? ? _('My Plan') + '(' + @plan.template.title + ')' :
@plan.title = current_user.firstname.blank? ? _('My Plan') + '(' + @plan.template.title + ')' :
current_user.firstname + "'s" + _(" Plan")
else
@plan.title = plan_params[:title]
end

if @plan.save
@plan.assign_creator(current_user)

# pre-select org's guidance
ggs = GuidanceGroup.where(org_id: plan_params[:org_id],
optional_subset: false,
ggs = GuidanceGroup.where(org_id: plan_params[:org_id],
optional_subset: false,
published: true)
if !ggs.blank? then @plan.guidance_groups << ggs end
if !ggs.blank? then @plan.guidance_groups << ggs end

default = Template.find_by(is_default: true)

msg = "#{_('Plan was successfully created.')} "

if !default.nil? && default == @plan.template
# We used the generic/default template
msg += _('This plan is based on the default template.')

elsif !@plan.template.customization_of.nil?
# We used a customized version of the the funder template
msg += "#{_('This plan is based on the')} #{plan_params[:funder_name]} #{_('template with customisations by the')} #{plan_params[:org_name]}"
Expand All @@ -82,9 +82,9 @@ def create
# We used the specified org's or funder's template
msg += "#{_('This plan is based on the')} #{@plan.template.org.name} template."
end

flash[:notice] = msg

respond_to do |format|
format.js { render js: "window.location='#{plan_url(@plan)}?editing=true'" }
end
Expand All @@ -93,7 +93,7 @@ def create
# Something went wrong so report the issue to the user
flash[:notice] = failed_create_error(@plan, 'Plan')
respond_to do |format|
format.js {}
format.js {}
end
end
end
Expand All @@ -115,8 +115,8 @@ def show
@important_ggs = []
@important_ggs << [current_user.org, @all_ggs_grouped_by_org.delete(current_user.org)]
@all_ggs_grouped_by_org.each do |org, ggs|
if org.organisation?
@important_ggs << [org,ggs]
if org.organisation?
@important_ggs << [org,ggs]
@all_ggs_grouped_by_org.delete(org)
end
end
Expand Down Expand Up @@ -226,96 +226,6 @@ def status
end
end


# TODO: Remove these endpoints now that we're no longer using them
=begin
def section_answers
@plan = Plan.find(params[:id])
authorize @plan
respond_to do |format|
format.json { render json: @plan.section_answers(params[:section_id]) }
end
end
def locked
@plan = Plan.find(params[:id])
authorize @plan
if !@plan.nil? && user_signed_in? && @plan.readable_by(current_user.id) then
respond_to do |format|
format.json { render json: @plan.locked(params[:section_id],current_user.id) }
end
else
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
end
end
def delete_recent_locks
@plan = Plan.find(params[:id])
authorize @plan
if user_signed_in? && @plan.editable_by(current_user.id) then
respond_to do |format|
if @plan.delete_recent_locks(current_user.id)
format.html { render action: "edit" }
else
format.html { render action: "edit" }
end
end
else
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
end
end
def unlock_all_sections
@plan = Plan.find(params[:id])
authorize @plan
if user_signed_in? && @plan.editable_by(current_user.id) then
respond_to do |format|
if @plan.unlock_all_sections(current_user.id)
format.html { render action: "edit" }
else
format.html { render action: "edit" }
end
end
else
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
end
end
def lock_section
@plan = Plan.find(params[:id])
authorize @plan
if user_signed_in? && @plan.editable_by(current_user.id) then
respond_to do |format|
if @plan.lock_section(params[:section_id], current_user.id)
format.html { render action: "edit" }
else
format.html { render action: "edit" }
format.json { render json: @plan.errors, status: :unprocessable_entity }
end
end
else
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
end
end
def unlock_section
@plan = Plan.find(params[:id])
authorize @plan
if user_signed_in? && @plan.editable_by(current_user.id) then
respond_to do |format|
if @plan.unlock_section(params[:section_id], current_user.id)
format.html { render action: "edit" }
else
format.html { render action: "edit" }
end
end
else
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
end
end
=end

def answer
@plan = Plan.find(params[:id])
authorize @plan
Expand Down Expand Up @@ -388,7 +298,7 @@ def export

private

def plan_params
def plan_params
params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title)
end

Expand Down Expand Up @@ -459,7 +369,7 @@ def rollup(plan, src_plan_key, super_id, obj_plan_key)
# --------------------------------------------------------------------------
def template_options(org_id, funder_id)
@templates = []

if !org_id.blank? || !funder_id.blank?
if funder_id.blank?
# Load the org's template(s)
Expand All @@ -468,15 +378,15 @@ def template_options(org_id, funder_id)
@templates = Template.valid.where(published: true, org: org, customization_of: nil).to_a
@msg = _("We found multiple DMP templates corresponding to the research organisation.") if @templates.count > 1
end

else
funder = Org.find(funder_id)
# Load the funder's template(s)
@templates = Template.valid.where(published: true, org: funder).to_a

unless org_id.blank?
org = Org.find(org_id)

# Swap out any organisational cusotmizations of a funder template
@templates.each do |tmplt|
customization = Template.valid.find_by(published: true, org: org, customization_of: tmplt.dmptemplate_id)
Expand All @@ -486,17 +396,17 @@ def template_options(org_id, funder_id)
end
end
end

msg = _("We found multiple DMP templates corresponding to the funder.") if @templates.count > 1
end
end

# If no templates were available use the generic templates
if @templates.empty?
@msg = _("Using the generic Data Management Plan")
@templates << Template.find_by(is_default: true)
end

@templates = @templates.sort{|x,y| x.title <=> y.title } if @templates.count > 1
end

Expand Down
11 changes: 11 additions & 0 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,21 @@ def admin_update
if guidance.blank?
guidance = @question.annotations.build
guidance.type = :guidance
guidance.org_id = current_user.org_id
end
guidance.text = params["question-guidance-#{params[:id]}"]
guidance.save
end
example_answer = @question.get_example_answer(current_user.org_id)
if params["question"]["annotations_attributes"].present? && params["question"]["annotations_attributes"]["0"]["id"].present?
if example_answer.blank?
example_answer = @question.annotations.build
example_answer.type = :example_answer
example_answer.org_id = current_user.org_id
end
example_answer.text = params["question"]["annotations_attributes"]["0"]["text"]
example_answer.save
end
if @question.question_format.textfield?
@question.default_value = params["question-default-value-textfield"]
elsif @question.question_format.textarea?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def admin_update_permissions
else
if perms.include? perm
@user.perms << perm
if perm.name == Perm.use_api.id
if perm.id == Perm.use_api.id
@user.keep_or_generate_token!
end
end
Expand Down
Loading

0 comments on commit 2d1ea52

Please sign in to comment.