Skip to content

Commit 2d1ea52

Browse files
authored
Merge pull request #493 from DMPRoadmap/development
Merging for release v.0.3.0
2 parents f894545 + 156fc6f commit 2d1ea52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+289
-409
lines changed

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def set_locale_session
3333
if FastGettext.default_available_locales.include?(params[:locale])
3434
session[:locale] = params[:locale]
3535
end
36-
redirect_to root_path
36+
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
3737
end
3838

3939
def store_location

app/controllers/guidances_controller.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,11 @@ def admin_create
3939
@guidance = Guidance.new(guidance_params)
4040
authorize @guidance
4141
@guidance.text = params["guidance-text"]
42-
42+
4343
@guidance.themes = []
4444
if !guidance_params[:theme_ids].nil?
4545
guidance_params[:theme_ids].map{|t| @guidance.themes << Theme.find(t.to_i) unless t.empty? }
4646
end
47-
48-
if @guidance.published == true then
49-
@gg = GuidanceGroup.find(@guidance.guidance_group_id)
50-
if @gg.published == false || @gg.published.nil? then
51-
@gg.published = true
52-
@gg.save
53-
end
54-
end
5547

5648
if @guidance.save
5749
redirect_to admin_show_guidance_path(@guidance), notice: _('Guidance was successfully created.')
@@ -69,8 +61,7 @@ def admin_update
6961
@guidance = Guidance.find(params[:id])
7062
authorize @guidance
7163
@guidance.text = params["guidance-text"]
72-
73-
if @guidance.save(guidance_params)
64+
if @guidance.update_attributes(guidance_params)
7465
redirect_to admin_show_guidance_path(params[:guidance]), notice: _('Guidance was successfully updated.')
7566
else
7667
flash[:notice] = failed_update_error(@guidance, _('guidance'))

app/controllers/orgs_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ def admin_update
4747
private
4848
def org_params
4949
params.require(:org).permit(:name, :abbreviation, :target_url, :is_other, :banner_text, :language_id,
50-
:region_id, :logo, :contact_email)
50+
:region_id, :logo, :contact_email, :remove_logo)
5151
end
5252
end

app/controllers/phases_controller.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ def edit
2323
# get the ids of the dynamically selected guidance groups
2424
# and keep a map of them so we can extract the names later
2525
guidance_groups_ids = @plan.guidance_groups.map{|pgg| pgg.id}
26-
guidance_groups = GuidanceGroup.includes({guidances: :themes}).find(guidance_groups_ids)
26+
guidance_groups = GuidanceGroup.includes({guidances: :themes}).where(published: true, id: guidance_groups_ids)
2727

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

32-
guidance_groups.each do |guidance_group|
32+
guidance_groups.includes(guidances:[:themes]).each do |guidance_group|
3333
guidance_group.guidances.each do |guidance|
34-
guidance.themes.each do |theme|
35-
title = theme.title
36-
if !theme_guidance.has_key?(title)
37-
theme_guidance[title] = Array.new
34+
if guidance.published
35+
guidance.themes.each do |theme|
36+
title = theme.title
37+
if !theme_guidance.has_key?(title)
38+
theme_guidance[title] = Array.new
39+
end
40+
theme_guidance[title] << {
41+
text: guidance.text,
42+
org: guidance_group.name + ':'
43+
}
3844
end
39-
theme_guidance[title] << {
40-
text: guidance.text,
41-
org: guidance_group.name + ':'
42-
}
4345
end
4446
end
4547
end

app/controllers/plans_controller.rb

Lines changed: 31 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ def index
1616
def new
1717
@plan = Plan.new
1818
authorize @plan
19-
19+
2020
# Get all of the available funders and non-funder orgs
2121
@funders = Org.funders.joins(:templates).where(templates: {published: true}).uniq.sort{|x,y| x.name <=> y.name }
2222
@orgs = (Org.institutions + Org.managing_orgs).flatten.uniq.sort{|x,y| x.name <=> y.name }
23-
23+
2424
# Get the current user's org
2525
@default_org = current_user.org if @orgs.include?(current_user.org)
26-
26+
2727
respond_to :html
2828
end
2929

@@ -32,48 +32,48 @@ def new
3232
def create
3333
@plan = Plan.new
3434
authorize @plan
35-
35+
3636
@plan.principal_investigator = current_user.surname.blank? ? nil : "#{current_user.firstname} #{current_user.surname}"
3737
@plan.data_contact = current_user.email
3838
@plan.funder_name = plan_params[:funder_name]
39-
39+
4040
# If a template hasn't been identified look for the available templates
4141
if plan_params[:template_id].blank?
4242
template_options(plan_params[:org_id], plan_params[:funder_id])
4343

4444
# Return the 'Select a template' section
4545
respond_to do |format|
46-
format.js {}
46+
format.js {}
4747
end
48-
48+
4949
# Otherwise create the plan
5050
else
5151
@plan.template = Template.find(plan_params[:template_id])
52-
52+
5353
if plan_params[:title].blank?
54-
@plan.title = current_user.firstname.blank? ? _('My Plan') + '(' + @plan.template.title + ')' :
54+
@plan.title = current_user.firstname.blank? ? _('My Plan') + '(' + @plan.template.title + ')' :
5555
current_user.firstname + "'s" + _(" Plan")
5656
else
5757
@plan.title = plan_params[:title]
5858
end
59-
59+
6060
if @plan.save
6161
@plan.assign_creator(current_user)
62-
62+
6363
# pre-select org's guidance
64-
ggs = GuidanceGroup.where(org_id: plan_params[:org_id],
65-
optional_subset: false,
64+
ggs = GuidanceGroup.where(org_id: plan_params[:org_id],
65+
optional_subset: false,
6666
published: true)
67-
if !ggs.blank? then @plan.guidance_groups << ggs end
68-
67+
if !ggs.blank? then @plan.guidance_groups << ggs end
68+
6969
default = Template.find_by(is_default: true)
70-
70+
7171
msg = "#{_('Plan was successfully created.')} "
72-
72+
7373
if !default.nil? && default == @plan.template
7474
# We used the generic/default template
7575
msg += _('This plan is based on the default template.')
76-
76+
7777
elsif !@plan.template.customization_of.nil?
7878
# We used a customized version of the the funder template
7979
msg += "#{_('This plan is based on the')} #{plan_params[:funder_name]} #{_('template with customisations by the')} #{plan_params[:org_name]}"
@@ -82,9 +82,9 @@ def create
8282
# We used the specified org's or funder's template
8383
msg += "#{_('This plan is based on the')} #{@plan.template.org.name} template."
8484
end
85-
85+
8686
flash[:notice] = msg
87-
87+
8888
respond_to do |format|
8989
format.js { render js: "window.location='#{plan_url(@plan)}?editing=true'" }
9090
end
@@ -93,7 +93,7 @@ def create
9393
# Something went wrong so report the issue to the user
9494
flash[:notice] = failed_create_error(@plan, 'Plan')
9595
respond_to do |format|
96-
format.js {}
96+
format.js {}
9797
end
9898
end
9999
end
@@ -115,8 +115,8 @@ def show
115115
@important_ggs = []
116116
@important_ggs << [current_user.org, @all_ggs_grouped_by_org.delete(current_user.org)]
117117
@all_ggs_grouped_by_org.each do |org, ggs|
118-
if org.organisation?
119-
@important_ggs << [org,ggs]
118+
if org.organisation?
119+
@important_ggs << [org,ggs]
120120
@all_ggs_grouped_by_org.delete(org)
121121
end
122122
end
@@ -226,96 +226,6 @@ def status
226226
end
227227
end
228228

229-
230-
# TODO: Remove these endpoints now that we're no longer using them
231-
=begin
232-
def section_answers
233-
@plan = Plan.find(params[:id])
234-
authorize @plan
235-
respond_to do |format|
236-
format.json { render json: @plan.section_answers(params[:section_id]) }
237-
end
238-
end
239-
240-
def locked
241-
@plan = Plan.find(params[:id])
242-
authorize @plan
243-
if [email protected]? && user_signed_in? && @plan.readable_by(current_user.id) then
244-
respond_to do |format|
245-
format.json { render json: @plan.locked(params[:section_id],current_user.id) }
246-
end
247-
else
248-
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
249-
end
250-
end
251-
252-
def delete_recent_locks
253-
@plan = Plan.find(params[:id])
254-
authorize @plan
255-
if user_signed_in? && @plan.editable_by(current_user.id) then
256-
respond_to do |format|
257-
if @plan.delete_recent_locks(current_user.id)
258-
format.html { render action: "edit" }
259-
else
260-
format.html { render action: "edit" }
261-
end
262-
end
263-
else
264-
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
265-
end
266-
end
267-
268-
def unlock_all_sections
269-
@plan = Plan.find(params[:id])
270-
authorize @plan
271-
if user_signed_in? && @plan.editable_by(current_user.id) then
272-
respond_to do |format|
273-
if @plan.unlock_all_sections(current_user.id)
274-
format.html { render action: "edit" }
275-
else
276-
format.html { render action: "edit" }
277-
end
278-
end
279-
else
280-
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
281-
end
282-
end
283-
284-
def lock_section
285-
@plan = Plan.find(params[:id])
286-
authorize @plan
287-
if user_signed_in? && @plan.editable_by(current_user.id) then
288-
respond_to do |format|
289-
if @plan.lock_section(params[:section_id], current_user.id)
290-
format.html { render action: "edit" }
291-
else
292-
format.html { render action: "edit" }
293-
format.json { render json: @plan.errors, status: :unprocessable_entity }
294-
end
295-
end
296-
else
297-
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
298-
end
299-
end
300-
301-
def unlock_section
302-
@plan = Plan.find(params[:id])
303-
authorize @plan
304-
if user_signed_in? && @plan.editable_by(current_user.id) then
305-
respond_to do |format|
306-
if @plan.unlock_section(params[:section_id], current_user.id)
307-
format.html { render action: "edit" }
308-
309-
else
310-
format.html { render action: "edit" }
311-
end
312-
end
313-
else
314-
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
315-
end
316-
end
317-
=end
318-
319229
def answer
320230
@plan = Plan.find(params[:id])
321231
authorize @plan
@@ -388,7 +298,7 @@ def export
388298

389299
private
390300

391-
def plan_params
301+
def plan_params
392302
params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title)
393303
end
394304

@@ -459,7 +369,7 @@ def rollup(plan, src_plan_key, super_id, obj_plan_key)
459369
# --------------------------------------------------------------------------
460370
def template_options(org_id, funder_id)
461371
@templates = []
462-
372+
463373
if !org_id.blank? || !funder_id.blank?
464374
if funder_id.blank?
465375
# Load the org's template(s)
@@ -468,15 +378,15 @@ def template_options(org_id, funder_id)
468378
@templates = Template.valid.where(published: true, org: org, customization_of: nil).to_a
469379
@msg = _("We found multiple DMP templates corresponding to the research organisation.") if @templates.count > 1
470380
end
471-
381+
472382
else
473383
funder = Org.find(funder_id)
474384
# Load the funder's template(s)
475385
@templates = Template.valid.where(published: true, org: funder).to_a
476-
386+
477387
unless org_id.blank?
478388
org = Org.find(org_id)
479-
389+
480390
# Swap out any organisational cusotmizations of a funder template
481391
@templates.each do |tmplt|
482392
customization = Template.valid.find_by(published: true, org: org, customization_of: tmplt.dmptemplate_id)
@@ -486,17 +396,17 @@ def template_options(org_id, funder_id)
486396
end
487397
end
488398
end
489-
399+
490400
msg = _("We found multiple DMP templates corresponding to the funder.") if @templates.count > 1
491401
end
492402
end
493-
403+
494404
# If no templates were available use the generic templates
495405
if @templates.empty?
496406
@msg = _("Using the generic Data Management Plan")
497407
@templates << Template.find_by(is_default: true)
498408
end
499-
409+
500410
@templates = @templates.sort{|x,y| x.title <=> y.title } if @templates.count > 1
501411
end
502412

app/controllers/questions_controller.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,21 @@ def admin_update
5656
if guidance.blank?
5757
guidance = @question.annotations.build
5858
guidance.type = :guidance
59+
guidance.org_id = current_user.org_id
5960
end
6061
guidance.text = params["question-guidance-#{params[:id]}"]
6162
guidance.save
6263
end
64+
example_answer = @question.get_example_answer(current_user.org_id)
65+
if params["question"]["annotations_attributes"].present? && params["question"]["annotations_attributes"]["0"]["id"].present?
66+
if example_answer.blank?
67+
example_answer = @question.annotations.build
68+
example_answer.type = :example_answer
69+
example_answer.org_id = current_user.org_id
70+
end
71+
example_answer.text = params["question"]["annotations_attributes"]["0"]["text"]
72+
example_answer.save
73+
end
6374
if @question.question_format.textfield?
6475
@question.default_value = params["question-default-value-textfield"]
6576
elsif @question.question_format.textarea?

app/controllers/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def admin_update_permissions
4141
else
4242
if perms.include? perm
4343
@user.perms << perm
44-
if perm.name == Perm.use_api.id
44+
if perm.id == Perm.use_api.id
4545
@user.keep_or_generate_token!
4646
end
4747
end

0 commit comments

Comments
 (0)