Skip to content

Commit

Permalink
(Fix) Do not show deleted projects in the "Added by" page
Browse files Browse the repository at this point in the history
A user reported that they were seeing a deleted project in their
"Added by" page. We were not explicity excluding deleted projects
from the "Added by" page or scope.
  • Loading branch information
lozette committed Oct 2, 2024
1 parent 4e8a0ee commit 32db203
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased][unreleased]

### Fixed

- Do not show deleted projects in the "Added by you" page

## [Release-90][release-90]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/your/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def in_progress

def added_by
authorize Project, :index?
@pager, @projects = pagy(Project.added_by(current_user).not_completed.not_inactive.ordered_by_significant_date.includes(:assigned_to))
@pager, @projects = pagy(Project.added_by(current_user).not_completed.not_inactive.not_deleted.ordered_by_significant_date.includes(:assigned_to))

AcademiesApiPreFetcherService.new.call!(@projects)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Project < ApplicationRecord

scope :assigned_to, ->(user) { where(assigned_to_id: user.id) }
scope :assigned_to_users, ->(users) { where(assigned_to_id: [users]) }
scope :added_by, ->(user) { where(regional_delivery_officer: user) }
scope :added_by, ->(user) { where(regional_delivery_officer: user).and(where.not(state: 2)) }

scope :ordered_by_created_at_date, -> { order(created_at: :desc) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
let!(:sponsored_in_progress_project) { create(:conversion_project, urn: 112209, directive_academy_order: true, regional_delivery_officer: user) }
let!(:voluntary_in_progress_project) { create(:conversion_project, urn: 103835, directive_academy_order: false, regional_delivery_officer: user) }
let!(:inactive_project) { create(:conversion_project, :inactive, urn: 187356, regional_delivery_officer: user) }
let!(:deleted_project) { create(:conversion_project, :deleted, urn: 137904, regional_delivery_officer: user) }
let!(:other_project) { create(:conversion_project) }

scenario "they can view all in progress projects that they added" do
Expand All @@ -45,6 +46,7 @@ def view_all_added_projects

expect(page).not_to have_content(completed_project.urn)
expect(page).not_to have_content(inactive_project.urn)
expect(page).not_to have_content(deleted_project.urn)
expect(page).not_to have_content(other_project.urn)
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,11 @@
user = create(:user)
added_project = create(:conversion_project, regional_delivery_officer: user)
other_project = create(:conversion_project)
deleted_project = create(:conversion_project, :deleted, regional_delivery_officer: user)

expect(Project.added_by(user)).to include(added_project)
expect(Project.added_by(user)).to_not include(other_project)
expect(Project.added_by(user)).to_not include(deleted_project)
end
end

Expand Down

0 comments on commit 32db203

Please sign in to comment.