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. 16
      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. 9
      app/services/user_search_service.rb

@ -37,7 +37,7 @@ class AuthorizationService
# context - single project or array of projects - default nil # context - single project or array of projects - default nil
# global - global - default false # global - global - default false
# user - user - default current user # 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 @permission = permission
@context = context @context = context
@global = global @global = global

@ -41,7 +41,7 @@ class PlanningComparisonService
where #{Journal.table_name}.created_at=latest.latest_date where #{Journal.table_name}.created_at=latest.latest_date
and #{Journal.table_name}.id=latest.latest_id; and #{Journal.table_name}.id=latest.latest_id;
SQL 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 @@work_package_select = <<SQL
Select #{Journal.table_name}.journable_id as id, 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 # the comparison always works on the current date, filters the current workpackages
# and returns the state of these work_packages at the given time # 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 # 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 # The query uses three steps to find the journalized entries for the filtered workpackages
# at the given point in time: # at the given point in time:
# 1 filter the ids using query # 1 filter the ids using query
@ -79,7 +78,7 @@ SQL
.map(&:id) .map(&:id)
# 3&4 fetch the journaled data and make rails think it is actually a work_package # 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) restore_references(work_packages)
end end
@ -107,7 +106,6 @@ SQL
# introduced by the json/xml-rendering # introduced by the json/xml-rendering
# the simple .includes does not work the work due to the find_by_sql # the simple .includes does not work the work due to the find_by_sql
def self.restore_references(work_packages) def self.restore_references(work_packages)
projects = resolve_projects(work_packages) projects = resolve_projects(work_packages)
types = resolve_types(work_packages) types = resolve_types(work_packages)
statuses = resolve_statuses(work_packages) statuses = resolve_statuses(work_packages)
@ -119,22 +117,20 @@ SQL
end end
work_packages work_packages
end end
def self.resolve_projects(work_packages) def self.resolve_projects(work_packages)
project_ids = work_packages.map(&:project_id).uniq.compact project_ids = work_packages.map(&:project_id).uniq.compact
projects = Hash[Project.find(project_ids).map {|wp| [wp.id,wp]}] projects = Hash[Project.find(project_ids).map { |wp| [wp.id, wp] }]
end end
def self.resolve_types(work_packages) def self.resolve_types(work_packages)
type_ids = work_packages.map(&:type_id).uniq.compact type_ids = work_packages.map(&:type_id).uniq.compact
types = Hash[Type.find(type_ids).map{|type| [type.id,type]}] types = Hash[Type.find(type_ids).map { |type| [type.id, type] }]
end end
def self.resolve_statuses(work_packages) def self.resolve_statuses(work_packages)
status_ids = work_packages.map(&:status_id).uniq.compact status_ids = work_packages.map(&:status_id).uniq.compact
statuses = Hash[Status.find(status_ids).map{|status| [status.id,status]}] statuses = Hash[Status.find(status_ids).map { |status| [status.id, status] }]
end end
end end

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

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

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

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

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

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

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

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

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

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

@ -30,7 +30,7 @@
class UpdateWorkPackageService class UpdateWorkPackageService
attr_accessor :user, :work_package, :permitted_params, :send_notifications 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.user = user
self.work_package = work_package self.work_package = work_package
self.permitted_params = permitted_params self.permitted_params = permitted_params

@ -67,21 +67,20 @@ class UserSearchService
else else
@status = params[:status] ? params[:status].to_i : User::STATUSES[:active] @status = params[:status] ? params[:status].to_i : User::STATUSES[:active]
scope = scope.not_blocked if @status == User::STATUSES[:active] scope = scope.not_blocked if @status == User::STATUSES[:active]
c << ["status = ?", @status] c << ['status = ?', @status]
end end
unless params[:name].blank? unless params[:name].blank?
name = "%#{params[:name].strip.downcase}%" 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 end
scope.where(c.conditions) scope.where(c.conditions)
# currently, the sort/paging-helpers are highly dependent on being included in a controller # 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 # 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 # to test outside a controller and especially hard to re-use this functionality
#.page(page_param) # .page(page_param)
#.per_page(per_page_param) # .per_page(per_page_param)
# .order(sort_clause) # .order(sort_clause)
end end
end end

Loading…
Cancel
Save