Skip to content

Commit

Permalink
Merge pull request #2810 from mschnitzer/enable_rubocop_case_indentation
Browse files Browse the repository at this point in the history
Enable Style/CaseIndentation Rubocop cop
  • Loading branch information
Ana06 committed Mar 20, 2017
2 parents 41441c6 + af832e0 commit 937115c
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 231 deletions.
4 changes: 4 additions & 0 deletions src/api/.rubocop.yml
Expand Up @@ -32,6 +32,10 @@ Style/AndOr:
Style/AsciiComments:
Enabled: true

# This cop checks how the 'when's of a case expression are indented in relation to its `case` or `end` keyword.
Style/CaseIndentation:
Enabled: true

# Checks for methods invoked via the :: operator
Style/ColonMethodCall:
Enabled: true
Expand Down
19 changes: 0 additions & 19 deletions src/api/.rubocop_todo.yml
Expand Up @@ -243,25 +243,6 @@ Style/BlockDelimiters:
Style/BracesAroundHashParameters:
Enabled: false

# Offense count: 79
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Style/CaseIndentation:
Exclude:
- 'app/controllers/group_controller.rb'
- 'app/controllers/search_controller.rb'
- 'app/controllers/webui/request_controller.rb'
- 'app/controllers/webui/webui_controller.rb'
- 'app/helpers/webui/package_helper.rb'
- 'app/models/bs_request.rb'
- 'app/models/bs_request_permission_check.rb'
- 'app/models/cache_line.rb'
- 'app/models/user_ldap_strategy.rb'
- 'db/migrate/20140908125426_convert_request_history.rb'
- 'lib/opensuse/backend.rb'
- 'lib/opensuse/validator.rb'

# Offense count: 110
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Expand Down
14 changes: 7 additions & 7 deletions src/api/app/controllers/group_controller.rb
Expand Up @@ -10,13 +10,13 @@ class GroupController < ApplicationController

rescue_from Pundit::NotAuthorizedError do |exception|
pundit_action = case exception.query.to_s
when "index?" then "list"
when "show?" then "view"
when "create?" then "create"
when "new?" then "create"
when "update?" then "update"
when "destroy?" then "delete"
else exception.query
when "index?" then "list"
when "show?" then "view"
when "create?" then "create"
when "new?" then "create"
when "update?" then "update"
when "destroy?" then "delete"
else exception.query
end

render_error status: 403, errorcode: "No permission to #{pundit_action} group"
Expand Down
12 changes: 6 additions & 6 deletions src/api/app/controllers/search_controller.rb
Expand Up @@ -92,12 +92,12 @@ def owner

def predicate_from_match_parameter(p)
pred = case p
when /^\(\[(.*)\]\)$/
$1
when /^\[(.*)\]$/
$1
else
p
when /^\(\[(.*)\]\)$/
$1
when /^\[(.*)\]$/
$1
else
p
end
pred = "*" if pred.nil? || pred.empty?
pred
Expand Down
18 changes: 9 additions & 9 deletions src/api/app/controllers/webui/request_controller.rb
Expand Up @@ -21,15 +21,15 @@ def add_reviewer
begin
opts = {}
case params[:review_type]
when 'user' then
opts[:by_user] = params[:review_user]
when 'group' then
opts[:by_group] = params[:review_group]
when 'project' then
opts[:by_project] = params[:review_project]
when 'package' then
opts[:by_project] = params[:review_project]
opts[:by_package] = params[:review_package]
when 'user' then
opts[:by_user] = params[:review_user]
when 'group' then
opts[:by_group] = params[:review_group]
when 'project' then
opts[:by_project] = params[:review_project]
when 'package' then
opts[:by_project] = params[:review_project]
opts[:by_package] = params[:review_package]
end
opts[:comment] = params[:review_comment] if params[:review_comment]

Expand Down
18 changes: 9 additions & 9 deletions src/api/app/controllers/webui/webui_controller.rb
Expand Up @@ -28,15 +28,15 @@ def handle_unverified_request

rescue_from Pundit::NotAuthorizedError do |exception|
pundit_action = case exception.try(:query).to_s
when "index?" then "list"
when "show?" then "view"
when "create?" then "create"
when "new?" then "create"
when "update?" then "update"
when "edit?" then "edit"
when "destroy?" then "delete"
when "branch?" then "branch"
else exception.try(:query)
when "index?" then "list"
when "show?" then "view"
when "create?" then "create"
when "new?" then "create"
when "update?" then "update"
when "edit?" then "edit"
when "destroy?" then "delete"
when "branch?" then "branch"
else exception.try(:query)
end
if pundit_action && exception.record
message = "Sorry, you are not authorized to #{pundit_action} this #{exception.record.class}."
Expand Down
24 changes: 12 additions & 12 deletions src/api/app/helpers/webui/package_helper.rb
Expand Up @@ -29,18 +29,18 @@ def guess_code_class( filename )
return 'spec' if filename =~ /^macros\.\w+/
ext = Pathname.new(filename).extname.downcase
case ext
when '.group' then return 'xml'
when '.kiwi' then return 'xml'
when '.patch', '.dif' then return 'diff'
when '.pl', '.pm' then return 'perl'
when '.product' then return 'xml'
when '.py' then return 'python'
when '.rb' then return 'ruby'
when '.tex' then return 'latex'
when '.js' then return 'javascript'
when '.sh' then return 'shell'
when '.spec' then return 'rpm-spec'
when '.changes' then return 'rpm-changes'
when '.group' then return 'xml'
when '.kiwi' then return 'xml'
when '.patch', '.dif' then return 'diff'
when '.pl', '.pm' then return 'perl'
when '.product' then return 'xml'
when '.py' then return 'python'
when '.rb' then return 'ruby'
when '.tex' then return 'latex'
when '.js' then return 'javascript'
when '.sh' then return 'shell'
when '.spec' then return 'rpm-spec'
when '.changes' then return 'rpm-changes'
end
ext = ext[1..-1]
return ext if ext.in?(["diff", "php", "html", "xml", "css", "perl"])
Expand Down
130 changes: 65 additions & 65 deletions src/api/app/models/bs_request.rb
Expand Up @@ -526,21 +526,21 @@ def change_state(opts)

params = {request: self, comment: opts[:comment], user_id: User.current.id}
case opts[:newstate]
when "accepted" then
history = HistoryElement::RequestAccepted
when "declined" then
history = HistoryElement::RequestDeclined
when "revoked" then
history = HistoryElement::RequestRevoked
when "superseded" then
history = HistoryElement::RequestSuperseded
params[:description_extension] = superseded_by.to_s
when "review" then
history = HistoryElement::RequestReopened
when "new" then
history = HistoryElement::RequestReopened
else
raise RuntimeError, "Unhandled state #{opts[:newstate]} for history"
when "accepted" then
history = HistoryElement::RequestAccepted
when "declined" then
history = HistoryElement::RequestDeclined
when "revoked" then
history = HistoryElement::RequestRevoked
when "superseded" then
history = HistoryElement::RequestSuperseded
params[:description_extension] = superseded_by.to_s
when "review" then
history = HistoryElement::RequestReopened
when "new" then
history = HistoryElement::RequestReopened
else
raise RuntimeError, "Unhandled state #{opts[:newstate]} for history"
end
history.create(params)
end
Expand Down Expand Up @@ -1052,63 +1052,63 @@ def webui_actions(with_diff = true)
end

case xml.action_type # All further stuff depends on action type...
when :submit then
action[:name] = "Submit #{action[:spkg]}"
action[:sourcediff] = xml.webui_infos if with_diff
creator = User.find_by_login(self.creator)
target_package = Package.find_by_project_and_name(action[:tprj], action[:tpkg])
action[:creator_is_target_maintainer] = true if creator.has_local_role?(Role.rolecache['maintainer'], target_package)

if target_package
linkinfo = target_package.linkinfo
target_package.developed_packages.each do |dev_pkg|
action[:forward] ||= []
action[:forward] << {project: dev_pkg.project.name, package: dev_pkg.name, type: 'devel' }
end
if linkinfo
lprj, lpkg = linkinfo['project'], linkinfo['package']
link_is_already_devel = false
if action[:forward]
action[:forward].each do |forward|
if forward[:project] == lprj && forward[:package] == lpkg
link_is_already_devel = true
break
end
when :submit then
action[:name] = "Submit #{action[:spkg]}"
action[:sourcediff] = xml.webui_infos if with_diff
creator = User.find_by_login(self.creator)
target_package = Package.find_by_project_and_name(action[:tprj], action[:tpkg])
action[:creator_is_target_maintainer] = true if creator.has_local_role?(Role.rolecache['maintainer'], target_package)

if target_package
linkinfo = target_package.linkinfo
target_package.developed_packages.each do |dev_pkg|
action[:forward] ||= []
action[:forward] << {project: dev_pkg.project.name, package: dev_pkg.name, type: 'devel' }
end
if linkinfo
lprj, lpkg = linkinfo['project'], linkinfo['package']
link_is_already_devel = false
if action[:forward]
action[:forward].each do |forward|
if forward[:project] == lprj && forward[:package] == lpkg
link_is_already_devel = true
break
end
end
unless link_is_already_devel
action[:forward] ||= []
action[:forward] << {project: linkinfo['project'], package: linkinfo['package'], type: 'link'}
end
end
unless link_is_already_devel
action[:forward] ||= []
action[:forward] << {project: linkinfo['project'], package: linkinfo['package'], type: 'link'}
end
end
end

when :delete then
if action[:tpkg]
action[:name] = "Delete #{action[:tpkg]}"
elsif action[:trepo]
action[:name] = "Delete #{action[:trepo]}"
else
action[:name] = "Delete #{action[:tprj]}"
end
when :delete then
if action[:tpkg]
action[:name] = "Delete #{action[:tpkg]}"
elsif action[:trepo]
action[:name] = "Delete #{action[:trepo]}"
else
action[:name] = "Delete #{action[:tprj]}"
end

if action[:tpkg] # API / Backend don't support whole project diff currently
action[:sourcediff] = xml.webui_infos if with_diff
end
when :add_role then
action[:name] = 'Add Role'
action[:role] = xml.role
action[:user] = xml.person_name
when :change_devel then
action[:name] = 'Change Devel'
when :set_bugowner then
action[:name] = 'Set Bugowner'
when :maintenance_incident then
action[:name] = "Incident #{action[:spkg]}"
action[:sourcediff] = xml.webui_infos if with_diff
when :maintenance_release then
action[:name] = "Release #{action[:spkg]}"
if action[:tpkg] # API / Backend don't support whole project diff currently
action[:sourcediff] = xml.webui_infos if with_diff
end
when :add_role then
action[:name] = 'Add Role'
action[:role] = xml.role
action[:user] = xml.person_name
when :change_devel then
action[:name] = 'Change Devel'
when :set_bugowner then
action[:name] = 'Set Bugowner'
when :maintenance_incident then
action[:name] = "Incident #{action[:spkg]}"
action[:sourcediff] = xml.webui_infos if with_diff
when :maintenance_release then
action[:name] = "Release #{action[:spkg]}"
action[:sourcediff] = xml.webui_infos if with_diff
end
actions << action
end
Expand Down
54 changes: 27 additions & 27 deletions src/api/app/models/bs_request_permission_check.rb
Expand Up @@ -152,12 +152,12 @@ def check_action_target(action)
else
err = nil
case action.action_type
when :change_devel
err = "Local source package is missing for request #{action.bs_request.number} (type #{action.action_type})"
when :set_bugowner
when :add_role
else
action.source_access_check!
when :change_devel
err = "Local source package is missing for request #{action.bs_request.number} (type #{action.action_type})"
when :set_bugowner
when :add_role
else
action.source_access_check!
end
raise SourceMissing.new err if err
end
Expand Down Expand Up @@ -392,30 +392,30 @@ def require_permissions_in_target_or_source
def extra_permissions_check_changestate
err =
case opts[:newstate]
when 'superseded'
when 'superseded'
# Is the user involved in any project or package ?
unless @write_permission_in_target || @write_permission_in_source
"You have no role in request #{req.number}"
end
when 'accepted'
unless @write_permission_in_target || @write_permission_in_source
"You have no role in request #{req.number}"
end
when 'accepted'
# requires write permissions in all targets, this is already handled in each action check
when 'revoked'
when 'revoked'
# general revoke permission check based on source maintainership. We don't get here if the user is the creator of request
unless @write_permission_in_source
"No permission to revoke request #{req.number}"
end
when 'new'
if (req.state == :revoked && !@write_permission_in_source) ||
(req.state == :declined && !@write_permission_in_target)
"No permission to reopen request #{req.number}"
end
when 'declined'
unless @write_permission_in_target
# at least on one target the permission must be granted on decline
"No permission to decline request #{req.number}"
end
else
"No permission to change request #{req.number} state"
unless @write_permission_in_source
"No permission to revoke request #{req.number}"
end
when 'new'
if (req.state == :revoked && !@write_permission_in_source) ||
(req.state == :declined && !@write_permission_in_target)
"No permission to reopen request #{req.number}"
end
when 'declined'
unless @write_permission_in_target
# at least on one target the permission must be granted on decline
"No permission to decline request #{req.number}"
end
else
"No permission to change request #{req.number} state"
end
raise PostRequestNoPermission.new err if err
end
Expand Down

0 comments on commit 937115c

Please sign in to comment.