diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-05-30 10:05:43 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-05-30 10:05:43 +0000 |
commit | 48d40a8c8884aefc2287f2030c439578057c9516 (patch) | |
tree | d316a50c5229ba8f5ae7cf2bbe10b0a7dba8c753 | |
parent | ff2532e52d406bb29509ee63b8329a70ddfc5c52 (diff) | |
download | redmine-48d40a8c8884aefc2287f2030c439578057c9516.tar.gz redmine-48d40a8c8884aefc2287f2030c439578057c9516.zip |
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
-rw-r--r-- | app/models/project.rb | 50 | ||||
-rw-r--r-- | test/unit/time_entry_activity_test.rb | 7 |
2 files changed, 17 insertions, 40 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 83c678bda..05a5fa2e7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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| diff --git a/test/unit/time_entry_activity_test.rb b/test/unit/time_entry_activity_test.rb index 8c6fef7aa..645f7474a 100644 --- a/test/unit/time_entry_activity_test.rb +++ b/test/unit/time_entry_activity_test.rb @@ -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 |