Skip to content

Commit

Permalink
Merge pull request #481 from sul-dlss/t478-collections_dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Jan 14, 2025
2 parents 0c48030 + 6536ea6 commit 2b83ed7
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def show
# Also, it processes all of a user's works, but not all may be rendered on the dashboard.
druid_to_status_map = Sdr::Repository.statuses(druids: druids_for_works_for_current_user)
@draft_works = []
@status_map = current_user.works.to_h do |work|
@status_map = current_user.your_works.to_h do |work|
version_status = druid_to_status_map[work.druid] || VersionStatus::NilStatus.new
@draft_works << work if version_status.draft?
[work.id, version_status]
Expand Down
14 changes: 14 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@ class User < ApplicationRecord
def sunetid
email_address.delete_suffix(EMAIL_SUFFIX)
end

# Returns all collections that the user manages, deposits to, or reviews.
def your_collections
Collection.left_outer_joins(:managers, :depositors, :reviewers).where(managers: { id: }).or(
Collection.left_outer_joins(:managers, :depositors, :reviewers).where(depositors: { id: })
).or(
Collection.left_outer_joins(:managers, :depositors, :reviewers).where(reviewers: { id: })
).distinct
end

# Returns all works for collections that the user manages, deposits to, or reviews.
def your_works
Work.where(collection: your_collections)
end
end
18 changes: 1 addition & 17 deletions app/views/dashboard/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,7 @@
<%= render Elements::ButtonLinkComponent.new(link: new_collection_path, label: 'Create a new collection', variant: :primary, classes: 'ml-auto text-nowrap h-50') if allowed_to?(:new?, Collection) %>
</div>

<% current_user.collections.each do |collection| %>
<div class="mb-3">
<%= render Collections::HeaderLinkComponent.new(collection:, level: :h4) %>
<%= render Dashboard::Show::WorksListComponent.new(collection:, status_map: @status_map) %>
<%= render Elements::ButtonLinkComponent.new(link: new_work_path(collection_druid: collection.druid), label: 'Deposit to this collection', variant: :primary) %>
</div>
<% end %>

<% current_user.manages.each do |collection| %>
<div class="mb-3">
<%= render Collections::HeaderLinkComponent.new(collection:, level: :h4) %>
<%= render Dashboard::Show::WorksListComponent.new(collection:, status_map: @status_map) %>
<%= render Elements::ButtonLinkComponent.new(link: new_work_path(collection_druid: collection.druid), label: 'Deposit to this collection', variant: :primary) %>
</div>
<% end %>

<% current_user.depositor_for.each do |collection| %>
<% current_user.your_collections.each do |collection| %>
<div class="mb-3">
<%= render Collections::HeaderLinkComponent.new(collection:, level: :h4) %>
<%= render Dashboard::Show::WorksListComponent.new(collection:, status_map: @status_map) %>
Expand Down
38 changes: 38 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe User do
let(:user) { create(:user) }
let!(:managed_collection) { create(:collection, managers: [user]) }
let!(:depositor_collection) { create(:collection, depositors: [user]) }
let!(:reviewed_collection) { create(:collection, reviewers: [user]) }
let!(:deduped_collection) { create(:collection, managers: [user], depositors: [user], reviewers: [user]) }

describe '.your_collections' do
before do
# Not your collection
create(:collection, user:)
end

it 'returns the collections for which the user is a manager, depositor, or reviewer' do
expect(user.your_collections).to contain_exactly(managed_collection, depositor_collection, reviewed_collection,
deduped_collection)
end
end

describe '.your_works' do
let!(:managed_work) { create(:work, collection: managed_collection) }
let!(:depositor_work) { create(:work, collection: depositor_collection) }
let!(:reviewed_work) { create(:work, collection: reviewed_collection) }

before do
# Not your work
create(:work, collection: create(:collection, user:))
end

it 'returns the works that are part of the your collections' do
expect(user.your_works).to contain_exactly(managed_work, depositor_work, reviewed_work)
end
end
end
2 changes: 1 addition & 1 deletion spec/requests/show_dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe 'drafts section' do
let!(:work) { create(:work, :with_druid, user:, collection:) }
let(:collection) { create(:collection, :with_druid, user:) }
let(:collection) { create(:collection, :with_druid, user:, managers: [user]) }

let(:drafts_header) { 'Drafts - please complete' }

Expand Down
2 changes: 1 addition & 1 deletion spec/system/create_work_deposit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Stubbing out for show page
allow(Sdr::Repository).to receive(:find).with(druid:).and_invoke(->(_arg) { @registered_cocina_object })
allow(Sdr::Repository).to receive(:status).with(druid:).and_return(version_status)
create(:collection, user:, druid: collection_druid_fixture)
create(:collection, user:, druid: collection_druid_fixture, managers: [user])
sign_in(user)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/system/create_work_draft_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
allow(Sdr::Repository).to receive(:find).with(druid:).and_invoke(->(_arg) { @registered_cocina_object })
allow(Sdr::Repository).to receive(:status).with(druid:).and_return(version_status)

create(:collection, user:, title: collection_title_fixture, druid: collection_druid_fixture)
create(:collection, user:, title: collection_title_fixture, druid: collection_druid_fixture, managers: [user])

sign_in(user)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/system/show_dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let!(:work) { create(:work, :with_druid, user:, collection:) }
let!(:work_without_druid) { create(:work, user:, collection:) }
let!(:draft_work) { create(:work, :with_druid, user:, collection:) }
let(:collection) { create(:collection, :with_druid, user:) }
let(:collection) { create(:collection, :with_druid, user:, managers: [user]) }
let(:user) { create(:user) }
let(:version_status) do
VersionStatus.new(status:
Expand Down

0 comments on commit 2b83ed7

Please sign in to comment.