-
Notifications
You must be signed in to change notification settings - Fork 143
/
regions_controller.rb
32 lines (26 loc) · 1.07 KB
/
regions_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Api
class RegionsController < BaseController
INVALID_REGIONS_ATTRS = ID_ATTRS + %w[created_at updated_at region guid migrations_ran maintenance_zone_id].freeze
# Edit an existing region (MiqRegion). Certain fields are meant for
# internal use only and may not be edited. Attempting to edit one of
# the forbidden fields will result in a bad request error.
#
def edit_resource(type, id, data)
bad_attrs = data_includes_invalid_attrs(data)
if bad_attrs.present?
msg = "Attribute(s) '#{bad_attrs}' should not be specified for updating a region resource"
raise BadRequestError, msg
end
super
end
private
# Check to see if any of the data attributes contain an invalid field.
# Returns a list of invalid fields as a comma separated string that you
# can use for error messages, or nil if the data argument is blank.
#
def data_includes_invalid_attrs(data)
return nil unless data
data.keys.select { |key| INVALID_REGIONS_ATTRS.include?(key) }.compact.join(", ")
end
end
end