diff --git a/modules/costs/app/models/time_entries/scopes/ongoing.rb b/modules/costs/app/models/time_entries/scopes/ongoing.rb index 4a52c40b0e0c..7ef8dc360f2e 100644 --- a/modules/costs/app/models/time_entries/scopes/ongoing.rb +++ b/modules/costs/app/models/time_entries/scopes/ongoing.rb @@ -37,7 +37,12 @@ def ongoing def visible_ongoing(user = User.current) TimeEntry - .where(work_package_id: WorkPackage.allowed_to(user, :log_own_time), user:, ongoing: true) + .where(work_package_id: visible_work_packages(user).select(:id), user:, ongoing: true) + end + + def visible_work_packages(user) + WorkPackage.allowed_to(user, :log_own_time).or( + WorkPackage.where(project_id: Project.allowed_to(User.current, :log_time))) end def not_ongoing diff --git a/modules/costs/spec/models/queries/time_entries/time_entry_query_integration_spec.rb b/modules/costs/spec/models/queries/time_entries/time_entry_query_integration_spec.rb index 37c0e98b6070..f98ddcfda3c0 100644 --- a/modules/costs/spec/models/queries/time_entries/time_entry_query_integration_spec.rb +++ b/modules/costs/spec/models/queries/time_entries/time_entry_query_integration_spec.rb @@ -55,6 +55,14 @@ it 'only returns the users own time entries' do expect(subject).to contain_exactly(user_timer) end + + context 'when user has log_time permission' do + let(:user) { create(:user, member_with_permissions: { project => %i[log_time] }) } + + it 'still returns the users own time entries' do + expect(subject).to contain_exactly(user_timer) + end + end end end end