-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #691 from djberg96/zones_post_actions
Allow Zones to be edited, deleted
- Loading branch information
Showing
3 changed files
with
171 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
module Api | ||
class ZonesController < BaseController | ||
INVALID_ZONES_ATTRS = ID_ATTRS + %w[created_on updated_on].freeze | ||
|
||
# Edit an existing zone. 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 zone 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_ZONES_ATTRS.include?(key) }.compact.join(", ") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters