diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 7a082c65..4fcf4243 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -14,7 +14,8 @@ jobs: - name: Setup Gemfile run: | - cp test/support/gemfile.rb Gemfile + touch .enable_dev + sed -i "3isource 'https://rubygems.org'" Gemfile - name: Setup Ruby uses: ruby/setup-ruby@v1 diff --git a/.gitignore b/.gitignore index 2469bbed..a09da796 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,9 @@ tmp/ Gemfile.lock .project .vscode +.bundle .settings/ docs/_build docs/_static docs/_templates +.enable_dev diff --git a/.rubocop.yml b/.rubocop.yml index 720aaf02..71548d6b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,10 @@ Metrics/AbcSize: Metrics/BlockLength: Enabled: false +Metrics/ParameterLists: + Enabled: true + CountKeywordArgs: false + Metrics/ClassLength: Enabled: false @@ -58,16 +62,45 @@ Performance/ChainArrayAllocation: Style/AutoResourceCleanup: Enabled: true +Style/ExpandPathArguments: + Enabled: true + Exclude: + - additionals.gemspec + - test/**/* + Style/FrozenStringLiteralComment: - Enabled: false + Enabled: true + Exclude: + - '/**/*.rsb' + +Style/OptionHash: + Enabled: true + SuspiciousParamNames: + - options + - api_options + - opts + - args + - params + - parameters + - settings + Exclude: + - lib/additionals/patches/*.rb + +Style/ReturnNil: + Enabled: true + +Style/UnlessLogicalOperators: + Enabled: true + +Style/MethodCallWithArgsParentheses: + Enabled: true + AllowParenthesesInMultilineCall: true + AllowParenthesesInChaining: true + EnforcedStyle: omit_parentheses Style/Documentation: Enabled: false -# required for travis/ci (symbolic links problem) -Style/ExpandPathArguments: - Enabled: false - Style/HashTransformValues: Enabled: false diff --git a/.slim-lint.yml b/.slim-lint.yml index 6579ae1c..ab007d27 100644 --- a/.slim-lint.yml +++ b/.slim-lint.yml @@ -4,6 +4,7 @@ linters: RuboCop: ignored_cops: - Layout/ArgumentAlignment + - Layout/ArrayAlignment - Layout/BlockEndNewline - Layout/EmptyLineAfterGuardClause - Layout/HashAlignment @@ -21,6 +22,7 @@ linters: - Lint/Void - Metrics/BlockNesting - Rails/OutputSafety + - Style/FrozenStringLiteralComment - Style/IdenticalConditionalBranches - Style/IfUnlessModifier - Style/Next diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6bbde0f7..9843c8b7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ Changelog ========= +3.0.3 ++++++ + +- Ruby 2.7 warnings fixed + 3.0.2 +++++ diff --git a/Gemfile b/Gemfile index 35ce81c5..d1a2a1a9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,20 @@ +# frozen_string_literal: true + # Specify your gem's dependencies in additionals.gemspec gemspec + +group :development do + # this is only used for development. + # if you want to use it, do: + # - create .enable_dev file in additionals directory + # - remove rubocop entries from REDMINE/Gemfile + # - remove REDMINE/.rubocop* files + if File.file? File.expand_path './.enable_dev', __dir__ + gem 'brakeman', require: false + gem 'pandoc-ruby', require: false + gem 'rubocop', require: false + gem 'rubocop-performance', require: false + gem 'rubocop-rails', require: false + gem 'slim_lint', require: false + end +end diff --git a/Rakefile b/Rakefile index 39a5d23b..8f3a82ad 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rake/testtask' diff --git a/additionals.gemspec b/additionals.gemspec index 6ede93aa..ac28e964 100644 --- a/additionals.gemspec +++ b/additionals.gemspec @@ -1,5 +1,7 @@ +# frozen_string_literal: true + lib = File.expand_path '../lib', __FILE__ -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib require 'additionals/version' Gem::Specification.new do |spec| @@ -22,9 +24,4 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'render_async' spec.add_runtime_dependency 'rss' spec.add_runtime_dependency 'slim-rails' - - spec.add_development_dependency 'brakeman' - spec.add_development_dependency 'bundler' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'slim_lint' end diff --git a/app/controllers/additionals_assign_to_me_controller.rb b/app/controllers/additionals_assign_to_me_controller.rb index 5569f645..9d0533e1 100644 --- a/app/controllers/additionals_assign_to_me_controller.rb +++ b/app/controllers/additionals_assign_to_me_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AdditionalsAssignToMeController < ApplicationController before_action :find_issue helper :additionals_issues @@ -11,11 +13,11 @@ class AdditionalsAssignToMeController < ApplicationController return end - @issue.init_journal(User.current) + @issue.init_journal User.current @issue.assigned_to = User.current if !@issue.save || old_user == @issue.assigned_to - flash[:error] = l(:error_issues_could_not_be_assigned_to_me) + flash[:error] = l :error_issues_could_not_be_assigned_to_me return redirect_to(issue_path(@issue)) end @@ -29,7 +31,7 @@ class AdditionalsAssignToMeController < ApplicationController private def find_issue - @issue = Issue.find(params[:issue_id]) + @issue = Issue.find params[:issue_id] raise Unauthorized unless @issue.visible? && @issue.editable? @project = @issue.project diff --git a/app/controllers/additionals_change_status_controller.rb b/app/controllers/additionals_change_status_controller.rb index f82c420a..17ff706b 100644 --- a/app/controllers/additionals_change_status_controller.rb +++ b/app/controllers/additionals_change_status_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AdditionalsChangeStatusController < ApplicationController before_action :find_issue helper :additionals_issues @@ -6,7 +8,7 @@ class AdditionalsChangeStatusController < ApplicationController issue_old_status_id = @issue.status.id issue_old_user = @issue.assigned_to new_status_id = params[:new_status_id].to_i - allowed_status = @issue.sidbar_change_status_allowed_to(User.current, new_status_id) + allowed_status = @issue.sidbar_change_status_allowed_to User.current, new_status_id if new_status_id < 1 || @issue.status_id == new_status_id || allowed_status.nil? redirect_to(issue_path(@issue)) @@ -18,7 +20,7 @@ class AdditionalsChangeStatusController < ApplicationController @issue.assigned_to = User.current if @issue.status_x_affected?(new_status_id) && issue_old_user != User.current if !@issue.save || issue_old_status_id == @issue.status_id - flash[:error] = l(:error_issue_status_could_not_changed) + flash[:error] = l :error_issue_status_could_not_changed return redirect_to(issue_path(@issue)) end @@ -33,7 +35,7 @@ class AdditionalsChangeStatusController < ApplicationController private def find_issue - @issue = Issue.find(params[:issue_id]) + @issue = Issue.find params[:issue_id] raise Unauthorized unless @issue.visible? && @issue.editable? @project = @issue.project diff --git a/app/controllers/additionals_macros_controller.rb b/app/controllers/additionals_macros_controller.rb index 3dd23d08..833fdbba 100644 --- a/app/controllers/additionals_macros_controller.rb +++ b/app/controllers/additionals_macros_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AdditionalsMacrosController < ApplicationController before_action :require_login diff --git a/app/controllers/dashboard_async_blocks_controller.rb b/app/controllers/dashboard_async_blocks_controller.rb index 410c868c..4f8ee797 100644 --- a/app/controllers/dashboard_async_blocks_controller.rb +++ b/app/controllers/dashboard_async_blocks_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'open-uri' class DashboardAsyncBlocksController < ApplicationController @@ -84,7 +86,7 @@ class DashboardAsyncBlocksController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end - deny_access unless User.current.allowed_to?(:view_project, @project) + deny_access unless User.current.allowed_to? :view_project, @project @project end diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index acab5a70..9a163eeb 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DashboardsController < ApplicationController menu_item :dashboards @@ -63,7 +65,7 @@ class DashboardsController < ApplicationController end def create - @dashboard = Dashboard.new(author: User.current) + @dashboard = Dashboard.new author: User.current @dashboard.safe_attributes = params[:dashboard] @dashboard.dashboard_type = assign_dashboard_type @dashboard.role_ids = params[:dashboard][:role_ids] if params[:dashboard].present? @@ -71,7 +73,7 @@ class DashboardsController < ApplicationController @allowed_projects = @dashboard.allowed_target_projects if @dashboard.save - flash[:notice] = l(:notice_successful_create) + flash[:notice] = l :notice_successful_create respond_to do |format| format.html { redirect_to dashboard_link_path(@project, @dashboard) } @@ -80,13 +82,13 @@ class DashboardsController < ApplicationController else respond_to do |format| format.html { render action: 'new' } - format.api { render_validation_errors(@dashboard) } + format.api { render_validation_errors @dashboard } end end end def edit - return render_403 unless @dashboard.editable_by?(User.current) + return render_403 unless @dashboard.editable_by? User.current @allowed_projects = @dashboard.allowed_target_projects @@ -97,7 +99,7 @@ class DashboardsController < ApplicationController end def update - return render_403 unless @dashboard.editable_by?(User.current) + return render_403 unless @dashboard.editable_by? User.current @dashboard.safe_attributes = params[:dashboard] @dashboard.role_ids = params[:dashboard][:role_ids] if params[:dashboard].present? @@ -106,9 +108,9 @@ class DashboardsController < ApplicationController @allowed_projects = @dashboard.allowed_target_projects if @dashboard.save - flash[:notice] = l(:notice_successful_update) + flash[:notice] = l :notice_successful_update respond_to do |format| - format.html { redirect_to dashboard_link_path @project, @dashboard } + format.html { redirect_to dashboard_link_path(@project, @dashboard) } format.api { head :ok } end else @@ -124,20 +126,20 @@ class DashboardsController < ApplicationController begin @dashboard.destroy - flash[:notice] = l(:notice_successful_delete) + flash[:notice] = l :notice_successful_delete respond_to do |format| format.html { redirect_to @project.nil? ? home_path : project_path(@project) } format.api { head :ok } end rescue ActiveRecord::RecordNotDestroyed - flash[:error] = l(:error_remove_db_entry) + flash[:error] = l :error_remove_db_entry redirect_to dashboard_path(@dashboard) end end def query_statement_invalid(exception) logger&.error "Query::StatementInvalid: #{exception.message}" - session.delete(additionals_query_session_key('dashboard')) + session.delete additionals_query_session_key('dashboard') render_error l(:error_query_statement_invalid) end @@ -145,7 +147,7 @@ class DashboardsController < ApplicationController block_settings = params[:settings] || {} block_settings.each do |block, settings| - @dashboard.update_block_settings(block, settings.to_unsafe_hash) + @dashboard.update_block_settings block, settings.to_unsafe_hash end @dashboard.save @updated_blocks = block_settings.keys @@ -201,7 +203,7 @@ class DashboardsController < ApplicationController end def find_dashboard - @dashboard = Dashboard.find(params[:id]) + @dashboard = Dashboard.find params[:id] raise ::Unauthorized unless @dashboard.visible? if @dashboard.dashboard_type == DashboardContentProject::TYPE_NAME && @dashboard.project.nil? diff --git a/app/helpers/additionals_chartjs_helper.rb b/app/helpers/additionals_chartjs_helper.rb index bb3f41b6..98605548 100644 --- a/app/helpers/additionals_chartjs_helper.rb +++ b/app/helpers/additionals_chartjs_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdditionalsChartjsHelper def chartjs_colorschemes_info_url link_to(l(:label_chartjs_colorscheme_info), @@ -7,6 +9,6 @@ module AdditionalsChartjsHelper def select_options_for_chartjs_colorscheme(selected) data = YAML.safe_load(ERB.new(IO.read(File.join(Additionals.plugin_dir, 'config', 'colorschemes.yml'))).result) || {} - grouped_options_for_select(data, selected) + grouped_options_for_select data, selected end end diff --git a/app/helpers/additionals_clipboardjs_helper.rb b/app/helpers/additionals_clipboardjs_helper.rb index b49cc1db..7adec197 100644 --- a/app/helpers/additionals_clipboardjs_helper.rb +++ b/app/helpers/additionals_clipboardjs_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdditionalsClipboardjsHelper def clipboardjs_button_for(target, clipboard_text_from_button = nil) render_clipboardjs_button(target, clipboard_text_from_button) + render_clipboardjs_javascript(target) @@ -34,6 +36,6 @@ module AdditionalsClipboardjsHelper end def render_clipboardjs_javascript(target) - javascript_tag("setClipboardJS('#zc_#{target}');") + javascript_tag "setClipboardJS('#zc_#{target}');" end end diff --git a/app/helpers/additionals_custom_fields_helper.rb b/app/helpers/additionals_custom_fields_helper.rb index d554b9d1..04153c45 100644 --- a/app/helpers/additionals_custom_fields_helper.rb +++ b/app/helpers/additionals_custom_fields_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdditionalsCustomFieldsHelper def custom_fields_with_full_with_layout ['IssueCustomField'] diff --git a/app/helpers/additionals_fontawesome_helper.rb b/app/helpers/additionals_fontawesome_helper.rb index fe03eddd..00cedd0a 100644 --- a/app/helpers/additionals_fontawesome_helper.rb +++ b/app/helpers/additionals_fontawesome_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdditionalsFontawesomeHelper # name = TYPE-FA_NAME, eg. fas_car # fas_cloud-upload-alt @@ -7,7 +9,7 @@ module AdditionalsFontawesomeHelper # pre_text # post_text # title - def font_awesome_icon(name, options = {}) + def font_awesome_icon(name, **options) info = AdditionalsFontAwesome.value_info name return '' if info.blank? @@ -29,7 +31,7 @@ module AdditionalsFontawesomeHelper post_text = options[:post_text] options.delete :post_text end - s << tag.span(options) + s << tag.span(**options) if post_text.present? s << ' ' s << post_text @@ -37,16 +39,16 @@ module AdditionalsFontawesomeHelper safe_join s end - def additionals_fontawesome_select(form, selected, options = {}) + def additionals_fontawesome_select(form, selected, **options) options[:include_blank] ||= true unless options[:required] html_options = {} additionals_fontawesome_add_selected selected - name, options = Additionals.hash_remove_with_default(:name, options, :icon) - loader, options = Additionals.hash_remove_with_default(:loader, options, true) - html_options[:class], options = Additionals.hash_remove_with_default(:class, options, 'select2-fontawesome-field') - html_options[:style], options = Additionals.hash_remove_with_default(:style, options) + name, options = Additionals.hash_remove_with_default :name, options, :icon + loader, options = Additionals.hash_remove_with_default :loader, options, true + html_options[:class], options = Additionals.hash_remove_with_default :class, options, 'select2-fontawesome-field' + html_options[:style], options = Additionals.hash_remove_with_default :style, options s = [] s << form.select(name, @@ -54,7 +56,7 @@ module AdditionalsFontawesomeHelper options, html_options) - s << additionals_fontawesome_loader(options, html_options) if loader + s << additionals_fontawesome_loader(**options, field_class: html_options[:class]) if loader safe_join s end @@ -70,21 +72,20 @@ module AdditionalsFontawesomeHelper '250px' end - def additionals_fontawesome_loader(options, html_options = {}) - html_options[:class] ||= 'select2-fontawesome-field' + def additionals_fontawesome_loader(field_class: 'select2-fontawesome-field', **options) options[:template_selection] = 'formatFontawesomeText' options[:template_result] = 'formatFontawesomeText' if options[:include_blank] - options[:placeholder] ||= l(:label_disabled) + options[:placeholder] ||= l :label_disabled options[:allow_clear] ||= true end options[:width] = additionals_fontawesome_default_select_width - render(layout: false, - partial: 'additionals/select2_ajax_call.js', + render layout: false, + partial: 'additionals/select2_ajax_call', formats: [:js], - locals: { field_class: html_options[:class], + locals: { field_class: field_class, ajax_url: fontawesome_auto_completes_path(selected: @selected_store.join(',')), - options: options }) + options: options } end end diff --git a/app/helpers/additionals_issues_helper.rb b/app/helpers/additionals_issues_helper.rb index e1843942..c87a258c 100644 --- a/app/helpers/additionals_issues_helper.rb +++ b/app/helpers/additionals_issues_helper.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module AdditionalsIssuesHelper def author_options_for_select(project, entity = nil, permission = nil) scope = project.present? ? project.users.visible : User.active.visible - scope = scope.with_permission(permission, project) unless permission.nil? + scope = scope.with_permission permission, project unless permission.nil? authors = scope.sorted.to_a unless entity.nil? @@ -15,7 +17,7 @@ module AdditionalsIssuesHelper s = [] return s unless authors.any? - s << tag.option("<< #{l :label_me} >>", value: User.current.id) if authors.include?(User.current) + s << tag.option("<< #{l :label_me} >>", value: User.current.id) if authors.include? User.current if entity.nil? s << options_from_collection_for_select(authors, 'id', 'name') diff --git a/app/helpers/additionals_journals_helper.rb b/app/helpers/additionals_journals_helper.rb index 4549ef6f..457a8f0f 100644 --- a/app/helpers/additionals_journals_helper.rb +++ b/app/helpers/additionals_journals_helper.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + module AdditionalsJournalsHelper - MultipleValuesDetail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value) + MultipleValuesDetail = Struct.new :property, :prop_key, :custom_field, :old_value, :value # Returns the textual representation of a journal details # as an array of strings - def entity_details_to_strings(entity, details, options = {}) + def entity_details_to_strings(entity, details, **options) entity_type = entity.model_name.param_key show_detail_method = "#{entity_type}_show_detail" options[:only_path] = options[:only_path] != false - no_html = options.delete(:no_html) + no_html = options.delete :no_html strings = [] values_by_field = {} @@ -21,21 +23,21 @@ module AdditionalsJournalsHelper next end end - strings << send(show_detail_method, detail, no_html, options) + strings << send(show_detail_method, detail, no_html, **options) end if values_by_field.present? values_by_field.each do |field, changes| if changes[:added].any? - detail = MultipleValuesDetail.new('cf', field.id.to_s, field) + detail = MultipleValuesDetail.new 'cf', field.id.to_s, field detail.value = changes[:added] - strings << send(show_detail_method, detail, no_html, options) + strings << send(show_detail_method, detail, no_html, **options) end next unless changes[:deleted].any? - detail = MultipleValuesDetail.new('cf', field.id.to_s, field) + detail = MultipleValuesDetail.new 'cf', field.id.to_s, field detail.old_value = changes[:deleted] - strings << send(show_detail_method, detail, no_html, options) + strings << send(show_detail_method, detail, no_html, **options) end end strings @@ -64,7 +66,7 @@ module AdditionalsJournalsHelper # Returns the textual representation of a single journal detail # rubocop: disable Rails/OutputSafety - def entity_show_detail(entity, detail, no_html = false, options = {}) # rubocop:disable Style/OptionalBooleanParameter: + def entity_show_detail(entity, detail, no_html = false, **options) # rubocop:disable Style/OptionalBooleanParameter: multiple = false no_detail = false show_diff = false @@ -82,17 +84,17 @@ module AdditionalsJournalsHelper if label || show_diff unless no_html - label = tag.strong(label) - old_value = tag.i(old_value) if detail.old_value - old_value = tag.del(old_value) if detail.old_value && detail.value.blank? - value = tag.i(value) if value + label = tag.strong label + old_value = tag.i old_value if detail.old_value + old_value = tag.del old_value if detail.old_value && detail.value.blank? + value = tag.i value if value end html = if no_detail - l(:text_journal_changed_no_detail, label: label) + l :text_journal_changed_no_detail, label: label elsif show_diff - s = l(:text_journal_changed_no_detail, label: label) + s = l :text_journal_changed_no_detail, label: label unless no_html diff_link = link_to l(:label_diff), send(diff_url_method, @@ -105,11 +107,11 @@ module AdditionalsJournalsHelper s.html_safe elsif detail.value.present? if detail.old_value.present? - l(:text_journal_changed, label: label, old: old_value, new: value) + l :text_journal_changed, label: label, old: old_value, new: value elsif multiple - l(:text_journal_added, label: label, value: value) + l :text_journal_added, label: label, value: value else - l(:text_journal_set_to, label: label, value: value) + l :text_journal_set_to, label: label, value: value end else l(:text_journal_deleted, label: label, old: old_value).html_safe @@ -138,20 +140,20 @@ module AdditionalsJournalsHelper prop = { label: custom_field.name } project = Project.visible.where(id: detail.value).first if detail.value.present? old_project = Project.visible.where(id: detail.old_value).first if detail.old_value.present? - prop[:value] = link_to_project(project) if project.present? - prop[:old_value] = link_to_project(old_project) if old_project.present? + prop[:value] = link_to_project project if project.present? + prop[:old_value] = link_to_project old_project if old_project.present? when 'db_entry' prop = { label: custom_field.name } db_entry = DbEntry.visible.where(id: detail.value).first if detail.value.present? old_db_entry = DbEntry.visible.where(id: detail.old_value).first if detail.old_value.present? - prop[:value] = link_to(db_entry.name, db_entry_url(db_entry)) if db_entry.present? - prop[:old_value] = link_to(old_db_entry.name, db_entry_url(old_db_entry)) if old_db_entry.present? + prop[:value] = link_to db_entry.name, db_entry_url(db_entry) if db_entry.present? + prop[:old_value] = link_to old_db_entry.name, db_entry_url(old_db_entry) if old_db_entry.present? when 'password' prop = { label: custom_field.name } password = Password.visible.where(id: detail.value).first if detail.value.present? && defined?(Password) old_password = Password.visible.where(id: detail.old_value).first if detail.old_value.present? && defined?(Password) - prop[:value] = link_to(password.name, password_url(password)) if password.present? - prop[:old_value] = link_to(old_password.name, password_url(old_password)) if old_password.present? + prop[:value] = link_to password.name, password_url(password) if password.present? + prop[:old_value] = link_to old_password.name, password_url(old_password) if old_password.present? end prop diff --git a/app/helpers/additionals_menu_helper.rb b/app/helpers/additionals_menu_helper.rb index ceee70ff..1fa04455 100644 --- a/app/helpers/additionals_menu_helper.rb +++ b/app/helpers/additionals_menu_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdditionalsMenuHelper def additionals_top_menu_setup return if Redmine::Plugin.installed? 'redmine_hrm' @@ -18,11 +20,11 @@ module AdditionalsMenuHelper end end - def handle_top_submenu_item(menu_name, item) - handle_top_menu_item menu_name, item, with_submenu: true + def handle_top_submenu_item(menu_name, **item) + handle_top_menu_item menu_name, with_submenu: true, **item end - def handle_top_menu_item(menu_name, item, with_submenu: false) + def handle_top_menu_item(menu_name, with_submenu: false, **item) Redmine::MenuManager.map(:top_menu).delete(menu_name.to_sym) if Redmine::MenuManager.map(:top_menu).exists?(menu_name.to_sym) html_options = {} @@ -30,7 +32,7 @@ module AdditionalsMenuHelper css_classes = [] css_classes << 'top-submenu' if with_submenu css_classes << 'external' if item[:url].include? '://' - html_options[:class] = css_classes.join(' ') if css_classes.present? + html_options[:class] = css_classes.join ' ' if css_classes.present? html_options[:title] = item[:title] if item[:title].present? @@ -40,9 +42,9 @@ module AdditionalsMenuHelper menu_options[:if] = menu_options[:if] if menu_options[:if].present? menu_options[:caption] = if item[:symbol].present? && item[:name].present? - font_awesome_icon(item[:symbol], post_text: item[:name]) + font_awesome_icon item[:symbol], post_text: item[:name] elsif item[:symbol].present? - font_awesome_icon(item[:symbol]) + font_awesome_icon item[:symbol] elsif item[:name].present? item[:name].to_s end @@ -149,8 +151,8 @@ module AdditionalsMenuHelper raise e unless e.class.to_s == 'NameError' end - plugin_item = plugin_item_base.try(:additionals_help_items) unless plugin_item_base.nil? - plugin_item = additionals_help_items_fallbacks(plugin.id) if plugin_item.nil? + plugin_item = plugin_item_base.try :additionals_help_items unless plugin_item_base.nil? + plugin_item = additionals_help_items_fallbacks plugin.id if plugin_item.nil? next if plugin_item.nil? @@ -186,12 +188,12 @@ module AdditionalsMenuHelper s << if item[:title] == '-' tag.li tag.hr else - html_options = { class: "help_item_#{idx}" } + html_options = { class: +"help_item_#{idx}" } if item[:url].include? '://' html_options[:class] << ' external' html_options[:target] = '_blank' end - tag.li(link_to(item[:title], item[:url], html_options)) + tag.li link_to(item[:title], item[:url], html_options) end end safe_join s @@ -200,13 +202,8 @@ module AdditionalsMenuHelper # Plugin help items definition for plugins, # which do not have additionals_help_menu_items integration def additionals_help_items_fallbacks(plugin_id) - plugins = { redmine_wiki_lists: [{ title: 'Wiki Lists Macros', - url: 'https://www.r-labs.org/projects/wiki_lists/wiki/Wiki_Lists_en' }], - redmine_wiki_extensions: [{ title: 'Wiki Extensions', - url: 'https://www.r-labs.org/projects/r-labs/wiki/Wiki_Extensions_en' }], - redmine_git_hosting: [{ title: 'Redmine Git Hosting', - url: 'http://redmine-git-hosting.io/get_started/', - admin: true }], + plugins = { redmine_drawio: [{ title: 'draw.io usage', + url: 'https://github.com/mikitex70/redmine_drawio#usage' }], redmine_contacts: [{ title: 'Redmine CRM', url: 'https://www.redmineup.com/pages/help/crm', admin: true }], diff --git a/app/helpers/additionals_projects_helper.rb b/app/helpers/additionals_projects_helper.rb index 5d44081d..9b917972 100644 --- a/app/helpers/additionals_projects_helper.rb +++ b/app/helpers/additionals_projects_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdditionalsProjectsHelper def project_overview_name(_project, dashboard = nil) name = [l(:label_overview)] diff --git a/app/helpers/additionals_queries_helper.rb b/app/helpers/additionals_queries_helper.rb index 4c357af4..fade52ad 100644 --- a/app/helpers/additionals_queries_helper.rb +++ b/app/helpers/additionals_queries_helper.rb @@ -1,22 +1,28 @@ +# frozen_string_literal: true + module AdditionalsQueriesHelper def additionals_query_session_key(object_type) "#{object_type}_query".to_sym end - def additionals_retrieve_query(object_type, options = {}) + def additionals_retrieve_query(object_type, user_filter: nil) session_key = additionals_query_session_key object_type query_class = Object.const_get "#{object_type.camelcase}Query" if params[:query_id].present? - additionals_load_query_id(query_class, session_key, params[:query_id], options, object_type) + additionals_load_query_id query_class, + session_key, + params[:query_id], + object_type, + user_filter: user_filter elsif api_request? || params[:set_filter] || session[session_key].nil? || session[session_key][:project_id] != (@project ? @project.id : nil) # Give it a name, required to be valid - @query = query_class.new(name: '_') + @query = query_class.new name: '_' @query.project = @project - @query.user_filter = options[:user_filter] if options[:user_filter] - @query.build_from_params(params) + @query.user_filter = user_filter if user_filter + @query.build_from_params params session[session_key] = { project_id: @query.project_id } # session has a limit to 4k, we have to use a cache for it for larger data Rails.cache.write(additionals_query_cache_key(object_type), @@ -27,7 +33,7 @@ module AdditionalsQueriesHelper sort_criteria: params[:sort].presence || @query.sort_criteria.to_a) else # retrieve from session - @query = query_class.find_by(id: session[session_key][:id]) if session[session_key][:id] + @query = query_class.find_by id: session[session_key][:id] if session[session_key][:id] session_data = Rails.cache.read additionals_query_cache_key(object_type) @query ||= query_class.new(name: '_', filters: session_data.nil? ? nil : session_data[:filters], @@ -51,14 +57,14 @@ module AdditionalsQueriesHelper end end - def additionals_load_query_id(query_class, session_key, query_id, options, object_type) - scope = query_class.where(project_id: nil) - scope = scope.or(query_class.where(project_id: @project.id)) if @project - @query = scope.find(query_id) + def additionals_load_query_id(query_class, session_key, query_id, object_type, user_filter: nil) + scope = query_class.where project_id: nil + scope = scope.or query_class.where(project_id: @project.id) if @project + @query = scope.find query_id raise ::Unauthorized unless @query.visible? @query.project = @project - @query.user_filter = options[:user_filter] if options[:user_filter] + @query.user_filter = user_filter if user_filter session[session_key] = { id: @query.id, project_id: @query.project_id } @query.sort_criteria = params[:sort] if params[:sort].present? @@ -76,62 +82,58 @@ module AdditionalsQueriesHelper "#{object_type}_query_data_#{session.id}_#{project_id}" end - def additionals_select2_search_users(options = {}) + def additionals_select2_search_users(all_visible: false, where_filter: nil, where_params: nil) q = params[:q].to_s.strip exclude_id = params[:user_id].to_i scope = User.active.where type: 'User' - scope = scope.visible unless options[:all_visible] - scope = scope.where.not(id: exclude_id) if exclude_id.positive? - scope = scope.where(options[:where_filter], options[:where_params]) if options[:where_filter] - q.split.map { |search_string| scope = scope.like(search_string) } if q.present? + scope = scope.visible unless all_visible + scope = scope.where.not id: exclude_id if exclude_id.positive? + scope = scope.where where_filter, where_params if where_filter + q.split.map { |search_string| scope = scope.like search_string } if q.present? scope = scope.order(last_login_on: :desc) .limit(Additionals::SELECT2_INIT_ENTRIES) @users = scope.to_a.sort! { |x, y| x.name <=> y.name } render layout: false, partial: 'auto_completes/additionals_users' end - def additionals_query_to_xlsx(items, query, options = {}) + def additionals_query_to_xlsx(items, query, no_id_link: false) require 'write_xlsx' - columns = if options[:columns].present? || options[:c].present? - query.available_columns - else - query.columns - end - options[:filename] = StringIO.new('') + options = { no_id_link: no_id_link, + filename: StringIO.new(+'') } - export_to_xlsx(items, columns, options) + export_to_xlsx items, query.columns, options options[:filename].string end - def additionals_result_to_xlsx(items, columns, options = {}) + def additionals_result_to_xlsx(items, columns, options) raise 'option filename is mission' if options[:filename].blank? require 'write_xlsx' - export_to_xlsx(items, columns, options) + export_to_xlsx items, columns, options end def export_to_xlsx(items, columns, options) - workbook = WriteXLSX.new(options[:filename]) + workbook = WriteXLSX.new options[:filename] worksheet = workbook.add_worksheet # Freeze header row and # column. freeze_row = options[:freeze_first_row].nil? || options[:freeze_first_row] ? 1 : 0 freeze_column = options[:freeze_first_column].nil? || options[:freeze_first_column] ? 1 : 0 - worksheet.freeze_panes(freeze_row, freeze_column) + worksheet.freeze_panes freeze_row, freeze_column options[:columns_width] = if options[:xlsx_write_header_row].present? - send(options[:xlsx_write_header_row], workbook, worksheet, columns) + send options[:xlsx_write_header_row], workbook, worksheet, columns else - xlsx_write_header_row(workbook, worksheet, columns) + xlsx_write_header_row workbook, worksheet, columns end options[:columns_width] = if options[:xlsx_write_item_rows].present? - send(options[:xlsx_write_item_rows], workbook, worksheet, columns, items, options) + send options[:xlsx_write_item_rows], workbook, worksheet, columns, items, options else - xlsx_write_item_rows(workbook, worksheet, columns, items, options) + xlsx_write_item_rows workbook, worksheet, columns, items, options end columns.size.times do |index| - worksheet.set_column(index, index, options[:columns_width][index]) + worksheet.set_column index, index, options[:columns_width][index] end workbook.close @@ -152,20 +154,20 @@ module AdditionalsQueriesHelper columns_width end - def xlsx_write_item_rows(workbook, worksheet, columns, items, options = {}) - hyperlink_format = workbook.add_format(xlsx_cell_format(:link)) - even_text_format = workbook.add_format(xlsx_cell_format(:text, '', 0)) - even_text_format.set_num_format(0x31) - odd_text_format = workbook.add_format(xlsx_cell_format(:text, '', 1)) - odd_text_format.set_num_format(0x31) + def xlsx_write_item_rows(workbook, worksheet, columns, items, options) + hyperlink_format = workbook.add_format xlsx_cell_format(:link) + even_text_format = workbook.add_format xlsx_cell_format(:text, '', 0) + even_text_format.set_num_format 0x31 + odd_text_format = workbook.add_format xlsx_cell_format(:text, '', 1) + odd_text_format.set_num_format 0x31 items.each_with_index do |line, line_index| columns.each_with_index do |c, column_index| - value = csv_content(c, line) + value = csv_content(c, line).dup if c.name == :id # ID if options[:no_id_link].blank? - link = url_for(controller: line.class.name.underscore.pluralize, action: 'show', id: line.id) - worksheet.write(line_index + 1, column_index, link, hyperlink_format, value) + link = url_for controller: line.class.name.underscore.pluralize, action: 'show', id: line.id + worksheet.write line_index + 1, column_index, link, hyperlink_format, value else # id without link worksheet.write(line_index + 1, @@ -173,13 +175,13 @@ module AdditionalsQueriesHelper value, workbook.add_format(xlsx_cell_format(:cell, value, line_index))) end - elsif xlsx_hyperlink_cell?(value) - worksheet.write(line_index + 1, column_index, value[0..254], hyperlink_format, value) + elsif xlsx_hyperlink_cell? value + worksheet.write line_index + 1, column_index, value[0..254], hyperlink_format, value elsif !c.inline? # block column can be multiline strings - value.gsub!("\r\n", "\n") + value.gsub! "\r\n", "\n" text_format = line_index.even? ? even_text_format : odd_text_format - worksheet.write_rich_string(line_index + 1, column_index, value, text_format) + worksheet.write_rich_string line_index + 1, column_index, value, text_format else worksheet.write(line_index + 1, column_index, @@ -187,7 +189,7 @@ module AdditionalsQueriesHelper workbook.add_format(xlsx_cell_format(:cell, value, line_index))) end - width = xlsx_get_column_width(value) + width = xlsx_get_column_width value options[:columns_width][column_index] = width if options[:columns_width][column_index] < width end end @@ -238,7 +240,7 @@ module AdditionalsQueriesHelper # TODO: this is a temporary fix and should be removed # after https://www.redmine.org/issues/29830 is in Redmine core. def query_as_hidden_field_tags(query) - tags = hidden_field_tag('set_filter', '1', id: nil) + tags = hidden_field_tag 'set_filter', '1', id: nil if query.filters.present? query.filters.each do |field, filter| @@ -254,7 +256,7 @@ module AdditionalsQueriesHelper ignored_block_columns = query.block_columns.map(&:name) query.columns.each do |column| - next if ignored_block_columns.include?(column.name) + next if ignored_block_columns.include? column.name tags << hidden_field_tag('c[]', column.name, id: nil) end diff --git a/app/helpers/additionals_routes_helper.rb b/app/helpers/additionals_routes_helper.rb index 9d2de5b0..9b6b4caf 100644 --- a/app/helpers/additionals_routes_helper.rb +++ b/app/helpers/additionals_routes_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdditionalsRoutesHelper def _dashboards_path(project, *args) if project @@ -71,7 +73,7 @@ module AdditionalsRoutesHelper end end - def dashboard_link_path(project, dashboard, options = {}) + def dashboard_link_path(project, dashboard, **options) options[:dashboard_id] = dashboard.id if dashboard.dashboard_type == DashboardContentProject::TYPE_NAME project_path project, options diff --git a/app/helpers/additionals_select2_helper.rb b/app/helpers/additionals_select2_helper.rb index 562c3e62..1362f71f 100644 --- a/app/helpers/additionals_select2_helper.rb +++ b/app/helpers/additionals_select2_helper.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module AdditionalsSelect2Helper - def additionals_select2_tag(name, option_tags = nil, options = {}) - s = select_tag(name, option_tags, options) + def additionals_select2_tag(name, option_tags, options) + s = select_tag name, option_tags, options id = options.delete(:id) || sanitize_to_id(name) s << hidden_field_tag("#{name}[]", '') if options[:multiple] && options.fetch(:include_hidden, true) @@ -8,7 +10,7 @@ module AdditionalsSelect2Helper end # Transforms select filters of +type+ fields into select2 - def additionals_transform_to_select2(type, options = {}) - javascript_tag("setSelect2Filter('#{type}', #{options.to_json});") unless type.empty? + def additionals_transform_to_select2(type, options) + javascript_tag "setSelect2Filter('#{type}', #{options.to_json});" unless type.empty? end end diff --git a/app/helpers/additionals_settings_helper.rb b/app/helpers/additionals_settings_helper.rb index e9e52049..55fdf829 100644 --- a/app/helpers/additionals_settings_helper.rb +++ b/app/helpers/additionals_settings_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdditionalsSettingsHelper def additionals_settings_tabs tabs = [{ name: 'general', partial: 'additionals/settings/general', label: :label_general }, @@ -13,7 +15,7 @@ module AdditionalsSettingsHelper tabs end - def additionals_settings_checkbox(name, options = {}) + def additionals_settings_checkbox(name, **options) active_value = options.delete(:active_value).presence || @settings.present? && @settings[name] tag_name = options.delete(:tag_name).presence || "settings[#{name}]" @@ -36,50 +38,50 @@ module AdditionalsSettingsHelper s = [label_tag(tag_name, label_title)] s << hidden_field_tag(tag_name, 0, id: nil) if !custom_value || value_is_bool - s << check_box_tag(tag_name, value, checked, options) + s << check_box_tag(tag_name, value, checked, **options) safe_join s end - def additionals_settings_numberfield(name, options = {}) - additionals_settings_input_field :number_field_tag, name, options + def additionals_settings_numberfield(name, **options) + additionals_settings_input_field :number_field_tag, name, **options end - def additionals_settings_textfield(name, options = {}) - additionals_settings_input_field :text_field_tag, name, options + def additionals_settings_textfield(name, **options) + additionals_settings_input_field :text_field_tag, name, **options end - def additionals_settings_passwordfield(name, options = {}) - additionals_settings_input_field :password_field_tag, name, options + def additionals_settings_passwordfield(name, **options) + additionals_settings_input_field :password_field_tag, name, **options end - def additionals_settings_urlfield(name, options = {}) - additionals_settings_input_field :url_field_tag, name, options + def additionals_settings_urlfield(name, **options) + additionals_settings_input_field :url_field_tag, name, **options end - def additionals_settings_select(name, values, options = {}) + def additionals_settings_select(name, values, **options) tag_name = options.delete(:tag_name).presence || "settings[#{name}]" label_title = [options.delete(:label).presence || l("label_#{name}")] label_title << tag.span('*', class: 'required') if options[:required].present? safe_join [label_tag(tag_name, safe_join(label_title, ' ')), - select_tag(tag_name, values, options)] + select_tag(tag_name, values, **options)] end - def additionals_settings_textarea(name, options = {}) + def additionals_settings_textarea(name, **options) label_title = options.delete(:label).presence || l("label_#{name}") value = options.delete(:value).presence || @settings[name] - options[:class] = 'wiki-edit' unless options.key?(:class) - options[:rows] = addtionals_textarea_cols(value) unless options.key?(:rows) + options[:class] = 'wiki-edit' unless options.key? :class + options[:rows] = addtionals_textarea_cols value unless options.key? :rows safe_join [label_tag("settings[#{name}]", label_title), - text_area_tag("settings[#{name}]", value, options)] + text_area_tag("settings[#{name}]", value, **options)] end private - def additionals_settings_input_field(tag_field, name, options = {}) + def additionals_settings_input_field(tag_field, name, **options) tag_name = options.delete(:tag_name).presence || "settings[#{name}]" value = if options.key? :value options.delete(:value).presence @@ -91,6 +93,6 @@ module AdditionalsSettingsHelper label_title << tag.span('*', class: 'required') if options[:required].present? safe_join [label_tag(tag_name, safe_join(label_title, ' ')), - send(tag_field, tag_name, value, options)], ' ' + send(tag_field, tag_name, value, **options)], ' ' end end diff --git a/app/helpers/additionals_wiki_pdf_helper.rb b/app/helpers/additionals_wiki_pdf_helper.rb index 4e3465b3..da9597e1 100644 --- a/app/helpers/additionals_wiki_pdf_helper.rb +++ b/app/helpers/additionals_wiki_pdf_helper.rb @@ -1,22 +1,24 @@ +# frozen_string_literal: true + module AdditionalsWikiPdfHelper include Redmine::Export::PDF def wiki_page_to_pdf(page, project) - pdf = ITCPDF.new(current_language) - pdf.set_title("#{project} - #{page.title}") + pdf = ITCPDF.new current_language + pdf.set_title "#{project} - #{page.title}" pdf.alias_nb_pages - pdf.footer_date = format_date(User.current.today) + pdf.footer_date = format_date User.current.today pdf.add_page - unless Additionals.setting?(:wiki_pdf_remove_title) - pdf.SetFontStyle('B', 11) + unless Additionals.setting? :wiki_pdf_remove_title + pdf.SetFontStyle 'B', 11 pdf.RDMMultiCell(190, 5, "#{project} - #{page.title} - # #{page.content.version}") end pdf.ln # Set resize image scale - pdf.set_image_scale(1.6) - pdf.SetFontStyle('', 9) - if Additionals.setting?(:wiki_pdf_remove_attachments) + pdf.set_image_scale 1.6 + pdf.SetFontStyle '', 9 + if Additionals.setting? :wiki_pdf_remove_attachments pdf.RDMwriteFormattedCell(190, 5, '', @@ -28,7 +30,7 @@ module AdditionalsWikiPdfHelper headings: false, inline_attachments: false), page.attachments) else - write_wiki_page(pdf, page) + write_wiki_page pdf, page end pdf.output end diff --git a/app/helpers/dashboards_helper.rb b/app/helpers/dashboards_helper.rb index f8355e05..989cda0a 100644 --- a/app/helpers/dashboards_helper.rb +++ b/app/helpers/dashboards_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DashboardsHelper def dashboard_async_cache(dashboard, block, async, settings, &content_block) cache render_async_cache_key(_dashboard_async_blocks_path(@project, dashboard.async_params(block, async, settings))), @@ -32,7 +34,7 @@ module DashboardsHelper def sidebar_dashboards(dashboard, project = nil, user = nil) user ||= User.current - scope = Dashboard.visible.includes([:author]) + scope = Dashboard.visible.includes [:author] scope = if project.present? scope = scope.project_only @@ -111,7 +113,7 @@ module DashboardsHelper return '' unless dashboards.any? tag.h3(title, class: 'dashboards') + - tag.ul(class: 'dashboards') do + tag.ul(class: 'dashboards') do # rubocop: disable Style/MethodCallWithArgsParentheses dashboards.each do |dashboard| selected = dashboard.id == if params[:dashboard_id].present? params[:dashboard_id].to_i @@ -119,7 +121,7 @@ module DashboardsHelper active_dashboard.id end - css = 'dashboard' + css = +'dashboard' css << ' selected' if selected li_class = nil @@ -143,14 +145,14 @@ module DashboardsHelper end end - def dashboard_link(dashboard, project, options = {}) + def dashboard_link(dashboard, project, **options) if options[:title].blank? && dashboard.public? author = if dashboard.author_id == User.current.id l :label_me else dashboard.author end - options[:title] = l(:label_dashboard_author, name: author) + options[:title] = l :label_dashboard_author, name: author end name = options.delete(:name) || dashboard.name @@ -171,10 +173,10 @@ module DashboardsHelper end end - def delete_dashboard_link(url, options = {}) + def delete_dashboard_link(url) options = { method: :delete, data: { confirm: l(:text_are_you_sure) }, - class: 'icon icon-del' }.merge(options) + class: 'icon icon-del' } link_to l(:button_dashboard_delete), url, options end @@ -252,7 +254,7 @@ module DashboardsHelper exposed_params: %i[sort], partial: 'dashboards/blocks/query_list' } partial_locals[:async][:unique_params] = [Redmine::Utils.random_hex(16)] if params[:refresh].present? - partial_locals[:async] = partial_locals[:async].merge(block_definition[:async]) if block_definition[:async] + partial_locals[:async] = partial_locals[:async].merge block_definition[:async] if block_definition[:async] elsif block_definition[:async] partial_locals[:async] = block_definition[:async] end @@ -277,9 +279,9 @@ module DashboardsHelper title << query_block[:label] title << if query_block[:with_project] - link_to(query.name, send(query_block[:link_helper], project, query.as_params)) + link_to query.name, send(query_block[:link_helper], project, query.as_params) else - link_to(query.name, send(query_block[:link_helper], query.as_params)) + link_to query.name, send(query_block[:link_helper], query.as_params) end safe_join title, Additionals::LIST_SEPARATOR @@ -289,9 +291,9 @@ module DashboardsHelper return if dashboard.visibility == Dashboard::VISIBILITY_PRIVATE title = if query.visibility == Query::VISIBILITY_PRIVATE - l(:alert_only_visible_by_yourself) + l :alert_only_visible_by_yourself elsif block_definition.key?(:admin_only) && block_definition[:admin_only] - l(:alert_only_visible_by_admins) + l :alert_only_visible_by_admins end return if title.nil? @@ -322,7 +324,7 @@ module DashboardsHelper max_entries = settings[:max_entries] || DashboardContent::DEFAULT_MAX_ENTRIES scope = Document.visible - scope = scope.where(project: dashboard.project) if dashboard.project + scope = scope.where project: dashboard.project if dashboard.project documents = scope.order(created_on: :desc) .limit(max_entries) @@ -357,10 +359,10 @@ module DashboardsHelper days = 7 if days < 1 || days > 365 scope = TimeEntry.where user_id: User.current.id - scope = scope.where(project_id: dashboard.content_project.id) unless dashboard.content_project.nil? + scope = scope.where project_id: dashboard.content_project.id unless dashboard.content_project.nil? - entries_today = scope.where(spent_on: User.current.today) - entries_days = scope.where(spent_on: User.current.today - (days - 1)..User.current.today) + entries_today = scope.where spent_on: User.current.today + entries_days = scope.where spent_on: User.current.today - (days - 1)..User.current.today render partial: 'dashboards/blocks/my_spent_time', locals: { block: block, @@ -379,7 +381,7 @@ module DashboardsHelper Redmine::Activity::Fetcher.new(user, options) .events(nil, nil, limit: max_entries) - .group_by { |event| user.time_to_date(event.event_datetime) } + .group_by { |event| user.time_to_date event.event_datetime } end def dashboard_feed_catcher(url, max_entries) @@ -391,7 +393,7 @@ module DashboardsHelper begin URI.parse(url).open do |rss_feed| - rss = RSS::Parser.parse(rss_feed) + rss = RSS::Parser.parse rss_feed rss.items.each do |item| cnt += 1 feed[:items] << { title: item.title.try(:content)&.presence || item.title, @@ -430,7 +432,7 @@ module DashboardsHelper # Renders a single block content def render_dashboard_block_content(block, block_definition, dashboard, overwritten_settings = {}) settings = dashboard.layout_settings block - settings = settings.merge(overwritten_settings) if overwritten_settings.present? + settings = settings.merge overwritten_settings if overwritten_settings.present? partial = block_definition[:partial] partial_locals = build_dashboard_partial_locals block, block_definition, settings, dashboard @@ -441,7 +443,7 @@ module DashboardsHelper begin render partial: partial, locals: partial_locals rescue ActionView::MissingTemplate - Rails.logger.warn("Partial \"#{partial}\" missing for block \"#{block}\" found in #{dashboard.name} (id=#{dashboard.id})") + Rails.logger.warn "Partial \"#{partial}\" missing for block \"#{block}\" found in #{dashboard.name} (id=#{dashboard.id})" nil end else diff --git a/app/jobs/additionals_job.rb b/app/jobs/additionals_job.rb index 613249a3..825904f8 100644 --- a/app/jobs/additionals_job.rb +++ b/app/jobs/additionals_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AdditionalsJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/app/models/additionals_chart.rb b/app/models/additionals_chart.rb index 84a27ad4..532291c4 100644 --- a/app/models/additionals_chart.rb +++ b/app/models/additionals_chart.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AdditionalsChart include ActiveRecord::Sanitization include Redmine::I18n @@ -15,7 +17,7 @@ class AdditionalsChart end # build return value - def build_chart_data(datasets, options = {}) + def build_chart_data(datasets, **options) cached_labels = labels data = { datasets: datasets.to_json, labels: cached_labels.keys, @@ -23,13 +25,13 @@ class AdditionalsChart required_labels = options.key?(:required_labels) ? options.delete(:required_labels) : 2 - data[:valid] = cached_labels.any? && cached_labels.count >= required_labels unless options.key?(:valid) - data[:width] = self::CHART_DEFAULT_WIDTH unless options.key?(:width) - data[:height] = self::CHART_DEFAULT_HEIGHT unless options.key?(:height) - data[:value_link_method] = '_project_issues_path' unless options.key?(:value_link_method) + data[:valid] = cached_labels.any? && cached_labels.count >= required_labels unless options.key? :valid + data[:width] = self::CHART_DEFAULT_WIDTH unless options.key? :width + data[:height] = self::CHART_DEFAULT_HEIGHT unless options.key? :height + data[:value_link_method] = '_project_issues_path' unless options.key? :value_link_method data[:color_schema] = color_schema - data.merge(options) + data.merge options end private @@ -37,7 +39,7 @@ class AdditionalsChart def build_values_without_gaps(data, gap_value = 0) values = [] labels.each do |label, _label_id| - values << if data.key?(label) + values << if data.key? label data[label] else gap_value diff --git a/app/models/additionals_font_awesome.rb b/app/models/additionals_font_awesome.rb index a1e16221..b95c3837 100644 --- a/app/models/additionals_font_awesome.rb +++ b/app/models/additionals_font_awesome.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AdditionalsFontAwesome include Redmine::I18n @@ -9,7 +11,7 @@ class AdditionalsFontAwesome data = YAML.safe_load(ERB.new(IO.read(File.join(Additionals.plugin_dir, 'config', 'fontawesome_icons.yml'))).result) || {} icons = {} data.each do |key, values| - icons[key] = { unicode: values['unicode'], label: values['label'] } if values['styles'].include?(convert_type2style(type)) + icons[key] = { unicode: values['unicode'], label: values['label'] } if values['styles'].include? convert_type2style(type) end icons end @@ -48,7 +50,7 @@ class AdditionalsFontAwesome end def classes(value) - info = value_info(value) + info = value_info value return '' if info.blank? info[:classes] @@ -65,27 +67,27 @@ class AdditionalsFontAwesome # show only one value as current selected # (all other options are retrieved by select2 def active_option_for_select(selected) - info = value_info(selected, with_details: true) + info = value_info selected, with_details: true return [] if info.blank? [[info[:label], selected]] end - def value_info(value, options = {}) + def value_info(value, with_details: false) return {} if value.blank? - values = value.split('_') + values = value.split '_' return {} unless values.count == 2 info = { type: values[0].to_sym, name: "fa-#{values[1]}" } info[:classes] = "#{info[:type]} #{info[:name]}" - info[:font_weight] = font_weight(info[:type]) - info[:font_family] = font_family(info[:type]) + info[:font_weight] = font_weight info[:type] + info[:font_family] = font_family info[:type] - if options[:with_details] - info.merge!(load_details(info[:type], values[1])) + if with_details + info.merge! load_details(info[:type], values[1]) return {} if info[:unicode].blank? end @@ -94,12 +96,12 @@ class AdditionalsFontAwesome def search_for_select(search, selected = nil) # could be more then one - selected_store = selected.to_s.split(',') - icons = search_in_type(:far, search, selected_store) + selected_store = selected.to_s.split ',' + icons = search_in_type :far, search, selected_store cnt = icons.count return icons if cnt >= SEARCH_LIMIT - icons += search_in_type(:fas, search, selected_store, cnt) + icons += search_in_type :fas, search, selected_store, cnt cnt = icons.count return icons if cnt >= SEARCH_LIMIT @@ -109,7 +111,7 @@ class AdditionalsFontAwesome def convert2mermaid(icon) return if icon.blank? - parts = icon.split('_') + parts = icon.split '_' return unless parts.count == 2 "#{parts.first}:fa-#{parts.last}" @@ -125,7 +127,7 @@ class AdditionalsFontAwesome search[0].downcase elsif search_length.zero? && selected_store.any? selected = selected_store.first - fa = selected.split('_') + fa = selected.split '_' search = fa[1][0] if fa.count > 1 search end @@ -147,7 +149,7 @@ class AdditionalsFontAwesome end def load_details(type, name) - return {} unless FONTAWESOME_ICONS.key?(type) + return {} unless FONTAWESOME_ICONS.key? type values = FONTAWESOME_ICONS[type][name] return {} if values.blank? diff --git a/app/models/additionals_import.rb b/app/models/additionals_import.rb index f8d31a84..ebaf3c73 100644 --- a/app/models/additionals_import.rb +++ b/app/models/additionals_import.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class AdditionalsImport < Import class_attribute :import_class # Returns the objects that were imported def saved_objects - object_ids = saved_items.pluck(:obj_id) + object_ids = saved_items.pluck :obj_id import_class.where(id: object_ids).order(:id) end @@ -24,17 +26,17 @@ class AdditionalsImport < Import object.custom_field_values.each_with_object({}) do |v, h| value = case v.custom_field.field_format when 'date' - row_date(row, "cf_#{v.custom_field.id}") + row_date row, "cf_#{v.custom_field.id}" else - row_value(row, "cf_#{v.custom_field.id}") + row_value row, "cf_#{v.custom_field.id}" end next unless value h[v.custom_field.id.to_s] = if value.is_a? Array - value.map { |val| v.custom_field.value_from_keyword(val.strip, object) }.flatten!&.compact + value.map { |val| v.custom_field.value_from_keyword val.strip, object }.flatten!&.compact else - v.custom_field.value_from_keyword(value, object) + v.custom_field.value_from_keyword value, object end end end diff --git a/app/models/additionals_info.rb b/app/models/additionals_info.rb index b4691b36..d83c9320 100644 --- a/app/models/additionals_info.rb +++ b/app/models/additionals_info.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AdditionalsInfo include Redmine::I18n @@ -43,11 +45,11 @@ class AdditionalsInfo days = (secs / 86_400).round end if days >= 1 - "#{days} #{l(:days, count: days)}" + "#{days} #{l :days, count: days}" elsif hours >= 1 - "#{hours} #{l(:hours, count: hours)}" + "#{hours} #{l :hours, count: hours}" else - "#{min} #{l(:minutes, count: min)}" + "#{min} #{l :minutes, count: min}" end else # this should be work on macOS @@ -61,7 +63,7 @@ class AdditionalsInfo end else days = `uptime | awk '{print $3}'`.to_i.round - "#{days} #{l(:days, count: days)}" + "#{days} #{l :days, count: days}" end end end diff --git a/app/models/additionals_journal.rb b/app/models/additionals_journal.rb index e6cc2555..7a60b1e6 100644 --- a/app/models/additionals_journal.rb +++ b/app/models/additionals_journal.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AdditionalsJournal class << self def save_journal_history(journal, prop_key, ids_old, ids) @@ -6,7 +8,7 @@ class AdditionalsJournal ids_all.each do |id| next if ids_old.include?(id) && ids.include?(id) - if ids.include?(id) + if ids.include? id value = id old_value = nil else @@ -29,10 +31,10 @@ class AdditionalsJournal new_entries = entries.select { |entry| entry.id.blank? } return true if new_entries.blank? - new_entries.map! { |entry| entry.send(entry_id) } + new_entries.map! { |entry| entry.send entry_id } return false if new_entries.count != new_entries.uniq.count - old_entries.map! { |entry| entry.send(entry_id) } + old_entries.map! { |entry| entry.send entry_id } return false unless (old_entries & new_entries).count.zero? true diff --git a/app/models/additionals_macro.rb b/app/models/additionals_macro.rb index b571892d..2a8c3690 100644 --- a/app/models/additionals_macro.rb +++ b/app/models/additionals_macro.rb @@ -1,75 +1,81 @@ +# frozen_string_literal: true + class AdditionalsMacro - def self.all(options = {}) - all = Redmine::WikiFormatting::Macros.available_macros - macros = {} - macro_list = [] + class << self + def all(only_names: false, filtered: [], controller_only: nil) + all = Redmine::WikiFormatting::Macros.available_macros + macros = {} + macro_list = [] - # needs to run every request (for each user once) - permissions = build_permissions(options) + # needs to run every request (for each user once) + permissions = build_permissions controller_only: controller_only - if options[:filtered].present? - options[:filtered] << 'hello_world' - else - options[:filtered] = ['hello_world'] + if filtered.present? + filtered << 'hello_world' + else + filtered = ['hello_world'] + end + + all.each do |macro, macro_options| + next if filtered.include? macro.to_s + next unless macro_allowed macro, permissions + + macro_list << macro.to_s + macros[macro] = macro_options + end + + if only_names + macro_list.sort + else + macros.sort + end end - all.each do |macro, macro_options| - next if options[:filtered].include?(macro.to_s) - next unless macro_allowed(macro, permissions) + private - macro_list << macro.to_s - macros[macro] = macro_options + def macro_allowed(macro, permissions) + permissions.each do |permission| + next if permission[:list].exclude? macro + return false unless permission[:access] + end + + true end - if options[:only_names] - macro_list.sort - else - macros.sort - end - end + def build_permissions(controller_only: nil) + gpermission = [] + macro_permissions.each do |permission| + permission[:access] = if controller_only && + permission[:controller].present? && + controller_only.to_sym != permission[:controller] + false + else + User.current.allowed_to? permission[:permission], nil, global: true + end + gpermission << permission + end - def self.macro_allowed(macro, permissions) - permissions.each do |permission| - next if permission[:list].exclude?(macro) - return false unless permission[:access] + gpermission end - true - end - - def self.build_permissions(options) - gpermission = [] - macro_permissions.each do |permission| - permission[:access] = if options[:controller_only] && - permission[:controller].present? && - options[:controller_only].to_sym != permission[:controller] - false - else - User.current.allowed_to?(permission[:permission], nil, global: true) - end - gpermission << permission + def macro_permissions + [{ list: %i[issue issue_name_link], + permission: :view_issues }, + { list: %i[password password_query password_tag password_tag_count], + permission: :view_passwords }, + { list: %i[contact deal contact_avatar contact_note contact_plain], + permission: :view_contacts }, + { list: %i[db db_query db_tag db_tag_count], + permission: :view_db_entries }, + { list: %i[child_pages last_updated_at last_updated_by lastupdated_at lastupdated_by + new_page recently_updated recent comments comment_form tags taggedpages tagcloud + show_count count vote show_vote terms_accept terms_reject], + permission: :view_wiki_pages, + controller: :wiki }, + { list: %i[mail send_file], + permission: :view_helpdesk_tickets }, + { list: %i[kb article_id article category], + permission: :view_kb_articles }] end - - gpermission - end - - def self.macro_permissions - [{ list: %i[issue issue_name_link], - permission: :view_issues }, - { list: %i[password password_query password_tag password_tag_count], - permission: :view_passwords }, - { list: %i[contact deal contact_avatar contact_note contact_plain], - permission: :view_contacts }, - { list: %i[db db_query db_tag db_tag_count], - permission: :view_db_entries }, - { list: %i[child_pages last_updated_at last_updated_by lastupdated_at lastupdated_by - new_page recently_updated recent comments comment_form tags taggedpages tagcloud - show_count count vote show_vote terms_accept terms_reject], - permission: :view_wiki_pages, - controller: :wiki }, - { list: %i[mail send_file], - permission: :view_helpdesk_tickets }, - { list: %i[kb article_id article category], - permission: :view_kb_articles }] end end diff --git a/app/models/additionals_query.rb b/app/models/additionals_query.rb index 8c3ccfa2..258fb3cf 100644 --- a/app/models/additionals_query.rb +++ b/app/models/additionals_query.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + module AdditionalsQuery def column_with_prefix?(prefix) - columns.detect { |c| c.name.to_s.start_with?("#{prefix}.") }.present? + columns.detect { |c| c.name.to_s.start_with? "#{prefix}." }.present? end - def available_column_names(options = {}) + def available_column_names(only_sortable: false) names = available_columns.dup names.flatten! - names.select! { |col| col.sortable.present? } if options[:only_sortable] + names.select! { |col| col.sortable.present? } if only_sortable names.map(&:name) end def sql_for_enabled_module(table_field, module_names) - module_names = Array(module_names) + module_names = Array module_names sql = [] module_names.each do |module_name| @@ -19,7 +21,7 @@ module AdditionalsQuery " AND #{EnabledModule.table_name}.name='#{module_name}')" end - sql.join(' AND ') + sql.join ' AND ' end def fix_sql_for_text_field(field, operator, value, table_name = nil, target_field = nil) @@ -27,15 +29,15 @@ module AdditionalsQuery target_field = field if target_field.blank? sql = [] - sql << "(#{sql_for_field(field, operator, value, table_name, target_field)})" + sql << "(#{sql_for_field field, operator, value, table_name, target_field})" sql << "#{table_name}.#{target_field} != ''" if operator == '*' - sql.join(' AND ') + sql.join ' AND ' end - def initialize_ids_filter(options = {}) - if options[:label] - add_available_filter 'ids', type: :integer, label: options[:label] + def initialize_ids_filter(label: nil) + if label + add_available_filter 'ids', type: :integer, label: label else add_available_filter 'ids', type: :integer, name: '#' end @@ -82,35 +84,29 @@ module AdditionalsQuery values: -> { project_statuses_values } end - def initialize_project_filter(options = {}) - if project.nil? || options[:always] - add_available_filter 'project_id', order: options[:position], + def initialize_project_filter(always: false, position: nil) + if project.nil? || always + add_available_filter 'project_id', order: position, type: :list, values: -> { project_values } end return if project.nil? || project.leaf? || subproject_values.empty? - add_available_filter 'subproject_id', order: options[:position], + add_available_filter 'subproject_id', order: position, type: :list_subprojects, values: -> { subproject_values } end - def initialize_created_filter(options = {}) - add_available_filter 'created_on', order: options[:position], + def initialize_created_filter(position: nil, label: nil) + add_available_filter 'created_on', order: position, type: :date_past, - label: options[:label].presence + label: label end - def initialize_updated_filter(options = {}) - add_available_filter 'updated_on', order: options[:position], + def initialize_updated_filter(position: nil, label: nil) + add_available_filter 'updated_on', order: position, type: :date_past, - label: options[:label].presence - end - - def initialize_tags_filter(options = {}) - add_available_filter 'tags', order: options[:position], - type: :list_optional, - values: -> { tag_values(project) } + label: label end def initialize_approved_filter @@ -123,38 +119,26 @@ module AdditionalsQuery label: :field_approved end - def initialize_author_filter(options = {}) - add_available_filter 'author_id', order: options[:position], + def initialize_author_filter(position: nil) + add_available_filter 'author_id', order: position, type: :list_optional, values: -> { author_values } end - def initialize_assignee_filter(options = {}) - add_available_filter 'assigned_to_id', order: options[:position], + def initialize_assignee_filter(position: nil) + add_available_filter 'assigned_to_id', order: position, type: :list_optional, values: -> { assigned_to_all_values } end - def initialize_watcher_filter(options = {}) + def initialize_watcher_filter(position: nil) return unless User.current.logged? - add_available_filter 'watcher_id', order: options[:position], + add_available_filter 'watcher_id', order: position, type: :list, values: -> { watcher_values_for_manage_public_queries } end - def tag_values(project) - values = if project - queried_class.available_tags project: project.id - else - queried_class.available_tags - end - - return [] if values.blank? - - values.collect { |t| [t.name, t.name] } - end - # issue independend values. Use assigned_to_values from Redmine, if you want it only for issues def assigned_to_all_values assigned_to_values = [] @@ -168,7 +152,7 @@ module AdditionalsQuery # and with users (not groups) def watcher_values_for_manage_public_queries watcher_values = [["<< #{l :label_me} >>", 'me']] - watcher_values += users.collect { |s| [s.name, s.id.to_s] } if User.current.allowed_to?(:manage_public_queries, project, global: true) + watcher_values += users.collect { |s| [s.name, s.id.to_s] } if User.current.allowed_to? :manage_public_queries, project, global: true watcher_values end @@ -181,12 +165,8 @@ module AdditionalsQuery " #{sql_for_field field, '=', value, db_table, 'user_id'})" end - def sql_for_tags_field(field, _operator, value) - AdditionalTags.sql_for_tags_field queried_class, operator_for(field), value - end - def sql_for_is_private_field(_field, operator, value) - if bool_operator(operator, value) + if bool_operator operator, value return '' if value.count > 1 "#{queried_table_name}.is_private = #{self.class.connection.quoted_true}" @@ -215,10 +195,10 @@ module AdditionalsQuery raise ::Query::StatementInvalid, e.message end - def results_scope(options = {}) + def results_scope(**options) order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten!.to_a.reject(&:blank?) - objects_scope(options) + objects_scope(**options.except(:order, :limit, :offset)) .order(order_option) .joins(joins_for_order_statement(order_option.join(','))) .limit(options[:limit]) diff --git a/app/models/dashboard.rb b/app/models/dashboard.rb index 41b5efe5..2a5b9977 100644 --- a/app/models/dashboard.rb +++ b/app/models/dashboard.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Dashboard < ActiveRecord::Base include Redmine::I18n include Redmine::SafeAttributes @@ -22,10 +24,10 @@ class Dashboard < ActiveRecord::Base VISIBILITY_ROLES = 1 VISIBILITY_PUBLIC = 2 - scope :by_project, (->(project_id) { where(project_id: project_id) if project_id.present? }) - scope :sorted, (-> { order("#{Dashboard.table_name}.name") }) - scope :welcome_only, (-> { where(dashboard_type: DashboardContentWelcome::TYPE_NAME) }) - scope :project_only, (-> { where(dashboard_type: DashboardContentProject::TYPE_NAME) }) + scope :by_project, (->(project_id) { where project_id: project_id if project_id.present? }) + scope :sorted, (-> { order "#{Dashboard.table_name}.name" }) + scope :welcome_only, (-> { where dashboard_type: DashboardContentWelcome::TYPE_NAME }) + scope :project_only, (-> { where dashboard_type: DashboardContentProject::TYPE_NAME }) safe_attributes 'name', 'description', 'enable_sidebar', 'always_expose', 'project_id', 'author_id', @@ -47,7 +49,7 @@ class Dashboard < ActiveRecord::Base safe_attributes 'system_default', if: (lambda do |dashboard, user| - user.allowed_to?(:set_system_dashboards, dashboard.project, global: true) + user.allowed_to? :set_system_dashboards, dashboard.project, global: true end) before_save :dashboard_type_check, :visibility_check, :set_options_hash, :clear_unused_block_settings @@ -73,10 +75,10 @@ class Dashboard < ActiveRecord::Base def default(dashboard_type, project = nil, user = User.current) recently_id = User.current.pref.recently_used_dashboard dashboard_type, project - scope = where(dashboard_type: dashboard_type) + scope = where dashboard_type: dashboard_type scope = scope.where(project_id: project.id).or(scope.where(project_id: nil)) if project.present? - dashboard = scope.visible.find_by(id: recently_id) if recently_id.present? + dashboard = scope.visible.find_by id: recently_id if recently_id.present? if dashboard.blank? scope = scope.where(system_default: true).or(scope.where(author_id: user.id)) @@ -86,7 +88,7 @@ class Dashboard < ActiveRecord::Base Rails.logger.debug 'default cleanup required' # Remove invalid recently_id if project.present? - User.current.pref.recently_used_dashboards[dashboard_type].delete(project.id) + User.current.pref.recently_used_dashboards[dashboard_type].delete project.id else User.current.pref.recently_used_dashboards[dashboard_type] = nil end @@ -101,7 +103,7 @@ class Dashboard < ActiveRecord::Base ["#{table}.name"] end - def visible(user = User.current, options = {}) + def visible(user = User.current, **options) scope = left_outer_joins :project scope = scope.where(projects: { id: nil }).or(scope.where(Project.allowed_to_condition(user, :view_project, options))) @@ -152,7 +154,7 @@ class Dashboard < ActiveRecord::Base super else h = (self[:options] || {}).dup - h.update(attr_name => value) + h.update attr_name => value self[:options] = h value end @@ -236,7 +238,7 @@ class Dashboard < ActiveRecord::Base return if content.groups.exclude?(group) || blocks.blank? blocks = blocks.map(&:underscore) & layout.values.flatten - blocks.each { |block| remove_block(block) } + blocks.each { |block| remove_block block } layout[group] = blocks end @@ -261,7 +263,7 @@ class Dashboard < ActiveRecord::Base end def editable?(usr = User.current) - @editable ||= editable_by?(usr) + @editable ||= editable_by? usr end def destroyable_by?(usr = User.current) @@ -274,7 +276,7 @@ class Dashboard < ActiveRecord::Base end def destroyable? - @destroyable ||= destroyable_by?(User.current) + @destroyable ||= destroyable_by? User.current end def to_s @@ -285,7 +287,7 @@ class Dashboard < ActiveRecord::Base def css_classes(user = User.current) s = ['dashboard'] s << 'created-by-me' if author_id == user.id - s.join(' ') + s.join ' ' end def allowed_target_projects(user = User.current) @@ -293,7 +295,7 @@ class Dashboard < ActiveRecord::Base end # this is used to get unique cache for blocks - def async_params(block, options, settings = {}) + def async_params(block, options, settings) if block.blank? msg = 'block is missing for dashboard_async' Rails.log.error msg @@ -326,7 +328,7 @@ class Dashboard < ActiveRecord::Base unique_params += options[:unique_params].reject(&:blank?) if options[:unique_params].present? # Rails.logger.debug "debug async_params for #{block}: unique_params=#{unique_params.inspect}" - config[:unique_key] = Digest::SHA256.hexdigest(unique_params.join('_')) + config[:unique_key] = Digest::SHA256.hexdigest unique_params.join('_') end # Rails.logger.debug "debug async_params for #{block}: config=#{config.inspect}" @@ -345,7 +347,7 @@ class Dashboard < ActiveRecord::Base def clear_unused_block_settings blocks = layout.values.flatten - layout_settings.keep_if { |block, _settings| blocks.include?(block) } + layout_settings.keep_if { |block, _settings| blocks.include? block } end def remove_unused_role_relations @@ -391,7 +393,7 @@ class Dashboard < ActiveRecord::Base .where(dashboard_type: dashboard_type) .where.not(id: id) - scope = scope.where(project: project) if dashboard_type == DashboardContentProject::TYPE_NAME + scope = scope.where project: project if dashboard_type == DashboardContentProject::TYPE_NAME scope.update_all system_default: false end @@ -409,22 +411,22 @@ class Dashboard < ActiveRecord::Base end def validate_visibility - errors.add(:visibility, :must_be_for_everyone) if system_default? && visibility != VISIBILITY_PUBLIC + errors.add :visibility, :must_be_for_everyone if system_default? && visibility != VISIBILITY_PUBLIC end def validate_name return if name.blank? - scope = self.class.visible.where(name: name) + scope = self.class.visible.where name: name if dashboard_type == DashboardContentProject::TYPE_NAME scope = scope.project_only scope = scope.where project_id: project_id - scope = scope.or(scope.where(project_id: nil)) if project_id.present? + scope = scope.or scope.where(project_id: nil) if project_id.present? else scope = scope.welcome_only end - scope = scope.where.not(id: id) unless new_record? - errors.add(:name, :name_not_unique) if scope.count.positive? + scope = scope.where.not id: id unless new_record? + errors.add :name, :name_not_unique if scope.count.positive? end end diff --git a/app/models/dashboard_content.rb b/app/models/dashboard_content.rb index b8af53d9..635ea6ee 100644 --- a/app/models/dashboard_content.rb +++ b/app/models/dashboard_content.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DashboardContent include Redmine::I18n @@ -100,7 +102,7 @@ class DashboardContent def find_block(block) block.to_s =~ /\A(.*?)(__\d+)?\z/ - name = Regexp.last_match(1) + name = Regexp.last_match 1 available_blocks.key?(name) ? available_blocks[name].merge(name: name) : nil end diff --git a/app/models/dashboard_content_project.rb b/app/models/dashboard_content_project.rb index 9884135c..fdc759f3 100644 --- a/app/models/dashboard_content_project.rb +++ b/app/models/dashboard_content_project.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class DashboardContentProject < DashboardContent - TYPE_NAME = 'ProjectDashboard'.freeze + TYPE_NAME = 'ProjectDashboard' def block_definitions blocks = super diff --git a/app/models/dashboard_content_welcome.rb b/app/models/dashboard_content_welcome.rb index 0074c559..0c4f2439 100644 --- a/app/models/dashboard_content_welcome.rb +++ b/app/models/dashboard_content_welcome.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class DashboardContentWelcome < DashboardContent - TYPE_NAME = 'WelcomeDashboard'.freeze + TYPE_NAME = 'WelcomeDashboard' def block_definitions blocks = super diff --git a/app/models/dashboard_role.rb b/app/models/dashboard_role.rb index f174f503..12dc520b 100644 --- a/app/models/dashboard_role.rb +++ b/app/models/dashboard_role.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DashboardRole < ActiveRecord::Base include Redmine::SafeAttributes diff --git a/app/overrides/admin/info.rb b/app/overrides/admin/info.rb index 184aa6d4..9dbca9ca 100644 --- a/app/overrides/admin/info.rb +++ b/app/overrides/admin/info.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'admin/info', name: 'add-system_info', insert_after: 'table.list', diff --git a/app/overrides/contacts/form.rb b/app/overrides/contacts/form.rb index 364e0bfc..3c6ff047 100644 --- a/app/overrides/contacts/form.rb +++ b/app/overrides/contacts/form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + unless Redmine::Plugin.installed? 'redmine_servicedesk' if defined?(CONTACTS_VERSION_TYPE) && CONTACTS_VERSION_TYPE == 'PRO version' Deface::Override.new virtual_path: 'contacts/_form', diff --git a/app/overrides/custom_fields/formats.rb b/app/overrides/custom_fields/formats.rb index cc8014c0..3d465629 100644 --- a/app/overrides/custom_fields/formats.rb +++ b/app/overrides/custom_fields/formats.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'custom_fields/formats/_text', name: 'custom_fields-formats-text', replace: 'erb[silent]:contains(\'if @custom_field.class.name == "IssueCustomField"\')', diff --git a/app/overrides/issues/edit.rb b/app/overrides/issues/edit.rb index 3cf7ae6e..d5b6ca02 100644 --- a/app/overrides/issues/edit.rb +++ b/app/overrides/issues/edit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'issues/_edit', name: 'edit-issue-permission', replace: 'erb[silent]:contains("User.current.allowed_to?(:log_time, @project)")', diff --git a/app/overrides/issues/list.rb b/app/overrides/issues/list.rb index 013f1650..216fe85b 100644 --- a/app/overrides/issues/list.rb +++ b/app/overrides/issues/list.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'issues/_list', name: 'list-issue-back-url', replace: 'erb[loud]:contains("hidden_field_tag \'back_url\'")', diff --git a/app/overrides/issues/show.rb b/app/overrides/issues/show.rb index bf9964b2..7fb774d1 100644 --- a/app/overrides/issues/show.rb +++ b/app/overrides/issues/show.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'issues/_action_menu', name: 'show-issue-log-time', replace: 'erb[loud]:contains("User.current.allowed_to?(:log_time, @project)")', diff --git a/app/overrides/reports/simple.rb b/app/overrides/reports/simple.rb index 12cb3adb..38f62e4e 100644 --- a/app/overrides/reports/simple.rb +++ b/app/overrides/reports/simple.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'reports/_simple', name: 'report-simple-user-scope', insert_before: 'erb[silent]:contains("rows.empty?")', diff --git a/app/overrides/roles/form.rb b/app/overrides/roles/form.rb index 163f3fe6..46cdb226 100644 --- a/app/overrides/roles/form.rb +++ b/app/overrides/roles/form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'roles/_form', name: 'roles-form-hide', insert_before: 'p.manage_members_shown', diff --git a/app/overrides/users/show.rb b/app/overrides/users/show.rb index c5d829be..8abc185d 100644 --- a/app/overrides/users/show.rb +++ b/app/overrides/users/show.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + unless Redmine::Plugin.installed? 'redmine_hrm' if Redmine::VERSION.to_s >= '4.2' Deface::Override.new virtual_path: 'users/show', diff --git a/app/overrides/wiki/edit.rb b/app/overrides/wiki/edit.rb index ae9be749..dc524b5a 100644 --- a/app/overrides/wiki/edit.rb +++ b/app/overrides/wiki/edit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'wiki/edit', name: 'wiki-edit-bottom', insert_before: 'fieldset', diff --git a/app/overrides/wiki/show.rb b/app/overrides/wiki/show.rb index bb13ae00..2cdacabe 100644 --- a/app/overrides/wiki/show.rb +++ b/app/overrides/wiki/show.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Deface::Override.new virtual_path: 'wiki/show', name: 'wiki-show-bottom', insert_before: 'p.wiki-update-info', diff --git a/app/views/additionals/_export_options.html.slim b/app/views/additionals/_export_options.html.slim index 2f87e45d..12be6b4c 100644 --- a/app/views/additionals/_export_options.html.slim +++ b/app/views/additionals/_export_options.html.slim @@ -1,32 +1,32 @@ div id="#{export_format}-export-options" style="display: none" - h3.title = l(:label_export_options, export_format: export_format.upcase) + h3.title = l :label_export_options, export_format: export_format.upcase - = form_tag(url, method: :get, id: "#{export_format}-export-form") do + = form_tag url, method: :get, id: "#{export_format}-export-form" do = query_as_hidden_field_tags @query - if defined?(selected_columns_only) && selected_columns_only = hidden_field_tag 'c[]', '' - = l(:description_selected_columns) + = l :description_selected_columns - else p label = radio_button_tag 'c[]', '', true - = l(:description_selected_columns) + = l :description_selected_columns br label = radio_button_tag 'c[]', 'all_inline' - = l(:description_all_columns) + = l :description_all_columns hr - - if @query.available_filters.key?('description') + - if @query.available_filters.key? 'description' p label = check_box_tag 'c[]', 'description', @query.has_column?(:description) - = l(:field_description) + = l :field_description - if defined?(with_last_notes) && with_last_notes label = check_box_tag 'c[]', 'last_notes', @query.has_column?(:last_notes) - = l(:label_last_notes) + = l :label_last_notes = export_csv_encoding_select_tag diff --git a/app/views/additionals/_settings_list_defaults.html.slim b/app/views/additionals/_settings_list_defaults.html.slim index bbde5410..032c9c9c 100644 --- a/app/views/additionals/_settings_list_defaults.html.slim +++ b/app/views/additionals/_settings_list_defaults.html.slim @@ -1,18 +1,18 @@ fieldset.box - legend = l(:additionals_query_list_defaults) + legend = l :additionals_query_list_defaults - setting_name_columns = "#{query_type}_list_defaults" - - query = query_class.new(@settings[setting_name_columns.to_sym]) + - query = query_class.new @settings[setting_name_columns.to_sym] .default-query-settings-label - = render_query_columns_selection(query, name: "settings[#{setting_name_columns}][column_names]") + = render_query_columns_selection query, name: "settings[#{setting_name_columns}][column_names]" - columns = query_class.new.available_totalable_columns - if columns.count.positive? fieldset.box - legend = l(:additionals_query_list_default_totals) + legend = l :additionals_query_list_default_totals .default-query-settings-totals - setting_name_totals = "#{query_type}_list_default_totals" - = hidden_field_tag("settings[#{setting_name_totals}][]", '') + = hidden_field_tag "settings[#{setting_name_totals}][]", '' - columns.each do |s| label.inline - value = @settings[setting_name_totals.to_sym].present? ? @settings[setting_name_totals.to_sym].include?(s.name.to_s) : false diff --git a/app/views/additionals/settings/_general.html.slim b/app/views/additionals/settings/_general.html.slim index 1fb0d72f..0abeb5a3 100644 --- a/app/views/additionals/settings/_general.html.slim +++ b/app/views/additionals/settings/_general.html.slim @@ -1,47 +1,47 @@ fieldset.settings - legend = l(:label_content_plural) + legend = l :label_content_plural p = additionals_settings_textarea :account_login_bottom em.info - = l(:account_login_info) + = l :account_login_info p = additionals_settings_textarea :global_sidebar em.info - = l(:global_sidebar_info) + = l :global_sidebar_info p = additionals_settings_textarea :global_footer em.info - = l(:global_footer_info) + = l :global_footer_info fieldset.settings - legend = l(:label_settings) + legend = l :label_settings p = additionals_settings_checkbox :open_external_urls em.info - = t(:open_external_urls_info) + = t :open_external_urls_info p = additionals_settings_checkbox :add_go_to_top em.info - = t(:add_go_to_top_info) + = t :add_go_to_top_info p = additionals_settings_checkbox :legacy_smiley_support em.info - = t(:legacy_smiley_support_info_html) + = t :legacy_smiley_support_info_html fieldset.settings - legend = l(:label_disabled_modules) + legend = l :label_disabled_modules p = tag.label l(:label_disabled_modules) - = hidden_field_tag('settings[disabled_modules][]', '') + = hidden_field_tag 'settings[disabled_modules][]', '' - Redmine::AccessControl.available_project_modules_all.sort.each do |m| label.block - value = @settings[:disabled_modules].present? ? @settings[:disabled_modules].include?(m.to_s) : false - = check_box_tag('settings[disabled_modules][]', m, value, id: nil) - = l_or_humanize(m, prefix: 'project_module_') + = check_box_tag 'settings[disabled_modules][]', m, value, id: nil + = l_or_humanize m, prefix: 'project_module_' br em.info - = l(:disabled_modules_info) + = l :disabled_modules_info diff --git a/app/views/additionals/settings/_issues.html.slim b/app/views/additionals/settings/_issues.html.slim index 495db56b..7b13fcb6 100644 --- a/app/views/additionals/settings/_issues.html.slim +++ b/app/views/additionals/settings/_issues.html.slim @@ -38,7 +38,7 @@ p options_for_select(rule_status.collect { |column| [column.name, column.id] }, @settings[:issue_status_y]), multiple: false, style: 'width:150px; vertical-align: top' -em.info = t(:rule_issue_status_change_info) +em.info = t :rule_issue_status_change_info br br @@ -51,7 +51,7 @@ p options_for_select(rule_status.collect { |column| [column.name, column.id] }, @settings[:issue_assign_to_x]), multiple: true, size: 6, style: 'width:150px' -em.info = t(:rule_issue_current_user_status_info_html) +em.info = t :rule_issue_current_user_status_info_html br br @@ -77,7 +77,7 @@ br p = additionals_settings_checkbox :issue_timelog_required span[style="vertical-align: top; margin-left: 15px;"] - = l(:label_tracker_plural) + = l :label_tracker_plural | : = select_tag 'settings[issue_timelog_required_tracker]', options_for_select(Tracker.all.sorted.collect { |column| [column.name, column.id] }, diff --git a/app/views/additionals/settings/_macros.html.slim b/app/views/additionals/settings/_macros.html.slim index bfa0ed4c..61cacc0c 100644 --- a/app/views/additionals/settings/_macros.html.slim +++ b/app/views/additionals/settings/_macros.html.slim @@ -1,15 +1,15 @@ em.info - = l(:hidden_macros_in_toolbar_info) + = l :hidden_macros_in_toolbar_info br p = tag.label l(:label_hidden_macros_in_toolbar) - = hidden_field_tag('settings[hidden_macros_in_toolbar][]', '') + = hidden_field_tag 'settings[hidden_macros_in_toolbar][]', '' - @available_macros = AdditionalsMacro.all(only_names: true).each do |m| label.block - value = @settings[:hidden_macros_in_toolbar].present? ? @settings[:hidden_macros_in_toolbar].include?(m) : false - = check_box_tag('settings[hidden_macros_in_toolbar][]', m, value, id: nil) + = check_box_tag 'settings[hidden_macros_in_toolbar][]', m, value, id: nil = m br diff --git a/app/views/additionals/settings/_menu.html.slim b/app/views/additionals/settings/_menu.html.slim index 009bd3bf..da73b4a0 100644 --- a/app/views/additionals/settings/_menu.html.slim +++ b/app/views/additionals/settings/_menu.html.slim @@ -20,14 +20,14 @@ h3 = l :label_custom_menu_items p label = h l(:label_permissions) - permission_field = "custom_menu#{i}_roles" - - menu_roles = Struct.new(:id, :name) + - menu_roles = Struct.new :id, :name = select_tag("settings[#{permission_field}]", - options_from_collection_for_select(Role.sorted.collect { |m| menu_roles.new(m.id, m.name) }, + options_from_collection_for_select(Role.sorted.collect { |m| menu_roles.new m.id, m.name }, :id, :name, @settings[permission_field]), multiple: true, style: 'height: 100px;') - em.info = l(:menu_roles_info) + em.info = l :menu_roles_info br diff --git a/app/views/additionals/settings/_web_apis.html.slim b/app/views/additionals/settings/_web_apis.html.slim index ef6ea346..643f50c3 100644 --- a/app/views/additionals/settings/_web_apis.html.slim +++ b/app/views/additionals/settings/_web_apis.html.slim @@ -1,5 +1,5 @@ p = additionals_settings_textfield :google_maps_api_key, size: 60 - em.info = t(:google_maps_embed_api_html) + em.info = t :google_maps_embed_api_html = call_hook :additionals_settings_web_apis, settings: @settings diff --git a/app/views/additionals/settings/_wiki.html.slim b/app/views/additionals/settings/_wiki.html.slim index f88d94b9..292bae36 100644 --- a/app/views/additionals/settings/_wiki.html.slim +++ b/app/views/additionals/settings/_wiki.html.slim @@ -1,23 +1,23 @@ -em.info = t(:top_wiki_help) +em.info = t :top_wiki_help br fieldset.settings - legend = l(:label_content_plural) + legend = l :label_content_plural p = additionals_settings_textarea :global_wiki_sidebar em.info - = l(:global_wiki_sidebar_info) + = l :global_wiki_sidebar_info fieldset.settings - legend = l(:label_pdf_wiki_settings) + legend = l :label_pdf_wiki_settings p = additionals_settings_checkbox :wiki_pdf_remove_title em.info - = l(:wiki_pdf_remove_title_info) + = l :wiki_pdf_remove_title_info p = additionals_settings_checkbox :wiki_pdf_remove_attachments em.info - = l(:wiki_pdf_remove_attachments_info) + = l :wiki_pdf_remove_attachments_info diff --git a/app/views/common/_dashboard.html.slim b/app/views/common/_dashboard.html.slim index e5889c21..bade72eb 100644 --- a/app/views/common/_dashboard.html.slim +++ b/app/views/common/_dashboard.html.slim @@ -1,6 +1,6 @@ = call_hook :view_dashboard_top, dashboard: dashboard, project: @project -#my-page.splitcontent class="#{dashboard_css_classes(dashboard)}" +#my-page.splitcontent class="#{dashboard_css_classes dashboard}" - dashboard.available_groups.each do |group| .block-receiver id="list-#{group}" class="splitcontent#{group}" = render_dashboard_blocks dashboard.layout[group], dashboard diff --git a/app/views/dashboards/_form.html.slim b/app/views/dashboards/_form.html.slim index 230b427d..2a25e726 100644 --- a/app/views/dashboards/_form.html.slim +++ b/app/views/dashboards/_form.html.slim @@ -19,7 +19,7 @@ {}, disabled: !@dashboard.project_id_can_change? em.info - = l(:info_dashboard_project_select) + = l :info_dashboard_project_select - else = hidden_field_tag 'dashboard[project_id]', @project&.id @@ -27,19 +27,19 @@ User.current.allowed_to?(:set_system_dashboards, @project, global: true) p - label = l(:field_visible) + label = l :field_visible label.block = radio_button 'dashboard', 'visibility', Dashboard::VISIBILITY_PRIVATE ' - = l(:label_visibility_private) + = l :label_visibility_private label.block = radio_button 'dashboard', 'visibility', Dashboard::VISIBILITY_PUBLIC ' - = l(:label_visibility_public) + = l :label_visibility_public label.block = radio_button 'dashboard', 'visibility', Dashboard::VISIBILITY_ROLES ' - = l(:label_visibility_roles) + = l :label_visibility_roles ' : - Role.givable.sorted.each do |role| label.block.role-visibility diff --git a/app/views/dashboards/blocks/_project_information.html.slim b/app/views/dashboards/blocks/_project_information.html.slim index a9144cf1..ac9fcbb6 100644 --- a/app/views/dashboards/blocks/_project_information.html.slim +++ b/app/views/dashboards/blocks/_project_information.html.slim @@ -11,7 +11,7 @@ h3 = block_definition[:label] = l :field_homepage ' : = link_to_if uri_with_safe_scheme?(@project.homepage), @project.homepage, @project.homepage, class: 'external' - - render_custom_field_values(@project) do |custom_field, formatted| + - render_custom_field_values @project do |custom_field, formatted| li class="#{custom_field.css_classes}" span.label = custom_field.name diff --git a/app/views/dashboards/blocks/_query_list.html.slim b/app/views/dashboards/blocks/_query_list.html.slim index f1091ea7..857644de 100644 --- a/app/views/dashboards/blocks/_query_list.html.slim +++ b/app/views/dashboards/blocks/_query_list.html.slim @@ -1,6 +1,6 @@ - dashboard_async_cache dashboard, block, async, settings do - - query = klass.visible.find_by(id: settings[:query_id]) + - query = klass.visible.find_by id: settings[:query_id] - if query ruby: query.project = @project if query_block[:with_project] diff --git a/app/views/dashboards/edit.html.slim b/app/views/dashboards/edit.html.slim index acfe00ac..b46f7e99 100644 --- a/app/views/dashboards/edit.html.slim +++ b/app/views/dashboards/edit.html.slim @@ -1,4 +1,4 @@ -h2 = l(:button_dashboard_edit) +h2 = l :button_dashboard_edit = labelled_form_for :dashboard, @dashboard, html: { multipart: true, id: 'dashboard-form' } do |f| diff --git a/app/views/dashboards/new.html.slim b/app/views/dashboards/new.html.slim index 00b5b98d..d2113e37 100644 --- a/app/views/dashboards/new.html.slim +++ b/app/views/dashboards/new.html.slim @@ -1,4 +1,4 @@ -h2 = l(:label_new_additional_dashboard) +h2 = l :label_new_additional_dashboard = labelled_form_for :dashboard, @dashboard, url: { action: 'create', project_id: @project }, diff --git a/app/views/issues/_change_author.html.slim b/app/views/issues/_change_author.html.slim index d14e4403..7be99dc2 100644 --- a/app/views/issues/_change_author.html.slim +++ b/app/views/issues/_change_author.html.slim @@ -1,5 +1,5 @@ - if show_issue_change_author?(issue) && issue.safe_attribute?('author_id') - - author_options = author_options_for_select(issue.project, issue) + - author_options = author_options_for_select issue.project, issue - if author_options.present? p#change_author = form.label_for_field :author_id diff --git a/app/views/issues/_change_author_bulk.html.slim b/app/views/issues/_change_author_bulk.html.slim index 786aa2b2..33d1114a 100644 --- a/app/views/issues/_change_author_bulk.html.slim +++ b/app/views/issues/_change_author_bulk.html.slim @@ -1,7 +1,7 @@ - if @project && User.current.allowed_to?(:edit_issue_author, @project) - - author_options = author_options_for_select(@project) + - author_options = author_options_for_select @project - if author_options.present? p#change_author - = label_tag('issue[author_id]', l(:field_author)) - = select_tag('issue[author_id]', - tag.option(l(:label_no_change_option), value: '') + author_options) + = label_tag 'issue[author_id]', l(:field_author) + = select_tag 'issue[author_id]', + tag.option(l(:label_no_change_option), value: '') + author_options diff --git a/app/views/projects/show.html.slim b/app/views/projects/show.html.slim index eede53a5..d23b8383 100644 --- a/app/views/projects/show.html.slim +++ b/app/views/projects/show.html.slim @@ -16,7 +16,7 @@ = actions_dropdown do - if User.current.allowed_to? :add_subprojects, @project = link_to l(:label_subproject_new), new_project_path(parent_id: @project), class: 'icon icon-add' - - if User.current.allowed_to?(:close_project, @project) + - if User.current.allowed_to? :close_project, @project - if @project.active? = link_to l(:button_close), close_project_path(@project), @@ -46,14 +46,13 @@ class: 'icon icon-add new-additionals-dashboard' - if @dashboard&.destroyable? - = delete_dashboard_link project_dashboard_path(@project, @dashboard), - class: 'icon icon-del' + = delete_dashboard_link project_dashboard_path(@project, @dashboard) = sidebar_action_toggle @dashboard_sidebar, @dashboard, @project = render_dashboard_actionlist @dashboard, @project unless @dashboard_sidebar = call_hook :view_project_actions_dropdown, project: @project - - if User.current.allowed_to?(:edit_project, @project) + - if User.current.allowed_to? :edit_project, @project = link_to_if_authorized l(:label_settings), { controller: 'projects', action: 'settings', id: @project }, class: 'icon icon-settings' @@ -63,7 +62,7 @@ h2 = project_overview_name @project, @dashboard - unless @project.active? p.warning span.icon.icon-lock - = l(:text_project_closed) + = l :text_project_closed = render partial: 'common/dashboard', locals: { dashboard: @dashboard } diff --git a/app/views/queries/_additionals_group_view.html.slim b/app/views/queries/_additionals_group_view.html.slim index e35f9273..f57e0080 100644 --- a/app/views/queries/_additionals_group_view.html.slim +++ b/app/views/queries/_additionals_group_view.html.slim @@ -9,5 +9,5 @@ tr.group.open span.badge.badge-count.count = group_count ' span.totals = group_totals - = link_to_function("#{l :button_collapse_all}/#{l :button_expand_all}", - 'toggleAllRowGroups(this)', class: 'toggle-all') + = link_to_function "#{l :button_collapse_all}/#{l :button_expand_all}", + 'toggleAllRowGroups(this)', class: 'toggle-all' diff --git a/app/views/roles/_additionals_form.html.slim b/app/views/roles/_additionals_form.html.slim index 666966c6..06e8f424 100644 --- a/app/views/roles/_additionals_form.html.slim +++ b/app/views/roles/_additionals_form.html.slim @@ -1,7 +1,7 @@ p = f.check_box :hide, disabled: @role.users_visibility != 'members_of_visible_projects' em.info - = t(:info_hidden_roles_html) + = t :info_hidden_roles_html javascript: $(function() { diff --git a/app/views/welcome/index.html.slim b/app/views/welcome/index.html.slim index df004a24..8f711b13 100644 --- a/app/views/welcome/index.html.slim +++ b/app/views/welcome/index.html.slim @@ -18,8 +18,7 @@ new_dashboard_path, class: 'icon icon-add new-additionals-dashboard' - if @dashboard&.destroyable? - = delete_dashboard_link dashboard_path(@dashboard), - class: 'icon icon-del' + = delete_dashboard_link dashboard_path(@dashboard) = sidebar_action_toggle @dashboard_sidebar, @dashboard = render_dashboard_actionlist @dashboard unless @dashboard_sidebar diff --git a/app/views/wiki/_project_macros.html.slim b/app/views/wiki/_project_macros.html.slim index 5996112e..12ab7f45 100644 --- a/app/views/wiki/_project_macros.html.slim +++ b/app/views/wiki/_project_macros.html.slim @@ -3,7 +3,7 @@ h3 = list_title table.list.projects - - project_tree(@projects, init_level: false) do |project, level| + - project_tree @projects, init_level: false do |project, level| tr id="project-#{project.id}" class="#{project_list_css_classes project, level}" td.name span[style='font-weight: bold;'] @@ -13,7 +13,7 @@ = link_to_project project - if project.homepage? ' : - = link_to(project.homepage, project.homepage, @html_options) + = link_to project.homepage, project.homepage, @html_options - if with_create_issue && User.current.allowed_to?(:add_issues, project) = link_to '', new_project_issue_path(project_id: project), diff --git a/app/views/wiki/_user_macros.html.slim b/app/views/wiki/_user_macros.html.slim index 00ead109..087b6a01 100644 --- a/app/views/wiki/_user_macros.html.slim +++ b/app/views/wiki/_user_macros.html.slim @@ -4,7 +4,7 @@ - users.each do |user| .user.box class="#{cycle 'odd', 'even'}" div[style="float: left; display: block; margin-right: 5px;"] - = avatar(user, size: 50) + = avatar user, size: 50 .user.line[style="font-weight: bold;"] = link_to_user user diff --git a/config/routes.rb b/config/routes.rb index 9b3fa3d7..0658ac49 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do resources :issues, only: [] do resource 'assign_to_me', only: %i[update], controller: 'additionals_assign_to_me' diff --git a/contrib/refresh_chartjs_colormap.rb b/contrib/refresh_chartjs_colormap.rb index 48d1242f..5c66193c 100644 --- a/contrib/refresh_chartjs_colormap.rb +++ b/contrib/refresh_chartjs_colormap.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # see https://github.com/nagix/chartjs-plugin-colorschemes # see https://nagix.github.io/chartjs-plugin-colorschemes/colorchart.html # @@ -16,8 +18,8 @@ colorschemes_files = [{ name: 'brewer', src: "#{working_path}/src/colorschemes/c FileUtils.rm_rf working_path system "git clone https://github.com/nagix/chartjs-plugin-colorschemes.git #{working_path}" -File.open(target_file, 'w') do |file| - file.write("---\n") +File.open target_file, 'w' do |file| + file.write "---\n" colorschemes_files.each do |color_scheme_file| file.write "#{color_scheme_file[:name].capitalize}:\n" File.readlines(color_scheme_file[:src]).each do |line| diff --git a/db/migrate/001_add_autowatch_involved_issue_to_user.rb b/db/migrate/001_add_autowatch_involved_issue_to_user.rb index 3254fc47..da95694a 100644 --- a/db/migrate/001_add_autowatch_involved_issue_to_user.rb +++ b/db/migrate/001_add_autowatch_involved_issue_to_user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAutowatchInvolvedIssueToUser < ActiveRecord::Migration[4.2] def change add_column :user_preferences, :autowatch_involved_issue, :boolean, default: true, null: false diff --git a/db/migrate/002_add_hide_to_roles.rb b/db/migrate/002_add_hide_to_roles.rb index e5a40d38..504965d6 100644 --- a/db/migrate/002_add_hide_to_roles.rb +++ b/db/migrate/002_add_hide_to_roles.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddHideToRoles < ActiveRecord::Migration[4.2] def change add_column :roles, :hide, :boolean, default: false, null: false diff --git a/db/migrate/003_create_dashboards.rb b/db/migrate/003_create_dashboards.rb index 70431bcf..a643563b 100644 --- a/db/migrate/003_create_dashboards.rb +++ b/db/migrate/003_create_dashboards.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateDashboards < ActiveRecord::Migration[5.2] def change create_table :dashboards do |t| diff --git a/db/migrate/004_create_dashboard_roles.rb b/db/migrate/004_create_dashboard_roles.rb index 207c775a..ffaa35d2 100644 --- a/db/migrate/004_create_dashboard_roles.rb +++ b/db/migrate/004_create_dashboard_roles.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateDashboardRoles < ActiveRecord::Migration[5.2] def change create_table :dashboard_roles do |t| diff --git a/db/migrate/005_create_dashboard_defaults.rb b/db/migrate/005_create_dashboard_defaults.rb index 61e32709..49376ba8 100644 --- a/db/migrate/005_create_dashboard_defaults.rb +++ b/db/migrate/005_create_dashboard_defaults.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + class CreateDashboardDefaults < ActiveRecord::Migration[5.2] def up User.current = User.find_by(id: ENV['DEFAULT_USER_ID'].presence || User.admin.active.first.id) - unless Dashboard.exists?(dashboard_type: DashboardContentWelcome::TYPE_NAME) + unless Dashboard.exists? dashboard_type: DashboardContentWelcome::TYPE_NAME Dashboard.create! name: 'Welcome dashboard', dashboard_type: DashboardContentWelcome::TYPE_NAME, system_default: true, @@ -10,7 +12,7 @@ class CreateDashboardDefaults < ActiveRecord::Migration[5.2] visibility: 2 end - return if Dashboard.exists?(dashboard_type: DashboardContentProject::TYPE_NAME) + return if Dashboard.exists? dashboard_type: DashboardContentProject::TYPE_NAME Dashboard.create! name: 'Project dashboard', dashboard_type: DashboardContentProject::TYPE_NAME, diff --git a/docs/conf.py b/docs/conf.py index 80fbd20c..f037f36f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,13 +24,13 @@ master_doc = 'index' # General information about the project. project = u'additionals' -copyright = u'2013-2020, AlphaNodes GmbH' +copyright = u'2013-2021, AlphaNodes GmbH' author = u'Alexander Meindl' # The short X.Y version. -version = u'3.0.0' +version = u'3.0.3' # The full version, including alpha/beta/rc tags. -release = u'3.0.0' +release = u'3.0.3' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. diff --git a/init.rb b/init.rb index d5bc61f3..f25be544 100644 --- a/init.rb +++ b/init.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Redmine::Plugin.register :additionals do name 'Additionals' author 'AlphaNodes GmbH' @@ -14,7 +16,7 @@ Redmine::Plugin.register :additionals do default_settings["custom_menu#{i}_title"] = '' end - settings(default: default_settings, partial: 'additionals/settings/additionals') + settings default: default_settings, partial: 'additionals/settings/additionals' permission :show_hidden_roles_in_memberbox, {} permission :set_system_dashboards, @@ -56,7 +58,7 @@ end Rails.application.paths['app/overrides'] ||= [] Dir.glob(Rails.root.join('plugins/*/app/overrides')).each do |dir| - Rails.application.paths['app/overrides'] << dir unless Rails.application.paths['app/overrides'].include?(dir) + Rails.application.paths['app/overrides'] << dir unless Rails.application.paths['app/overrides'].include? dir end Rails.configuration.to_prepare do diff --git a/lib/additionals.rb b/lib/additionals.rb index f3079877..8047e655 100644 --- a/lib/additionals.rb +++ b/lib/additionals.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'additionals/version' module Additionals MAX_CUSTOM_MENU_ITEMS = 5 SELECT2_INIT_ENTRIES = 20 - DEFAULT_MODAL_WIDTH = '350px'.freeze - GOTO_LIST = " \xc2\xbb".freeze - LIST_SEPARATOR = "#{GOTO_LIST} ".freeze + DEFAULT_MODAL_WIDTH = '350px' + GOTO_LIST = " \xc2\xbb" + LIST_SEPARATOR = "#{GOTO_LIST} " class << self def setup @@ -27,6 +29,7 @@ module Additionals ReportsController Principal QueryFilter + QueriesHelper Role User UserPreference] @@ -95,7 +98,8 @@ module Additionals def debug(message) return if Rails.env.production? - Rails.logger.debug "#{Time.current.strftime('%H:%M:%S')} DEBUG [#{caller_locations(1..1).first.label}]: #{message}" + msg = message.is_a?(String) ? message : message.inspect + Rails.logger.debug "#{Time.current.strftime '%H:%M:%S'} DEBUG [#{caller_locations(1..1).first.label}]: #{msg}" end def class_prefix(klass) @@ -113,19 +117,19 @@ module Additionals def incompatible_plugins(plugins = [], title = 'additionals') plugins.each do |plugin| - raise "\n\033[31m#{title} plugin cannot be used with #{plugin} plugin.\033[0m" if Redmine::Plugin.installed?(plugin) + raise "\n\033[31m#{title} plugin cannot be used with #{plugin} plugin.\033[0m" if Redmine::Plugin.installed? plugin end end def patch(patches = [], plugin_id = 'additionals') patches.each do |name| - patch_dir = Rails.root.join("plugins/#{plugin_id}/lib/#{plugin_id}/patches") + patch_dir = Rails.root.join "plugins/#{plugin_id}/lib/#{plugin_id}/patches" require "#{patch_dir}/#{name.underscore}_patch" target = name.constantize patch = "#{plugin_id.camelize}::Patches::#{name}Patch".constantize - target.include(patch) unless target.included_modules.include?(patch) + target.include patch unless target.included_modules.include? patch end end diff --git a/lib/additionals/entity_methods.rb b/lib/additionals/entity_methods.rb index 8da93ff4..d1b17407 100644 --- a/lib/additionals/entity_methods.rb +++ b/lib/additionals/entity_methods.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module EntityMethods def assignable_users(prj = nil) diff --git a/lib/additionals/formatter.rb b/lib/additionals/formatter.rb index 793045d4..4267b950 100644 --- a/lib/additionals/formatter.rb +++ b/lib/additionals/formatter.rb @@ -1,4 +1,5 @@ -# Formater +# frozen_string_literal: true + module Additionals module Formatter SMILEYS = { 'smiley' => ':-?\)', # :) @@ -27,16 +28,16 @@ module Additionals def render_inline_smileys(text) return text if text.blank? - inline_smileys(text) + inline_smileys text text end def inline_smileys(text) SMILEYS.each do |name, regexp| text.gsub!(/(\s|^|>|\))(!)?(#{regexp})(?=\W|$|<)/m) do - leading = Regexp.last_match(1) - esc = Regexp.last_match(2) - smiley = Regexp.last_match(3) + leading = Regexp.last_match 1 + esc = Regexp.last_match 2 + smiley = Regexp.last_match 3 if esc.nil? leading + tag.span(class: "additionals smiley smiley-#{name}", title: smiley) @@ -49,8 +50,8 @@ module Additionals def inline_emojify(text) text.gsub!(/:([\w+-]+):/) do |match| - emoji_code = Regexp.last_match(1) - emoji = Emoji.find_by_alias(emoji_code) # rubocop:disable Rails/DynamicFindBy + emoji_code = Regexp.last_match 1 + emoji = Emoji.find_by_alias emoji_code # rubocop:disable Rails/DynamicFindBy if emoji.present? tag.img src: inline_emojify_image_path(emoji.image_filename), title: ":#{emoji_code}:", diff --git a/lib/additionals/gemify.rb b/lib/additionals/gemify.rb index d2386268..17f77a07 100644 --- a/lib/additionals/gemify.rb +++ b/lib/additionals/gemify.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals class Gemify class << self @@ -10,11 +12,11 @@ module Additionals return unless File.directory? source source_files = Dir["#{source}/**/*"] - source_dirs = source_files.select { |d| File.directory?(d) } + source_dirs = source_files.select { |d| File.directory? d } source_files -= source_dirs unless source_files.empty? - base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, '')) + base_target_dir = File.join destination, File.dirname(source_files.first).gsub(source, '') begin FileUtils.mkdir_p base_target_dir rescue StandardError => e @@ -23,9 +25,9 @@ module Additionals end source_dirs.each do |dir| - target_dir = File.join(destination, dir.gsub(source, '')) + target_dir = File.join destination, dir.gsub(source, '') begin - FileUtils.mkdir_p(target_dir) + FileUtils.mkdir_p target_dir rescue StandardError => e raise "Could not create directory #{target_dir}: " + e.message end @@ -33,7 +35,7 @@ module Additionals source_files.each do |file| target = File.join destination, file.gsub(source, '') - FileUtils.cp(file, target) unless File.exist?(target) && FileUtils.identical?(file, target) + FileUtils.cp file, target unless File.exist?(target) && FileUtils.identical?(file, target) rescue StandardError => e raise "Could not copy #{file} to #{target}: " + e.message end @@ -42,12 +44,12 @@ module Additionals # Create text file to Redmine's plugins directory. # The purpose is telling plugins directory to users. def create_plugin_hint(plugin_id = 'additionals') - plugins_dir = File.join(Bundler.root, 'plugins') + plugins_dir = File.join Bundler.root, 'plugins' path = File.join plugins_dir, plugin_id return if File.exist? path - File.open(path, 'w') do |f| - f.write(< 1 if permission == :edit_issues - new_issue_path('issue[assigned_to_id]' => user.id, 'issue[project_id]' => project_id) + new_issue_path 'issue[assigned_to_id]' => user.id, 'issue[project_id]' => project_id else - new_issue_path('issue[project_id]' => project_id) + new_issue_path 'issue[project_id]' => project_id end elsif permission == :edit_issues - new_project_issue_path(project_id, 'issue[assigned_to_id]' => user.id) + new_project_issue_path project_id, 'issue[assigned_to_id]' => user.id else - new_project_issue_path(project_id) + new_project_issue_path project_id end end @@ -125,10 +127,10 @@ module Additionals return rc end - uri = URI.parse(url) + uri = URI.parse url # support issue_id plugin # see https://www.redmine.org/plugins/issue_id - issue_id_parts = url.split('-') + issue_id_parts = url.split '-' if uri.scheme.nil? && uri.path[0] != '/' && issue_id_parts.count == 2 rc[:issue_id] = url else @@ -153,10 +155,10 @@ module Additionals safe_join s end - def autocomplete_select_entries(name, type, option_tags, options = {}) + def autocomplete_select_entries(name, type, option_tags, **options) unless option_tags.is_a?(String) || option_tags.blank? # if option_tags is not an array, it should be an object - option_tags = options_for_select([[option_tags.try(:name), option_tags.try(:id)]], option_tags.try(:id)) + option_tags = options_for_select [[option_tags.try(:name), option_tags.try(:id)]], option_tags.try(:id) end options[:project] = @project if @project && options[:project].blank? @@ -168,7 +170,7 @@ module Additionals multiple: options[:multiple], disabled: options[:disabled]) s << render(layout: false, - partial: 'additionals/select2_ajax_call.js', + partial: 'additionals/select2_ajax_call', formats: [:js], locals: { field_id: sanitize_to_id(name), ajax_url: send("#{type}_path", project_id: options[:project], user_id: options[:user_id]), @@ -186,12 +188,12 @@ module Additionals classes.join ' ' end - def addtionals_textarea_cols(text, options = {}) - [[(options[:min].presence || 8), text.to_s.length / 50].max, (options[:max].presence || 20)].min + def addtionals_textarea_cols(text, min: 8, max: 20) + [[min, text.to_s.length / 50].max, max].min end def title_with_fontawesome(title, symbole, wrapper = 'span') - tag.send(wrapper) do + tag.send wrapper do concat tag.i class: "#{symbole} for-fa-title", 'aria-hidden': 'true' concat title end @@ -202,7 +204,7 @@ module Additionals def additionals_already_loaded(scope, js_name) locked = "#{js_name}.#{scope}" @alreaded_loaded = [] if @alreaded_loaded.nil? - return true if @alreaded_loaded.include?(locked) + return true if @alreaded_loaded.include? locked @alreaded_loaded << locked false @@ -276,21 +278,19 @@ module Additionals additionals_include_js 'd3plus-network.full.min' end - def user_with_avatar(user, options = {}) + def user_with_avatar(user, no_link: false, css_class: 'additionals-avatar', size: 14) return if user.nil? if user.type == 'Group' - if options[:no_link] || !Redmine::Plugin.installed?('redmine_hrm') + if no_link || !Redmine::Plugin.installed?('redmine_hrm') user.name else link_to_hrm_group user end else - options[:size] = 14 if options[:size].nil? - options[:class] = 'additionals-avatar' if options[:class].nil? s = [] - s << avatar(user, options) - s << if options[:no_link] + s << avatar(user, { size: size, class: css_class }) + s << if no_link user.name else link_to_user user @@ -305,10 +305,10 @@ module Additionals l(:label_app_menu) => 'app' }, active) end - def human_float_number(value, options = {}) + def human_float_number(value, precision: 2, separator: '.') ActionController::Base.helpers.number_with_precision(value, - precision: options[:precision].presence || 2, - separator: options[:separator].presence || '.', + precision: precision, + separator: separator, strip_insignificant_zeros: true) end diff --git a/lib/additionals/hooks.rb b/lib/additionals/hooks.rb index 926d28f5..b2657f81 100644 --- a/lib/additionals/hooks.rb +++ b/lib/additionals/hooks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals class AdditionalsHookListener < Redmine::Hook::ViewListener include IssuesHelper diff --git a/lib/additionals/patches/access_control_patch.rb b/lib/additionals/patches/access_control_patch.rb index 4a9c6aa1..ca48d968 100644 --- a/lib/additionals/patches/access_control_patch.rb +++ b/lib/additionals/patches/access_control_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module AccessControlPatch diff --git a/lib/additionals/patches/application_controller_patch.rb b/lib/additionals/patches/application_controller_patch.rb index 5f0ad608..cd69572c 100644 --- a/lib/additionals/patches/application_controller_patch.rb +++ b/lib/additionals/patches/application_controller_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module ApplicationControllerPatch diff --git a/lib/additionals/patches/auto_completes_controller_patch.rb b/lib/additionals/patches/auto_completes_controller_patch.rb index a3544ff1..615f61ba 100644 --- a/lib/additionals/patches/auto_completes_controller_patch.rb +++ b/lib/additionals/patches/auto_completes_controller_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module AutoCompletesControllerPatch diff --git a/lib/additionals/patches/formatter_markdown_patch.rb b/lib/additionals/patches/formatter_markdown_patch.rb index 490aa03a..520f9bb6 100644 --- a/lib/additionals/patches/formatter_markdown_patch.rb +++ b/lib/additionals/patches/formatter_markdown_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module FormatterMarkdownPatch @@ -8,7 +10,7 @@ module Additionals # Add a postprocess hook to redcarpet's html formatter def postprocess(text) - if Additionals.setting?(:legacy_smiley_support) + if Additionals.setting? :legacy_smiley_support render_inline_smileys(inline_emojify(text)) else text diff --git a/lib/additionals/patches/formatter_textile_patch.rb b/lib/additionals/patches/formatter_textile_patch.rb index 498be2b2..d5678520 100644 --- a/lib/additionals/patches/formatter_textile_patch.rb +++ b/lib/additionals/patches/formatter_textile_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module FormatterTextilePatch diff --git a/lib/additionals/patches/formatting_helper_patch.rb b/lib/additionals/patches/formatting_helper_patch.rb index 428ccb40..7e25781a 100644 --- a/lib/additionals/patches/formatting_helper_patch.rb +++ b/lib/additionals/patches/formatting_helper_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module FormattingHelperPatch diff --git a/lib/additionals/patches/issue_patch.rb b/lib/additionals/patches/issue_patch.rb index c3203a83..cb399baa 100644 --- a/lib/additionals/patches/issue_patch.rb +++ b/lib/additionals/patches/issue_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module IssuePatch @@ -23,27 +25,22 @@ module Additionals end class_methods do - def join_issue_status(options = {}) - sql = "JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{table_name}.status_id" - return sql unless options.key?(:is_closed) + def join_issue_status(is_closed: nil) + sql = +"JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{table_name}.status_id" + return sql if is_closed.nil? - sql << " AND #{IssueStatus.table_name}.is_closed =" - sql << if options[:is_closed] - " #{connection.quoted_true}" - else - " #{connection.quoted_false}" - end + sql << " AND #{IssueStatus.table_name}.is_closed = #{is_closed ? connection.quoted_true : connection.quoted_false}" sql end end module InstanceMethods def sidbar_change_status_allowed_to(user, new_status_id = nil) - statuses = new_statuses_allowed_to(user) + statuses = new_statuses_allowed_to user if new_status_id.present? statuses.detect { |s| new_status_id == s.id && !timelog_required?(s.id) } else - statuses.reject { |s| timelog_required?(s.id) } + statuses.reject { |s| timelog_required? s.id } end end @@ -63,7 +60,7 @@ module Additionals return if Redmine::Plugin.installed?('redmine_automation') && author_id == RedmineAutomation.bot_user_id add_autowatcher User.current - add_autowatcher(author) if (new_record? || author_id != author_id_was) && author != User.current + add_autowatcher author if (new_record? || author_id != author_id_was) && author != User.current if !assigned_to_id.nil? && assigned_to_id != User.current.id && (new_record? || assigned_to_id != assigned_to_id_was) add_autowatcher assigned_to @@ -127,7 +124,7 @@ module Additionals end def auto_assigned_to_user - manager_role = Role.builtin.find_by(id: Additionals.setting(:issue_auto_assign_role)) + manager_role = Role.builtin.find_by id: Additionals.setting(:issue_auto_assign_role) groups = autoassign_get_group_list return groups[manager_role].first.id unless groups.nil? || groups[manager_role].blank? @@ -150,7 +147,7 @@ module Additionals end def validate_timelog_required - return true unless timelog_required?(status_id) + return true unless timelog_required? status_id errors.add :base, :issue_requires_timelog end diff --git a/lib/additionals/patches/issue_priority_patch.rb b/lib/additionals/patches/issue_priority_patch.rb index 3844e8d0..623d787b 100644 --- a/lib/additionals/patches/issue_priority_patch.rb +++ b/lib/additionals/patches/issue_priority_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module IssuePriorityPatch @@ -13,7 +15,7 @@ module Additionals module InstanceMethods def css_classes_with_additionals classes = [css_classes_without_additionals, css_name_based_class] - classes.join(' ') + classes.join ' ' end # css class based on priority name diff --git a/lib/additionals/patches/principal_patch.rb b/lib/additionals/patches/principal_patch.rb index 2aa679f9..fd4ed456 100644 --- a/lib/additionals/patches/principal_patch.rb +++ b/lib/additionals/patches/principal_patch.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + module Additionals module Patches module PrincipalPatch extend ActiveSupport::Concern included do - scope :assignable, -> { active.visible.where(type: %w[User Group]) } + scope :assignable, -> { active.visible.where type: %w[User Group] } scope :assignable_for_issues, lambda { |*args| project = args.first users = assignable - users = users.where.not(type: 'Group') unless Setting.issue_group_assignment? + users = users.where.not type: 'Group' unless Setting.issue_group_assignment? users = users.joins(members: :roles) .where(roles: { assignable: true }) .distinct @@ -35,7 +37,7 @@ module Additionals active else # self and members of visible projects - scope = if user.allowed_to?(:show_hidden_roles_in_memberbox, nil, global: true) + scope = if user.allowed_to? :show_hidden_roles_in_memberbox, nil, global: true active.where("#{table_name}.id = ? OR #{table_name}.id IN (SELECT user_id " \ "FROM #{Member.table_name} WHERE project_id IN (?))", user.id, user.visible_project_ids) diff --git a/lib/additionals/patches/project_patch.rb b/lib/additionals/patches/project_patch.rb index 4b4a0f1c..ba16f1bc 100644 --- a/lib/additionals/patches/project_patch.rb +++ b/lib/additionals/patches/project_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module ProjectPatch @@ -52,12 +54,12 @@ module Additionals end def visible_principals - query = ::Query.new(project: self, name: '_') + query = ::Query.new project: self, name: '_' query&.principals end def visible_users - query = ::Query.new(project: self, name: '_') + query = ::Query.new project: self, name: '_' query&.users end diff --git a/lib/additionals/patches/projects_controller_patch.rb b/lib/additionals/patches/projects_controller_patch.rb index b6178621..7dd84c72 100644 --- a/lib/additionals/patches/projects_controller_patch.rb +++ b/lib/additionals/patches/projects_controller_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency 'projects_controller' module Additionals @@ -27,7 +29,7 @@ module Additionals def find_dashboard if params[:dashboard_id].present? begin - @dashboard = Dashboard.project_only.find(params[:dashboard_id]) + @dashboard = Dashboard.project_only.find params[:dashboard_id] raise ::Unauthorized unless @dashboard.visible? raise ::Unauthorized unless @dashboard.project.nil? || @dashboard.project == @project rescue ActiveRecord::RecordNotFound diff --git a/lib/additionals/patches/queries_helper_patch.rb b/lib/additionals/patches/queries_helper_patch.rb new file mode 100644 index 00000000..f12aa57f --- /dev/null +++ b/lib/additionals/patches/queries_helper_patch.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Additionals + module Patches + module QueriesHelperPatch + extend ActiveSupport::Concern + included do + def additional_csv_separator + l(:general_csv_separator) == ',' ? ';' : ',' + end + end + end + end +end diff --git a/lib/additionals/patches/query_filter_patch.rb b/lib/additionals/patches/query_filter_patch.rb index 72242ff4..8b1998a7 100644 --- a/lib/additionals/patches/query_filter_patch.rb +++ b/lib/additionals/patches/query_filter_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency 'query' module Additionals diff --git a/lib/additionals/patches/reports_controller_patch.rb b/lib/additionals/patches/reports_controller_patch.rb index e5898e04..11e7ffa1 100644 --- a/lib/additionals/patches/reports_controller_patch.rb +++ b/lib/additionals/patches/reports_controller_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module ReportsControllerPatch diff --git a/lib/additionals/patches/role_patch.rb b/lib/additionals/patches/role_patch.rb index 2e225353..83db7146 100644 --- a/lib/additionals/patches/role_patch.rb +++ b/lib/additionals/patches/role_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module RolePatch diff --git a/lib/additionals/patches/time_entry_patch.rb b/lib/additionals/patches/time_entry_patch.rb index ba8d1d4f..8957f063 100644 --- a/lib/additionals/patches/time_entry_patch.rb +++ b/lib/additionals/patches/time_entry_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module TimeEntryPatch @@ -17,11 +19,11 @@ module Additionals # NOTE: do not use user time zone here, because issue do not use it return if Setting.commit_logtime_enabled? && (issue.updated_on + 5.seconds) > Time.zone.now - errors.add(:issue_id, :issue_log_time_not_allowed) unless issue.log_time_allowed? + errors.add :issue_id, :issue_log_time_not_allowed unless issue.log_time_allowed? end def editable_by_with_additionals?(usr) - return false unless editable_by_without_additionals?(usr) + return false unless editable_by_without_additionals? usr return true unless issue_id && issue issue.log_time_allowed? diff --git a/lib/additionals/patches/user_patch.rb b/lib/additionals/patches/user_patch.rb index 68730331..0a341676 100644 --- a/lib/additionals/patches/user_patch.rb +++ b/lib/additionals/patches/user_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module UserPatch @@ -51,7 +53,7 @@ module Additionals scope = Principal.joins(members: :roles) .where(users: { id: id }, roles: { assignable: true }) - scope = scope.where(members: { project_id: project.id }) if project + scope = scope.where members: { project_id: project.id } if project scope.exists? end end diff --git a/lib/additionals/patches/user_preference_patch.rb b/lib/additionals/patches/user_preference_patch.rb index a351bfc6..43e05702 100644 --- a/lib/additionals/patches/user_preference_patch.rb +++ b/lib/additionals/patches/user_preference_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module Patches module UserPreferencePatch diff --git a/lib/additionals/patches/welcome_controller_patch.rb b/lib/additionals/patches/welcome_controller_patch.rb index 83080f21..44deb5fc 100644 --- a/lib/additionals/patches/welcome_controller_patch.rb +++ b/lib/additionals/patches/welcome_controller_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency 'welcome_controller' module Additionals @@ -26,7 +28,7 @@ module Additionals def find_dashboard if params[:dashboard_id].present? begin - @dashboard = Dashboard.welcome_only.find(params[:dashboard_id]) + @dashboard = Dashboard.welcome_only.find params[:dashboard_id] raise ::Unauthorized unless @dashboard.visible? rescue ActiveRecord::RecordNotFound return render_404 diff --git a/lib/additionals/patches/wiki_patch.rb b/lib/additionals/patches/wiki_patch.rb index 803dd275..d28b20c4 100644 --- a/lib/additionals/patches/wiki_patch.rb +++ b/lib/additionals/patches/wiki_patch.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency 'wiki' module Additionals @@ -15,12 +17,12 @@ module Additionals module InstanceMethods def sidebar_with_additionals - @sidebar ||= find_page('Sidebar', with_redirect: false) + @sidebar ||= find_page 'Sidebar', with_redirect: false if @sidebar&.content sidebar_without_additionals else wiki_sidebar = Additionals.setting(:global_wiki_sidebar).to_s - @sidebar ||= find_page(project.wiki.start_page, with_redirect: false) + @sidebar ||= find_page project.wiki.start_page, with_redirect: false @sidebar.content.text = wiki_sidebar if wiki_sidebar != '' && @sidebar.try(:content) end end diff --git a/lib/additionals/version.rb b/lib/additionals/version.rb index cf9e29ba..ff7fa652 100644 --- a/lib/additionals/version.rb +++ b/lib/additionals/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals - VERSION = '3.0.3-master'.freeze unless defined? VERSION + VERSION = '3.0.3-master' unless defined? VERSION end diff --git a/lib/additionals/wiki_macros/asciinema_macro.rb b/lib/additionals/wiki_macros/asciinema_macro.rb index 2b39e236..a11113ec 100644 --- a/lib/additionals/wiki_macros/asciinema_macro.rb +++ b/lib/additionals/wiki_macros/asciinema_macro.rb @@ -1,4 +1,5 @@ -# asciinema wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -7,7 +8,7 @@ module Additionals macro :asciinema do |_obj, args| raise 'The correct usage is {{asciinema()}}' if args.empty? - javascript_tag(nil, id: "asciicast-#{args[0]}", src: "//asciinema.org/a/#{args[0]}.js", async: true) + javascript_tag nil, id: "asciicast-#{args[0]}", src: "//asciinema.org/a/#{args[0]}.js", async: true end end end diff --git a/lib/additionals/wiki_macros/cryptocompare_macro.rb b/lib/additionals/wiki_macros/cryptocompare_macro.rb index a692ca5d..2f69b7cb 100644 --- a/lib/additionals/wiki_macros/cryptocompare_macro.rb +++ b/lib/additionals/wiki_macros/cryptocompare_macro.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # CryptoCompare wiki macros # see https://www.cryptocompare.com/dev/widget/wizard/ module Additionals @@ -12,7 +14,7 @@ module Additionals macro :cryptocompare do |_obj, args| raise 'The correct usage is {{cryptocompare(options)}}' if args.empty? - _args, options = extract_macro_options(args, :fsym, :fsyms, :tsym, :tsyms, :period, :type) + _args, options = extract_macro_options args, :fsym, :fsyms, :tsym, :tsyms, :period, :type options[:fsym] = 'BTC' if options[:fsym].blank? options[:tsym] = 'EUR' if options[:tsym].blank? @@ -90,7 +92,7 @@ module Additionals if options[name].blank? defaults else - options[name].tr(';', ',') + options[name].tr ';', ',' end end end diff --git a/lib/additionals/wiki_macros/date_macro.rb b/lib/additionals/wiki_macros/date_macro.rb index d5e46f7b..b9388371 100644 --- a/lib/additionals/wiki_macros/date_macro.rb +++ b/lib/additionals/wiki_macros/date_macro.rb @@ -1,4 +1,5 @@ -# Date wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -42,9 +43,9 @@ module Additionals d = Additionals.now_with_user_time_zone date_result = case type when 'current_date' - format_date(User.current.today) + format_date User.current.today when 'current_date_with_time' - format_time(d, true) + format_time d, true when 'current_year' d.year when 'current_month' @@ -56,11 +57,11 @@ module Additionals when 'current_minute' d.min when 'current_weekday' - day_name(d.wday) + day_name d.wday when 'current_weeknumber' User.current.today.cweek else - format_date(type.to_date) + format_date type.to_date end tag.span date_result, class: 'current-date' diff --git a/lib/additionals/wiki_macros/fa_macro.rb b/lib/additionals/wiki_macros/fa_macro.rb index 00637ce7..69827331 100644 --- a/lib/additionals/wiki_macros/fa_macro.rb +++ b/lib/additionals/wiki_macros/fa_macro.rb @@ -1,4 +1,5 @@ -# Font Awesome wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -34,7 +35,7 @@ module Additionals DESCRIPTION macro :fa do |_obj, args| - args, options = extract_macro_options(args, :class, :title, :text, :size, :color, :link) + args, options = extract_macro_options args, :class, :title, :text, :size, :color, :link raise 'The correct usage is {{fa(, class=CLASS, title=TITLE, text=TEXT, size=SIZE, color=COLOR)}}' if args.empty? values = args[0].split '_' @@ -62,7 +63,7 @@ module Additionals tag.i text, content_options end else - tag.i text, content_options + tag.i text, **content_options end end end diff --git a/lib/additionals/wiki_macros/gist_macro.rb b/lib/additionals/wiki_macros/gist_macro.rb index 6b9754b2..fc80254c 100644 --- a/lib/additionals/wiki_macros/gist_macro.rb +++ b/lib/additionals/wiki_macros/gist_macro.rb @@ -1,4 +1,5 @@ -# Gist wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -7,7 +8,7 @@ module Additionals macro :gist do |_obj, args| raise 'The correct usage is {{gist()}}' if args.empty? - javascript_tag(nil, src: "https://gist.github.com/#{args[0]}.js") + javascript_tag nil, src: "https://gist.github.com/#{args[0]}.js" end end end diff --git a/lib/additionals/wiki_macros/gmap_macro.rb b/lib/additionals/wiki_macros/gmap_macro.rb index ee1e9c32..6e0277ad 100644 --- a/lib/additionals/wiki_macros/gmap_macro.rb +++ b/lib/additionals/wiki_macros/gmap_macro.rb @@ -1,4 +1,5 @@ -# Gist wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -70,11 +71,11 @@ module Additionals raise 'The correct usage is {{gmap([q=QUERY, mode=MODE, widths=x, height=y])}}' end - src = "https://www.google.com/maps/embed/v1/#{mode}?key=" + Additionals.setting(:google_maps_api_key) + src = +"https://www.google.com/maps/embed/v1/#{mode}?key=" + Additionals.setting(:google_maps_api_key) if options[:q].present? - src << "&q=#{ERB::Util.url_encode(options[:q])}" + src << "&q=#{ERB::Util.url_encode options[:q]}" elsif mode == 'search' - src << "&q=#{ERB::Util.url_encode(args[0])}" + src << "&q=#{ERB::Util.url_encode args[0]}" end src_options.each do |key| diff --git a/lib/additionals/wiki_macros/google_docs_macro.rb b/lib/additionals/wiki_macros/google_docs_macro.rb index 854dc6b9..011ab09e 100644 --- a/lib/additionals/wiki_macros/google_docs_macro.rb +++ b/lib/additionals/wiki_macros/google_docs_macro.rb @@ -1,4 +1,5 @@ -# Google docs wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -16,7 +17,7 @@ module Additionals DESCRIPTION macro :google_docs do |_obj, args| - args, options = extract_macro_options(args, :width, :height, :edit_link) + args, options = extract_macro_options args, :width, :height, :edit_link width = options[:width].presence || '100%' height = options[:height].presence || 485 @@ -29,7 +30,7 @@ module Additionals src = v.dup unless src.include? '?' - src << if src.include?('edit') + src << if src.include? 'edit' '?rm=minimal' else '?widget=true&headers=false' diff --git a/lib/additionals/wiki_macros/group_users_macro.rb b/lib/additionals/wiki_macros/group_users_macro.rb index 8bd5a03c..d5c064d4 100644 --- a/lib/additionals/wiki_macros/group_users_macro.rb +++ b/lib/additionals/wiki_macros/group_users_macro.rb @@ -1,4 +1,5 @@ -# Group wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do diff --git a/lib/additionals/wiki_macros/iframe_macro.rb b/lib/additionals/wiki_macros/iframe_macro.rb index a63ac240..414b167f 100644 --- a/lib/additionals/wiki_macros/iframe_macro.rb +++ b/lib/additionals/wiki_macros/iframe_macro.rb @@ -1,4 +1,5 @@ -# Slideshare wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -19,7 +20,7 @@ module Additionals DESCRIPTION macro :iframe do |_obj, args| - args, options = extract_macro_options(args, :width, :height, :slide, :with_link) + args, options = extract_macro_options args, :width, :height, :slide, :with_link width = options[:width].presence || '100%' height = options[:height].presence || 485 @@ -27,7 +28,7 @@ module Additionals raise 'The correct usage is {{iframe([, width=x, height=y, with_link=bool])}}' if args.empty? src = args[0] - if Additionals.valid_iframe_url?(src) + if Additionals.valid_iframe_url? src s = [tag.iframe(width: width, height: height, src: src, @@ -47,7 +48,7 @@ module Additionals end def self.valid_iframe_url?(url) - uri = URI.parse(url) + uri = URI.parse url if Setting.protocol == 'https' uri.is_a?(URI::HTTPS) && !uri.host.nil? else diff --git a/lib/additionals/wiki_macros/issue_macro.rb b/lib/additionals/wiki_macros/issue_macro.rb index 385df6e2..1ebc4582 100644 --- a/lib/additionals/wiki_macros/issue_macro.rb +++ b/lib/additionals/wiki_macros/issue_macro.rb @@ -1,4 +1,5 @@ -# Issue wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -34,12 +35,12 @@ module Additionals DESCRIPTION macro :issue do |_obj, args| - args, options = extract_macro_options(args, :id, :note_id, :format) + args, options = extract_macro_options args, :id, :note_id, :format raise 'The correct usage is {{issue(, format=FORMAT, id=INT, note_id=INT)}}' if args.empty? && options[:id].blank? comment_id = options[:note_id].to_i if options[:note_id].present? issue_id = options[:id].presence || - (info = parse_issue_url(args[0], comment_id) + (info = parse_issue_url args[0], comment_id comment_id = info[:comment_id] if comment_id.nil? info[:issue_id]) @@ -56,7 +57,7 @@ module Additionals end if options[:format].blank? || options[:format] != 'text' - render_issue_macro_link(issue, text, comment_id) + render_issue_macro_link issue, text, comment_id else text end diff --git a/lib/additionals/wiki_macros/last_updated_at_macro.rb b/lib/additionals/wiki_macros/last_updated_at_macro.rb index 1f5a2860..e7ae5d35 100644 --- a/lib/additionals/wiki_macros/last_updated_at_macro.rb +++ b/lib/additionals/wiki_macros/last_updated_at_macro.rb @@ -1,4 +1,5 @@ -# Last_updated_at wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -19,14 +20,14 @@ module Additionals project_name = args[0].strip page_name = args[1].strip - project = Project.find_by(name: project_name) - project ||= Project.find_by(identifier: project_name) + project = Project.find_by name: project_name + project ||= Project.find_by identifier: project_name return unless project - wiki = Wiki.find_by(project_id: project.id) + wiki = Wiki.find_by project_id: project.id return unless wiki - page = wiki.find_page(page_name) + page = wiki.find_page page_name end return unless page diff --git a/lib/additionals/wiki_macros/last_updated_by_macro.rb b/lib/additionals/wiki_macros/last_updated_by_macro.rb index e0f4b683..f48c68a8 100644 --- a/lib/additionals/wiki_macros/last_updated_by_macro.rb +++ b/lib/additionals/wiki_macros/last_updated_by_macro.rb @@ -1,4 +1,5 @@ -# Last_updated_by wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do diff --git a/lib/additionals/wiki_macros/member_macro.rb b/lib/additionals/wiki_macros/member_macro.rb index ebf37200..7f4cf8d9 100644 --- a/lib/additionals/wiki_macros/member_macro.rb +++ b/lib/additionals/wiki_macros/member_macro.rb @@ -1,4 +1,5 @@ -# Member wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -32,7 +33,7 @@ module Additionals DESCRIPTION macro :members do |_obj, args| - args, options = extract_macro_options(args, :role, :title, :with_sum) + args, options = extract_macro_options args, :role, :title, :with_sum project_id = args[0] user_roles = [] @@ -40,9 +41,9 @@ module Additionals if project_id.present? project_id.strip! - project = Project.visible.find_by(id: project_id) - project ||= Project.visible.find_by(identifier: project_id) - project ||= Project.visible.find_by(name: project_id) + project = Project.visible.find_by id: project_id + project ||= Project.visible.find_by identifier: project_id + project ||= Project.visible.find_by name: project_id return if project.nil? principals = project.visible_users @@ -52,7 +53,7 @@ module Additionals principals.each do |principal| next unless principal.type == 'User' - user_roles[principal.id] = principal.roles_for_project(project) + user_roles[principal.id] = principal.roles_for_project project users << principal if options[:role].blank? || Additionals.check_role_matches(user_roles[principal.id], options[:role]) end else diff --git a/lib/additionals/wiki_macros/meteoblue_macro.rb b/lib/additionals/wiki_macros/meteoblue_macro.rb index c051457c..9ec26a9a 100644 --- a/lib/additionals/wiki_macros/meteoblue_macro.rb +++ b/lib/additionals/wiki_macros/meteoblue_macro.rb @@ -1,4 +1,5 @@ -# meteoblue wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -47,9 +48,9 @@ module Additionals height = options[:height].presence || 368 src = if User.current.language.blank? ? ::I18n.locale : User.current.language == 'de' - 'https://www.meteoblue.com/de/wetter/widget/daily/' + +'https://www.meteoblue.com/de/wetter/widget/daily/' else - 'https://www.meteoblue.com/en/weather/widget/daily/' + +'https://www.meteoblue.com/en/weather/widget/daily/' end src << ERB::Util.url_encode(args[0]) @@ -75,11 +76,12 @@ module Additionals end def self.meteoblue_flag(options, name, default = tue) - flag = "&#{name}=" + flag = +"#{name}=" flag << if Additionals.true?(options[name]) || default '1' else '0' end + flag end end diff --git a/lib/additionals/wiki_macros/new_issue_macro.rb b/lib/additionals/wiki_macros/new_issue_macro.rb index 80133d0a..9d273d98 100644 --- a/lib/additionals/wiki_macros/new_issue_macro.rb +++ b/lib/additionals/wiki_macros/new_issue_macro.rb @@ -1,4 +1,5 @@ -# Issue wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -28,20 +29,20 @@ module Additionals macro :new_issue do |_obj, args| if args.any? args, options = extract_macro_options(args, *additionals_titles_for_locale(:name)) - i18n_name = additionals_i18n_title(options, :name) + i18n_name = additionals_i18n_title options, :name project_id = args[0] end - i18n_name = l(:label_issue_new) if i18n_name.blank? + i18n_name = l :label_issue_new if i18n_name.blank? if project_id.present? project_id.strip! - project = Project.visible.find_by(id: project_id) - project ||= Project.visible.find_by(identifier: project_id) - project ||= Project.visible.find_by(name: project_id) + project = Project.visible.find_by id: project_id + project ||= Project.visible.find_by identifier: project_id + project ||= Project.visible.find_by name: project_id return '' if project.nil? || !User.current.allowed_to?(:add_issues, project) - return link_to(i18n_name, new_project_issue_path(project), class: 'macro-new-issue icon icon-add') + return link_to i18n_name, new_project_issue_path(project), class: 'macro-new-issue icon icon-add' else @memberships = User.current .memberships @@ -49,8 +50,8 @@ module Additionals .where(Project.visible_condition(User.current)) .to_a if @memberships.present? - project_url = memberships_new_issue_project_url(User.current, @memberships, :add_issues) - return link_to(i18n_name, project_url, class: 'macro-new-issue icon icon-add') if project_url.present? + project_url = memberships_new_issue_project_url User.current, @memberships, :add_issues + return link_to i18n_name, project_url, class: 'macro-new-issue icon icon-add' if project_url.present? end end diff --git a/lib/additionals/wiki_macros/project_macro.rb b/lib/additionals/wiki_macros/project_macro.rb index 5e0adff9..4535a9b8 100644 --- a/lib/additionals/wiki_macros/project_macro.rb +++ b/lib/additionals/wiki_macros/project_macro.rb @@ -1,4 +1,5 @@ -# Project wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -22,7 +23,7 @@ module Additionals DESCRIPTION macro :projects do |_obj, args| - _args, options = extract_macro_options(args, :title, :with_create_issue) + _args, options = extract_macro_options args, :title, :with_create_issue @projects = User.current.projects.active.includes(:enabled_modules).sorted return if @projects.nil? diff --git a/lib/additionals/wiki_macros/recently_updated_macro.rb b/lib/additionals/wiki_macros/recently_updated_macro.rb index de9560cd..31c61440 100644 --- a/lib/additionals/wiki_macros/recently_updated_macro.rb +++ b/lib/additionals/wiki_macros/recently_updated_macro.rb @@ -1,4 +1,5 @@ -# Recently updated wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -33,13 +34,13 @@ module Additionals .where("#{WikiContent.table_name}.updated_on > ?", User.current.today - days) .order("#{WikiContent.table_name}.updated_on desc") - pages = pages.visible(User.current, project: project) if pages.respond_to? :visible + pages = pages.visible User.current, project: project if pages.respond_to? :visible s = [] date = nil pages.each do |page_raw| content = page_raw.content - updated_on = Date.new(content.updated_on.year, content.updated_on.month, content.updated_on.day) + updated_on = Date.new content.updated_on.year, content.updated_on.month, content.updated_on.day if date != updated_on date = updated_on s << tag.strong(format_date(date)) diff --git a/lib/additionals/wiki_macros/reddit_macro.rb b/lib/additionals/wiki_macros/reddit_macro.rb index 8ff097f3..eebbf368 100644 --- a/lib/additionals/wiki_macros/reddit_macro.rb +++ b/lib/additionals/wiki_macros/reddit_macro.rb @@ -1,4 +1,5 @@ -# Reddit wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do diff --git a/lib/additionals/wiki_macros/redmine_issue_macro.rb b/lib/additionals/wiki_macros/redmine_issue_macro.rb index cf8e26a2..7c1200d1 100644 --- a/lib/additionals/wiki_macros/redmine_issue_macro.rb +++ b/lib/additionals/wiki_macros/redmine_issue_macro.rb @@ -1,4 +1,5 @@ -# Redmine.org issue wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -10,21 +11,21 @@ module Additionals macro :redmine_issue do |_obj, args| raise 'The correct usage is {{redmine_issue()}}' if args.empty? - args, options = extract_macro_options(args, :title) + args, options = extract_macro_options args, :title raw_link = args[0].to_s.strip if !/\A\d+\z/.match(raw_link[0]) # https://www.redmine.org/issues/12066#note-7 if raw_link =~ %r{redmine.org/issues/([0-9].+?)#(.*)} || raw_link =~ %r{redmine.org/issues/([0-9].+)} - link_name = Regexp.last_match(1) - link = raw_link.gsub('http://', 'https://') + link_name = Regexp.last_match 1 + link = raw_link.gsub 'http://', 'https://' else raise 'The correct usage is {{redmine_issue()}}' end elsif raw_link =~ /([0-9].+?)\D/ # ID with parameters - link_name = Regexp.last_match(1) + link_name = Regexp.last_match 1 link = "https://www.redmine.org/issues/#{raw_link}" else # just ID @@ -35,7 +36,7 @@ module Additionals link_options = { class: 'external redmine-link' } link_options[:title] = options[:title].presence || l(:label_redmine_org_issue) - link_to("##{link_name}", link, link_options) + link_to "##{link_name}", link, link_options end end end diff --git a/lib/additionals/wiki_macros/redmine_wiki_macro.rb b/lib/additionals/wiki_macros/redmine_wiki_macro.rb index 3c2f6134..9ff6845d 100644 --- a/lib/additionals/wiki_macros/redmine_wiki_macro.rb +++ b/lib/additionals/wiki_macros/redmine_wiki_macro.rb @@ -1,4 +1,5 @@ -# Redmine.org issue wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -10,19 +11,19 @@ module Additionals macro :redmine_wiki do |_obj, args| raise 'The correct usage is {{redmine_wiki()}}' if args.empty? - args, options = extract_macro_options(args, :title, :name) + args, options = extract_macro_options args, :title, :name raw_link = args[0].to_s.strip if raw_link[0..3] == 'http' - start_pos = raw_link.index('redmine.org/projects/redmine/wiki/') + start_pos = raw_link.index 'redmine.org/projects/redmine/wiki/' raise 'The correct usage is {{redmine_wiki()}}' if start_pos.nil? || start_pos.zero? options[:name] = raw_link[(start_pos + 34)..-1] if options[:name].blank? - link = raw_link.gsub('http://', 'https://') + link = raw_link.gsub 'http://', 'https://' elsif /\w/.match?(raw_link[0]) options[:name] = raw_link if options[:name].blank? - link = "https://www.redmine.org/projects/redmine/wiki/#{Wiki.titleize(raw_link)}" + link = "https://www.redmine.org/projects/redmine/wiki/#{Wiki.titleize raw_link}" else raise 'The correct usage is {{redmine_wiki()}}' end @@ -30,7 +31,7 @@ module Additionals link_options = { class: 'external redmine-link' } link_options[:title] = options[:title].presence || l(:label_redmine_org_wiki) - link_to(options[:name], link, link_options) + link_to options[:name], link, link_options end end end diff --git a/lib/additionals/wiki_macros/slideshare_macro.rb b/lib/additionals/wiki_macros/slideshare_macro.rb index 863f57de..57bb3514 100644 --- a/lib/additionals/wiki_macros/slideshare_macro.rb +++ b/lib/additionals/wiki_macros/slideshare_macro.rb @@ -1,4 +1,5 @@ -# Slideshare wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -17,7 +18,7 @@ module Additionals DESCRIPTION macro :slideshare do |_obj, args| - args, options = extract_macro_options(args, :width, :height, :slide) + args, options = extract_macro_options args, :width, :height, :slide width = options[:width].presence || 595 height = options[:height].presence || 485 @@ -26,7 +27,7 @@ module Additionals raise 'The correct usage is {{slideshare([, width=x, height=y, slide=number])}}' if args.empty? v = args[0] - src = "//www.slideshare.net/slideshow/embed_code/#{v}" + src = +"//www.slideshare.net/slideshow/embed_code/#{v}" src += "?startSlide=#{slide}" if slide.positive? tag.iframe width: width, height: height, src: src, frameborder: 0, allowfullscreen: 'true' diff --git a/lib/additionals/wiki_macros/tradingview_macro.rb b/lib/additionals/wiki_macros/tradingview_macro.rb index 8bcb232a..1c46eb30 100644 --- a/lib/additionals/wiki_macros/tradingview_macro.rb +++ b/lib/additionals/wiki_macros/tradingview_macro.rb @@ -1,4 +1,5 @@ -# Tradingview wiki macros +# frozen_string_literal: true + # see https://www.tradingview.com/widget/ module Additionals module WikiMacros diff --git a/lib/additionals/wiki_macros/twitter_macro.rb b/lib/additionals/wiki_macros/twitter_macro.rb index b6df33b2..f84bc176 100644 --- a/lib/additionals/wiki_macros/twitter_macro.rb +++ b/lib/additionals/wiki_macros/twitter_macro.rb @@ -1,4 +1,5 @@ -# Twitter wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do diff --git a/lib/additionals/wiki_macros/user_macro.rb b/lib/additionals/wiki_macros/user_macro.rb index f5df7db0..0dc90acc 100644 --- a/lib/additionals/wiki_macros/user_macro.rb +++ b/lib/additionals/wiki_macros/user_macro.rb @@ -1,4 +1,5 @@ -# User wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -22,7 +23,7 @@ module Additionals "...Link to user with username 'admin' and show firstname as link text" macro :user do |_obj, args| - args, options = extract_macro_options(args, :format, :avatar, :text) + args, options = extract_macro_options args, :format, :avatar, :text raise 'The correct usage is {{user(, format=USER_FORMAT)}}' if args.empty? user_id = args[0] diff --git a/lib/additionals/wiki_macros/vimeo_macro.rb b/lib/additionals/wiki_macros/vimeo_macro.rb index 77653385..93eea17c 100644 --- a/lib/additionals/wiki_macros/vimeo_macro.rb +++ b/lib/additionals/wiki_macros/vimeo_macro.rb @@ -1,4 +1,5 @@ -# Vimeo wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -17,7 +18,7 @@ module Additionals DESCRIPTION macro :vimeo do |_obj, args| - args, options = extract_macro_options(args, :width, :height, :autoplay) + args, options = extract_macro_options args, :width, :height, :autoplay width = options[:width].presence || 640 height = options[:height].presence || 360 diff --git a/lib/additionals/wiki_macros/youtube_macro.rb b/lib/additionals/wiki_macros/youtube_macro.rb index fe2e434e..6b8ce4a2 100644 --- a/lib/additionals/wiki_macros/youtube_macro.rb +++ b/lib/additionals/wiki_macros/youtube_macro.rb @@ -1,4 +1,5 @@ -# Youtube wiki macros +# frozen_string_literal: true + module Additionals module WikiMacros Redmine::WikiFormatting::Macros.register do @@ -17,7 +18,7 @@ module Additionals DESCRIPTION macro :youtube do |_obj, args| - args, options = extract_macro_options(args, :width, :height, :autoplay) + args, options = extract_macro_options args, :width, :height, :autoplay width = options[:width].presence || 640 height = options[:height].presence || 360 diff --git a/lib/tasks/additionals.rake b/lib/tasks/additionals.rake index dc43589a..c1cdc6cc 100644 --- a/lib/tasks/additionals.rake +++ b/lib/tasks/additionals.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :redmine do namespace :additionals do desc <<-DESCRIPTION @@ -31,7 +33,7 @@ namespace :redmine do name = ENV['name'] ||= 'redmine' setting = ENV['setting'] value = if ENV['values'].present? - ENV['values'].split(',') + ENV['values'].split ',' else ENV['value'] end diff --git a/test/crud_controller_base.rb b/test/crud_controller_base.rb index d19ea310..9892eaaf 100644 --- a/test/crud_controller_base.rb +++ b/test/crud_controller_base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module CrudControllerBase extend ActiveSupport::Concern @@ -97,7 +99,7 @@ module CrudControllerBase return end - assert_difference("#{@crud[:entity].class.name}.count") do + assert_difference "#{@crud[:entity].class.name}.count" do assert_no_difference 'Journal.count' do post :create, params: form_params(:create) end @@ -133,7 +135,7 @@ module CrudControllerBase def test_create_without_permission return unless prepare_crud_test :create, no_permission: true - assert_no_difference("#{@crud[:entity].class.name}.count") do + assert_no_difference "#{@crud[:entity].class.name}.count" do post :create, params: form_params(:create) end @@ -247,7 +249,7 @@ module CrudControllerBase def test_delete_without_permission return unless prepare_crud_test :delete, no_permission: true - assert_no_difference("#{@crud[:entity].class.name}.count") do + assert_no_difference "#{@crud[:entity].class.name}.count" do delete :destroy, params: { id: @crud[:entity].id } end diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 04633f63..6987c53f 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AccountControllerTest < Additionals::ControllerTest diff --git a/test/functional/additionals_assign_to_me_controller_test.rb b/test/functional/additionals_assign_to_me_controller_test.rb index 758394f7..1a5572e2 100644 --- a/test/functional/additionals_assign_to_me_controller_test.rb +++ b/test/functional/additionals_assign_to_me_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AdditionalsAssignToMeControllerTest < Additionals::ControllerTest @@ -28,7 +30,7 @@ class AdditionalsAssignToMeControllerTest < Additionals::ControllerTest test 'assign issue to user' do session[:user_id] = 2 - assert_difference('Journal.count') do + assert_difference 'Journal.count' do put :update, params: { issue_id: 1 } end @@ -36,7 +38,7 @@ class AdditionalsAssignToMeControllerTest < Additionals::ControllerTest test 'no update for issue, which already same user is assigned' do session[:user_id] = 3 - assert_no_difference('Journal.count') do + assert_no_difference 'Journal.count' do put :update, params: { issue_id: 2 } end diff --git a/test/functional/additionals_change_status_controller_test.rb b/test/functional/additionals_change_status_controller_test.rb index 906a36c5..86a1053d 100644 --- a/test/functional/additionals_change_status_controller_test.rb +++ b/test/functional/additionals_change_status_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AdditionalsChangeStatusControllerTest < Additionals::ControllerTest @@ -28,7 +30,7 @@ class AdditionalsChangeStatusControllerTest < Additionals::ControllerTest test 'assign new status to issue' do session[:user_id] = 2 - assert_difference('Journal.count') do + assert_difference 'Journal.count' do put :update, params: { issue_id: 4, new_status_id: 3 } end @@ -36,7 +38,7 @@ class AdditionalsChangeStatusControllerTest < Additionals::ControllerTest test 'no update for issue, which already has same status' do session[:user_id] = 2 - assert_no_difference('Journal.count') do + assert_no_difference 'Journal.count' do put :update, params: { issue_id: 2, new_status_id: 2 } end diff --git a/test/functional/additionals_macros_controller_test.rb b/test/functional/additionals_macros_controller_test.rb index 3ca5ae16..fe42158b 100644 --- a/test/functional/additionals_macros_controller_test.rb +++ b/test/functional/additionals_macros_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AdditionalsMacrosControllerTest < Additionals::ControllerTest diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb index c2154bd7..e1045122 100644 --- a/test/functional/auto_completes_controller_test.rb +++ b/test/functional/auto_completes_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AutoCompletesControllerTest < Additionals::ControllerTest @@ -11,7 +13,7 @@ class AutoCompletesControllerTest < Additionals::ControllerTest get :fontawesome assert_response :success - json = ActiveSupport::JSON.decode(response.body) + json = ActiveSupport::JSON.decode response.body assert_kind_of Array, json icon = json.first assert_kind_of Hash, icon @@ -24,7 +26,7 @@ class AutoCompletesControllerTest < Additionals::ControllerTest params: { q: 'sun' } assert_response :success - json = ActiveSupport::JSON.decode(response.body) + json = ActiveSupport::JSON.decode response.body assert_kind_of Array, json assert_equal 5, json.count icon = json.first @@ -38,7 +40,7 @@ class AutoCompletesControllerTest < Additionals::ControllerTest params: { q: 'doesnotexist' } assert_response :success - json = ActiveSupport::JSON.decode(response.body) + json = ActiveSupport::JSON.decode response.body assert_kind_of Array, json assert_equal 0, json.count end diff --git a/test/functional/dashboard_async_blocks_controller_test.rb b/test/functional/dashboard_async_blocks_controller_test.rb index 6d2c367d..0c156230 100644 --- a/test/functional/dashboard_async_blocks_controller_test.rb +++ b/test/functional/dashboard_async_blocks_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class DashboardAsyncBlocksControllerTest < Additionals::ControllerTest diff --git a/test/functional/dashboards_controller_test.rb b/test/functional/dashboards_controller_test.rb index d0f31cc3..d518bd21 100644 --- a/test/functional/dashboards_controller_test.rb +++ b/test/functional/dashboards_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class DashboardsControllerTest < Additionals::ControllerTest diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 55bfd014..d4d34171 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class IssuesControllerTest < Additionals::ControllerTest @@ -22,8 +24,8 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'author field as authorized user in new with change' do - manager_role = roles(:roles_001) - manager_role.add_permission!(:change_new_issue_author) + manager_role = roles :roles_001 + manager_role.add_permission! :change_new_issue_author session[:user_id] = 2 get :new, params: { project_id: 1 } @@ -60,7 +62,7 @@ class IssuesControllerTest < Additionals::ControllerTest test 'update author as authorized user' do session[:user_id] = 2 - assert_difference('Journal.count') do + assert_difference 'Journal.count' do put :update, params: { id: 1, issue: { author_id: 1 } } end @@ -69,14 +71,14 @@ class IssuesControllerTest < Additionals::ControllerTest test 'update author as unauthorized user' do session[:user_id] = 3 - assert_no_difference('Journal.count') do + assert_no_difference 'Journal.count' do put :update, params: { id: 1, issue: { author_id: 3 } } end end test 'show assign-to-me on issue' do - with_additionals_settings(issue_assign_to_me: 1) do + with_additionals_settings issue_assign_to_me: 1 do @request.session[:user_id] = 2 get :show, params: { id: 2 } @@ -86,7 +88,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'don\'t show assign-to-me on issue without activation' do - with_additionals_settings(issue_assign_to_me: 0) do + with_additionals_settings issue_assign_to_me: 0 do @request.session[:user_id] = 2 get :show, params: { id: 2 } @@ -95,7 +97,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'don\'t show assign-to-me on issue with already assigned_to me' do - with_additionals_settings(issue_assign_to_me: 1) do + with_additionals_settings issue_assign_to_me: 1 do @request.session[:user_id] = 2 get :show, params: { id: 4 } @@ -104,7 +106,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'show change status in issue sidebar' do - with_additionals_settings(issue_change_status_in_sidebar: 1) do + with_additionals_settings issue_change_status_in_sidebar: 1 do @request.session[:user_id] = 2 get :show, params: { id: 2 } @@ -113,7 +115,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'don\'t show change status in issue sidebar without activation' do - with_additionals_settings(issue_change_status_in_sidebar: 0) do + with_additionals_settings issue_change_status_in_sidebar: 0 do @request.session[:user_id] = 2 get :show, params: { id: 2 } @@ -127,7 +129,7 @@ class IssuesControllerTest < Additionals::ControllerTest issue_timelog_required_tracker: ['1'], issue_timelog_required_status: ['5']) do @request.session[:user_id] = 2 - issue = Issue.generate!(tracker_id: 1, status_id: 1) + issue = Issue.generate! tracker_id: 1, status_id: 1 get :show, params: { id: issue.id } @@ -143,7 +145,7 @@ class IssuesControllerTest < Additionals::ControllerTest issue_timelog_required_tracker: [1], issue_timelog_required_status: [5]) do @request.session[:user_id] = 2 - issue = Issue.generate!(tracker_id: 1, status_id: 1) + issue = Issue.generate! tracker_id: 1, status_id: 1 get :show, params: { id: issue.id } @@ -154,15 +156,15 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'show forbidden status in issue sidebar with permission issue_timelog_never_required' do - manager_role = roles(:roles_002) - manager_role.add_permission!(:issue_timelog_never_required) + manager_role = roles :roles_002 + manager_role.add_permission! :issue_timelog_never_required with_additionals_settings(issue_change_status_in_sidebar: 1, issue_timelog_required: 1, issue_timelog_required_tracker: [1], issue_timelog_required_status: [5]) do @request.session[:user_id] = 2 - issue = Issue.generate!(tracker_id: 1, status_id: 1) + issue = Issue.generate! tracker_id: 1, status_id: 1 get :show, params: { id: issue.id } diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 1c3fe026..d443013c 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class ViewDashboardTopRenderOn < Redmine::Hook::ViewListener diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 6c99f7bd..d972c262 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class ViewUsersShowContextualRenderOn < Redmine::Hook::ViewListener diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb index fe06e75c..6a1ffd15 100644 --- a/test/functional/welcome_controller_test.rb +++ b/test/functional/welcome_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class ViewWelcomeIndexTopRenderOn < Redmine::Hook::ViewListener @@ -74,9 +76,9 @@ class WelcomeControllerTest < Additionals::ControllerTest end def test_show_index_with_help_menu - skip if Redmine::Plugin.installed?('redmine_hrm') + skip if Redmine::Plugin.installed? 'redmine_hrm' - with_additionals_settings(remove_help: 0) do + with_additionals_settings remove_help: 0 do @request.session[:user_id] = 1 get :index @@ -85,9 +87,9 @@ class WelcomeControllerTest < Additionals::ControllerTest end def test_show_index_without_help_menu - skip if Redmine::Plugin.installed?('redmine_hrm') + skip if Redmine::Plugin.installed? 'redmine_hrm' - with_additionals_settings(remove_help: 1) do + with_additionals_settings remove_help: 1 do @request.session[:user_id] = 1 get :index diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 9d292f5f..c3605d70 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class WikiControllerTest < Additionals::ControllerTest @@ -24,11 +26,11 @@ class WikiControllerTest < Additionals::ControllerTest def setup prepare_tests - EnabledModule.create(project_id: 1, name: 'wiki') + EnabledModule.create project_id: 1, name: 'wiki' @project = projects :projects_001 @wiki = @project.wiki @page_name = 'additionals_macro_test' - @page = @wiki.find_or_new_page(@page_name) + @page = @wiki.find_or_new_page @page_name @page.content = WikiContent.new @page.content.text = 'test' @page.save! diff --git a/test/global_test_helper.rb b/test/global_test_helper.rb index 4e0ac946..db64ee7b 100644 --- a/test/global_test_helper.rb +++ b/test/global_test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Additionals module GlobalTestHelper def assert_select_td_column(column_name) @@ -11,7 +13,7 @@ module Additionals end def with_additionals_settings(settings, &_block) - change_additionals_settings(settings) + change_additionals_settings settings yield ensure restore_additionals_settings @@ -34,18 +36,18 @@ module Additionals end end - def assert_query_sort_order(table_css, column, options = {}) - options[:action] = :index if options[:action].blank? + def assert_query_sort_order(table_css, column, action: nil) + action = :index if action.blank? column = column.to_s - column_css = column.tr('_', '-') + column_css = column.tr '_', '-' - get options[:action], + get action, params: { sort: "#{column}:asc", c: [column] } assert_response :success assert_select "table.list.#{table_css}.sort-by-#{column_css}.sort-asc" - get options[:action], + get action, params: { sort: "#{column}:desc", c: [column] } assert_response :success diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb index 50176b62..d471a3bc 100644 --- a/test/integration/api_test/issues_test.rb +++ b/test/integration/api_test/issues_test.rb @@ -1,4 +1,6 @@ -require File.expand_path('../../../test_helper', __FILE__) +# frozen_string_literal: true + +require File.expand_path '../../../test_helper', __FILE__ module ApiTest class IssuesTest < Redmine::ApiTest::Base @@ -31,7 +33,7 @@ module ApiTest end test 'GET /issues/:id.xml with subtasks' do - issue = Issue.generate_with_descendants!(project_id: 1) + issue = Issue.generate_with_descendants! project_id: 1 get "/issues/#{issue.id}.xml?include=children" assert_select 'issue id', text: issue.id.to_s do @@ -55,7 +57,7 @@ module ApiTest XML - assert_difference('Issue.count') do + assert_difference 'Issue.count' do post '/issues.xml', params: payload, headers: { 'CONTENT_TYPE' => 'application/xml' }.merge(credentials('jsmith')) @@ -84,7 +86,7 @@ module ApiTest XML - assert_difference('Issue.count') do + assert_difference 'Issue.count' do post '/issues.xml', params: payload, headers: { 'CONTENT_TYPE' => 'application/xml' }.merge(credentials('jsmith')) diff --git a/test/integration/common_views_test.rb b/test/integration/common_views_test.rb index a396b50f..7962d9b1 100644 --- a/test/integration/common_views_test.rb +++ b/test/integration/common_views_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class CommonViewsTest < Additionals::IntegrationTest diff --git a/test/integration/library_test.rb b/test/integration/library_test.rb index a566eb21..53795a62 100644 --- a/test/integration/library_test.rb +++ b/test/integration/library_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class JavascriptLibraryTest < Additionals::IntegrationTest @@ -19,9 +21,9 @@ class JavascriptLibraryTest < Additionals::IntegrationTest :queries def test_not_loaded_chart_css_library - skip if Redmine::Plugin.installed?('redmine_reporting') + skip if Redmine::Plugin.installed? 'redmine_reporting' - log_user('admin', 'admin') + log_user 'admin', 'admin' get '/' assert_response :success @@ -29,9 +31,9 @@ class JavascriptLibraryTest < Additionals::IntegrationTest end def test_not_loaded_chart_js_library - skip if Redmine::Plugin.installed?('redmine_reporting') + skip if Redmine::Plugin.installed? 'redmine_reporting' - log_user('admin', 'admin') + log_user 'admin', 'admin' get '/' assert_response :success @@ -39,7 +41,7 @@ class JavascriptLibraryTest < Additionals::IntegrationTest end def test_not_loaded_javascript_libraries - log_user('admin', 'admin') + log_user 'admin', 'admin' get '/' assert_response :success diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 8ad1eb42..7d57c2cf 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class RoutingTest < Redmine::RoutingTest diff --git a/test/support/gemfile.rb b/test/support/gemfile.rb deleted file mode 100644 index 6ba644cb..00000000 --- a/test/support/gemfile.rb +++ /dev/null @@ -1,10 +0,0 @@ -source 'https://rubygems.org' - -group :test do - gem 'brakeman', require: false - gem 'pandoc-ruby', require: false - gem 'rubocop', require: false - gem 'rubocop-performance', require: false - gem 'rubocop-rails', require: false - gem 'slim_lint', require: false -end diff --git a/test/test_helper.rb b/test/test_helper.rb index aeb7452e..28cd20e2 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,4 @@ -$VERBOSE = nil +# frozen_string_literal: true if ENV['JENKINS'] require 'simplecov' @@ -38,9 +38,9 @@ module Additionals def fixtures(*table_names) dir = "#{File.dirname __FILE__}/fixtures/" table_names.each do |x| - ActiveRecord::FixtureSet.create_fixtures(dir, x) if File.exist?("#{dir}/#{x}.yml") + ActiveRecord::FixtureSet.create_fixtures dir, x if File.exist? "#{dir}/#{x}.yml" end - super(table_names) + super table_names end end diff --git a/test/unit/additionals_fontawesome_test.rb b/test/unit/additionals_fontawesome_test.rb index 7d371605..63e9c72c 100644 --- a/test/unit/additionals_fontawesome_test.rb +++ b/test/unit/additionals_fontawesome_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AdditionalsFontAwesomeTest < Additionals::TestCase @@ -17,10 +19,10 @@ class AdditionalsFontAwesomeTest < Additionals::TestCase end def test_value_info_should_return_infos - info = AdditionalsFontAwesome.value_info('invalid') + info = AdditionalsFontAwesome.value_info 'invalid' assert_equal({}, info) - info = AdditionalsFontAwesome.value_info('fas_car') + info = AdditionalsFontAwesome.value_info 'fas_car' assert info.key?(:classes) assert_equal :fas, info[:type] assert_equal 'fas fa-car', info[:classes] @@ -28,28 +30,28 @@ class AdditionalsFontAwesomeTest < Additionals::TestCase end def test_value_info_regular_icons - info = AdditionalsFontAwesome.value_info('far_address-book') + info = AdditionalsFontAwesome.value_info 'far_address-book' assert info.key?(:classes) assert_equal 'normal', info[:font_weight] assert_equal 'Font Awesome\ 5 Free', info[:font_family] end def test_value_info_solid_icons - info = AdditionalsFontAwesome.value_info('fas_address-book') + info = AdditionalsFontAwesome.value_info 'fas_address-book' assert info.key?(:classes) assert_equal 900, info[:font_weight] assert_equal 'Font Awesome\ 5 Free', info[:font_family] end def test_value_info_brands_icons - info = AdditionalsFontAwesome.value_info('fab_xing') + info = AdditionalsFontAwesome.value_info 'fab_xing' assert info.key?(:classes) assert_equal 'normal', info[:font_weight] assert_equal 'Font Awesome\ 5 Brands', info[:font_family] end def test_brands_icon_with_details - info = AdditionalsFontAwesome.value_info('fab_amazon', with_details: true) + info = AdditionalsFontAwesome.value_info 'fab_amazon', with_details: true assert info.key?(:unicode) assert info.key?(:label) assert_equal '', info[:unicode] @@ -57,7 +59,7 @@ class AdditionalsFontAwesomeTest < Additionals::TestCase end def test_regular_icon_with_details - info = AdditionalsFontAwesome.value_info('far_calendar', with_details: true) + info = AdditionalsFontAwesome.value_info 'far_calendar', with_details: true assert info.key?(:unicode) assert info.key?(:label) assert_equal '', info[:unicode] @@ -65,7 +67,7 @@ class AdditionalsFontAwesomeTest < Additionals::TestCase end def test_solid_icon_with_details - info = AdditionalsFontAwesome.value_info('fas_archive', with_details: true) + info = AdditionalsFontAwesome.value_info 'fas_archive', with_details: true assert info.key?(:unicode) assert info.key?(:label) assert_equal '', info[:unicode] diff --git a/test/unit/additionals_info_test.rb b/test/unit/additionals_info_test.rb index aad490cc..cf52eb67 100644 --- a/test/unit/additionals_info_test.rb +++ b/test/unit/additionals_info_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AdditionalsInfoTest < Additionals::TestCase diff --git a/test/unit/additionals_journal_test.rb b/test/unit/additionals_journal_test.rb index 97e7ed9b..2a91d86b 100644 --- a/test/unit/additionals_journal_test.rb +++ b/test/unit/additionals_journal_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AdditionalsJournalTest < Additionals::TestCase @@ -16,7 +18,7 @@ class AdditionalsJournalTest < Additionals::TestCase end def test_journal_history_with_added_entries - assert_difference('JournalDetail.count', 2) do + assert_difference 'JournalDetail.count', 2 do assert AdditionalsJournal.save_journal_history(@current_journal, 'issue_test_relation', [1], @@ -25,7 +27,7 @@ class AdditionalsJournalTest < Additionals::TestCase end def test_journal_history_with_removed_entries - assert_difference('JournalDetail.count', 2) do + assert_difference 'JournalDetail.count', 2 do assert AdditionalsJournal.save_journal_history(@current_journal, 'issue_test_relation', [1, 2, 3], @@ -34,7 +36,7 @@ class AdditionalsJournalTest < Additionals::TestCase end def test_journal_history_without_changes - assert_difference('JournalDetail.count', 0) do + assert_no_difference 'JournalDetail.count' do assert AdditionalsJournal.save_journal_history(@current_journal, 'issue_test_relation', [1, 2, 3], diff --git a/test/unit/additionals_macro_test.rb b/test/unit/additionals_macro_test.rb index 3adda906..9b8d74fe 100644 --- a/test/unit/additionals_macro_test.rb +++ b/test/unit/additionals_macro_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AdditionalsMacroTest < Additionals::TestCase @@ -25,31 +27,31 @@ class AdditionalsMacroTest < Additionals::TestCase end def test_all_with_only_names - available_macros = AdditionalsMacro.all(only_names: true) + available_macros = AdditionalsMacro.all only_names: true assert available_macros.include?('child_pages') end def test_with_filter - available_macros = AdditionalsMacro.all(filtered: ['child_pages'], only_names: true) + available_macros = AdditionalsMacro.all filtered: ['child_pages'], only_names: true assert available_macros.exclude?('child_pages') for_two_macros_selection = @all_macros - %w[child_pages collapse] + ['', 'nonexistingmacro'] - available_macros = AdditionalsMacro.all(filtered: for_two_macros_selection, only_names: true) + available_macros = AdditionalsMacro.all filtered: for_two_macros_selection, only_names: true # -1 (hello world is always removed) assert_equal %w[child_pages collapse], available_macros end def test_with_filter_all - available_macros = AdditionalsMacro.all(filtered: @all_macros, only_names: true) + available_macros = AdditionalsMacro.all filtered: @all_macros, only_names: true assert_equal 0, available_macros.count end def test_with_controller_limit - available_macros = AdditionalsMacro.all(only_names: true, controller_only: 'issue') + available_macros = AdditionalsMacro.all only_names: true, controller_only: 'issue' assert available_macros.exclude?('child_pages') - available_macros = AdditionalsMacro.all(only_names: true, controller_only: 'wiki') + available_macros = AdditionalsMacro.all only_names: true, controller_only: 'wiki' assert available_macros.include?('child_pages') end end diff --git a/test/unit/additionals_test.rb b/test/unit/additionals_test.rb index 40c35198..fea52f7c 100644 --- a/test/unit/additionals_test.rb +++ b/test/unit/additionals_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class AdditionalsTest < Additionals::TestCase diff --git a/test/unit/dashboard_content_test.rb b/test/unit/dashboard_content_test.rb index 3a3bf737..d794b2bb 100644 --- a/test/unit/dashboard_content_test.rb +++ b/test/unit/dashboard_content_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class DashboardContentTest < Additionals::TestCase diff --git a/test/unit/dashboard_test.rb b/test/unit/dashboard_test.rb index 0dd08ebe..7965991b 100644 --- a/test/unit/dashboard_test.rb +++ b/test/unit/dashboard_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class DashboardTest < Additionals::TestCase @@ -150,7 +152,7 @@ class DashboardTest < Additionals::TestCase end def test_system_default_welcome_should_not_be_deletable - assert_raise(Exception) do + assert_raise Exception do Dashboard.welcome_only .where(system_default: true) .destroy_all @@ -158,7 +160,7 @@ class DashboardTest < Additionals::TestCase end def test_system_default_project_should_not_be_deletable - assert_raise(Exception) do + assert_raise Exception do Dashboard.project_only .where(system_default: true) .destroy_all @@ -205,7 +207,7 @@ class DashboardTest < Additionals::TestCase dashboard = dashboards :welcome_for_roles assert_equal 2, dashboard.roles.count - relation = DashboardRole.new(role_id: 3, dashboard_id: dashboard.id) + relation = DashboardRole.new role_id: 3, dashboard_id: dashboard.id assert_save relation dashboard.reload diff --git a/test/unit/helpers/global_helper_test.rb b/test/unit/helpers/global_helper_test.rb index a1c4b450..13b98712 100644 --- a/test/unit/helpers/global_helper_test.rb +++ b/test/unit/helpers/global_helper_test.rb @@ -1,4 +1,6 @@ -require File.expand_path('../../../test_helper', __FILE__) +# frozen_string_literal: true + +require File.expand_path '../../../test_helper', __FILE__ class GlobalHelperTest < ActionView::TestCase include Additionals::Helpers @@ -22,7 +24,7 @@ class GlobalHelperTest < ActionView::TestCase def setup super - set_language_if_valid('en') + set_language_if_valid 'en' User.current = nil end @@ -33,16 +35,16 @@ class GlobalHelperTest < ActionView::TestCase end def test_font_awesome_icon - html = font_awesome_icon('fas_cloud-upload-alt', class: 'test') + html = font_awesome_icon 'fas_cloud-upload-alt', class: 'test' assert_include 'class="fas fa-cloud-upload-alt test"', html - html = font_awesome_icon('fab_xing', class: 'test') + html = font_awesome_icon 'fab_xing', class: 'test' assert_include 'class="fab fa-xing test"', html - html = font_awesome_icon('fas_cloud-upload-alt', pre_text: 'Testing') + html = font_awesome_icon 'fas_cloud-upload-alt', pre_text: 'Testing' assert_include 'Testing Testing', html end @@ -65,7 +67,7 @@ class GlobalHelperTest < ActionView::TestCase def test_render_issue_macro_link issue = Issue.generate! - issue.init_journal(User.first, 'Adding notes') + issue.init_journal User.first, 'Adding notes' issue.save stubs(:request).returns(stub('original_url' => 'http://redmine.local/issues/1#note-2')) diff --git a/test/unit/i18n_test.rb b/test/unit/i18n_test.rb index 9174ab8d..46e1e7ad 100644 --- a/test/unit/i18n_test.rb +++ b/test/unit/i18n_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class I18nTest < Additionals::TestCase @@ -30,6 +32,6 @@ class I18nTest < Additionals::TestCase end end - set_language_if_valid('en') + set_language_if_valid 'en' end end diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index c5352166..9a700baa 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class IssueTest < Additionals::TestCase @@ -22,14 +24,14 @@ class IssueTest < Additionals::TestCase end def test_create - issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') + issue = Issue.new project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create' assert_save issue assert_equal issue.tracker.default_status, issue.status assert_nil issue.description end def test_change_open_issue - with_additionals_settings(issue_freezed_with_close: 1) do + with_additionals_settings issue_freezed_with_close: 1 do User.current = users :users_003 issue = issues :issues_007 issue.subject = 'Should be be saved' @@ -38,12 +40,12 @@ class IssueTest < Additionals::TestCase end def test_change_closed_issue_with_permission - with_additionals_settings(issue_freezed_with_close: 1) do + with_additionals_settings issue_freezed_with_close: 1 do User.current = users :users_003 - role = Role.create!(name: 'Additionals Tester', permissions: [:edit_closed_issues]) + role = Role.create! name: 'Additionals Tester', permissions: [:edit_closed_issues] Member.where(user_id: User.current).delete_all project = projects :projects_001 - Member.create!(principal: User.current, project_id: project.id, role_ids: [role.id]) + Member.create! principal: User.current, project_id: project.id, role_ids: [role.id] issue = issues :issues_008 @@ -56,7 +58,7 @@ class IssueTest < Additionals::TestCase end def test_change_closed_issue_without_permission - with_additionals_settings(issue_freezed_with_close: 1) do + with_additionals_settings issue_freezed_with_close: 1 do User.current = users :users_003 issue = issues :issues_008 @@ -116,7 +118,7 @@ class IssueTest < Additionals::TestCase with_additionals_settings issue_auto_assign: 1, issue_auto_assign_status: ['1'], issue_auto_assign_role: '1' do - issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') + issue = Issue.new project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create' assert_save issue assert_equal 2, issue.assigned_to_id end @@ -126,7 +128,7 @@ class IssueTest < Additionals::TestCase with_additionals_settings issue_auto_assign: 0, issue_auto_assign_status: ['1'], issue_auto_assign_role: '1' do - issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') + issue = Issue.new project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create' assert_save issue assert_nil issue.assigned_to_id end @@ -134,7 +136,7 @@ class IssueTest < Additionals::TestCase with_additionals_settings issue_auto_assign: 1, issue_auto_assign_status: [], issue_auto_assign_role: '1' do - issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') + issue = Issue.new project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create' assert_save issue assert_nil issue.assigned_to_id end @@ -142,7 +144,7 @@ class IssueTest < Additionals::TestCase with_additionals_settings issue_auto_assign: 1, issue_auto_assign_status: ['1'], issue_auto_assign_role: '' do - issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') + issue = Issue.new project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create' assert_save issue assert_nil issue.assigned_to_id end diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 71282ea1..ea6ddfc8 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class ProjectTest < Additionals::TestCase @@ -24,11 +26,11 @@ class ProjectTest < Additionals::TestCase def test_assignable_users_amount with_settings issue_group_assignment: '1' do - project = Project.find(5) + project = Project.find 5 assert_equal project.assignable_users.count, project.assignable_users_and_groups.count end with_settings issue_group_assignment: '0' do - project = Project.find(5) + project = Project.find 5 assert_not_equal project.assignable_users.count, project.assignable_users_and_groups.count end end @@ -52,7 +54,7 @@ class ProjectTest < Additionals::TestCase @ecookbook.destroy # make sure that the project non longer exists - assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } + assert_raise(ActiveRecord::RecordNotFound) { Project.find @ecookbook.id } # make sure related data was removed assert_nil Dashboard.where(project_id: @ecookbook.id).first end @@ -60,7 +62,7 @@ class ProjectTest < Additionals::TestCase def test_users_by_role users_by_role = Project.find(1).users_by_role assert_kind_of Hash, users_by_role - role = Role.find(1) + role = Role.find 1 assert_kind_of Array, users_by_role[role] assert users_by_role[role].include?(User.find(2)) end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index ee24b11d..11d3a799 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class QueryTest < Additionals::TestCase @@ -15,7 +17,7 @@ class QueryTest < Additionals::TestCase def test_issue_query_principals_with_hide prepare_query_tests User.current = @user_with_hide - query = IssueQuery.new(project: @project, name: '_') + query = IssueQuery.new project: @project, name: '_' # show all members + current user of hidden role assert_equal 3, query.principals.count @@ -24,7 +26,7 @@ class QueryTest < Additionals::TestCase def test_issue_query_principals_with_show_hide_permission prepare_query_tests User.current = @user_with_show_hide - query = IssueQuery.new(project: @project, name: '_') + query = IssueQuery.new project: @project, name: '_' # show all members with 2 users of hidden role assert_equal 4, query.principals.count @@ -33,24 +35,24 @@ class QueryTest < Additionals::TestCase private def prepare_query_tests - @role1 = Role.new(name: 'principal test hide1', users_visibility: 'members_of_visible_projects', hide: true) - @role1.add_permission!('view_issues') + @role1 = Role.new name: 'principal test hide1', users_visibility: 'members_of_visible_projects', hide: true + @role1.add_permission! 'view_issues' @role1.save! - @role2 = Role.new(name: 'principal test hide2', users_visibility: 'members_of_visible_projects', hide: true) - @role2.add_permission!('view_issues', 'show_hidden_roles_in_memberbox') + @role2 = Role.new name: 'principal test hide2', users_visibility: 'members_of_visible_projects', hide: true + @role2.add_permission! 'view_issues', 'show_hidden_roles_in_memberbox' @role2.save! @project = projects :projects_001 - @user_with_hide = User.generate!(firstname: 'hide1', lastname: 'role') - m = Member.new(user_id: @user_with_hide.id, project_id: @project.id) - m.member_roles.build(role_id: @role1.id) + @user_with_hide = User.generate! firstname: 'hide1', lastname: 'role' + m = Member.new user_id: @user_with_hide.id, project_id: @project.id + m.member_roles.build role_id: @role1.id m.save! - @user_with_show_hide = User.generate!(firstname: 'hide2', lastname: 'role') - m = Member.new(user_id: @user_with_show_hide.id, project_id: @project.id) - m.member_roles.build(role_id: @role2.id) + @user_with_show_hide = User.generate! firstname: 'hide2', lastname: 'role' + m = Member.new user_id: @user_with_show_hide.id, project_id: @project.id + m.member_roles.build role_id: @role2.id m.save! end end diff --git a/test/unit/role_test.rb b/test/unit/role_test.rb index 67ce5dd6..594d1aef 100644 --- a/test/unit/role_test.rb +++ b/test/unit/role_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class RoleTest < Additionals::TestCase @@ -11,13 +13,13 @@ class RoleTest < Additionals::TestCase end def test_with_permission - role = Role.new(name: 'role without hide') + role = Role.new name: 'role without hide' assert_save role role.reload assert_not role.hide - role = Role.new(name: 'role with hide', hide: true) + role = Role.new name: 'role with hide', hide: true assert_save role role.reload @@ -25,7 +27,7 @@ class RoleTest < Additionals::TestCase end def test_edit - role = roles(:roles_001) + role = roles :roles_001 role.hide = true assert_save role diff --git a/test/unit/time_entry_test.rb b/test/unit/time_entry_test.rb index 8f9f96e6..5a9754ef 100644 --- a/test/unit/time_entry_test.rb +++ b/test/unit/time_entry_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class TimeEntryTest < Additionals::TestCase @@ -20,13 +22,13 @@ class TimeEntryTest < Additionals::TestCase end def test_create_time_entry_without_issue - entry = TimeEntry.generate(project: projects(:projects_001)) + entry = TimeEntry.generate project: projects(:projects_001) assert entry.valid? assert_save entry end def test_create_time_entry_with_open_issue - entry = TimeEntry.generate(issue: issues(:issues_002)) + entry = TimeEntry.generate issue: issues(:issues_002) assert_not entry.issue.closed? assert entry.valid? assert_save entry @@ -35,7 +37,7 @@ class TimeEntryTest < Additionals::TestCase def test_create_time_entry_with_closed_issue_without_permission User.current = nil - entry = TimeEntry.generate(issue: issues(:issues_008)) + entry = TimeEntry.generate issue: issues(:issues_008) assert entry.issue.closed? assert_not entry.valid? assert_not entry.save @@ -43,12 +45,12 @@ class TimeEntryTest < Additionals::TestCase def test_create_time_entry_with_closed_issue_with_permission User.current = users :users_003 - role = Role.create!(name: 'Additionals Tester', permissions: [:log_time_on_closed_issues]) + role = Role.create! name: 'Additionals Tester', permissions: [:log_time_on_closed_issues] Member.where(user_id: User.current).delete_all project = projects :projects_001 - Member.create!(principal: User.current, project_id: project.id, role_ids: [role.id]) + Member.create! principal: User.current, project_id: project.id, role_ids: [role.id] - entry = TimeEntry.generate(issue: issues(:issues_008)) + entry = TimeEntry.generate issue: issues(:issues_008) assert entry.issue.closed? assert entry.valid? assert_save entry diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index c79e1f23..0d2ea63c 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class UserTest < Additionals::TestCase @@ -18,9 +20,9 @@ class UserTest < Additionals::TestCase end def test_with_permission - admin_user = User.generate!(admin: true) + admin_user = User.generate! admin: true - users = User.visible.active.with_permission(:save_dashboards) + users = User.visible.active.with_permission :save_dashboards assert_equal 5, users.count assert users.exists?(id: admin_user) end @@ -38,7 +40,7 @@ class UserTest < Additionals::TestCase end def test_sudoer_should_can_be_admin - skip 'Skip redmine_sudo test, because redmine_contacts is not installed' unless Redmine::Plugin.installed?('redmine_sudo') + skip 'Skip redmine_sudo test, because redmine_contacts is not installed' unless Redmine::Plugin.installed? 'redmine_sudo' user = users :users_001 user.sudoer = true @@ -59,7 +61,7 @@ class UserTest < Additionals::TestCase end def test_non_sudoer_without_admin_can_not_be_admin - skip 'Skip redmine_sudo test, because redmine_contacts is not installed' unless Redmine::Plugin.installed?('redmine_sudo') + skip 'Skip redmine_sudo test, because redmine_contacts is not installed' unless Redmine::Plugin.installed? 'redmine_sudo' assert_not User.where(sudoer: false, admin: false).first.can_be_admin? end diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index 70c18162..8587c2cf 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path '../../test_helper', __FILE__ class WatcherTest < Additionals::TestCase @@ -25,11 +27,11 @@ class WatcherTest < Additionals::TestCase end def test_new_issue_with_no_autowatch_by_user - with_additionals_settings(issue_autowatch_involved: 1) do + with_additionals_settings issue_autowatch_involved: 1 do User.current = @author User.current.pref.update_attribute :autowatch_involved_issue, false - issue = Issue.generate(author_id: @author.id) + issue = Issue.generate author_id: @author.id issue.save assert_equal 0, issue.watchers.count assert_not issue.watched_by?(@author) @@ -37,9 +39,9 @@ class WatcherTest < Additionals::TestCase end def test_new_issue_with_author_watch_only - with_additionals_settings(issue_autowatch_involved: 1) do + with_additionals_settings issue_autowatch_involved: 1 do User.current = @author - issue = Issue.generate(author_id: @author.id) + issue = Issue.generate author_id: @author.id issue.save assert_equal 1, issue.watchers.count assert issue.watched_by?(@author) @@ -47,9 +49,9 @@ class WatcherTest < Additionals::TestCase end def test_new_issue_with_author_and_assigned_to_watchers - with_additionals_settings(issue_autowatch_involved: 1) do + with_additionals_settings issue_autowatch_involved: 1 do User.current = @author - issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) + issue = Issue.generate author_id: @author.id, assigned_to: @assigned_user issue.save assert_equal 2, issue.watchers.count @@ -59,14 +61,14 @@ class WatcherTest < Additionals::TestCase end def test_issue_do_not_add_author_with_user_change - with_additionals_settings(issue_autowatch_involved: 1) do + with_additionals_settings issue_autowatch_involved: 1 do User.current = @author - issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) + issue = Issue.generate author_id: @author.id, assigned_to: @assigned_user issue.save assert_equal 2, issue.watchers.count - issue.remove_watcher(@author) + issue.remove_watcher @author issue.reload assert_equal 1, issue.watchers.count @@ -81,14 +83,14 @@ class WatcherTest < Additionals::TestCase end def test_issue_do_not_add_assigned_to_with_user_change - with_additionals_settings(issue_autowatch_involved: 1) do + with_additionals_settings issue_autowatch_involved: 1 do User.current = @author - issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) + issue = Issue.generate author_id: @author.id, assigned_to: @assigned_user issue.save assert_equal 2, issue.watchers.count - issue.remove_watcher(@assigned_user) + issue.remove_watcher @assigned_user issue.reload assert_equal 1, issue.watchers.count