1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

[bug] the count of successfully updated events was not correct

This commit is contained in:
Sylvain 2021-05-12 15:53:32 +02:00
parent 436db80ccf
commit 390f62fd41
3 changed files with 14 additions and 8 deletions

View File

@ -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)

View File

@ -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

View File

@ -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