mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Fixed that project activity without parent hides system activities and removed duplicated code.
git-svn-id: http://svn.redmine.org/redmine/trunk@14292 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ff2532e52d
commit
48d40a8c88
@ -234,11 +234,17 @@ class Project < ActiveRecord::Base
|
||||
|
||||
# Returns the Systemwide and project specific activities
|
||||
def activities(include_inactive=false)
|
||||
if include_inactive
|
||||
return all_activities
|
||||
else
|
||||
return active_activities
|
||||
t = TimeEntryActivity.table_name
|
||||
scope = TimeEntryActivity.where("#{t}.project_id IS NULL OR #{t}.project_id = ?", id)
|
||||
|
||||
overridden_activity_ids = self.time_entry_activities.pluck(:parent_id).compact
|
||||
if overridden_activity_ids.any?
|
||||
scope = scope.where("#{t}.id NOT IN (?)", overridden_activity_ids)
|
||||
end
|
||||
unless include_inactive
|
||||
scope = scope.active
|
||||
end
|
||||
scope
|
||||
end
|
||||
|
||||
# Will create a new Project specific Activity or update an existing one
|
||||
@ -989,42 +995,6 @@ class Project < ActiveRecord::Base
|
||||
@actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
|
||||
end
|
||||
|
||||
# Returns all the active Systemwide and project specific activities
|
||||
def active_activities
|
||||
overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
|
||||
|
||||
if overridden_activity_ids.empty?
|
||||
return TimeEntryActivity.shared.active
|
||||
else
|
||||
return system_activities_and_project_overrides
|
||||
end
|
||||
end
|
||||
|
||||
# Returns all the Systemwide and project specific activities
|
||||
# (inactive and active)
|
||||
def all_activities
|
||||
overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
|
||||
|
||||
if overridden_activity_ids.empty?
|
||||
return TimeEntryActivity.shared
|
||||
else
|
||||
return system_activities_and_project_overrides(true)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the systemwide active activities merged with the project specific overrides
|
||||
def system_activities_and_project_overrides(include_inactive=false)
|
||||
t = TimeEntryActivity.table_name
|
||||
scope = TimeEntryActivity.where(
|
||||
"(#{t}.project_id IS NULL AND #{t}.id NOT IN (?)) OR (#{t}.project_id = ?)",
|
||||
time_entry_activities.map(&:parent_id), id
|
||||
)
|
||||
unless include_inactive
|
||||
scope = scope.active
|
||||
end
|
||||
scope
|
||||
end
|
||||
|
||||
# Archives subprojects recursively
|
||||
def archive!
|
||||
children.each do |subproject|
|
||||
|
||||
@ -120,4 +120,11 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
|
||||
end
|
||||
assert entries.all? {|entry| entry.reload.activity.name == 'Development'}
|
||||
end
|
||||
|
||||
def test_project_activity_without_parent_should_not_disable_system_activities
|
||||
project = Project.find(1)
|
||||
activity = TimeEntryActivity.create!(:name => 'Csutom', :project => project)
|
||||
assert_include activity, project.activities
|
||||
assert_include TimeEntryActivity.find(9), project.activities
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user