Add note templates with fund-level and personal templates#3540
Open
Rolling2405 wants to merge 6 commits into
Open
Add note templates with fund-level and personal templates#3540Rolling2405 wants to merge 6 commits into
Rolling2405 wants to merge 6 commits into
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
NoteTemplatemodel with validations (name + body required, uniqueness scoped to fund + user)NoteTemplatesControllerwith CRUD actions (create, index, destroy)data-actionattributes (no inline JS)Notes:
form-selectclass.#3532→#3540.(If there are changes to the views, please include a screenshot so we know what to look for!)
For reviewer:
featureif 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.dependenciesif it contains library upgrades or similar. This is anything that upgrades any dependency, such as a Gemfile update or npm package upgrade.