Skip to content

Commit

Permalink
[frontend] DRY code in BsRequest model
Browse files Browse the repository at this point in the history
Move duplicated code for checking associated bs_request_actions
into private method.
  • Loading branch information
bgeuken committed Oct 10, 2017
1 parent e9d9064 commit 9812972
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,7 @@ def permission_check_change_state!(opts)
# check target write permissions
return unless opts[:newstate] == 'accepted'

bs_request_actions.each do |action|
action.check_action_permission!(true)
action.check_for_expand_errors! !@addrevision.nil?
raisepriority(action.minimum_priority)
end
check_bs_request_actions!(skip_source: true)
end

def changestate_accepted(opts)
Expand Down Expand Up @@ -994,12 +990,7 @@ def sanitize!
# expand release and submit request targets if not specified
expand_targets

bs_request_actions.each do |action|
# permission checks
action.check_action_permission!
action.check_for_expand_errors! !@addrevision.nil?
raisepriority(action.minimum_priority)
end
check_bs_request_actions!

# Autoapproval? Is the creator allowed to accept it?
if accept_at
Expand Down Expand Up @@ -1213,6 +1204,17 @@ def update_cache
User.where(id: user_ids).update_all(updated_at: Time.now)
# rubocop:enable Rails/SkipsModelValidations
end

private

def check_bs_request_actions!(opts = {})
bs_request_actions.each do |action|
action.check_action_permission!(opts[:skip_source])
action.check_for_expand_errors!(!@addrevision.nil?)
raisepriority(action.minimum_priority)
end
end

end

# == Schema Information
Expand Down

0 comments on commit 9812972

Please sign in to comment.