Skip to content

Commit

Permalink
lint with rubocop --autocorrect (safe cops only)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbliard committed Jun 2, 2022
1 parent 454f4e0 commit 48a4f1b
Show file tree
Hide file tree
Showing 2,105 changed files with 10,727 additions and 10,611 deletions.
2 changes: 1 addition & 1 deletion app/cells/members/row_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def role_form_cell
row: self,
params: controller.params,
roles: table.available_roles,
context: { controller: controller }
context: { controller: }
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/cells/members/user_filter_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def extra_user_status_options

def status_members_query(status)
params = { project_id: project.id,
status: status }
status: }

self.class.filter(params)
end
Expand Down
4 changes: 1 addition & 3 deletions app/cells/oauth/applications/row_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def client_credentials
end
end

def confidential
application.confidential
end
delegate :confidential, to: :application

def edit_link
link_to(
Expand Down
23 changes: 10 additions & 13 deletions app/cells/projects/table_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ def href_only_when_not_sort_lft
end

def all_columns
@all_columns ||= begin
[
[:hierarchy, { builtin: true }],
[:name, { builtin: true, caption: Project.human_attribute_name(:name) }],
[:project_status, { caption: Project.human_attribute_name(:status) }],
[:status_explanation, { caption: Projects::Status.human_attribute_name(:explanation) }],
[:public, { caption: Project.human_attribute_name(:public) }],
*custom_field_columns,
*admin_columns
]
end
@all_columns ||= [
[:hierarchy, { builtin: true }],
[:name, { builtin: true, caption: Project.human_attribute_name(:name) }],
[:project_status, { caption: Project.human_attribute_name(:status) }],
[:status_explanation, { caption: Projects::Status.human_attribute_name(:explanation) }],
[:public, { caption: Project.human_attribute_name(:public) }],
*custom_field_columns,
*admin_columns
]
end

def headers
Expand Down Expand Up @@ -104,8 +102,7 @@ def project_custom_fields
end

fields
.map { |cf| [:"cf_#{cf.id}", cf] }
.to_h
.index_by { |cf| :"cf_#{cf.id}" }
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions app/cells/row_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def table
options[:table]
end

def columns
table.columns
end
delegate :columns, to: :table

def column_value(column)
value = send column
Expand Down Expand Up @@ -40,7 +38,7 @@ def column_css_class(column)
def column_css_classes
entries = columns.map { |name| [name, name] }

Hash[entries]
entries.to_h
end

def column_title(_column)
Expand Down
12 changes: 6 additions & 6 deletions app/cells/settings/time_zone_setting_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ def render_form_select
form.select(
name,
time_zone_entries,
include_blank: include_blank,
container_class: container_class,
title: title
include_blank:,
container_class:,
title:
)
end

def render_setting_select
setting_select(
name,
time_zone_entries,
include_blank: include_blank,
container_class: container_class,
title: title
include_blank:,
container_class:,
title:
)
end

Expand Down
8 changes: 2 additions & 6 deletions app/cells/table_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,9 @@ def empty_row_message

# required by the sort helper

def controller_name
controller.controller_name
end
delegate :controller_name, to: :controller

def action_name
controller.action_name
end
delegate :action_name, to: :controller

def options
super
Expand Down
1 change: 0 additions & 1 deletion app/cells/user_filter_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def base_query
Queries::Users::UserQuery
end


protected

def apply_filters(params, query)
Expand Down
4 changes: 1 addition & 3 deletions app/cells/versions/row_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def version
model
end

def project
version.project
end
delegate :project, to: :version

def row_css_class
shared = "shared" if version.project != table.project
Expand Down
4 changes: 2 additions & 2 deletions app/contracts/backups/create_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def check_waiting_period(token)
valid_at = token.created_at + OpenProject::Configuration.backup_initial_waiting_period
hours = ((valid_at - Time.zone.now) / 60.0 / 60.0).round

errors.add :base, :token_cooldown, message: I18n.t("backup.error.token_cooldown", hours: hours)
errors.add :base, :token_cooldown, message: I18n.t("backup.error.token_cooldown", hours:)
end
end

def backup_limit
limit = OpenProject::Configuration.backup_daily_limit
if Backup.where("created_at >= ?", Time.zone.today).count > limit
errors.add :base, :limit_reached, message: I18n.t("backup.error.limit_reached", limit: limit)
errors.add :base, :limit_reached, message: I18n.t("backup.error.limit_reached", limit:)
end
end

Expand Down
6 changes: 2 additions & 4 deletions app/contracts/base_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def attribute_alias(db, outside)
attribute_aliases[db] = outside
end

def property(name, options = {}, &block)
def property(name, options = {}, &)
if (twin = options.delete(:form))
options[:twin] = twin
end
Expand Down Expand Up @@ -135,9 +135,7 @@ def read_attribute_for_validation(attribute)
end

def writable_attributes
@writable_attributes ||= begin
reduce_writable_attributes(collect_writable_attributes)
end
@writable_attributes ||= reduce_writable_attributes(collect_writable_attributes)
end

def writable?(attribute)
Expand Down
2 changes: 1 addition & 1 deletion app/contracts/params_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ParamsContract < BaseContract
attr_reader :params

def initialize(model, user, params:, options: {})
super(model, user, options: options)
super(model, user, options:)

@params = params
end
Expand Down
4 changes: 1 addition & 3 deletions app/contracts/projects/base_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def available_custom_fields
end
end

def assignable_versions
model.assignable_versions
end
delegate :assignable_versions, to: :model

def assignable_status_codes
Projects::Status.codes.keys
Expand Down
2 changes: 1 addition & 1 deletion app/contracts/projects/create_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CreateContract < BaseContract

def validate_user_allowed_to_manage
unless user.allowed_to_globally?(:add_project) ||
model.parent && user.allowed_to?(:add_subprojects, model.parent)
(model.parent && user.allowed_to?(:add_subprojects, model.parent))

errors.add :base, :error_unauthorized
end
Expand Down
2 changes: 1 addition & 1 deletion app/contracts/wiki_pages/base_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BaseContract < ::ModelContract
private

def validate_user_edit_allowed
if model.project && !user.allowed_to?(:edit_wiki_pages, model.project) ||
if (model.project && !user.allowed_to?(:edit_wiki_pages, model.project)) ||
(model.protected_was && !user.allowed_to?(:protect_wiki_pages, model.project))
errors.add :base, :error_unauthorized
end
Expand Down
36 changes: 18 additions & 18 deletions app/controllers/account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def lost_password

@user = @token.user
if request.post?
call = ::Users::ChangePasswordService.new(current_user: @user, session: session).call(params)
call = ::Users::ChangePasswordService.new(current_user: @user, session:).call(params)
call.apply_flash_message!(flash) if call.errors.empty?

if call.success?
Expand Down Expand Up @@ -179,7 +179,7 @@ def handle_expired_token(token)
end

def send_activation_email!(user)
new_token = Token::Invitation.create!(user: user)
new_token = Token::Invitation.create!(user:)
UserMailer.user_signed_up(new_token).deliver_later
end

Expand All @@ -188,15 +188,7 @@ def activate_self_registered(token)

user = token.user

if not user.registered?
if user.active?
flash[:notice] = I18n.t(:notice_account_already_activated)
else
flash[:error] = I18n.t(:notice_activation_failed)
end

redirect_to home_url
else
if user.registered?
user.activate

if user.save
Expand All @@ -207,6 +199,14 @@ def activate_self_registered(token)
end

redirect_to signin_path
else
if user.active?
flash[:notice] = I18n.t(:notice_account_already_activated)
else
flash[:error] = I18n.t(:notice_activation_failed)
end

redirect_to home_url
end
end

Expand Down Expand Up @@ -257,7 +257,7 @@ def change_password
# Retrieve user_id from session
@user = User.find(params[:password_change_user_id])

change_password_flow(user: @user, params: params, show_user_name: true) do
change_password_flow(user: @user, params:, show_user_name: true) do
password_authentication(@user.login, params[:new_password])
end
rescue ActiveRecord::RecordNotFound
Expand Down Expand Up @@ -390,7 +390,7 @@ def direct_login(user)
error = !user.anonymous? || flash[:error]
instructions = error ? :after_error : :after_registration

render :exit, locals: { instructions: instructions }
render :exit, locals: { instructions: }
end
end

Expand Down Expand Up @@ -439,7 +439,7 @@ def password_authentication(username, password)

def login_user_if_active(user, just_registered:)
if user.active?
successful_authentication(user, just_registered: just_registered)
successful_authentication(user, just_registered:)
return
end

Expand Down Expand Up @@ -475,15 +475,15 @@ def self_registration_disabled
# Call if an account is inactive - either registered or locked
def account_inactive(user, flash_now: true)
if user.registered?
account_not_activated(flash_now: flash_now)
account_not_activated(flash_now:)
else
flash_and_log_invalid_credentials(flash_now: flash_now)
flash_and_log_invalid_credentials(flash_now:)
end
end

# Log an attempt to log in to an account in "registered" state and show a flash message.
def account_not_activated(flash_now: true)
flash_error_message(log_reason: 'NOT ACTIVATED', flash_now: flash_now) do
flash_error_message(log_reason: 'NOT ACTIVATED', flash_now:) do
if Setting::SelfRegistration.by_email?
'account.error_inactive_activation_by_mail'
else
Expand All @@ -510,7 +510,7 @@ def disable_api
# Changing this to not use api_request? to determine whether a request is an API
# request can have security implications regarding CSRF. See handle_unverified_request
# for more information.
head 410 if api_request?
head :gone if api_request?
end

def invalid_token_and_redirect
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/backups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def check_enabled
def find_backup(status: :success, user: current_user)
Backup
.joins(:job_status)
.where(job_status: { user: user, status: status })
.where(job_status: { user:, status: })
.last
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ def default_breadcrumb
end
end
end

Loading

0 comments on commit 48a4f1b

Please sign in to comment.