Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect user's work #648

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions app/controllers/api/pxe_servers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def create_resource(_type, _id, data = {})
server.update_authentication({:default => authentication.compact}, {:save => true})
end

server.pxe_menus = create_pxe_menus(menus) if menus
server.ensure_menu_list(menus.map { |el| el['file_name'] }) if menus

if server.invalid?
raise BadRequestError, "Failed to add a pxe server - #{server.errors.full_messages.join(', ')}"
Expand All @@ -48,27 +48,15 @@ def edit_resource(type, id, data)
menus = data.delete('pxe_menus')
authentication = data.delete('authentication')
PxeServer.transaction do
if menus
server.pxe_menus.destroy_all
data['pxe_menus'] = create_pxe_menus(menus)
end
server.update!(data)
server.update_authentication({:default => authentication.transform_keys(&:to_sym)}, {:save => true}) if authentication && server.requires_credentials?
server.ensure_menu_list(menus.map { |el| el['file_name'] }) if menus
server
end
end

private

def create_pxe_menus(menus)
menus.each do |menu|
validate_data_for('PxeMenu', menu)
end
menus.map do |menu|
collection_class(:pxe_menus).create(menu)
end
end

def validate_data_for(klass, data)
bad_attrs = []
PXE_ATTRIBUTES[klass].each { |attr| bad_attrs << attr if data[attr].blank? }
Expand Down