Changelog

Stay up to date with the latest changes and improvements we've made to make your experience even better.

## [v1.3.2] - 2025-07-21

### Added
- Scoped the following roles to a `Program` resource:
  - `reader`
  - `principal_investigator`
- Hidden form field support for `program` in both AD and manual user creation forms.

### Changed
- `UsersController#create_user`:
  - Assigns roles like `reader` and `principal_investigator` with associated `Program` resource.
  - Global roles like `admin` and `lab_support` remain unscoped.
  - Flash messages now include program context where applicable.
- Role assignment logic now prevents assigning duplicate scoped roles.

### Fixed
- Bug where scoped roles were being assigned without program resource in manual form.
- Fixed incorrect passing of `program` to global roles (`admin`, `lab_support`).

### UI
- Added `short_name` column to `programs` table for abbreviated display names (e.g., `"Neuro"` for `"Neuroradiology"`).
- Added `Program#display_name` method to return `short_name` if present.
- Added `Role#display_name` method to map long role names to short labels (e.g., `"principal_investigator"` → `"PI"`).

### Developer Notes
- To fetch scoped readers:
  ```ruby
  User.with_role(:reader, Program.find_by(name: "Neuroradiology"))

```
neuro = Program.find_by(name: "Neuroradiology")

# Find all global (non-scoped) reader roles
global_reader_role = Role.find_by(
  name: "principal_investigator",
  resource_type: nil,
  resource_id: nil
)

# Fetch all users who currently have the global reader role
users = User.joins(:roles).where(roles: { id: global_reader_role.id })

# Update each user: remove global role, add program-scoped role
users.find_each do |user|
  user.remove_role(:principal_investigator)
  user.add_role(:principal_investigator, neuro)
  puts "Updated user #{user.id} - #{user.email}"
end

neuro = Program.find_by(name: "Neuroradiology")

# Find all global (non-scoped) reader roles
global_reader_role = Role.find_by(
  name: "reader",
  resource_type: nil,
  resource_id: nil
)

# Fetch all users who currently have the global reader role
users = User.joins(:roles).where(roles: { id: global_reader_role.id })

# Update each user: remove global role, add program-scoped role
users.find_each do |user|
  user.remove_role(:reader)
  user.add_role(:reader, neuro)
  puts "Updated user #{user.id} - #{user.email}"
end
```

## [v1.3.1] - 2025-07-17
### Added
- Added `program_id` foreign key to `coordinator_requests` table, linking each request to a `Program`.
- Created model associations: `CoordinatorRequest belongs_to :program`, `Program has_many :coordinator_requests`.

### Changed
- Updated `request_role` method in `WelcomeController` to temporarily assign the "Neuroradiology" program to new coordinator requests.
- Refactored `confirm_reader` method to assign the `:coordinator` role scoped to the associated `program`.

### Notes
- run `rails db:migration` to add the foreign key reference in the programs table

## [v1.3.0] - 2025-07-17
✅ Role Management Enhancements
- Refactored coordinator role to require a Program association (e.g., Neuroradiology, Nuclear Medicine).
- Removed support for global coordinator roles; all role assignments are now resource-scoped.
- Added support for assigning program-specific coordinator roles during user creation and editing

### Refactor coordinator role migration
- Run this in rails console
``` 
neuro = Program.find_by(name: "Neuroradiology")
global_coordinator_role = Role.find_by(
  name: "coordinator",
  resource_type: nil,
  resource_id: nil
)

users = User.joins(:roles).where(roles: { id: global_coordinator_role.id })

users.find_each do |user|
  user.remove_role(:coordinator)
  user.add_role(:coordinator, neuro)
  puts "Updated user #{user.id} - #{user.email}"
end
  
```

## [v1.2.7] - 2025-07-14
### Added
- Reader column to the exam table

## [v1.2.6] - 2025-07-02
### Added
- Added **Edit Exam** button next to the Delete button on the exam details page for easier navigation.

### Changed
- Updated Exam `update` action logic:
  - Redirect now goes to the Reading Pool **only if a summary is present** (indicating the exam was read).
  - Otherwise, after a successful update, users are redirected back to the exam’s show page.
- Improved study dropdown in the exam form:
  - The study select box now displays both Lab and Study names (e.g. “UWNI - Study A”) as the selected text.
  - Maintains optgroup grouping of studies by Lab for better organization.
  
## [v1.2.5] - 2025-07-01
### Fixed
- Fixed an error in `ExamsController#create` where the `@studies` instance variable was not set when rendering the form after a failed save.

## [v1.2.4] - 2025-06-25
### Added
- Implemented `ApplicationSetting.instance` as a true singleton accessor to ensure only one configuration record exists.
- Created comprehensive RSpec tests for `ApplicationSetting` model covering:
- Added tests to ensure `User.display_banner` is toggled when banner message is updated.

### Fixed
- Replaced outdated validation-based singleton enforcement (`validates :id`) with exception-based enforcement using `before_create`.

### Improved
- Added logging when `admin_email` is missing in non-production environments to assist with debugging.

## [v1.2.3] - 2025-06-25
### Added
- **Monthly Usage Report**: Summarizes total exams submitted each month, grouped by year, with a single table layout. Available to admins and readers.
- **Per-Study Usage Breakdown**: Displays exams submitted per study over the last 5 years, with a column for each year, plus total submissions and active status.
- **User Activity Report**: Tracks user roles, last sign-in, active status, and exam submission totals over the past 5 years, with breakdown by year.

### UI Enhancements
- Added "Reports" dropdown to the top navigation bar with links to:
  - Monthly Usage Report
  - Per-Study Usage
  - User Activity Report
- Used contextual Bootstrap styling (e.g., `table-success`, `badge`) for improved visual clarity.

### Security & Access Control
- All reports require user to be either an `admin` or a `reader` (`authorized_as_reader_or_admin!`).

## v1.2.2 - 2025-06-24
### Fixed
- Fixed `ActionView::Template::Error` caused by `@studies` being `nil` when rendering the exam form after validation failure. Added a `before_action :set_studies` to ensure `@studies` is always set in `ExamsController#create`.
- Fixed issue where `comparison_date_cannot_be_before_scan_date` validation caused form rendering to fail by ensuring controller sets necessary data.

### Added
- RSpec model validations for `Exam`, `Study`, `Lab`, `Diagnosis`, and `Log` models.
- Scope tests for `Exam.unread`.
- Tests for file presence validation in `ExamAttachment` using `FactoryBot` with attached test files.

## v1.2.1 - 2025-06-23
- RSpec test coverage for the `Study` model, including:
  - Validations and associations
  - `after_initialize` behavior to assign default program ("Neuroradiology")
  - Ransack configuration via `.ransackable_attributes` and `.ransackable_associations`
  - Edge cases for blank coordinator IDs, invalid billing arrangements, and default values
  
## v1.2.0 - 2025-06-19
- Renamed `users.role` to `users.requested_role` to reduce confusion with actual assigned roles via Rolify.
- Changed `on_holds.reader_id` column type from text to integer for data integrity.
- Removed unused `lab_id` column from `labs` table
- Removed migrations logic

## v1.1.21 - 2025-06-18
- Fix bug causing error when creating a new PI 

## v1.1.20 - 2025-06-17
- Fixes to abnormal email attachment for missing field and incorrect name

## v1.1.19 - 2025-06-16
- Improved coordinator request approval flow:
  - Added friendly feedback for users who re-click confirmation links after approval.
  - Clarified flash messages for already-approved coordinator requests.
- Improvements to Manual user sign-up flow
- Flash notifications on successful account creation.
- Resolved issue where manual passwords weren’t being saved due to strong-params guard.

## v1.1.18 - 2025-06-05
- Preserve original URL during authentication:
  - Users are now redirected back to their originally requested page (e.g., `/panda`) after logging in
  - Improves support for automation tools and redirect-following scripts
  
## v1.1.17 - 2025-06-04
- Remove auth token from panda page

## v1.1.16 - 2025-06-04
- Allow users to post to the panda page

## v1.1.15 - 2025-06-02
- CC the reader on email notification sent to PI's and Coordinators
- Improved formatting of abnormal report `.doc` attachments:
    - Added bordered tables for clearer layout
    - Centered and italicized header to match legacy style
    - Included all missing metadata fields (scan date, PI, coordinators, contact info)
    - Replaced placeholder date in filename with actual date (e.g., `2025-06-02`)
    - Enhanced disclaimer styling for readability
    
## v1.1.14 - 2025-05-30
- Fix email bug for abnormal report attachment

## v1.1.13 - 2025-05-29
- Added delete functionality for exams

## v1.1.12 - 2025-05-27
- Send admin email notification upon role request
- Fix role removal in admin form
- Improve PI confirm coordinator confirmation message

## v1.1.11 - 2025-05-19
- Fix diagonsis form fields
- Improvements to formatting on studies list

## v1.1.10 - 2025-05-19
- Allow On-hold to be released by anyone

## v1.1.4 - v1.1.9 - 2025-05-15
- Fix coordinator insert
- Fix bug that would not allow users to select multiple coordinators
- Fixed an issue that sometimes prevented a Study from being saved when Coordinators were selected.
- Resolved a problem that caused an error message to appear when creating a new Study.
- Fix study dropdown menu for principal investigators

## v1.1.3 - 2025-05-14
### Improvements
- Refactored the Users index page to improve performance by eager-loading roles and removing in-place role editing.
- Added role management fields to the User edit page (admin-only).
- Coordinator role assignment now clears any pending Coordinator request and resets the user's `role` field.
- Daily Reader Report emails now include a direct link to access the application homepage.

## v1.1.2 - 2025-05-13
### Improvements
- Added funding to the billing reports page
- Role requested information and notification

## v1.1.1 - 2025-05-08
### Fixed
- Fix authorization issue that blocked Readers from submitting an exam as "On Hold"

## v1.1.0 - 2025-05-08
### Fixed
- Corrected an issue where unchecking a user role did not properly remove the role from the database.
- Improved handling of New User creation during Study#new when no Study record exists yet.
- Updated user authentication flow with clearer flash alert messages.
- Fixed inconsistencies in redirects to fallback paths when study context was missing.

## v1.0.9 (2025-04-25)
- Fixed search filter for exams that are "on hold"
- Fixed redirect error upon authentication

## v1.0.8 (2025-04-28)
- Implemented placeholder email generation (missing-email-@placeholder.local) when LDAP mail attribute is missing
- Incomplete users are redirected to edit their profile after login
- Successful profile completion redirects users to root dashboard
- Added Admin-only editable fields (username and password) on the users#edit page

## v1.0.7 (2025-04-21)
- Add safe handling for missing LDAP mail attribute when creating new users

## v1.0.6 (2025-04-17)
- Fixed crash caused by missing `mail` attribute in LDAP user login
- Added defensive handling for missing email values during AD authentication
- Simulated missing LDAP `mail` attribute in development for testing edge cases

## v1.0.5 (2025-04-16)
- Hot fix to search page

## v1.0.4 (2025-04-16)
- Fixed Ransack-related table sorting bugs across multiple views
- Added dynamic modal system to logs#index for viewing detailed log information
- AJAX-powered modals allow users to inspect individual log entries without leaving the page
- Improved log table layout and viewer link styling
- Minor controller and view cleanups for consistency

## v1.0.3 (2025-04-15)
- Fix migrations error for adding studies

## v1.0.2 (2025-04-14)
- Added global banner alert system for application-wide announcements
- Admins can edit banner content via Application Settings
- Users can dismiss banner; dismissal is tracked per user
- Added buttons to force-show or hide the banner for all users
- Improved styling and layout of the Application Settings page
- 
## v1.0.1 (2025-04-02)
- Fixes to search filters

## v1.0.0 (2025-03-27)
- MVP release

## v0.0.2 (02-27-2025) - Fix authorization
- coordinator requests fixed
- improvements to table data
- format email notification

## v0.0.1 (02-21-2025) - Base app MVP 
- Enter Scans
- Reading pools
- Billing Page
- Search page
- Coordinator Request workflow
- Email notifications