Skip to content

Commit c0b31a6

Browse files
author
John Pinto
committed
Issue #3555 - Add fix for user own org template query list.
Fixed rubocop offenses. Co-authored-by: gjacob24 <[email protected]>
1 parent 9528145 commit c0b31a6

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

app/controllers/plans_controller.rb

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,64 +29,62 @@ def index
2929
# rubocop:enable Metrics/AbcSize
3030

3131
# GET /plans/new
32-
# rubocop:disable Metrics/AbcSize
32+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
3333
def new
3434
@plan = Plan.new
3535
authorize @plan
3636
@plan.org_id = current_user.org&.id
3737
# looks into the list of families of templates
3838
customizations = Template.latest_customized_version_per_org(@plan.org_id)
39-
customization_ids = customizations.select { |t| t.published? }.collect(&:customization_of)
39+
customization_ids = customizations.select(&:published?).collect(&:customization_of)
4040

4141
# get templates of user's own org
4242
user_org_own_templates = Template.organisationally_visible
43-
.where(org_id: @plan.org_id, customization_of: nil)
44-
.published
45-
.uniq.sort_by(&:title)
46-
43+
.where(org_id: @plan.org_id, customization_of: nil)
44+
.published
45+
.uniq.sort_by(&:title)
4746

4847
# get templates of user's customised org
49-
user_org_custom_templates = Template.latest_customizable.where(family_id: customization_ids)
48+
user_org_custom_templates = Template.latest_customized_version_per_org(@plan.org_id)
49+
.published
5050
.uniq.sort_by(&:title)
51-
52-
51+
5352
# get funder templates no customised templates
5453
funder_non_customised_templates = Template.published
5554
.joins(:org)
5655
.where(orgs: { org_type: Org.org_type_values_for(:funder) })
57-
# The next line removes templates that belong to a family that
56+
# The next line removes templates that belong to a family that
5857
# has customised templates
5958
.where.not(family_id: customization_ids)
6059
.uniq.sort_by(&:title)
61-
60+
6261
# get global templates
6362
global_templates = Template.published
64-
.where(is_default: true)
65-
# The next line removes templates that belong to a family that
66-
# has customised templates
67-
.where.not(family_id: customization_ids)
68-
.uniq.sort_by(&:title)
69-
63+
.where(is_default: true)
64+
# The next line removes templates that belong to a family that
65+
# has customised templates
66+
.where.not(family_id: customization_ids)
67+
.uniq.sort_by(&:title)
7068

7169
# create templates-grouped hash
7270
@templates_grouped = {
73-
_("Your Organisation's Templates:") => user_org_own_templates.map {
74-
|t| [t.title, t.id]
75-
},
76-
_("Your Organisation's Customised Templates:") => user_org_custom_templates.map {
77-
|t| [t.title, t.id]
78-
},
79-
_("Global Templates:") => global_templates.map {
80-
|t| [t.title, t.id]
81-
},
82-
_("Funder Templates:") => funder_non_customised_templates.map {
83-
|t| [t.title, t.id]
84-
}
71+
_("Your Organisation's Templates:") => user_org_own_templates.map do |t|
72+
[t.title, t.id]
73+
end,
74+
_("Your Organisation's Customised Templates:") => user_org_custom_templates.map do |t|
75+
[t.title, t.id]
76+
end,
77+
_('Global Templates:') => global_templates.map do |t|
78+
[t.title, t.id]
79+
end,
80+
_('Funder Templates:') => funder_non_customised_templates.map do |t|
81+
[t.title, t.id]
82+
end
8583
}.reject { |_, val| val.empty? }
8684

8785
respond_to :html
8886
end
89-
# rubocop:enable Metrics/AbcSize
87+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
9088

9189
# POST /plans
9290
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength

0 commit comments

Comments
 (0)