Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove TimeEntries visible scope as this is already implemented by cost scope

Klaus Zanders3d26a24dbd51
diff --git a/modules/costs/app/models/time_entries/scopes/visible.rb b/modules/costs/app/models/time_entries/scopes/visible.rb
deleted file mode 100644
index cc4d39d51b9..00000000000
--- a/modules/costs/app/models/time_entries/scopes/visible.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module TimeEntries::Scopes
- module Visible
- extend ActiveSupport::Concern
-
- class_methods do
- def visible(user = User.current)
- all_scope = TimeEntry
- .where(project_id: Project.allowed_to(user, :view_time_entries))
-
- own_scope = TimeEntry
- .where(work_package_id: WorkPackage.allowed_to(user, :view_own_time_entries))
- .where(user:)
-
- all_scope.or(own_scope)
- end
- end
- end
-end
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index c745e6df00c..e317762078f 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -52,7 +52,6 @@ class TimeEntry < ApplicationRecord
include Entry::SplashedDates
scopes :of_user_and_day,
- :visible,
:ongoing
# TODO: move into service
diff --git a/modules/costs/spec/models/time_entries/scopes/visible_spec.rb b/modules/costs/spec/models/time_entries/scopes/visible_spec.rb
index 1311e537157..b1305c96ee2 100644
--- a/modules/costs/spec/models/time_entries/scopes/visible_spec.rb
+++ b/modules/costs/spec/models/time_entries/scopes/visible_spec.rb
@@ -28,13 +28,8 @@
require 'spec_helper'
-RSpec.describe TimeEntries::Scopes::Visible do
+RSpec.describe TimeEntry, "visible scope" do
let(:project) { create(:project) }
- let(:user) do
- create(:user,
- member_with_permissions: { project => permissions })
- end
- let(:permissions) { [:view_time_entries] }
let(:work_package) do
create(:work_package,
@@ -68,18 +63,20 @@ RSpec.describe TimeEntries::Scopes::Visible do
subject { TimeEntry.visible(user) }
context 'for a user having the view_time_entries permission' do
+ let(:user) { create(:user, member_with_permissions: { project => [:view_time_entries] }) }
+
it 'retrieves all the time entries of projects the user has the permissions in' do
expect(subject)
- .to match_array([own_project_time_entry, project_time_entry])
+ .to contain_exactly(own_project_time_entry, project_time_entry)
end
end
- context 'for a user having the view_own_time_entries permission' do
- let(:permissions) { [:view_own_time_entries] }
+ context 'for a user having the view_own_time_entries permission on a work package' do
+ let(:user) { create(:user, member_with_permissions: { work_package => [:view_own_time_entries] }) }
it 'retrieves all the time entries of the user in projects the user has the permissions in' do
expect(subject)
- .to match_array([own_project_time_entry])
+ .to contain_exactly(own_project_time_entry)
end
end
end
diff --git a/spec/factories/principal_factory.rb b/spec/factories/principal_factory.rb
index d9d821674fe..c9e683c9938 100644
--- a/spec/factories/principal_factory.rb
+++ b/spec/factories/principal_factory.rb
@@ -77,7 +77,7 @@ FactoryBot.define do
create(:member, principal:, project: object, roles: [role])
elsif Member.can_be_member_of?(object)
role = create(:work_package_role, permissions:)
- create(:member, principal:, entity: object, project: entity.project, roles: [role])
+ create(:member, principal:, entity: object, project: object.project, roles: [role])
end
end