Skip to content

Commit

Permalink
Merge pull request #16679 from eduardoj/refactoring/fix_rubocop_style…
Browse files Browse the repository at this point in the history
…_optional_boolean_parameter

Manually fix some Style/OptionalBooleanParameter RuboCop offenses
  • Loading branch information
krauselukas authored Aug 13, 2024
2 parents 8d7619e + cf1054c commit d41fd16
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
3 changes: 0 additions & 3 deletions src/api/.rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1064,14 +1064,11 @@ Style/OpenStructUse:
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'app/controllers/public_controller.rb'
- 'app/helpers/webui/staging/workflow_helper.rb'
- 'app/helpers/webui/webui_helper.rb'
- 'app/jobs/consistency_check_job.rb'
- 'app/models/attrib_type.rb'
- 'app/models/maintenance_incident.rb'
- 'app/models/package.rb'
- 'app/models/project.rb'
- 'app/models/user.rb'
- 'app/policies/package_policy.rb'

Expand Down
6 changes: 3 additions & 3 deletions src/api/app/controllers/public_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def package_index

# GET /public/source/:project/:package/_meta
def package_meta
check_package_access(params[:project], params[:package], false)
check_package_access(params[:project], params[:package], use_source: false)

path = unshift_public(request.path_info)
# we should do this via user agent instead, but BSRPC is not only used for interconnect.
Expand Down Expand Up @@ -144,7 +144,7 @@ def show_request

# GET /public/binary_packages/:project/:package
def binary_packages
check_package_access(params[:project], params[:package], false)
check_package_access(params[:project], params[:package], use_source: false)
@pkg = Package.find_by_project_and_name(params[:project], params[:package])

begin
Expand Down Expand Up @@ -210,7 +210,7 @@ def unshift_public(path)
path =~ %r{/public(.*)} ? Regexp.last_match(1) : path
end

def check_package_access(project_name, package_name, use_source = true)
def check_package_access(project_name, package_name, use_source: true)
# don't use the cache for use_source
if use_source
begin
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/models/attrib_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ class InvalidAttributeError < APIError

#### Class methods using self. (public and then private)
def self.find_by_name!(name)
find_by_name(name, true)
find_by_name(name, or_fail: true)
end

def self.find_by_name(name, or_fail = false)
def self.find_by_name(name, or_fail: false)
name_parts = name.split(':')
raise InvalidAttributeError, "Attribute '#{name}' must be in the $NAMESPACE:$NAME style" if name_parts.length != 2

find_by_namespace_and_name(name_parts[0], name_parts[1], or_fail)
find_by_namespace_and_name(name_parts[0], name_parts[1], or_fail: or_fail)
end

def self.find_by_namespace_and_name!(namespace, name)
find_by_namespace_and_name(namespace, name, true)
find_by_namespace_and_name(namespace, name, or_fail: true)
end

def self.find_by_namespace_and_name(namespace, name, or_fail = false)
def self.find_by_namespace_and_name(namespace, name, or_fail: false)
raise ArgumentError, 'Need namespace and name as parameters' unless namespace && name

attribute_type = joins(:attrib_namespace).find_by('attrib_namespaces.name = ? and attrib_types.name = ?', namespace, name)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/bs_request_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def matches_package?(source_or_target, pkg)
end

def is_from_remote?
Project.unscoped.is_remote_project?(source_project, true)
Project.unscoped.is_remote_project?(source_project, skip_access: true)
end

def store_from_xml(hash)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/event/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def headers_for_actions
end

def source_from_remote?
payload['actions'].any? { |action| Project.unscoped.is_remote_project?(action['sourceproject'], true) }
payload['actions'].any? { |action| Project.unscoped.is_remote_project?(action['sourceproject'], skip_access: true) }
end

def payload_without_target_project?
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def deleted_instance
project
end

def is_remote_project?(name, skip_access = false)
lpro = find_remote_project(name, skip_access)
def is_remote_project?(name, skip_access: false)
lpro = find_remote_project(name, skip_access: skip_access)

lpro && lpro[0].defines_remote_instance?
end
Expand Down Expand Up @@ -285,7 +285,7 @@ def find_by_attribute_type(attrib_type)
Project.joins(:attribs).where(attribs: { attrib_type_id: attrib_type.id })
end

def find_remote_project(name, skip_access = false)
def find_remote_project(name, skip_access: false)
return unless name

fragments = name.split(':')
Expand Down Expand Up @@ -675,7 +675,7 @@ def check_weak_dependencies!
raise DeleteError, 'This maintenance project has incident projects and can therefore not be deleted.'
end

def can_be_unlocked?(with_exception = true)
def can_be_unlocked?(with_exception: true)
if is_maintenance_incident?
requests = BsRequest.where(state: %i[new review declined]).joins(:bs_request_actions)
maintenance_release_requests = requests.where(bs_request_actions: { type: 'maintenance_release', source_project: name })
Expand Down Expand Up @@ -1230,7 +1230,7 @@ def unlock!(comment = nil)
end

def unlock(comment = nil)
if can_be_unlocked?(false)
if can_be_unlocked?(with_exception: false)
do_unlock(comment)
else
false
Expand Down

0 comments on commit d41fd16

Please sign in to comment.