Skip to content

Conversation

@johnpinto1
Copy link
Contributor

@johnpinto1 johnpinto1 commented Oct 27, 2025

Redesigned plan-creation page to enforce template access rules and simplify UI #3534
Co-authored-by: don-stuckey dstuckey@ed.ac.uk

This feature was contributed to DMPonline by @don-stuckey.

Changes:

  • Complete re-write of 'Create a new plan' view app/views/plans/new.html.erb.
  • The Plans controller app/controllers/plans_controller.rb has be greatly simplified to get three types og templates for selection in view: The global templates, the user's org templates and the funder templates available.
  • The seeds.rb file has been updated to include templates for the three groups.
  • The tests has been updated.

New Create a new plan page
Selection_142

Screenshot when running RSpec test in spec/features/plans_spec.rb
screenshot1

@johnpinto1 johnpinto1 changed the title Feature that re-designs Plan creation page to enforce template access Redesigned plan-creation page to enforce template access rules and simplify UI Oct 27, 2025
@johnpinto1 johnpinto1 force-pushed the issue/new-3534 branch 2 times, most recently from 908c3e8 to 000c04a Compare October 27, 2025 16:16
…mplify UI [#3534](#3534)

Co-authored-by: don-stuckey dstuckey@ed.ac.uk

This feature was contributed to DMPonline by @don-stuckey.

Changes:
- Complete re-write of 'Create a new plan' view
  app/views/plans/new.html.erb.
- The Plans controller app/controllers/plans_controller.rb has be
  greatly simplified to get three types og templates for selection in
view: The global templates, the user's org templates and the funder
templates available.
- The seeds.rb file has been updated to include templates for the three
  groups.
- The tests has been updated.
Comment on lines 37 to 51
# get funder templates
funder_templates = Template.published
.joins(:org)
.merge(Org.funder)
.distinct

# get global templates
global_templates = Template.published
.where(is_default: true)
.distinct

# get templates of user's org
user_org_templates = Template.published
.where(org: current_user.org)
.distinct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm comparing this simplified logic with what we were previously using (https://github.com/DMPRoadmap/roadmap/blob/main/app/controllers/template_options_controller.rb).

One thing I am concerned about with this new logic is the same template being listed in two, or all three sections. For example, what if Org.funder has a default template (which is the case with DMP Assistant). Then that same template is listed in both funder_templates and global_templates. And if user.org == Org.funder (again the case with DMP Assistant), then funder_templates and user_org_templates will have identical lists.

TemplateOptionsController also performed special handling for template customisations. Specifically, if an org had a customisation of the most recent version of a funder_template, then only that customisation would appear as an template option. With this logic, it looks like the most recent customisation will appear in user_org_templates, but the non-customised version of it will also be listed as an option in funder_templates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are no longer fetching all of the possible org options, maybe PlansController#new should use the existing logic in TemplateOptionsController?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronskiba Given that you are implementing this differently, maybe we keep this change in one place that only affects us. What do you think. We can discuss at Developers' meeting on Monday. I am off tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm comparing this simplified logic with what we were previously using (https://github.com/DMPRoadmap/roadmap/blob/main/app/controllers/template_options_controller.rb).

One thing I am concerned about with this new logic is the same template being listed in two, or all three sections. For example, what if Org.funder has a default template (which is the case with DMP Assistant). Then that same template is listed in both funder_templates and global_templates. And if user.org == Org.funder (again the case with DMP Assistant), then funder_templates and user_org_templates will have identical lists.

TemplateOptionsController also performed special handling for template customisations. Specifically, if an org had a customisation of the most recent version of a funder_template, then only that customisation would appear as an template option. With this logic, it looks like the most recent customisation will appear in user_org_templates, but the non-customised version of it will also be listed as an option in funder_templates.

During the Monday meeting, I was informed that your team had recently implemented a fix for the duplicate templates I mentioned, and that it could be added to this PR.

</legend>
<div class="row form-row">
<div class="col-12">
<% @templates_grouped.each do |group_label, group_templates| %>
Copy link
Contributor

@aaronskiba aaronskiba Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the label grouping. Maybe we should also be ordering the templates by title?

@momo3404
Copy link
Collaborator

momo3404 commented Oct 28, 2025

I just wanted to point out the fun coincidence that I'm also working on a similar redesign for the templates dropdown in DMP Assistant. This is the PR if you're curious, and here's what it looks like right now.

Screencast.from.2025-10-28.11-16-28.webm

For more details about our approach, we initially edited template_options_controller.rb to organize the templates appropriately in this PR. Then, in the PR I tagged above, we're editing the styling of the dropdown (with the new order) to include headers and a "Show more templates" button due to how many funder templates we have publicly available. We're only editing code in template_options_controller.rb and app/javascript/src/plans/new.js, so it is a bit of a simpler implementation.

If you want, I'm interested on collaborating on this if you want to match our approach.

@johnpinto1
Copy link
Contributor Author

@aaronskiba @momo3404 Just saw your 2 comments. Our version is live and working as per our requirements and @don-stuckey did a lot of work on this. Maybe we can work out a way that we can chose which feature to use in config? Worth discussing and finding a solution we can go forward with for other features.

@aaronskiba
Copy link
Contributor

@aaronskiba @momo3404 Just saw your 2 comments. Our version is live and working as per our requirements and @don-stuckey did a lot of work on this. Maybe we can work out a way that we can chose which feature to use in config? Worth discussing and finding a solution we can go forward with for other features.

Sounds good. This PR enforces the org selection to user.org, which is something we'll need at some point (maybe we should add a PR for the feature flags in the near future too?). @momo3404's PR maintains the current template options logic via template_options_controller.rb, which I think this PR would benefit from.

@johnpinto1
Copy link
Contributor Author

@aaronskiba @momo3404 Just saw your 2 comments. Our version is live and working as per our requirements and @don-stuckey did a lot of work on this. Maybe we can work out a way that we can chose which feature to use in config? Worth discussing and finding a solution we can go forward with for other features.

Sounds good. This PR enforces the org selection to user.org, which is something we'll need at some point (maybe we should add a PR for the feature flags in the near future too?). @momo3404's PR maintains the current template options logic via template_options_controller.rb, which I think this PR would benefit from.

I will fix this on Monday or after meeting.

…and/or global templates when there aren't any customised ones.
@johnpinto1
Copy link
Contributor Author

@aaronskiba @momo3404 Updated the code with @martaribeiro and @gjacob24 fixes mentioned in last roadmap meeting.
BTW I will be missing the next Roadmap meeting as we are on strike on Nov 17-19.

Comment on lines 47 to 68
@plan.org_id = current_user.org&.id
# looks into the list of families of templates
customizations = Template.latest_customized_version_per_org(@plan.org_id)
customization_ids = customizations.select(&:published?).collect(&:customization_of)

# get templates of user's own org
user_org_own_templates = Template.organisationally_visible
.where(org_id: @plan.org_id, customization_of: nil)
.published
.uniq.sort_by(&:title)

# get templates of user's customised org
user_org_custom_templates = Template.latest_customized_version_per_org(@plan.org_id)
.published
.uniq.sort_by(&:title)

# get funder templates no customised templates
funder_non_customised_templates = Template.published
.joins(:org)
.where(orgs: { org_type: Org.org_type_values_for(:funder) })
# The next line removes templates that belong to a family that
# has customised templates
.where.not(family_id: customization_ids)
.uniq.sort_by(&:title)

# get global templates
global_templates = Template.published
.where(is_default: true)
# The next line removes templates that belong to a family that
# has customised templates
.where.not(family_id: customization_ids)
.uniq.sort_by(&:title)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added commits appear to address some of my earlier concerns regarding duplicate templates, so thank you for that.

That said, I still notice that the upgrade_customization? handling from TemplateOptionsController isn’t being used here, and it’s unclear what other behavioural differences now exist compared to that controller.

I am wondering if, instead of a complete rework of the template selection logic, we could instead pass user.org to TemplateOptionsController. And if there is in fact any required behavioural changes (e.g. always return default/global templates, grouping the templates into the three categories, etc.) then the code could be changed there. Re-using the existing logic could also help mitigate any further regressions or follow-up fixes, and keep template-selection behaviour consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look at this.

@johnpinto1
Copy link
Contributor Author

@aaronskiba I think your suggestion on chat for server side validation is a good idea. Will sort that soon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't directly related to this PR, but I am surprised that the codebase doesn't include spec/controllers/plans_controller_spec.rb. The PlansController is so central to the app, that not having that Spec file makes me worry that we are missing some key code coverage. I will add a GitHub issue for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Will address this and validation issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a related issue here. I'd be happy to get started on this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am current writing tests. Not got it right yet. I will push what I have got once I get it working correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed code for an RSpec test of methods introduced. Review and let me know if you think more tests are needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I like that you added the validation and accompanying tests.

only create plan's from templates available to their org.
…spec.rb. This deals with testing methods used by the new Plan creation functionality introduced.
Copy link
Contributor

@aaronskiba aaronskiba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s substantial work here. Regarding the update/removal of the org-selection logic in the “create plan” form, I recognize the need for these changes in DMP Online. This creates a divergence between DMP Online and DMP Assistant that we’ll need to accommodate.

My main hesitation is around the template-selection changes. The new implementation replaces the existing TemplateOptionsController, which introduces a larger split in how the two applications handle this area. Since the underlying template-selection requirements still seem quite similar, keeping the shared logic aligned would be preferable. I’m concerned that merging this approach could make that more difficult going forward.

@aaronskiba
Copy link
Contributor

There’s substantial work here. Regarding the update/removal of the org-selection logic in the “create plan” form, I recognize the need for these changes in DMP Online. This creates a divergence between DMP Online and DMP Assistant that we’ll need to accommodate.

My main hesitation is around the template-selection changes. The new implementation replaces the existing TemplateOptionsController, which introduces a larger split in how the two applications handle this area. Since the underlying template-selection requirements still seem quite similar, keeping the shared logic aligned would be preferable. I’m concerned that merging this approach could make that more difficult going forward.

If you'd like, I could point a new PR at this one that attempts to refactor these changes so that the TemplateOptionsController logic is still utilised.

@johnpinto1
Copy link
Contributor Author

johnpinto1 commented Nov 26, 2025

There’s substantial work here. Regarding the update/removal of the org-selection logic in the “create plan” form, I recognize the need for these changes in DMP Online. This creates a divergence between DMP Online and DMP Assistant that we’ll need to accommodate.

My main hesitation is around the template-selection changes. The new implementation replaces the existing TemplateOptionsController, which introduces a larger split in how the two applications handle this area. Since the underlying template-selection requirements still seem quite similar, keeping the shared logic aligned would be preferable. I’m concerned that merging this approach could make that more difficult going forward.

if you'd like, I could point a new PR at this one that attempts to refactor these changes so that the TemplateOptionsController logic is still utilised.

Agree, I think we should resolve this problem as you suggest with a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants