Fix syntax (w/Rubocop) in lib code

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/3194/head
Alex Coles 9 years ago
parent ea713284a8
commit a6212fb304
  1. 4
      lib/api/root.rb
  2. 4
      lib/api/utilities/grape_helper.rb
  3. 4
      lib/api/v3/activities/activities_api.rb
  4. 2
      lib/api/v3/activities/activity_representer.rb
  5. 1
      lib/api/v3/attachments/attachment_representer.rb
  6. 2
      lib/api/v3/attachments/attachments_api.rb
  7. 4
      lib/api/v3/attachments/attachments_by_work_package_api.rb
  8. 1
      lib/api/v3/priorities/priority_representer.rb
  9. 1
      lib/api/v3/projects/project_representer.rb
  10. 4
      lib/api/v3/queries/queries_api.rb
  11. 1
      lib/api/v3/statuses/status_representer.rb
  12. 1
      lib/api/v3/string_objects/string_objects_api.rb
  13. 3
      lib/api/v3/users/users_api.rb
  14. 8
      lib/api/v3/utilities/custom_field_injector.rb
  15. 5
      lib/api/v3/versions/version_representer.rb
  16. 2
      lib/api/v3/versions/versions_api.rb
  17. 1
      lib/api/v3/watchers/watcher_representer.rb
  18. 4
      lib/api/v3/work_packages/watchers_api.rb
  19. 4
      lib/api/v3/work_packages/work_package_representer.rb
  20. 6
      lib/copy_model.rb
  21. 5
      lib/custom_field_form_builder.rb
  22. 18
      lib/diff.rb
  23. 8
      lib/open_project/authentication/manager.rb
  24. 2
      lib/open_project/authentication/strategies/warden/global_basic_auth.rb
  25. 3
      lib/open_project/concerns/preview.rb
  26. 4
      lib/open_project/configuration/helpers.rb
  27. 19
      lib/open_project/nested_set/rebuild_patch.rb
  28. 7
      lib/open_project/nested_set/root_id_rebuilding.rb
  29. 3
      lib/open_project/object_linking.rb
  30. 4
      lib/open_project/omni_auth/authorization.rb
  31. 4
      lib/open_project/passwords.rb
  32. 2
      lib/open_project/principal_allowance_evaluator/base.rb
  33. 4
      lib/open_project/static_routing.rb
  34. 61
      lib/open_project/text_formatting.rb
  35. 2
      lib/open_project/themes/theme.rb
  36. 2
      lib/open_project/version.rb
  37. 1
      lib/open_project/wiki_formatting/macros/default.rb
  38. 6
      lib/pagination/controller.rb
  39. 5
      lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb
  40. 8
      lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
  41. 7
      lib/plugins/acts_as_journalized/lib/acts/journalized/journal_object_cache.rb
  42. 11
      lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/changes.rb
  43. 5
      lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/creation.rb
  44. 6
      lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/format_hooks.rb
  45. 20
      lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/save_hooks.rb
  46. 4
      lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/users.rb
  47. 3
      lib/plugins/acts_as_journalized/lib/redmine/acts/journalized/versions.rb
  48. 15
      lib/plugins/acts_as_journalized/test/reset_test.rb
  49. 7
      lib/plugins/acts_as_journalized/test/reversion_test.rb
  50. 6
      lib/plugins/acts_as_journalized/test/version_test.rb
  51. 3
      lib/plugins/acts_as_journalized/test/versions_test.rb
  52. 3
      lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
  53. 8
      lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
  54. 6
      lib/plugins/verification/lib/action_controller/verification.rb
  55. 2
      lib/redmine/access_control.rb
  56. 10
      lib/redmine/activity/fetcher.rb
  57. 2
      lib/redmine/core_ext/string/conversions.rb
  58. 12
      lib/redmine/default_data/loader.rb
  59. 2
      lib/redmine/helpers/diff.rb
  60. 4
      lib/redmine/i18n.rb
  61. 72
      lib/redmine/menu_manager/menu_helper.rb
  62. 4
      lib/redmine/menu_manager/top_menu_helper.rb
  63. 2
      lib/redmine/menu_manager/tree_node.rb
  64. 6
      lib/redmine/mime_type.rb
  65. 2
      lib/redmine/plugin.rb
  66. 6
      lib/redmine/scm/adapters/filesystem_adapter.rb
  67. 26
      lib/redmine/scm/adapters/git_adapter.rb
  68. 24
      lib/redmine/scm/adapters/subversion_adapter.rb
  69. 3
      lib/redmine/unified_diff.rb
  70. 11
      lib/redmine/views/my_page/block.rb
  71. 4
      lib/redmine/wiki_formatting.rb
  72. 6
      lib/redmine/wiki_formatting/textile/formatter.rb
  73. 8
      lib/tabular_form_builder.rb

@ -130,7 +130,7 @@ module API
raise ArgumentError if projects.nil? && !global
projects = Array(projects)
authorized = permissions.any? do |permission|
authorized = permissions.any? { |permission|
allowed_condition = Project.allowed_to_condition(user, permission)
allowed_projects = Project.where(allowed_condition)
@ -139,7 +139,7 @@ module API
else
!(allowed_projects & projects).empty?
end
end
}
raise API::Errors::Unauthorized unless authorized
authorized

@ -49,12 +49,12 @@ module API
end
def error_response(rescued_error, error = nil, rescue_subclasses: nil, headers: {})
default_response = lambda do |e|
default_response = lambda { |e|
representer = ::API::V3::Errors::ErrorRepresenter.new e
env['api.format'] = 'hal+json'
error_response status: e.code, message: representer.to_json, headers: headers
end
}
response =
if error.nil?

@ -33,12 +33,10 @@ module API
module Activities
class ActivitiesAPI < ::API::OpenProjectAPI
resources :activities do
params do
requires :id, desc: 'Activity id'
end
route_param :id do
before do
@activity = Journal.find(params[:id])
@representer = ActivityRepresenter.new(@activity, current_user: current_user)
@ -77,9 +75,7 @@ module API
save_activity(@activity)
end
end
end
end
end

@ -65,7 +65,7 @@ module API
exec_context: :decorator,
getter: -> (*) {
::API::Decorators::Formattable.new(represented.notes,
object: represented.journable)
object: represented.journable)
},
setter: -> (value, *) { represented.notes = value['raw'] },
render_nil: true

@ -34,7 +34,6 @@ module API
module V3
module Attachments
class AttachmentRepresenter < ::API::Decorators::Single
self_link title_getter: -> (*) { represented.filename }
linked_property :author,

@ -33,12 +33,10 @@ module API
module Attachments
class AttachmentsAPI < ::API::OpenProjectAPI
resources :attachments do
params do
requires :id, desc: 'Attachment id'
end
route_param :id do
before do
@attachment = Attachment.find(params[:id])

@ -42,7 +42,7 @@ module API
unless metadata.file_name
raise ::API::Errors::Validation.new(
"fileName #{I18n.t('activerecord.errors.messages.blank')}.")
"fileName #{I18n.t('activerecord.errors.messages.blank')}.")
end
metadata
@ -75,7 +75,7 @@ module API
unless metadata && file
raise ::API::Errors::InvalidRequestBody.new(
I18n.t('api_v3.errors.multipart_body_error'))
I18n.t('api_v3.errors.multipart_body_error'))
end
attachment = make_attachment(metadata, file)

@ -34,7 +34,6 @@ module API
module V3
module Priorities
class PriorityRepresenter < ::API::Decorators::Single
self_link
property :id, render_nil: true

@ -34,7 +34,6 @@ module API
module V3
module Projects
class ProjectRepresenter < ::API::Decorators::Single
self_link
link :createWorkPackage do

@ -58,10 +58,10 @@ module API
# Normalizing the query name can result in conflicts and empty names in case all
# characters are filtered out. A random name doesn't have these problems.
query_menu_item = MenuItems::QueryMenuItem.find_or_initialize_by(
navigatable_id: @query.id) do |item|
navigatable_id: @query.id) { |item|
item.name = SecureRandom.uuid
item.title = @query.name
end
}
query_menu_item.save!
@representer
end

@ -31,7 +31,6 @@ module API
module V3
module Statuses
class StatusRepresenter < ::API::Decorators::Single
self_link
property :id, render_nil: true

@ -34,7 +34,6 @@ module API
module StringObjects
class StringObjectsAPI < ::API::OpenProjectAPI
resources :string_objects do
params do
requires :value, type: String
end

@ -47,12 +47,10 @@ module API
end
resources :users do
params do
requires :id, desc: 'User\'s id'
end
route_param :id do
before do
@user = User.find(params[:id])
end
@ -70,7 +68,6 @@ module API
end
namespace :lock do
# Authenticate lock transitions
before do
unless current_user.admin?

@ -83,9 +83,9 @@ module API
end
def create_value_representer_for_property_patching(customizable, representer)
property_fields = customizable.available_custom_fields.select do |cf|
property_fields = customizable.available_custom_fields.select { |cf|
property_field?(cf)
end
}
injector = CustomFieldInjector.new(representer)
property_fields.each do |custom_field|
@ -96,9 +96,9 @@ module API
end
def create_value_representer_for_link_patching(customizable, representer)
linked_fields = customizable.available_custom_fields.select do |cf|
linked_fields = customizable.available_custom_fields.select { |cf|
linked_field?(cf)
end
}
injector = CustomFieldInjector.new(representer)
linked_fields.each do |custom_field|

@ -34,7 +34,6 @@ module API
module V3
module Versions
class VersionRepresenter < ::API::Decorators::Single
self_link
linked_property :definingProject,
@ -55,8 +54,8 @@ module API
exec_context: :decorator,
getter: -> (*) {
::API::Decorators::Formattable.new(represented.description,
object: represented,
format: 'plain')
object: represented,
format: 'plain')
},
render_nil: true

@ -32,9 +32,7 @@ module API
module Versions
class VersionsAPI < ::API::OpenProjectAPI
resources :versions do
route_param :id do
before do
@version = Version.find(params[:id])

@ -34,7 +34,6 @@ module API
module V3
module Watchers
class WatcherRepresenter < ::API::Decorators::Single
property :user,
exec_context: :decorator,
getter: -> (*) {

@ -81,9 +81,9 @@ module API
Services::CreateWatcher.new(@work_package, user).run(
success: -> (result) { status(200) unless result[:created] },
failure: -> (watcher) {
messages = watcher.errors.map do |attribute, message|
messages = watcher.errors.map { |attribute, message|
watcher.errors.full_message(attribute, message) + '.'
end
}
raise ::API::Errors::Validation.new(messages)
}
)

@ -333,9 +333,9 @@ module API
def relations
relations = represented.relations
visible_relations = relations.select do |relation|
visible_relations = relations.select { |relation|
relation.other_work_package(represented).visible?
end
}
visible_relations.map do |relation|
Relations::RelationRepresenter.new(relation,

@ -59,9 +59,9 @@ module CopyModel
to_be_copied = self.class.reflect_on_all_associations.map(&:name)
to_be_copied = Array(options[:only]) unless options[:only].nil?
to_be_copied = to_be_copied.map(&:to_s).sort do |a, b|
to_be_copied = to_be_copied.map(&:to_s).sort { |a, b|
(copy_precedence.map(&:to_s).index(a) || -1) <=> (copy_precedence.map(&:to_s).index(b) || -1)
end.map(&:to_sym)
}.map(&:to_sym)
with_model(from_model) do |model|
self.class.transaction do
@ -102,8 +102,6 @@ module CopyModel
else
return model
end
else
nil
end
end

@ -30,7 +30,6 @@
require 'action_view/helpers/form_helper'
class CustomFieldFormBuilder < TabularFormBuilder
# Return custom field html tag corresponding to its format
def custom_field(options = {})
input = custom_field_input(options)
@ -90,11 +89,11 @@ class CustomFieldFormBuilder < TabularFormBuilder
end
def custom_field_field_name
"#{object_name}[#{ object.custom_field.id }]"
"#{object_name}[#{object.custom_field.id}]"
end
def custom_field_field_id
"#{object_name}#{ object.custom_field.id }".gsub(/[\[\]]+/, '_')
"#{object_name}#{object.custom_field.id}".gsub(/[\[\]]+/, '_')
end
# Return custom field label tag

@ -56,11 +56,11 @@ module RedmineDiff
thresh = []
links = []
(astart..afinish).each { |aindex|
(astart..afinish).each do |aindex|
aelem = a[aindex]
next unless bmatches.has_key? aelem
k = nil
bmatches[aelem].reverse.each { |bindex|
bmatches[aelem].reverse_each { |bindex|
if k && (thresh[k] > bindex) && (thresh[k - 1] < bindex)
thresh[k] = bindex
else
@ -68,7 +68,7 @@ module RedmineDiff
end
links[k] = [(k == 0) ? nil : links[k - 1], aindex, bindex] if k
}
}
end
if !thresh.empty?
link = links[thresh.length - 1]
@ -112,7 +112,7 @@ module RedmineDiff
def compactdiffs
diffs = []
@diffs.each { |df|
@diffs.each do |df|
i = 0
curdiff = []
while i < df.length
@ -129,7 +129,7 @@ module RedmineDiff
curdiff.push [whot, p, s]
end
diffs.push curdiff
}
end
diffs
end
@ -184,14 +184,14 @@ module Diffable
def reverse_hash(range = (0...length))
revmap = {}
range.each { |i|
range.each do |i|
elem = self[i]
if revmap.has_key? elem
revmap[elem].push i
else
revmap[elem] = [i]
end
}
end
revmap
end
@ -231,7 +231,7 @@ module Diffable
end
ai = 0
bi = 0
diff.diffs.each { |d|
diff.diffs.each do |d|
d.each { |mod|
case mod[0]
when '-'
@ -253,7 +253,7 @@ module Diffable
raise 'Unknown diff action'
end
}
}
end
while ai < length
newary << self[ai]
ai += 1

@ -1,20 +1,18 @@
module OpenProject
module Authentication
class Manager < Warden::Manager
serialize_into_session do |user|
user.id
end
serialize_into_session(&:id)
serialize_from_session do |id|
User.find id
end
def initialize(app, options = {}, &configure)
block = lambda do |config|
block = lambda { |config|
self.class.configure config
configure.call config if configure
end
}
super app, options, &block
end

@ -40,7 +40,7 @@ module OpenProject
end
if config[:password].blank?
raise ArgumentError, "password must not be empty"
raise ArgumentError, 'password must not be empty'
end
@configuration = config

@ -72,8 +72,7 @@ module OpenProject::Concerns::Preview
klass ||= param_name.to_s.classify.constantize
texts = Array(attributes).each_with_object({}) do |attribute, list|
caption = (attribute == :notes) ? Journal.human_attribute_name(:notes)
: klass.human_attribute_name(attribute)
caption = (attribute == :notes) ? Journal.human_attribute_name(:notes) : klass.human_attribute_name(attribute)
text = params[param_name][attribute]
list[caption] = text
end

@ -71,9 +71,9 @@ module OpenProject
end
def hidden_menu_items
menus = self['hidden_menu_items'].map do |label, nodes|
menus = self['hidden_menu_items'].map { |label, nodes|
[label, array(nodes)]
end
}
Hash[menus]
end

@ -56,9 +56,9 @@ module OpenProject::NestedSet::RebuildPatch
"#{quoted_table_name}.#{quoted_right_column_name} >= parent.#{quoted_right_column_name}))"
scope :invalid_duplicates_in_columns, lambda {
scope_string = Array(acts_as_nested_set_options[:scope]).map do |c|
scope_string = Array(acts_as_nested_set_options[:scope]).map { |c|
"#{quoted_table_name}.#{connection.quote_column_name(c)} = duplicates.#{connection.quote_column_name(c)}"
end.join(' AND ')
}.join(' AND ')
scope_string = scope_string.size > 0 ? scope_string + ' AND ' : ''
@ -71,9 +71,9 @@ module OpenProject::NestedSet::RebuildPatch
}
scope :invalid_roots, lambda {
scope_string = Array(acts_as_nested_set_options[:scope]).map do |c|
scope_string = Array(acts_as_nested_set_options[:scope]).map { |c|
"#{quoted_table_name}.#{connection.quote_column_name(c)} = other.#{connection.quote_column_name(c)}"
end.join(' AND ')
}.join(' AND ')
scope_string = scope_string.size > 0 ? scope_string + ' AND ' : ''
@ -132,8 +132,7 @@ module OpenProject::NestedSet::RebuildPatch
h[k] = 0
end
set_left_and_rights = lambda do |node|
set_left_and_rights = lambda { |node|
# set left
node[left_column_name] = indices[scope.call(node)] += 1
# find
@ -142,18 +141,18 @@ module OpenProject::NestedSet::RebuildPatch
quoted_right_column_name,
acts_as_nested_set_options[:order]].compact.join(', '))
children.each { |n| set_left_and_rights.call(n) }
children.each do |n| set_left_and_rights.call(n) end
# set right
node[right_column_name] = indices[scope.call(node)] += 1
changes = node.changes.inject({}) do |hash, (attribute, _values)|
changes = node.changes.inject({}) { |hash, (attribute, _values)|
hash[attribute] = node.send(attribute.to_s)
hash
end
}
update_all(changes, id: node.id) unless changes.empty?
end
}
# Find root node(s)
# or take provided

@ -36,7 +36,6 @@ module OpenProject::NestedSet
module RootIdRebuilding
def self.included(base)
base.class_eval do
include RebuildPatch
# find all nodes
@ -86,7 +85,7 @@ module OpenProject::NestedSet
hash[ancestor_id] = find_by(id: ancestor_id)
end
fix_known_invalid_root_ids = lambda do
fix_known_invalid_root_ids = lambda {
invalid_nodes = invalid_root_ids
invalid_roots = []
@ -104,12 +103,12 @@ module OpenProject::NestedSet
if invalid_root_ids_to_fix.empty? || invalid_root_ids_to_fix.map(&:id).include?(ancestor.id)
update_all({ root_id: ancestor.id },
{ id: node.id })
id: node.id)
end
end
fix_known_invalid_root_ids.call unless (invalid_roots.map(&:id) & invalid_root_ids_to_fix.map(&:id)).empty?
end
}
fix_known_invalid_root_ids.call

@ -45,8 +45,7 @@ module OpenProject
def link_to_work_package_preview(context = nil, options = {})
form_id = options[:form_id] || 'work_package-form-preview'
path = (context.is_a? WorkPackage) ? preview_work_package_path(context)
: preview_work_packages_path
path = (context.is_a? WorkPackage) ? preview_work_package_path(context) : preview_work_packages_path
preview_link path, "#{form_id}-preview"
end

@ -35,7 +35,7 @@ module OpenProject
# Checks whether the given user is authorized to login by calling
# all registered callbacks. If all callbacks approve the user is authorized and may log in.
def self.authorized?(auth_hash)
rejection = callbacks.find_map do |callback|
rejection = callbacks.find_map { |callback|
d = callback.authorize auth_hash
if d.is_a? Decision
@ -43,7 +43,7 @@ module OpenProject
else
fail ArgumentError, 'Expecting Callback#authorize to return a Decision.'
end
end
}
rejection || Approval.new
end

@ -104,10 +104,10 @@ module OpenProject
def self.rules_description
return '' if min_adhered_rules == 0
rules = active_rules.map do |rule|
rules = active_rules.map { |rule|
I18n.t(rule.to_sym,
scope: [:activerecord, :errors, :models, :user, :attributes, :password])
end
}
I18n.t(:weak,
scope: [:activerecord, :errors, :models, :user, :attributes, :password],

@ -55,7 +55,7 @@ class OpenProject::PrincipalAllowanceEvaluator::Base
[]
end
def self.eager_load_for_project_authorization(project)
def self.eager_load_for_project_authorization(_project)
nil
end
end

@ -43,11 +43,11 @@ module OpenProject
def default_url_options
options = ActionMailer::Base.default_url_options.clone
reverse_merge = lambda do |opt, value|
reverse_merge = lambda { |opt, value|
unless options[opt] || value.blank?
options[opt] = value
end
end
}
reverse_merge.call :script_name, OpenProject::Configuration.rails_relative_url_root
reverse_merge.call :host, OpenProject::StaticRouting::UrlHelpers.host

@ -88,17 +88,17 @@ module OpenProject
text = Redmine::WikiFormatting.to_html(format, text,
object: obj,
attribute: attr,
edit: edit) do |macro, macro_args|
edit: edit) { |macro, macro_args|
exec_macro(macro, obj, macro_args, view: self, edit: edit, project: project)
end
}
# TODO: transform modifications into WikiFormatting Helper, or at least ask the helper if he wants his stuff to be modified
@parsed_headings = []
text = parse_non_pre_blocks(text) do |text|
text = parse_non_pre_blocks(text) { |text|
[:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings, :parse_relative_urls].each do |method_name|
send method_name, text, project, obj, attr, only_path, options
end
end
}
if @parsed_headings.any?
replace_toc(text, @parsed_headings)
@ -115,7 +115,10 @@ module OpenProject
parsed = ''
while !s.eos?
s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
text = s[1]
full_tag = s[2]
closing = s[3]
tag = s[4]
if tags.empty?
yield text
end
@ -156,16 +159,19 @@ module OpenProject
def parse_relative_urls(text, _project, _obj, _attr, only_path, _options)
return if only_path
text.gsub!(RELATIVE_LINK_RE) do |m|
href, relative_url = $1, $2 || $3
href = $1
relative_url = $2 || $3
next m unless href.present?
if defined?(request) && request.present?
# we have a request!
protocol, host_with_port = request.protocol, request.host_with_port
protocol = request.protocol
host_with_port = request.host_with_port
elsif @controller
# use the same methods as url_for in the Mailer
url_opts = @controller.class.default_url_options
next m unless url_opts && url_opts[:protocol] && url_opts[:host]
protocol, host_with_port = "#{url_opts[:protocol]}://", url_opts[:host]
protocol = "#{url_opts[:protocol]}://"
host_with_port = url_opts[:host]
else
next m
end
@ -178,7 +184,10 @@ module OpenProject
if options[:attachments] || (obj && obj.respond_to?(:attachments))
attachments = nil
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
filename, ext, alt, alttext = $1.downcase, $2, $3, $4
filename = $1.downcase
ext = $2
alt = $3
alttext = $4
attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
# search for the picture in attachments
if found = attachments.detect { |att| att.filename.downcase == filename }
@ -208,7 +217,10 @@ module OpenProject
def parse_wiki_links(text, project, _obj, _attr, only_path, options)
text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |_m|
link_project = project
esc, all, page, title = $1, $2, $3, $5
esc = $1
all = $2
page = $3
title = $5
if esc.nil?
if page =~ /\A([^\:]+)\:(.*)\z/
link_project = Project.find_by(identifier: $1) || Project.find_by(name: $1)
@ -220,16 +232,17 @@ module OpenProject
# extract anchor
anchor = nil
if page =~ /\A(.+?)\#(.+)\z/
page, anchor = $1, $2
page = $1
anchor = $2
end
# check if page exists
wiki_page = link_project.wiki.find_page(page)
url = case options[:wiki_links]
when :local; "#{title}.html"
when :anchor; "##{title}" # used for single-file wiki export
else
wiki_page_id = page.present? ? Wiki.titleize(page) : nil
url_for(only_path: only_path, controller: '/wiki', action: 'show', project_id: link_project, id: wiki_page_id, anchor: anchor)
when :local; "#{title}.html"
when :anchor; "##{title}" # used for single-file wiki export
else
wiki_page_id = page.present? ? Wiki.titleize(page) : nil
url_for(only_path: only_path, controller: '/wiki', action: 'show', project_id: link_project, id: wiki_page_id, anchor: anchor)
end
link_to(h(title || page), url, class: ('wiki-page' + (wiki_page ? '' : ' new')))
else
@ -276,7 +289,13 @@ module OpenProject
# identifier:source:some/file
def parse_redmine_links(text, project, obj, attr, only_path, options)
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|version|commit|source|export|message|project)?((#+|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |_m|
leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10
leading = $1
esc = $2
project_prefix = $3
project_identifier = $4
prefix = $5
sep = $7 || $9
identifier = $8 || $10
link = nil
if project_identifier
project = Project.visible.find_by(identifier: project_identifier)
@ -342,7 +361,9 @@ module OpenProject
when 'source', 'export'
if project && project.repository && User.current.allowed_to?(:browse_repository, project)
name =~ %r{\A[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?\z}
path, rev, anchor = $1, $3, $5
path = $1
rev = $3
anchor = $5
link = link_to h("#{project_prefix}#{prefix}:#{name}"), { controller: '/repositories', action: 'entry', project_id: project,
path: path.to_s,
rev: rev,
@ -375,7 +396,9 @@ module OpenProject
return if options[:headings] == false
text.gsub!(HEADING_RE) do
level, attrs, content = $1.to_i, $2, $3
level = $1.to_i
attrs = $2
content = $3
item = strip_tags(content).strip
anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
@parsed_headings << [level, anchor, item]

@ -101,7 +101,7 @@ module OpenProject
def overridden_images
@overridden_images ||= \
begin
Dir.chdir(overridden_images_path) { Dir.glob('**/*') }
Dir.chdir(overridden_images_path) do Dir.glob('**/*') end
rescue Errno::ENOENT # overridden_images_path missing
[]
end.to_set

@ -55,8 +55,6 @@ module OpenProject
revision = `git rev-parse HEAD`
if revision.present?
revision.strip[0..8]
else
nil
end
end

@ -74,7 +74,6 @@ module OpenProject
pages = ([page] + page.descendants).group_by(&:parent_id)
render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id)
end
end
Redmine::WikiFormatting::Macros.register do

@ -195,9 +195,9 @@ module Pagination::Controller
search_call = (options.presence ? methods[:search].call(params[:q], options) : methods[:search].call(params[:q]))
@paginated_items = methods[:pagination].call(
search_call,
page: page, page_limit: size
)
search_call,
page: page, page_limit: size
)
@more = @paginated_items.total_pages > page
@total = @paginated_items.total_entries

@ -97,7 +97,7 @@ module Redmine
end
result.flatten!
result.each { |e| e.event_type = event_type.dup.singularize unless e.event_type }
result.each do |e| e.event_type = event_type.dup.singularize unless e.event_type end
result
end
@ -210,8 +210,7 @@ module Redmine
def fill_events(provider, activity, events)
events.each_with_object([]) do |e, result|
datetime = e['event_datetime'].is_a?(String) ? DateTime.parse(e['event_datetime'])
: e['event_datetime']
datetime = e['event_datetime'].is_a?(String) ? DateTime.parse(e['event_datetime']) : e['event_datetime']
event = Redmine::Acts::ActivityProvider::Event.new(self,
nil,
nil,

@ -66,13 +66,13 @@ module Redmine
# Sets the values of the object's custom fields
# values is an array like [{'id' => 1, 'value' => 'foo'}, {'id' => 2, 'value' => 'bar'}]
def custom_fields=(values)
values_to_hash = values.inject({}) do |hash, v|
values_to_hash = values.inject({}) { |hash, v|
v = v.stringify_keys
if v['id'] && v.has_key?('value')
hash[v['id']] = v['value']
end
hash
end
}
self.custom_field_values = values_to_hash
end
@ -89,12 +89,12 @@ module Redmine
end
def custom_field_values
@custom_field_values ||= available_custom_fields.map do |custom_field|
@custom_field_values ||= available_custom_fields.map { |custom_field|
existing_cv = custom_values.detect { |v| v.custom_field == custom_field }
existing_cv || custom_values.build(customized: self,
custom_field: custom_field,
value: nil)
end
}
end
def visible_custom_field_values

@ -31,12 +31,11 @@ module Acts
class JournalObjectCache
# unloadable
def fetch(klass, id, &block)
def fetch(klass, id, &_block)
@cache ||= Hash.new do |klass_hash, klass_key|
klass_hash[klass_key] = Hash.new do |id_hash, id_key|
id_hash[id_key] = yield klass_key, id_key
end
id_hash[id_key] = yield klass_key, id_key
end
end
@cache[klass][id]

@ -86,7 +86,8 @@ module Redmine::Acts::Journalized
# version number, a symbol representing an association proxy method, a string representing a
# journal tag or a journal object itself.
def changes_between(from, to)
from_number, to_number = journals.journal_at(from), journals.journal_at(to)
from_number = journals.journal_at(from)
to_number = journals.journal_at(to)
return {} if from_number == to_number
chain = journals.between(from_number, to_number).reject(&:initial?)
return {} if chain.empty?
@ -118,11 +119,11 @@ module Redmine::Acts::Journalized
# creation. Incremental changes are reset when the record is saved because they represent
# a subset of the dirty attribute changes, which are reset upon save.
def incremental_journal_changes
changed.inject({}) do |h, attr|
changed.inject({}) { |h, attr|
h[attr] = attribute_change(attr) unless !attribute_change(attr).nil? &&
attribute_change(attr)[0].blank? && attribute_change(attr)[1].blank?
h
end.slice(*journaled_columns)
}.slice(*journaled_columns)
end
# Simply resets the cumulative changes after journal creation.
@ -156,10 +157,10 @@ module Redmine::Acts::Journalized
# "age" => [25, 54]
# }
def append_changes(changes)
changes.inject(self) do |new_changes, (attribute, change)|
changes.inject(self) { |new_changes, (attribute, change)|
new_change = [new_changes.fetch(attribute, change).first, change.last]
new_changes.merge(attribute => new_change)
end.reject do |_attribute, change|
}.reject do |_attribute, change|
change.first == change.last
end
end

@ -105,7 +105,6 @@ module Redmine::Acts::Journalized
initial_changes = {}
JournalManager.journal_class(self.class).journaled_attributes.each do |name|
# Set the current attributes as initial attributes
# This works as a fallback if no prior change is found
initial_changes[name] = send(name)
@ -166,8 +165,8 @@ module Redmine::Acts::Journalized
def journaled_columns
case
when vestal_journals_options[:only] then self.class.column_names & vestal_journals_options[:only]
when vestal_journals_options[:except] then self.class.column_names - vestal_journals_options[:except]
else self.class.column_names
when vestal_journals_options[:except] then self.class.column_names - vestal_journals_options[:except]
else self.class.column_names
end - %w(created_at updated_at)
end

@ -67,11 +67,11 @@ module Redmine::Acts::Journalized
def register_journal_formatter(formatter, klass = nil, &block)
if block_given?
klass = Class.new(JournalFormatter::Proc) do
@proc = block
end
@proc = block
end
end
raise ArgumentError "Provide either a class or a block defining the value formatting" if klass.nil?
raise ArgumentError 'Provide either a class or a block defining the value formatting' if klass.nil?
JournalFormatter.register formatter.to_sym => klass
end

@ -82,17 +82,15 @@ module Redmine::Acts::Journalized
end
def save_journal_with_retry(journal, tries: 2)
begin
journal.save!
rescue ActiveRecord::RecordInvalid => e
# TODO: rescue from ActiveRecord::RecordNotUnique as well
if e.message =~ /Version has already been taken/ && tries > 0
journal.increment(:version)
tries -= 1
retry
else
raise
end
journal.save!
rescue ActiveRecord::RecordInvalid => e
# TODO: rescue from ActiveRecord::RecordNotUnique as well
if e.message =~ /Version has already been taken/ && tries > 0
journal.increment(:version)
tries -= 1
retry
else
raise
end
end

@ -107,8 +107,8 @@ module Redmine::Acts::Journalized
# +user_name+ string column is populated.
def user_with_name=(value)
case value
when ActiveRecord::Base then self.user_without_name = value
else self.user = User.find_by_login(value)
when ActiveRecord::Base then self.user_without_name = value
else self.user = User.find_by_login(value)
end
end
end

@ -75,7 +75,8 @@ module Redmine::Acts::Journalized
# given by the arguments. If the +from+ value represents a journal before that of the +to+
# value, the array will be ordered from earliest to latest. The reverse is also true.
def between(from, to)
from_number, to_number = journal_at(from), journal_at(to)
from_number = journal_at(from)
to_number = journal_at(to)
return [] if from_number.nil? || to_number.nil?
condition = (from_number == to_number) ? to_number : Range.new(*[from_number, to_number].sort)

@ -33,7 +33,8 @@ class ResetTest < Test::Unit::TestCase
context 'Resetting a model' do
setup do
@original_dependent = User.reflect_on_association(:journals).options[:dependent]
@user, @journals = User.new, []
@user = User.new
@journals = []
@names = ['Steve Richert', 'Stephen Richert', 'Stephen Jobs', 'Steve Jobs']
@names.each do |name|
@user.update_attribute(:name, name)
@ -49,7 +50,7 @@ class ResetTest < Test::Unit::TestCase
end
should 'dissociate all journals after the target' do
@journals.reverse.each do |journal|
@journals.reverse_each do |journal|
@user.reset_to!(journal)
assert_equal 0, @user.journals(true).after(journal).count
end
@ -61,7 +62,7 @@ class ResetTest < Test::Unit::TestCase
end
should 'delete all journals after the target journal' do
@journals.reverse.each do |journal|
@journals.reverse_each do |journal|
later_journals = @user.journals.after(journal)
@user.reset_to!(journal)
later_journals.each do |later_journal|
@ -74,7 +75,7 @@ class ResetTest < Test::Unit::TestCase
should 'not destroy all journals after the target journal' do
VestalVersions::Version.any_instance.stub(:destroy).and_raise(RuntimeError)
@journals.reverse.each do |journal|
@journals.reverse_each do |journal|
assert_nothing_raised do
@user.reset_to!(journal)
end
@ -88,7 +89,7 @@ class ResetTest < Test::Unit::TestCase
end
should 'delete all journals after the target journal' do
@journals.reverse.each do |journal|
@journals.reverse_each do |journal|
later_journals = @user.journals.after(journal)
@user.reset_to!(journal)
later_journals.each do |later_journal|
@ -101,7 +102,7 @@ class ResetTest < Test::Unit::TestCase
should 'destroy all journals after the target journal' do
VestalVersions::Version.any_instance.stub(:destroy).and_raise(RuntimeError)
@journals.reverse.each do |journal|
@journals.reverse_each do |journal|
later_journals = @user.journals.after(journal)
if later_journals.empty?
assert_nothing_raised do
@ -122,7 +123,7 @@ class ResetTest < Test::Unit::TestCase
end
should 'leave all journals after the target journal' do
@journals.reverse.each do |journal|
@journals.reverse_each do |journal|
later_journals = @user.journals.after(journal)
@user.reset_to!(journal)
later_journals.each do |later_journal|

@ -32,7 +32,9 @@ require File.join(File.dirname(__FILE__), 'test_helper')
class RejournalTest < Test::Unit::TestCase
context 'A model rejournal' do
setup do
@user, @attributes, @times = User.new, {}, {}
@user = User.new
@attributes = {}
@times = {}
names = ['Steve Richert', 'Stephen Richert', 'Stephen Jobs', 'Steve Jobs']
time = names.size.hours.ago
names.each do |name|
@ -45,7 +47,8 @@ class RejournalTest < Test::Unit::TestCase
@times[@user.journal] = time
end
@user.reload.journals.reload
@first_journal, @last_journal = @attributes.keys.min, @attributes.keys.max
@first_journal = @attributes.keys.min
@last_journal = @attributes.keys.max
end
should 'return the new journal number' do

@ -35,7 +35,8 @@ class VersionTest < Test::Unit::TestCase
@user = User.create(name: 'Stephen Richert')
@user.update_attribute(:name, 'Steve Jobs')
@user.update_attribute(:last_name, 'Richert')
@first_journal, @last_journal = @user.journals.first, @user.journals.last
@first_journal = @user.journals.first
@last_journal = @user.journals.last
end
should 'be comparable to another journal based on journal number' do
@ -53,7 +54,8 @@ class VersionTest < Test::Unit::TestCase
user = User.create(name: 'Stephen Richert')
user.update_attribute(:name, 'Steve Jobs')
user.update_attribute(:last_name, 'Richert')
first_journal, last_journal = user.journals.first, user.journals.last
first_journal = user.journals.first
last_journal = user.journals.last
assert_not_equal @first_journal, first_journal
assert_not_equal @last_journal, last_journal
end

@ -32,7 +32,8 @@ require File.join(File.dirname(__FILE__), 'test_helper')
class VersionsTest < Test::Unit::TestCase
context 'A collection of associated journals' do
setup do
@user, @times = User.new, {}
@user = User.new
@times = {}
names = ['Steve Richert', 'Stephen Richert', 'Stephen Jobs', 'Steve Jobs']
time = names.size.hours.ago
names.each do |name|

@ -66,7 +66,8 @@ module ActiveRecord
#
# subchild1.ancestors # => [child1, root]
def ancestors
node, nodes = self, []
node = self
nodes = []
nodes << node = node.parent while node.parent
nodes
end

@ -99,9 +99,9 @@ module Redmine
possible_watcher_ids = watchers.pluck(:id)
User.where(id: possible_watcher_ids)
.authorize_within(project) do |scope|
scope.select { |user| visible?(user) }
end
.authorize_within(project) do |scope|
scope.select { |user| visible?(user) }
end
end
watchers
@ -149,7 +149,7 @@ module Redmine
# Returns an array of watchers' email addresses
def watcher_recipients
notified = watcher_users.active.where(['mail_notification != ?', 'none'])
notified.select! { |user| possible_watcher?(user) }
notified.select! do |user| possible_watcher?(user) end
notified.map(&:mail).compact
end

@ -121,9 +121,9 @@ module ActionController #:nodoc:
def apply_remaining_actions(options) # :nodoc:
case
when options[:render]; render(options[:render])
when options[:redirect_to]; redirect_to(apply_redirect_to(options[:redirect_to]))
else head(:bad_request)
when options[:render]; render(options[:render])
when options[:redirect_to]; redirect_to(apply_redirect_to(options[:redirect_to]))
else head(:bad_request)
end
end
end

@ -70,7 +70,7 @@ module Redmine
def available_project_modules
@available_project_modules ||= (
@permissions.map(&:project_module) + @project_modules_without_permissions
).uniq.compact
).uniq.compact
end
def modules_permissions(modules)

@ -51,15 +51,15 @@ module Redmine
@event_types = Redmine::Activity.available_event_types
if @project
@event_types = @event_types.select do |o|
@event_types = @event_types.select { |o|
@project.self_and_descendants.detect do |_p|
permissions = constantized_providers(o).map do |p|
permissions = constantized_providers(o).map { |p|
p.activity_provider_options[o].try(:[], :permission)
end.compact
}.compact
return @user.allowed_to?("view_#{o}".to_sym, @project) if permissions.blank?
permissions.all? { |p| @user.allowed_to?(p, @project) }
end
end
}
end
@event_types
end
@ -107,7 +107,7 @@ module Redmine
e.project = projects.find { |p| p.id == e.project_id } if e.project_id
end
e.sort! { |a, b| b.event_datetime <=> a.event_datetime }
e.sort! do |a, b| b.event_datetime <=> a.event_datetime end
e
end

@ -40,7 +40,7 @@ module Redmine #:nodoc:
s = $1
else
# 2:30 => 2.5
s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 }
s.gsub!(%r{^(\d+):(\d+)$}) do $1.to_i + $2.to_i / 60.0 end
# 2h30, 2h, 30m => 2.5, 2, 0.5
s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}) { |m| ($1 || $4) ? ($2.to_i + $5.to_i / 60.0) : m[0] }
end

@ -143,11 +143,11 @@ module Redmine
# Colors
colors_list = PlanningElementTypeColor.colors
colors = Hash[*(colors_list.map do |color|
colors = Hash[*(colors_list.map { |color|
color.save
color.reload
[color.name.to_sym, color.id]
end).flatten]
}).flatten]
# Types
task = ::Type.create! name: l(:default_type_task),
@ -250,7 +250,7 @@ module Redmine
phase.id => [new, to_be_scheduled, scheduled, in_progress, on_hold, rejected, closed],
bug.id => [new, confirmed, in_progress, tested, on_hold, rejected, closed],
feature.id => [new, specified, confirmed, in_progress, tested, on_hold, rejected, closed] }
workflows.each { |type_id, statuses_for_type|
workflows.each do |type_id, statuses_for_type|
statuses_for_type.each { |old_status|
statuses_for_type.each { |new_status|
[manager.id, member.id].each { |role_id|
@ -261,7 +261,7 @@ module Redmine
}
}
}
}
end
# Enumerations
@ -287,9 +287,9 @@ module Redmine
ProjectType.create!(name: l(:default_project_type_internal))
reported_status_ids = ReportedProjectStatus.find(:all).map(&:id)
ProjectType.find(:all).each { |project|
ProjectType.find(:all).each do |project|
project.update_attributes(reported_project_status_ids: reported_status_ids)
}
end
Setting['notified_events'] = ['work_package_added', \
'work_package_updated',\

@ -63,7 +63,7 @@ module Redmine
else
del_at = pos unless del_at
deleted << ' ' + h(change[2])
words_del += 1
words_del += 1
end
end
if add_at

@ -128,9 +128,9 @@ module Redmine
@cached_attribute_translations ||= {}
@cached_attribute_translations[locale] ||= (
general_attributes = ::I18n.t('attributes', locale: locale)
::I18n.t('activerecord.attributes', locale: locale).inject(general_attributes) do |attr_t, model_t|
::I18n.t('activerecord.attributes', locale: locale).inject(general_attributes) { |attr_t, model_t|
attr_t.merge(model_t.last || {})
end)
})
@cached_attribute_translations[locale]
end
end

@ -53,24 +53,24 @@ module Redmine::MenuManager::MenuHelper
Redmine::MenuManager.loose :project_menu do |menu|
menu.push "#{main_item.item_class}".to_sym,
{ controller: '/wiki', action: 'show', id: CGI.escape(main_item.title) },
param: :project_id,
caption: main_item.name,
after: :repository,
html: {class: 'icon2 icon-wiki'}
param: :project_id,
caption: main_item.name,
after: :repository,
html: { class: 'icon2 icon-wiki' }
menu.push :"#{main_item.item_class}_new_page",
{ action:"new_child", controller:"/wiki", id: CGI.escape(main_item.title) },
{ action: 'new_child', controller: '/wiki', id: CGI.escape(main_item.title) },
param: :project_id,
caption: :create_child_page,
html: {class: 'icon2 icon-add'},
html: { class: 'icon2 icon-add' },
parent: "#{main_item.item_class}".to_sym if main_item.new_wiki_page and
WikiPage.find_by(wiki_id: project_wiki.id, title: main_item.title)
WikiPage.find_by(wiki_id: project_wiki.id, title: main_item.title)
menu.push :"#{main_item.item_class}_toc",
{ action: 'index', controller: '/wiki', id: CGI.escape(main_item.title) },
param: :project_id,
caption: :label_table_of_contents,
html: {class: 'icon2 icon-list-view1'},
html: { class: 'icon2 icon-list-view1' },
parent: "#{main_item.item_class}".to_sym if main_item.index_page
main_item.children.each do |child|
@ -78,7 +78,7 @@ module Redmine::MenuManager::MenuHelper
{ controller: '/wiki', action: 'show', id: CGI.escape(child.title) },
param: :project_id,
caption: child.name,
html: {class: 'icon2 icon-wiki2'},
html: { class: 'icon2 icon-wiki2' },
parent: "#{main_item.item_class}".to_sym
end
# FIXME using wiki_menu_item#title to reference the wiki page and wiki_menu_item#name as the menu item representation feels wrong
@ -86,13 +86,13 @@ module Redmine::MenuManager::MenuHelper
end
end
def build_work_packages_menu(project)
def build_work_packages_menu(_project)
query_menu_items = visible_queries.map(&:query_menu_item).compact
Redmine::MenuManager.loose :project_menu do |menu|
query_menu_items.each do |query_menu_item|
# url = project_work_packages_path(project, query_id: query_menu_item.navigatable_id) does not work because the authorization check fails
url = { controller: '/work_packages', action: 'index', params: {query_id: query_menu_item.navigatable_id} }
url = { controller: '/work_packages', action: 'index', params: { query_id: query_menu_item.navigatable_id } }
menu.push query_menu_item.unique_name,
url,
param: :project_id,
@ -100,7 +100,7 @@ module Redmine::MenuManager::MenuHelper
parent: :work_packages,
html: {
class: 'icon2 icon-pin query-menu-item',
"data-ui-route" => '',
'data-ui-route' => '',
'query-menu-item' => 'query-menu-item',
'object-id' => query_menu_item.navigatable_id
}
@ -113,42 +113,40 @@ module Redmine::MenuManager::MenuHelper
Redmine::MenuManager.items(menu_name).size > 1 # 1 element is the root
end
def render_menu(menu, project=nil)
def render_menu(menu, project = nil)
links = []
menu_items_for(menu, project) do |node|
links << render_menu_node(node, project)
end
links.empty? ? nil : content_tag('ul', links.join("\n").html_safe, class: "menu_root")
links.empty? ? nil : content_tag('ul', links.join("\n").html_safe, class: 'menu_root')
end
def render_drop_down_menu_node(label, items_or_options_with_block = nil, html_options = {}, &block)
def render_drop_down_menu_node(label, items_or_options_with_block = nil, html_options = {}, &_block)
items, options = if block_given?
[[], items_or_options_with_block || {} ]
[[], items_or_options_with_block || {}]
else
[items_or_options_with_block, html_options]
end
return "" if items.empty? && !block_given?
return '' if items.empty? && !block_given?
options.reverse_merge!({ class: "drop-down" })
options.reverse_merge!(class: 'drop-down')
content_tag :li, options do
label + if block_given?
yield
else
content_tag :ul, style: "display:none" do
items.map do |item|
content_tag :ul, style: 'display:none' do
items.map { |item|
render_menu_node(item)
end.join(" ").html_safe
}.join(' ').html_safe
end
end
end
end
def render_menu_node(node, project=nil)
return "" if project and not allowed_node?(node, User.current, project)
def render_menu_node(node, project = nil)
return '' if project and not allowed_node?(node, User.current, project)
if node.has_children? || !node.child_menus.nil?
render_menu_node_with_children(node, project)
else
@ -157,14 +155,14 @@ module Redmine::MenuManager::MenuHelper
end
end
def render_menu_node_with_children(node, project=nil)
def render_menu_node_with_children(node, project = nil)
caption, url, selected = extract_node_details(node, project)
content_tag :li do
# Standard children
standard_children_list = node.children.map do |child|
render_menu_node(child, project)
end.join.html_safe
standard_children_list = node.children.map { |child|
render_menu_node(child, project)
}.join.html_safe
# Unattached children
unattached_children_list = render_unattached_children_menu(node, project)
@ -184,7 +182,7 @@ module Redmine::MenuManager::MenuHelper
def render_unattached_children_menu(node, project)
return nil unless node.child_menus
"".tap do |child_html|
''.tap do |child_html|
unattached_children = node.child_menus.call(project)
# Tree nodes support #each so we need to do object detection
if unattached_children.is_a? Array
@ -192,7 +190,7 @@ module Redmine::MenuManager::MenuHelper
child_html << content_tag(:li, render_unattached_menu_item(child, project))
end
else
raise Redmine::MenuManager::MenuError, ":child_menus must be an array of MenuItems"
raise Redmine::MenuManager::MenuError, ':child_menus must be an array of MenuItems'
end
end.html_safe
end
@ -208,7 +206,7 @@ module Redmine::MenuManager::MenuHelper
end
def render_unattached_menu_item(menu_item, project)
raise Redmine::MenuManager::MenuError, ":child_menus must be an array of MenuItems" unless menu_item.is_a? Redmine::MenuManager::MenuItem
raise Redmine::MenuManager::MenuError, ':child_menus must be an array of MenuItems' unless menu_item.is_a? Redmine::MenuManager::MenuItem
if User.current.allowed_to?(menu_item.url, project)
link_to(menu_item.caption,
@ -217,7 +215,7 @@ module Redmine::MenuManager::MenuHelper
end
end
def menu_items_for(menu, project=nil)
def menu_items_for(menu, project = nil)
items = []
Redmine::MenuManager.items(menu).root.children.each do |node|
if allowed_node?(node, User.current, project) && visible_node?(menu, node)
@ -228,14 +226,14 @@ module Redmine::MenuManager::MenuHelper
end
end
end
return block_given? ? nil : items
block_given? ? nil : items
end
def extract_node_details(node, project=nil)
def extract_node_details(node, project = nil)
item = node
url = case item.url
when Hash
project.nil? ? item.url : {item.param => project}.merge(item.url)
project.nil? ? item.url : { item.param => project }.merge(item.url)
when Symbol
send(item.url)
else
@ -245,7 +243,7 @@ module Redmine::MenuManager::MenuHelper
selected = current_menu_item == item.name
return [caption, url, selected]
[caption, url, selected]
end
# Checks if a user is allowed to access the menu item by:

@ -142,9 +142,9 @@ module Redmine::MenuManager::TopMenuHelper
end
def render_main_top_menu_nodes(items = main_top_menu_items)
items.map do |item|
items.map { |item|
render_menu_node(item)
end.join(' ')
}.join(' ')
end
# Menu items for the main top menu

@ -65,7 +65,7 @@ class Redmine::MenuManager::TreeNode < Tree::TreeNode
raise 'Child already added' if @children_hash.has_key?(child.name)
@children_hash[child.name] = child
@children << child
@children << child
@last_items_count += 1
child.parent = self
child

@ -81,10 +81,10 @@ module Redmine
'video/x-msvideo' => 'avi',
}.freeze
EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
exts.split(',').each { |ext| map[ext.strip] = type }
EXTENSIONS = MIME_TYPES.inject({}) { |map, (type, exts)|
exts.split(',').each do |ext| map[ext.strip] = type end
map
end
}
# returns mime type for name or nil if unknown
def self.of(name)

@ -303,7 +303,7 @@ module Redmine #:nodoc:
# permission :say_hello, { :example => :say_hello }, :require => :member
def permission(name, actions, options = {})
if @project_module
Redmine::AccessControl.map { |map| map.project_module(@project_module) { |map|map.permission(name, actions, options) } }
Redmine::AccessControl.map { |map| map.project_module(@project_module) { |map| map.permission(name, actions, options) } }
else
Redmine::AccessControl.map { |map| map.permission(name, actions, options) }
end

@ -56,7 +56,7 @@ module Redmine
def info
info = Info.new(root_url: target,
lastrev: nil
)
)
info
rescue CommandFailed
return nil
@ -70,7 +70,7 @@ module Redmine
e_utf8 = scm_encode('UTF-8', @path_encoding, e1)
next if e_utf8.blank?
relative_path_utf8 = format_path_ends(
(format_path_ends(path, false, true) + e_utf8), false, false)
(format_path_ends(path, false, true) + e_utf8), false, false)
t1_utf8 = target(relative_path_utf8)
t1 = scm_encode(@path_encoding, 'UTF-8', t1_utf8)
relative_path = scm_encode(@path_encoding, 'UTF-8', relative_path_utf8)
@ -88,7 +88,7 @@ module Redmine
size: (File.directory?(t1) ? nil : [File.size(t1)].pack('l').unpack('L').first),
lastrev:
Revision.new(time: (File.mtime(t1)))
)
)
end
end
entries.sort_by_name

@ -43,7 +43,7 @@ module Redmine
class << self
def client_command
@@bin ||= GIT_BIN
@@bin ||= GIT_BIN
end
def sq_bin
@ -141,7 +141,7 @@ module Redmine
kind: (type == 'tree') ? 'dir' : 'file',
size: (type == 'tree') ? nil : size,
lastrev: @flag_report_last_commit ? lastrev(full_path, identifier) : Revision.new
) unless entries.detect { |entry| entry.name == name }
) unless entries.detect { |entry| entry.name == name }
end
end
end
@ -156,7 +156,7 @@ module Redmine
cmd_args << rev if rev
cmd_args << '--' << path unless path.empty?
lines = []
scm_cmd(*cmd_args) { |io| lines = io.readlines }
scm_cmd(*cmd_args) do |io| lines = io.readlines end
begin
id = lines[0].split[1]
author = lines[1].match('Author:\s+(.*)$')[1]
@ -169,7 +169,7 @@ module Redmine
time: time,
message: nil,
paths: nil
)
)
rescue NoMethodError => e
logger.error("The revision '#{path}' has a wrong format")
return nil
@ -230,15 +230,13 @@ module Redmine
elsif (parsing_descr == 0) && line.chomp.to_s == ''
parsing_descr = 1
changeset[:description] = ''
elsif (parsing_descr == 1 || parsing_descr == 2) \
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\t(.+)$/
elsif (parsing_descr == 1 || parsing_descr == 2) && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\t(.+)$/
parsing_descr = 2
fileaction = $1
filepath = $2
p = scm_encode('UTF-8', @path_encoding, filepath)
files << { action: fileaction, path: p }
elsif (parsing_descr == 1 || parsing_descr == 2) \
&& line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\t(.+)$/
elsif (parsing_descr == 1 || parsing_descr == 2) && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\t(.+)$/
parsing_descr = 2
fileaction = $1
filepath = $3
@ -277,11 +275,11 @@ module Redmine
path ||= ''
cmd_args = []
if identifier_to
cmd_args << 'diff' << '--no-color' << identifier_to << identifier_from
cmd_args << 'diff' << '--no-color' << identifier_to << identifier_from
else
cmd_args << 'show' << '--no-color' << identifier_from
end
cmd_args << '--' << scm_encode(@path_encoding, 'UTF-8', path) unless path.empty?
cmd_args << '--' << scm_encode(@path_encoding, 'UTF-8', path) unless path.empty?
diff = []
scm_cmd *cmd_args do |io|
io.each_line do |line|
@ -296,10 +294,10 @@ module Redmine
def annotate(path, identifier = nil)
identifier = 'HEAD' if identifier.blank?
cmd_args = %w|blame|
cmd_args << '-p' << identifier << '--' << scm_encode(@path_encoding, 'UTF-8', path)
cmd_args << '-p' << identifier << '--' << scm_encode(@path_encoding, 'UTF-8', path)
blame = Annotate.new
content = nil
scm_cmd(*cmd_args) { |io| io.binmode; content = io.read }
scm_cmd(*cmd_args) do |io| io.binmode; content = io.read end
# git annotates binary files
if content.respond_to?('is_binary_data?') && content.is_binary_data? # Ruby 1.8.x and <1.9.2
return nil
@ -317,8 +315,8 @@ module Redmine
authors_by_commit[identifier] = $1.strip
elsif line =~ /^\t(.*)/
blame.add_line($1, Revision.new(
identifier: identifier,
author: authors_by_commit[identifier]))
identifier: identifier,
author: authors_by_commit[identifier]))
identifier = ''
author = ''
end

@ -39,7 +39,7 @@ module Redmine
class << self
def client_command
@@bin ||= SVN_BIN
@@bin ||= SVN_BIN
end
def sq_bin
@ -84,10 +84,10 @@ module Redmine
# root_url = doc.elements["info/entry/repository/root"].text
info = Info.new(root_url: doc['info']['entry']['repository']['root']['__content__'],
lastrev: Revision.new(
identifier: doc['info']['entry']['commit']['revision'],
time: Time.parse(doc['info']['entry']['commit']['date']['__content__']).localtime,
author: (doc['info']['entry']['commit']['author'] ? doc['info']['entry']['commit']['author']['__content__'] : '')
)
identifier: doc['info']['entry']['commit']['revision'],
time: Time.parse(doc['info']['entry']['commit']['date']['__content__']).localtime,
author: (doc['info']['entry']['commit']['author'] ? doc['info']['entry']['commit']['author']['__content__'] : '')
)
)
rescue
end
@ -125,11 +125,11 @@ module Redmine
kind: entry['kind'],
size: ((s = entry['size']) ? s['__content__'].to_i : nil),
lastrev: Revision.new(
identifier: commit['revision'],
time: Time.parse(commit_date['__content__'].to_s).localtime,
author: ((a = commit['author']) ? a['__content__'] : nil)
)
)
identifier: commit['revision'],
time: Time.parse(commit_date['__content__'].to_s).localtime,
author: ((a = commit['author']) ? a['__content__'] : nil)
)
)
end
rescue => e
logger.error("Error parsing svn output: #{e.message}")
@ -192,14 +192,14 @@ module Redmine
from_revision: path['copyfrom-rev']
}
end if logentry['paths'] && logentry['paths']['path']
paths.sort! { |x, y| x[:path] <=> y[:path] }
paths.sort! do |x, y| x[:path] <=> y[:path] end
revisions << Revision.new(identifier: logentry['revision'],
author: (logentry['author'] ? logentry['author']['__content__'] : ''),
time: Time.parse(logentry['date']['__content__'].to_s).localtime,
message: logentry['msg']['__content__'],
paths: paths
)
)
end
rescue
end

@ -105,7 +105,8 @@ module Redmine
end
def each_line
prev_line_left, prev_line_right = nil, nil
prev_line_left = nil
prev_line_right = nil
each do |line|
spacing = prev_line_left && prev_line_right && (line.nb_line_left != prev_line_left + 1) && (line.nb_line_right != prev_line_right + 1)
yield spacing, line

@ -34,23 +34,22 @@ module Redmine
def self.additional_blocks
# look at the gemspecs of all plugins trying to find views in a /my/blocks subdirectory
@@additional_blocks ||= Dir.glob(
Plugin.registered_plugins.map do |plugin_id, _|
Plugin.registered_plugins.map { |plugin_id, _|
gem_name = plugin_id.to_s.gsub('openproject_', 'openproject-') if plugin_id.to_s.starts_with?('openproject_')
gem_spec = Gem.loaded_specs[gem_name]
if gem_spec.nil?
error = 'No Gemspec found for plugin: ' + plugin_id.to_s \
+ ', expected gem name to match the plugin name but starting with openproject-'
error = 'No Gemspec found for plugin: ' + plugin_id.to_s + ', expected gem name to match the plugin name but starting with openproject-'
ActiveSupport::Deprecation.warn(error)
nil
else
gem_spec.full_gem_path + '/app/views/my/blocks/_*.{rhtml,erb}'
end
end.compact
).inject({}) do |h, file|
}.compact
).inject({}) { |h, file|
name = File.basename(file).split('.').first.gsub(/\A_/, '')
h[name] = ('label_' + name).to_sym
h
end
}
end
end
end

@ -97,7 +97,9 @@ module Redmine
# Macros substitution
def execute_macros(text, macros_runner)
text.gsub!(MACROS_RE) do
esc, all, macro = $1, $2, $3.downcase
esc = $1
all = $2
macro = $3.downcase
args = ($5 || '').split(',').each(&:strip!)
if esc.nil?
begin

@ -97,7 +97,11 @@ module Redmine
# Turns all urls into clickable links (code from Rails).
def inline_auto_link(text)
text.gsub!(AUTO_LINK_RE) do
all, leading, proto, url, post = $&, $1, $2, $3, $6
all = $&
leading = $1
proto = $2
url = $3
post = $6
if leading =~ /<a\s/i || leading =~ /![<>=]?/ || leading =~ /\{\{\w+\(/
# don't replace URLs that are already linked
# and URLs prefixed with ! !> !< != (textile images)

@ -132,7 +132,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
end
def localize_field(field, options, meth)
localized_field = Proc.new do |translation_form, multiple|
localized_field = Proc.new do |translation_form, _multiple|
localized_field(translation_form, meth, field, options)
end
@ -203,7 +203,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
id.sub(/\_id$/, "_#{field}")
end
label_options[:lang] = options[:lang]
label_options.reject! { |_k, v| v.nil? }
label_options.reject! do |_k, v| v.nil? end
@template.label(@object_name, field, h(text), label_options)
end
@ -262,9 +262,9 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
object.translations.build locale: user_locale
object.translations
else
translations = object.translations.select do |t|
translations = object.translations.select { |t|
t.send(field).present?
end
}
if translations.size > 0
translations

Loading…
Cancel
Save