Fix syntax (w/Rubocop) in services

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/2136/head
Alex Coles 10 years ago
parent a2b4e97eea
commit 10f578d00b
  1. 2
      app/services/authorization_service.rb
  2. 90
      app/services/planning_comparison_service.rb
  3. 8
      app/services/reports/assignee_report.rb
  4. 7
      app/services/reports/author_report.rb
  5. 5
      app/services/reports/category_report.rb
  6. 5
      app/services/reports/priority_report.rb
  7. 4
      app/services/reports/report.rb
  8. 8
      app/services/reports/reports_service.rb
  9. 8
      app/services/reports/responsible_report.rb
  10. 5
      app/services/reports/subproject_report.rb
  11. 6
      app/services/reports/type_report.rb
  12. 6
      app/services/reports/version_report.rb
  13. 2
      app/services/update_work_package_service.rb
  14. 17
      app/services/user_search_service.rb

@ -37,7 +37,7 @@ class AuthorizationService
# context - single project or array of projects - default nil
# global - global - default false
# user - user - default current user
def initialize(permission, context: nil , global: false, user: User.current)
def initialize(permission, context: nil, global: false, user: User.current)
@permission = permission
@context = context
@global = global

@ -41,7 +41,7 @@ class PlanningComparisonService
where #{Journal.table_name}.created_at=latest.latest_date
and #{Journal.table_name}.id=latest.latest_id;
SQL
@@mapped_attributes = Journal::WorkPackageJournal.journaled_attributes.map{|attribute| "#{Journal::WorkPackageJournal.table_name}.#{attribute}"}.join ','
@@mapped_attributes = Journal::WorkPackageJournal.journaled_attributes.map { |attribute| "#{Journal::WorkPackageJournal.table_name}.#{attribute}" }.join ','
@@work_package_select = <<SQL
Select #{Journal.table_name}.journable_id as id,
@ -58,8 +58,7 @@ SQL
# the comparison always works on the current date, filters the current workpackages
# and returns the state of these work_packages at the given time
# filters are given in the format expected by Query and are just passed through to query
def self.compare(projects, at_time, filter={})
def self.compare(projects, at_time, filter = {})
# The query uses three steps to find the journalized entries for the filtered workpackages
# at the given point in time:
# 1 filter the ids using query
@ -76,65 +75,62 @@ SQL
# 2 fetch latest journal-entries for the given time
journal_ids = Journal.find_by_sql([@@journal_sql, at_time, work_package_ids])
.map(&:id)
.map(&:id)
# 3&4 fetch the journaled data and make rails think it is actually a work_package
work_packages = WorkPackage.find_by_sql([@@work_package_select,journal_ids])
work_packages = WorkPackage.find_by_sql([@@work_package_select, journal_ids])
restore_references(work_packages)
end
protected
def self.filtered_work_packages(projects, filter)
work_package_scope = WorkPackage.scoped
.joins(:status)
.joins(:project) # query doesn't provide these joins itself...
.for_projects(projects)
query = Query.new name: 'generated-query'
query.add_filters(filter[:f], filter[:op], filter[:v])
work_package_scope.with_query(query)
.pluck(:id)
end
def self.unfiltered_work_packages(projects)
WorkPackage.for_projects(projects).pluck(:id)
end
# This is a very crude way to work around n+1-issues, that are
# introduced by the json/xml-rendering
# the simple .includes does not work the work due to the find_by_sql
def self.restore_references(work_packages)
def self.filtered_work_packages(projects, filter)
work_package_scope = WorkPackage.scoped
.joins(:status)
.joins(:project) # query doesn't provide these joins itself...
.for_projects(projects)
projects = resolve_projects(work_packages)
types = resolve_types(work_packages)
statuses = resolve_statuses(work_packages)
query = Query.new name: 'generated-query'
query.add_filters(filter[:f], filter[:op], filter[:v])
work_packages.each do |wp|
wp.project = projects[wp.project_id]
wp.type = types[wp.type_id]
wp.status = statuses[wp.status_id]
end
work_package_scope.with_query(query)
.pluck(:id)
end
work_packages
def self.unfiltered_work_packages(projects)
WorkPackage.for_projects(projects).pluck(:id)
end
# This is a very crude way to work around n+1-issues, that are
# introduced by the json/xml-rendering
# the simple .includes does not work the work due to the find_by_sql
def self.restore_references(work_packages)
projects = resolve_projects(work_packages)
types = resolve_types(work_packages)
statuses = resolve_statuses(work_packages)
work_packages.each do |wp|
wp.project = projects[wp.project_id]
wp.type = types[wp.type_id]
wp.status = statuses[wp.status_id]
end
def self.resolve_projects(work_packages)
project_ids = work_packages.map(&:project_id).uniq.compact
projects = Hash[Project.find(project_ids).map {|wp| [wp.id,wp]}]
end
work_packages
end
def self.resolve_types(work_packages)
type_ids = work_packages.map(&:type_id).uniq.compact
types = Hash[Type.find(type_ids).map{|type| [type.id,type]}]
end
def self.resolve_projects(work_packages)
project_ids = work_packages.map(&:project_id).uniq.compact
projects = Hash[Project.find(project_ids).map { |wp| [wp.id, wp] }]
end
def self.resolve_statuses(work_packages)
status_ids = work_packages.map(&:status_id).uniq.compact
statuses = Hash[Status.find(status_ids).map{|status| [status.id,status]}]
end
def self.resolve_types(work_packages)
type_ids = work_packages.map(&:type_id).uniq.compact
types = Hash[Type.find(type_ids).map { |type| [type.id, type] }]
end
def self.resolve_statuses(work_packages)
status_ids = work_packages.map(&:status_id).uniq.compact
statuses = Hash[Status.find(status_ids).map { |status| [status.id, status] }]
end
end

@ -28,17 +28,16 @@
#++
class Reports::AssigneeReport < Reports::Report
def self.report_type
"assigned_to"
'assigned_to'
end
def field
@field ||= "assigned_to_id"
@field ||= 'assigned_to_id'
end
def rows
@rows ||= @project.members.collect { |m| m.user }.sort
@rows ||= @project.members.collect(&:user).sort
end
def data
@ -48,5 +47,4 @@ class Reports::AssigneeReport < Reports::Report
def title
@title ||= WorkPackage.human_attribute_name(:assigned_to)
end
end

@ -28,17 +28,16 @@
#++
class Reports::AuthorReport < Reports::Report
def self.report_type
"author"
'author'
end
def field
"author_id"
'author_id'
end
def rows
@rows ||= @project.members.collect { |m| m.user }.sort
@rows ||= @project.members.collect(&:user).sort
end
def data

@ -28,13 +28,12 @@
#++
class Reports::CategoryReport < Reports::Report
def self.report_type
"category"
'category'
end
def field
"category_id"
'category_id'
end
def rows

@ -28,13 +28,12 @@
#++
class Reports::PriorityReport < Reports::Report
def self.report_type
"priority"
'priority'
end
def field
"priority_id"
'priority_id'
end
def rows

@ -28,13 +28,12 @@
#++
class Reports::Report
def initialize(project)
@project = project
end
def self.report_type
"default"
'default'
end
def report_type
@ -61,5 +60,4 @@ class Reports::Report
def title
raise NotImplementedError
end
end

@ -28,7 +28,6 @@
#++
class Reports::ReportsService
class_attribute :report_types
def self.add_report(report)
@ -40,7 +39,6 @@ class Reports::ReportsService
self.report_types.has_key? report_type
end
# automate this? by cycling through each instance of Reports::Report? or is this to automagically?
# and there is no reason, why plugins shouldn't be able to use this to add their own customized reports...
add_report Reports::SubprojectReport
@ -52,11 +50,8 @@ class Reports::ReportsService
add_report Reports::CategoryReport
add_report Reports::VersionReport
def initialize(project)
raise "You must provide a project to report upon" unless project && project.is_a?(Project)
raise 'You must provide a project to report upon' unless project && project.is_a?(Project)
@project = project
end
@ -64,5 +59,4 @@ class Reports::ReportsService
report_klass = self.class.report_types[report_type]
report_klass.new(@project) if report_klass
end
end

@ -28,17 +28,16 @@
#++
class Reports::ResponsibleReport < Reports::Report
def self.report_type
"responsible"
'responsible'
end
def field
@field ||= "responsible_id"
@field ||= 'responsible_id'
end
def rows
@rows ||= @project.members.collect { |m| m.user }.sort
@rows ||= @project.members.collect(&:user).sort
end
def data
@ -48,5 +47,4 @@ class Reports::ResponsibleReport < Reports::Report
def title
@title ||= WorkPackage.human_attribute_name(:responsible)
end
end

@ -28,13 +28,12 @@
#++
class Reports::SubprojectReport < Reports::Report
def self.report_type
"subproject"
'subproject'
end
def field
"project_id"
'project_id'
end
def rows

@ -28,13 +28,12 @@
#++
class Reports::TypeReport < Reports::Report
def self.report_type
"type"
'type'
end
def field
@field || "type_id"
@field || 'type_id'
end
def rows
@ -48,5 +47,4 @@ class Reports::TypeReport < Reports::Report
def title
@title = WorkPackage.human_attribute_name(:type)
end
end

@ -28,13 +28,12 @@
#++
class Reports::VersionReport < Reports::Report
def self.report_type
"version"
'version'
end
def field
@field ||= "fixed_version_id"
@field ||= 'fixed_version_id'
end
def rows
@ -48,5 +47,4 @@ class Reports::VersionReport < Reports::Report
def title
@title ||= WorkPackage.human_attribute_name(:version)
end
end

@ -30,7 +30,7 @@
class UpdateWorkPackageService
attr_accessor :user, :work_package, :permitted_params, :send_notifications
def initialize(user, work_package, permitted_params, send_notifications=true)
def initialize(user, work_package, permitted_params, send_notifications = true)
self.user = user
self.work_package = work_package
self.permitted_params = permitted_params

@ -67,21 +67,20 @@ class UserSearchService
else
@status = params[:status] ? params[:status].to_i : User::STATUSES[:active]
scope = scope.not_blocked if @status == User::STATUSES[:active]
c << ["status = ?", @status]
c << ['status = ?', @status]
end
unless params[:name].blank?
name = "%#{params[:name].strip.downcase}%"
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name]
c << ['LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?', name, name, name, name]
end
scope.where(c.conditions)
# currently, the sort/paging-helpers are highly dependent on being included in a controller
# and having access to things like the session or the params: this makes it harder
# to test outside a controller and especially hard to re-use this functionality
#.page(page_param)
#.per_page(per_page_param)
# .order(sort_clause)
# currently, the sort/paging-helpers are highly dependent on being included in a controller
# and having access to things like the session or the params: this makes it harder
# to test outside a controller and especially hard to re-use this functionality
# .page(page_param)
# .per_page(per_page_param)
# .order(sort_clause)
end
end

Loading…
Cancel
Save