Skip to content

Commit

Permalink
Merge pull request #194 from portagenetwork/issue191
Browse files Browse the repository at this point in the history
Only show managed orgs when user create a plan & french translation added & brakeman update
  • Loading branch information
pengyin-shan authored Aug 26, 2022
2 parents fa57c99 + 294b38b commit 1571a11
Show file tree
Hide file tree
Showing 17 changed files with 20,104 additions and 45,635 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [3.0.4+portage-3.0.12] - 2022-08-26
### Added

- Added french translation of the Request Feedback email [#188](https://github.com/portagenetwork/roadmap/issues/188)

### Fixed

- Allowed user to proceed after checking 'No primary research institution' checkbox when creating a new plan [#221](https://github.com/portagenetwork/roadmap/issues/221)

- Removed unmanaged organizations from the selection list when a user creates a new plan [#191](https://github.com/portagenetwork/roadmap/issues/191)

## [3.0.4+portage-3.0.13] - 2022-07-13

### Changed
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ def setup_local_orgs
@orgs = (Org.includes(identifiers: :identifier_scheme).organisation +
Org.includes(identifiers: :identifier_scheme).institution +
Org.includes(identifiers: :identifier_scheme).default_orgs)
@orgs = @orgs.flatten.uniq.sort_by(&:name)
@orgs = @orgs.flatten.uniq.sort_by(&:name)

end

end
Expand Down
72 changes: 26 additions & 46 deletions app/controllers/template_options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ def index

@templates = []

if (org.present? && !org.new_record?) ||
(funder.present? && !funder.new_record?)
if (org.present? && !org.new_record?) || (funder.present? && !funder.new_record?)
if funder.present? && !funder.new_record?
# Load the funder's template(s) minus the default template (that gets swapped
# in below if NO other templates are available)
@templates = Template.latest_customizable
.where(org_id: funder.id, is_default: false).to_a
if org.present? && !org.new_record?
# Load the funder's template(s) minus the default template (that gets swapped
# in below if NO other templates are available)
@templates = Template.latest_customizable.where(org_id: funder.id, is_default: false).to_a
# Swap out any organisational cusotmizations of a funder template
@templates = @templates.map do |tmplt|
customization = Template.published
.latest_customized_version(tmplt.family_id,
org.id).first
org.id).first
# Only provide the customized version if its still up to date with the
# funder template!
# rubocop:disable Metrics/BlockNesting
Expand All @@ -41,49 +39,31 @@ def index
else
tmplt
end
# rubocop:enable Metrics/BlockNesting
end
# We are using a default funder to provide with the default templates, but
# We still want to provide the organization templates.
# If the no funder was specified OR the funder matches the org
# if funder.blank? || funder.id == org&.id
# Retrieve the Org's templates
@templates << Template.published.organisationally_visible.where(org_id: org.id, customization_of: nil).to_a
@templates = @templates.flatten.uniq
else # if'No Primary Research Institution' checkbox is checked, only show publicly available template without customization
@templates = Template.published.publicly_visible.where(org_id: funder.id, customization_of: nil)
end
# DMP Assistant: We do not want to include not customized templates from default funder
# Include customizable funder templates
# @templates << funder_templates = Template.latest_customizable
# Always use the default template
if Template.default.present? && org.present?
customization = Template.published.latest_customized_version(Template.default.family_id, org.id).first
customization = Template.default unless customization
@templates.select! { |t| t.id != Template.default.id && t.id != customization.id}
# We want the default template to appear at the beggining of the list
@templates.unshift(customization)
end
@templates = @templates.uniq.sort_by(&:title)
end

# We are using a default funder to provide with the default templates, but
# We still want to provide the organization templates.

# If the no funder was specified OR the funder matches the org
# if funder.blank? || funder.id == org&.id
# Retrieve the Org's templates
@templates << Template.published
.organisationally_visible
.where(org_id: org.id, customization_of: nil).to_a
# end

# DMP Assistant: We do not want to include not customized templates from
# default funder

# Include customizable funder templates
# @templates << funder_templates = Template.latest_customizable

@templates = @templates.flatten.uniq
end

@templates = @templates.uniq.sort_by(&:title)

# Always use the default template

if Template.default.present?
customization = Template.published
.latest_customized_version(Template.default.family_id,
org.id).first

customization = Template.default unless customization

@templates.select! { |t| t.id != Template.default.id && t.id != customization.id}

# We want the default template to appear at the beggining of the list
@templates.unshift(customization)
end


end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable
Expand Down
16 changes: 9 additions & 7 deletions app/javascript/src/plans/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ $(() => {
const orgContext = $('#research-org-controls');
const funderContext = $('#funder-org-controls');
const validOrg = validOptions(orgContext);

// DMP Assistant does not require a funder for creating a plan. Instead the
// Plan controller will search for the default funder when creating the
// plan. In our current case this will be "Portage Network"
Expand All @@ -101,7 +102,7 @@ $(() => {
$('#plan_template_id option').remove();

let orgId = orgContext.find('input[id$="org_id"]').val();
let funderId = funderContext.find('input[id$="funder_id"]').val();
let funderId = funderContext.find('input[id$="funder_id"]').val(); // funder id is default to 8 (Portage Network)

// For some reason Rails freaks out it everything is empty so send
// the word "none" instead and handle on the controller side
Expand All @@ -111,13 +112,14 @@ $(() => {
if (funderId.length <= 0) {
funderId = '"none"';
}
const data = `{"plan": {"research_org_id":${orgId},"funder_id":${funderId}}}`;

// Pass '8'(portage network) for DMP Assistant directly to funder_id,
// Otherwise it will automatically add an extra 'name' attribute
const data = `{"research_org_id":${orgId},"funder_id":8}`;
// Fetch the available templates based on the funder and research org selected
$.ajax({
url: $('#template-option-target').val(),
data: JSON.parse(data),
}).done(success).fail(error);
$.get($('#template-option-target').val(),
{
plan: JSON.parse(data),
}).done(success).fail(error);
}
}, 150);

Expand Down
2 changes: 1 addition & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def feedback_notification(recipient, plan, requestor)
@recipient_name = @recipient.name(false)
@requestor_name = @user.name(false)
@plan_name = @plan.title

I18n.with_locale I18n.default_locale do
mail(to: @recipient.email,
subject: _("%{user_name} has requested feedback on a %{tool_name} plan") %
Expand Down
6 changes: 4 additions & 2 deletions app/views/plans/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</div>
</div>

<!-- Organisation selection -->
<!-- Organisation selection. -->
<h2 id="research-org">
<span class="red" title="<%= required_research_org_tooltip %>">*<em class="sr-only"><%= required_research_org_tooltip %></em> </span>
<%= _('Indicate the primary research organisation') %>
Expand All @@ -51,12 +51,14 @@
<em class="sr-only"><%= research_org_tooltip %></em>
<% dflt = @orgs.include?(current_user.org) ? current_user.org : nil %>
<%= f.fields_for :org, @plan.org do |org_fields| %>
<!-- Since local_only view is shared in many views, add managed org filter here instead of controller so that unmanged orgs are only elimated from 'Primary Research Institue' -->
<!-- #191: DMP Assistant allows free-text input of funders, which are saved as unmanaged orgs, Thus only show filtered primay orgs here (since local_only is shared among the app, change parameter to view here instead of controller) -->
<%= render partial: "shared/org_selectors/local_only",
locals: {
form: org_fields,
id_field: :id,
default_org: nil,
orgs: @orgs,
orgs: @orgs.filter { |org| org.managed == true },
required: false
} %>
<% end %>
Expand Down
9 changes: 6 additions & 3 deletions app/views/user_mailer/feedback_notification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
<%= _('Hello %{user_name},') % {user_name: @recipient_name} %>
</p>
<p>
<%= sanitize _(%Q{%{requestor} has requested feedback on a plan %{link_html}. To add comments, please visit the 'Plans' page under the Admin menu in %{tool_name} and open the plan.}) % {
<%=
sanitize _('%{requestor} has requested feedback on a plan %{link_html}. To add comments, please visit the "Plans" page under the Admin menu in %{tool_name} and open the plan.') % {
requestor: @requestor_name,
plan_name: @plan_name,
tool_name: tool_name,
allow_change_prefs: false,
link_html: link_to(@plan_name, plan_url(@plan))
} %>
}
%>
</p>

<p>
Alternatively, you can click the link below:<br>
<%= _("Alternatively, you can click the link below:") %>
<br>
<%= link_to plan_url(@plan), plan_url(@plan) %>
</p>

Expand Down
38 changes: 3 additions & 35 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
{
"ignored_warnings": [
{
"warning_type": "Unmaintained Dependency",
"warning_code": 122,
"fingerprint": "21ab0fe00fdd5899ffc405cff75aadb91b805ee996a614f7e27b08a287e9062d",
"check_name": "EOLRails",
"message": "Support for Rails 5.2.6.2 ends on 2022-06-01",
"file": "Gemfile.lock",
"line": 368,
"link": "https://brakemanscanner.org/docs/warning_types/unmaintained_dependency/",
"code": null,
"render_path": null,
"location": null,
"user_input": null,
"confidence": "Weak",
"note": ""
},
{
"warning_type": "SQL Injection",
"warning_code": 0,
Expand All @@ -36,30 +20,14 @@
"confidence": "Medium",
"note": ""
},
{
"warning_type": "Unmaintained Dependency",
"warning_code": 121,
"fingerprint": "9a3951031616a07c8e02c86652f537e92c08685da97f5ec2b12d5d3602b55bb8",
"check_name": "EOLRuby",
"message": "Support for Ruby 2.6.3 ended on 2022-03-31",
"file": "Gemfile.lock",
"line": 368,
"link": "https://brakemanscanner.org/docs/warning_types/unmaintained_dependency/",
"code": null,
"render_path": null,
"location": null,
"user_input": null,
"confidence": "High",
"note": ""
},
{
"warning_type": "Redirect",
"warning_code": 18,
"fingerprint": "c94d0d02516558699b49eb76787d02665041a45b490686266e4f42d5c19088d6",
"check_name": "Redirect",
"message": "Possible unprotected redirect",
"file": "app/controllers/plans_controller.rb",
"line": 391,
"line": 390,
"link": "https://brakemanscanner.org/docs/warning_types/redirect/",
"code": "redirect_to(Plan.deep_copy(Plan.find(params[:id])), :notice => success_message(Plan.deep_copy(Plan.find(params[:id])), _(\"copied\")))",
"render_path": null,
Expand Down Expand Up @@ -93,6 +61,6 @@
"note": ""
}
],
"updated": "2022-04-05 08:31:53 -0700",
"brakeman_version": "5.2.1"
"updated": "2022-05-04 12:37:38 -0400",
"brakeman_version": "5.1.1"
}
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ sandbox:

production:
<<: *defaults
url: <%= Rails.application.secrets.database_url %>
url: <%= Rails.application.secrets.database_url %>
Loading

0 comments on commit 1571a11

Please sign in to comment.