Skip to content

Commit

Permalink
Create model definitions and user associations for (#20426)
Browse files Browse the repository at this point in the history
* Removes Sidekiq Enterprise and Pro dependencies

Removes enterprise-specific Sidekiq gems and their dependencies (einhorn, gserver) to simplify the application's job processing infrastructure and reduce external dependencies.

* Adds user action tracking models and specs

Implements models to track user actions and events with:
- Status tracking (initial, success, error)
- IP address and user agent logging
- Association between actions and events
- Validation and dependency restrictions

Provides comprehensive test coverage including factories

* Restore original Gemfile.lock

* Update CODEOWNERS: Add user_action.rb and remove Gemfile.lock

* Update CODEOWNERS: Add user_action files with octo-identity ownership

* Fix CODEOWNERS: Add user_action entries in correct alphabetical order

* Fix CODEOWNERS: Update user_action entries to only use octo-identity team

* Update CODEOWNERS: Add spec files and ensure alphabetical order

* Removes trailing whitespace from model and spec files

Cleans up code style by removing unnecessary trailing whitespace characters at the end of files in:
- User action models
- Factory definitions
- Test specifications

This maintains consistent code formatting and follows Ruby style conventions.

* Update CODEOWNERS: Add factory files

* Fix CODEOWNERS: Move factory entries to correct alphabetical order

* Fix CODEOWNERS: Add parent directory entries and maintain alphabetical order

* Fix CODEOWNERS: Move user_action entries to correct alphabetical order

* Refactor UserAction and UserActionEvent specs

- Remove prefix from UserAction status enum for cleaner method names
- Update specs to use shoulda-matchers for associations
- Remove redundant tests for Rails built-in functionality (factory traits and enum transitions)

* Remove presence validations for IP and User Agent

- Remove presence validations for acting_ip_address and acting_user_agent

- Update tests to allow nil values for these fields

- These fields can be nil for system-initiated actions

* Use Faker gem in factories

- Use Faker::Lorem.sentence for user_action_event details

- Use Faker::Internet.ip_v4_address for IP addresses

- Use Faker::Internet.user_agent for user agents

* Update UserAction model to match new schema

- Remove UserAccount associations

- Add required SubjectUserVerification association

- Add optional ActingUserVerification association

- Keep IP address and user agent as optional fields

- Update tests to verify new associations and validations

* Add system_initiated trait for UserAction

- Add trait for system-initiated actions without user verification

- Set acting_user_verification, ip_address, and user_agent to nil

- Add comprehensive tests to verify trait behavior

- Ensure subject_user_verification remains required

* Remove system_initiated trait and its tests as requested

* Refactor UserAction specs to use let statements and contexts

* Removes trailing whitespace from spec files

* Refactor UserAction specs to use let statements and contexts

* Removes trailing whitespace in user action spec

* Update CODEOWNERS: Add user_action entries in alphabetical order

* Adds code owners for user action files

* Adds CODEOWNERS for UserActionEvent files

* Updates CODEOWNERS for user action files

* Assigns OCTO Identity team ownership for user actions

Removed duplicate code ownership entries

* Removes duplicate CODEOWNERS entries for user specs

* Simplifies enum status validation in UserAction

Reduces code duplication by leveraging Rails' built-in enum validation
functionality instead of custom validation rules. Consolidates status
validation tests to be more focused and maintainable.

* Adds newline at end of files

* Cleans up CODEOWNERS file redundancy and naming

* Simplifies user action specs with focused test cases
Removes unnecessary status predicate tests
Improves status enum testing with invalid status case

* Renames spec factory files to match plural convention:
- user_action_event.rb -> user_action_events.rb
- user_action.rb -> user_actions.rb

* Simplifies user action model specs

* Fix linting
  • Loading branch information
anjolovic authored Jan 29, 2025
1 parent 7501c69 commit 4950713
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ app/models/triage_team.rb @department-of-veterans-affairs/vfs-mhv-secure-messagi
app/models/all_triage_teams.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/models/user_acceptable_verified_credential.rb @department-of-veterans-affairs/octo-identity
app/models/user_account.rb @department-of-veterans-affairs/octo-identity
app/models/user_action_event.rb @department-of-veterans-affairs/octo-identity
app/models/user_action.rb @department-of-veterans-affairs/octo-identity
app/models/user_credential_email.rb @department-of-veterans-affairs/octo-identity
app/models/user_identity.rb @department-of-veterans-affairs/octo-identity
app/models/user_profile_attributes.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/octo-identity
Expand Down Expand Up @@ -1268,6 +1270,8 @@ spec/factories/supporting_evidence_attachment.rb @department-of-veterans-affairs
spec/factories/triage_teams.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/factories/user_acceptable_verified_credentials.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_accounts.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_action_events.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_actions.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_credential_emails.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_identities.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_identity_attributes.rb @department-of-veterans-affairs/octo-identity
Expand Down Expand Up @@ -1663,6 +1667,8 @@ spec/models/terms_of_use_agreement_spec.rb @department-of-veterans-affairs/octo-
spec/models/triage_team_spec.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/models/user_acceptable_verified_credential_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_account_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_action_event_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_action_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_credential_email_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_relationship_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_session_form_spec.rb @department-of-veterans-affairs/octo-identity
Expand Down
9 changes: 9 additions & 0 deletions app/models/user_action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class UserAction < ApplicationRecord
belongs_to :acting_user_verification, class_name: 'UserVerification', optional: true
belongs_to :subject_user_verification, class_name: 'UserVerification'
belongs_to :user_action_event

enum :status, { initial: 'initial', success: 'success', error: 'error' }, validate: true
end
7 changes: 7 additions & 0 deletions app/models/user_action_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class UserActionEvent < ApplicationRecord
has_many :user_actions, dependent: :restrict_with_exception

validates :details, presence: true
end
7 changes: 7 additions & 0 deletions spec/factories/user_action_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

FactoryBot.define do
factory :user_action_event do
details { Faker::Lorem.sentence }
end
end
12 changes: 12 additions & 0 deletions spec/factories/user_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

FactoryBot.define do
factory :user_action do
association :subject_user_verification, factory: :user_verification
association :user_action_event
status { 'initial' }
acting_ip_address { Faker::Internet.ip_v4_address }
acting_user_agent { Faker::Internet.user_agent }
association :acting_user_verification, factory: :user_verification
end
end
23 changes: 23 additions & 0 deletions spec/models/user_action_event_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe UserActionEvent, type: :model do
describe 'validations' do
it { is_expected.to validate_presence_of(:details) }
end

describe 'associations' do
let(:user_action_event) { create(:user_action_event) }

it { is_expected.to have_many(:user_actions).dependent(:restrict_with_exception) }

context 'when user actions exist' do
let!(:user_action) { create(:user_action, user_action_event: user_action_event) }

it 'restricts destruction when user actions exist' do
expect { user_action_event.destroy }.to raise_error(ActiveRecord::DeleteRestrictionError)
end
end
end
end
19 changes: 19 additions & 0 deletions spec/models/user_action_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe UserAction, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:acting_user_verification).class_name('UserVerification').optional }
it { is_expected.to belong_to(:subject_user_verification).class_name('UserVerification') }
it { is_expected.to belong_to(:user_action_event) }
end

describe 'enum status' do
it {
expect(subject).to define_enum_for(:status).with_values({ initial: 'initial',
success: 'success',
error: 'error' }).backed_by_column_of_type(:enum)
}
end
end

0 comments on commit 4950713

Please sign in to comment.