Closed aaronskiba closed 1 month ago
Relevant code:
# app/controllers/org_admin/template_customizations_controller.rb
# POST /org_admin/templates/:id/customize
# rubocop:disable Metrics/AbcSize
def create
@template = Template.find(params[:template_id])
authorize(@template, :customize?)
if @template.customize?(current_user.org)
begin
@customisation = @template.customize!(current_user.org)
redirect_to org_admin_template_path(@customisation)
return
rescue ArgumentError
flash[:alert] = _('Unable to customize that template.')
end
else
flash[:notice] = _('That template is not customizable.')
# app/models/template.rb
# Determines whether or not a customization for the customizing_org passed
# should be generated
def customize?(customizing_org)
if customizing_org.is_a?(Org) && (org.funder_only? || is_default)
return !Template.unarchived.where(customization_of: family_id,
org: customizing_org).exists?
end
false
end
# app/models/template.rb
# Generates a new copy of self for the specified customizing_org
def customize!(customizing_org)
# Assume customizing_org is persisted
raise ArgumentError, _('customize! requires an organisation target') unless customizing_org.is_a?(Org)
# Assume self has org associated
raise ArgumentError, _('customize! requires a template from a funder') if !org.funder_only? && !is_default
The following code change results in the following changed behaviour:
When we add another change (below) the customizable template becomes accessible:
Portage Network
is the only org that is type funder. However, it is not merely a funder. It is a funder AND an institution.
$ rails c
Loading development environment (Rails 6.1.7.6)
irb: warn: can't alias context from irb_context.
2.7.6 :001 > x = Org.funder,6,7,10,11,14,15,18,19,22,23,26,27,30,31,34,35,38,39,42,43,46,47,50,51,54,55,58,59,62,63))) /* loading for inspect */ LIMIT $1 [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Org id: 8, name: "Portage Network", abbrevi...
2.7.6 :002 > y = Org.where(org_type: Org.org_type_values_for(:funder).min)
Org Load (0.9ms) SELECT "orgs".* FROM "orgs" WHERE "orgs"."org_type" = $1 /* loading for inspect */ LIMIT $2 [["org_type", 2], ["LIMIT", 11]]
=> #<ActiveRecord::Relation []>
2.7.6 :003 > x.count
(2.3ms) SELECT COUNT(*) FROM "orgs" WHERE (("orgs"."org_type" in (2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31,34,35,38,39,42,43,46,47,50,51,54,55,58,59,62,63)))
=> 1
2.7.6 :004 > y.count
(1.9ms) SELECT COUNT(*) FROM "orgs" WHERE "orgs"."org_type" = $1 [["org_type", 2]]
=> 0
2.7.6 :005 > x
Org Load (2.2ms) SELECT "orgs".* FROM "orgs" WHERE (("orgs"."org_type" in (2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31,34,35,38,39,42,43,46,47,50,51,54,55,58,59,62,63))) /* loading for inspect */ LIMIT $1 [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Org id: 8, name: "Portage Network", abbreviation: "Portage", target_url: "https://portagenetwork.ca/", created_at: "2015-05-21 21:28:39.000000000 +0000", updated_at: "2024-05-09 19:42:02.163511000 +0000", is_other: false, display_in_registration: true, logo_uid: nil, logo_name: nil, banner_uid: nil, banner_name: nil, region_id: nil, language_id: 1, contact_email: "dmp-assistant@tech.alliancecan.ca", org_type: 3, links: {"org"=>[{"link"=>"https://portagenetwork.ca/", "text"=>"portagenetwork.ca"}]}, contact_name: "Support", feedback_enabled: false, feedback_msg: "<p>Hello %{user_name}.</p><p>Your plan \"%{plan_nam...", managed: true, helpdesk_email: "">]>
2.7.6 :006 >
This is why funder_only?
was giving us trouble. And because Portage Network is the only Org that is type funder
, it will be the only Org affected by changing the funder_only?
check to funder?
.
Also, only Super Admins can edit the org types of an org, so we shouldn't have to worry about other Orgs setting themselves as funders.
(Super admin access)
(Org admin access)
Please complete the following fields as applicable:
What version of the DMPRoadmap code are you running? (e.g. v2.2.0)
4.0.2+portage-4.0.3
Expected behaviour:
/org_admin/templates/customisable
.Actual behaviour: