Skip to content

Add note templates with fund-level and personal templates#3540

Open
Rolling2405 wants to merge 6 commits into
DARIAEngineering:mainfrom
Rolling2405:feature/note-templates
Open

Add note templates with fund-level and personal templates#3540
Rolling2405 wants to merge 6 commits into
DARIAEngineering:mainfrom
Rolling2405:feature/note-templates

Conversation

@Rolling2405

@Rolling2405 Rolling2405 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

I rule and have completed some work on Case Manager that's ready for review!

This lets case managers save and reuse note templates, with support for both personal templates and fund-wide shared templates managed by admins. It saves time when writing common types of notes.

This pull request makes the following changes:

  • Add NoteTemplate model with validations (name + body required, uniqueness scoped to fund + user)
  • Add NoteTemplatesController with CRUD actions (create, index, destroy)
  • Admin-only access for destroying fund-level templates
  • Click-to-apply uses CSP-compliant data-action attributes (no inline JS)
  • Views use Bootstrap 5 classes

Notes:

(If there are changes to the views, please include a screenshot so we know what to look for!)

For reviewer:

  • Adjust the title to explain what it does for the notification email to the listserv.
  • Tag this PR:
    • feature if it contains a feature, fix, or similar. This is anything that contains a user-facing fix in some way, such as frontend changes, alterations to backend behavior, or bug fixes.
    • dependencies if it contains library upgrades or similar. This is anything that upgrades any dependency, such as a Gemfile update or npm package upgrade.
  • If it contains neither, no need to tag this PR.

Rolling2405 and others added 2 commits April 7, 2026 18:42
NoteTemplate model:
- Fund-level templates (user_id nil): visible to all fund users
- Personal templates (user_id set): visible only to that user
- available_to(user) scope returns both, sorted by name
- Unique name per fund + user combination

Template insertion:
- Dropdown above note text area on patient page
- Select template to instantly populate the text field
- Shows (Fund) or (Personal) suffix to distinguish types

NoteTemplatesController:
- JSON index for API access (available_to current user)
- Create: personal by default, fund-level if admin checks flag
- Destroy: users delete own, admins delete fund-level

Routes:
- resources :note_templates (index, create, destroy)

Migration:
- note_templates table with fund_id, user_id (nullable), name, full_text

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ve tests

Bug fixes:
- Remove broken before_action :confirm_admin_user targeting
  nonexistent :destroy_fund_template action. Authorization for
  destroy is handled inline (users delete own; admins delete fund-level)
- Fix migration version [8.0] -> [8.1]

Tests:
- Model tests (8): validations (name, full_text presence), uniqueness
  scoped to fund+user, same name for different users, fund_level scope,
  personal scope, available_to scope
- Controller tests (7): index JSON returns correct templates, excludes
  others' templates, create personal template, reject blank name,
  user deletes own template, user cannot delete others', admin can
  delete fund-level templates

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rolling2405 and others added 4 commits April 9, 2026 16:12
Change form-control → form-select for <select> elements per BS5 conventions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
form-select is a BS5 class. The app uses BS4.6.2 where select
elements use form-control / form-control-sm instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The inline script used DOMContentLoaded to attach the change listener
to the note template selector. This only fires once on initial page
load — if the partial is ever re-rendered (e.g., via Turbo or AJAX),
the listener won't be re-attached.

Since the <script> tag is positioned after the <select> element in
the DOM, the element already exists when the script executes. Using
an IIFE ensures the listener is attached immediately on every render.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add test for admin creating fund-level templates
- Add test for creating template without full_text
- Add test for unauthenticated access to create
- Add test admin cannot delete other users personal template
- Add test for available_to scope ordering
- Add test for dependent destroy on user deletion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant