|
|
@@ -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| |