diff --git a/CHANGELOG.md b/CHANGELOG.md index 143d8e48d..b24f9a321 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Increased the width of the input field for the prices of the events - Fix a bug: the notification sent to the project author when a collaborator has confirmed his participation is not sent - Fix a bug: the event themes are not kept when editing the event again +- Fix a bug: the count of successfully updated events was not correct - Fix a security issue: updated underscore to 1.12.1 to fix [CVE-2021-23358](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-23358) - Fix a security issue: updated lodash to 4.17.21 to fix [CVE-2021-23337](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-23337) - Fix a security issue: updated url-parse to 1.5.1 to fix [CVE-2021-27515](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-27515) diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb index 3c145cb0f..0c051743a 100644 --- a/app/controllers/api/events_controller.rb +++ b/app/controllers/api/events_controller.rb @@ -64,7 +64,9 @@ class API::EventsController < API::ApiController def update authorize Event res = EventService.update(@event, event_params.permit!, params[:edit_mode]) - render json: { action: 'update', total: res.length, updated: res.select { |r| r[:status] }.length, details: res }, status: :ok, location: @event + render json: { action: 'update', total: res[:events].length, updated: res[:events].select { |r| r[:status] }.length, details: res }, + status: :ok, + location: @event end def destroy diff --git a/app/services/event_service.rb b/app/services/event_service.rb index 91b617c6c..6747aca36 100644 --- a/app/services/event_service.rb +++ b/app/services/event_service.rb @@ -102,7 +102,10 @@ class EventService private def update_events(event, events, event_params) - results = [] + results = { + events: [], + slots: [] + } events.each do |e| next unless e.id != event.id @@ -164,18 +167,18 @@ class EventService event_files_attributes: ef_attributes ) begin - results.push status: !!e.update(e_params.permit!), event: e # rubocop:disable Style/DoubleNegation + results[:events].push status: !!e.update(e_params.permit!), event: e # rubocop:disable Style/DoubleNegation rescue StandardError => err - results.push status: false, event: e, error: err.try(:record).try(:class).try(:name), message: err.message + results[:events].push status: false, event: e, error: err.try(:record).try(:class).try(:name), message: err.message end - results.concat(update_slots(e.availability_id)) + results[:slots].concat(update_slots(e.availability_id)) end begin - results.push status: !!event.update(event_params), event: event # rubocop:disable Style/DoubleNegation + results[:events].push status: !!event.update(event_params), event: event # rubocop:disable Style/DoubleNegation rescue StandardError => err - results.push status: false, event: event, error: err.try(:record).try(:class).try(:name), message: err.message + results[:events].push status: false, event: event, error: err.try(:record).try(:class).try(:name), message: err.message end - results.concat(update_slots(event.availability_id)) + results[:slots].concat(update_slots(event.availability_id)) results end