Skip to content

Commit

Permalink
[frontend] Cleanup usage of constants
Browse files Browse the repository at this point in the history
* Make IntermediateStates a local variable, since it was only used in
  one method.
* Fix naming of ActionNotifyLimit constant and move it up to the other
  constants. Constants should be written in CAMEL_CASE;-)
  • Loading branch information
bgeuken committed Oct 11, 2017
1 parent 15878f7 commit 050a392
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class SaveError < APIException

FINAL_REQUEST_STATES = %w(accepted declined superseded revoked)

ACTION_NOTIFY_LIMIT = 50

scope :to_accept, -> { where(state: 'new').where('accept_at < ?', DateTime.now) }
# Scopes for collections
scope :with_actions, -> { includes(:bs_request_actions).references(:bs_request_actions).distinct.order(priority: :asc, id: :desc) }
Expand Down Expand Up @@ -133,7 +135,7 @@ def self.list_numbers(opts)

def self.actions_summary(payload)
ret = []
payload.with_indifferent_access['actions'][0..ActionNotifyLimit].each do |a|
payload.with_indifferent_access['actions'][0..ACTION_NOTIFY_LIMIT].each do |a|
str = "#{a['type']} #{a['targetproject']}"
str += "/#{a['targetpackage']}" if a['targetpackage']
str += "/#{a['targetrepository']}" if a['targetrepository']
Expand Down Expand Up @@ -837,17 +839,14 @@ def setincident(incident)
HistoryElement::RequestSetIncident.create(p)
end

IntermediateStates = %w(new review)

def send_state_change
intermediate_state = %w(new review)
return if state_was.to_s == state.to_s
# new->review && review->new are not worth an event - it's just spam
return if state.to_s.in?(IntermediateStates) && state_was.to_s.in?(IntermediateStates)
return if state.to_s.in?(intermediate_state) && state_was.to_s.in?(intermediate_state)
Event::RequestStatechange.create(notify_parameters)
end

ActionNotifyLimit = 50

def notify_parameters(ret = {})
ret[:number] = number
ret[:description] = description
Expand All @@ -860,7 +859,7 @@ def notify_parameters(ret = {})

# Use a nested data structure to support multiple actions in one request
ret[:actions] = []
bs_request_actions[0..ActionNotifyLimit].each do |a|
bs_request_actions[0..ACTION_NOTIFY_LIMIT].each do |a|
ret[:actions] << a.notify_params
end
ret
Expand Down

0 comments on commit 050a392

Please sign in to comment.