From fc1689cf2e8e0fe02608588f1aa59618d838e5bf Mon Sep 17 00:00:00 2001 From: Du Peng Date: Wed, 27 Sep 2023 12:39:04 +0200 Subject: [PATCH 1/8] (bug) unable to generate stats --- CHANGELOG.md | 4 ++++ app/services/statistics/builder_service.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index caa42abbc..4fbc0728b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog Fab-manager +- Fix a bug: unable to generate statistic +- [TODO DEPLOY] `rails fablab:es:build_stats` +- [TODO DEPLOY] `rails fablab:maintenance:regenerate_statistics[2023,6]` + ## v6.1.0 2023 September 25 - improves api/notification controller to avoid failing when there is a notification with wrong notification_type in db diff --git a/app/services/statistics/builder_service.rb b/app/services/statistics/builder_service.rb index 9e84eb697..60fcc57d2 100644 --- a/app/services/statistics/builder_service.rb +++ b/app/services/statistics/builder_service.rb @@ -17,7 +17,7 @@ class Statistics::BuilderService private def default_options - yesterday = Time.current + yesterday = 1.day.ago { start_date: yesterday.beginning_of_day, end_date: yesterday.end_of_day From 13ff17cdea352b156a75409719630dd659f840c2 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 27 Sep 2023 15:36:00 +0200 Subject: [PATCH 2/8] (ui) Fix projects grid button --- app/frontend/src/stylesheets/modules/projects/projects.scss | 4 ++++ app/frontend/templates/projects/index.html | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/frontend/src/stylesheets/modules/projects/projects.scss b/app/frontend/src/stylesheets/modules/projects/projects.scss index b8ce90a45..cc69f474c 100644 --- a/app/frontend/src/stylesheets/modules/projects/projects.scss +++ b/app/frontend/src/stylesheets/modules/projects/projects.scss @@ -39,6 +39,10 @@ grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 3.2rem; & > span { grid-column: 1/-1;} + & > a { + grid-column: 1/-1; + justify-self: center; + } } @media (min-width: 1200px) { diff --git a/app/frontend/templates/projects/index.html b/app/frontend/templates/projects/index.html index fde57a138..b2bde70ed 100644 --- a/app/frontend/templates/projects/index.html +++ b/app/frontend/templates/projects/index.html @@ -126,8 +126,7 @@

{{project.name}}

{{ project.app_name }} - - {{ 'app.public.projects_list.load_next_projects' }} + {{ 'app.public.projects_list.load_next_projects' }} From fe1b55599036c62829056223ed9409a3629c9181 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Wed, 27 Sep 2023 15:36:19 +0200 Subject: [PATCH 3/8] Fix a bug: unable to sync projects with openprojects --- CHANGELOG.md | 7 +++++++ app/services/open_lab_service.rb | 10 ++++------ test/services/open_lab_service_test.rb | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 test/services/open_lab_service_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index caa42abbc..5cb635acb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog Fab-manager +## next release + +- Fix a bug: unable to sync projects with openprojects + +- [TODO DEPLOY] `rails fablab:openlab:bulk_export` +- [TODO DEPLOY] `rails fablab:openlab:bulk_update` + ## v6.1.0 2023 September 25 - improves api/notification controller to avoid failing when there is a notification with wrong notification_type in db diff --git a/app/services/open_lab_service.rb b/app/services/open_lab_service.rb index 0aae0d0ec..c05385e76 100644 --- a/app/services/open_lab_service.rb +++ b/app/services/open_lab_service.rb @@ -3,8 +3,6 @@ # Provides methods to sync projects on OpenLab class OpenLabService class << self - include ActionView::Helpers::SanitizeHelper - def to_hash(project) { id: project.id, @@ -20,9 +18,9 @@ class OpenLabService steps_body: steps_body(project), image_path: project.project_image&.attachment&.medium&.url, project_path: "/#!/projects/#{project.slug}", - updated_at: project.updated_at.to_s(:iso8601), - created_at: project.created_at.to_s(:iso8601), - published_at: project.published_at.to_s(:iso8601) + updated_at: project.updated_at.to_fs(:iso8601), + created_at: project.created_at.to_fs(:iso8601), + published_at: project.published_at.to_fs(:iso8601) } end @@ -32,7 +30,7 @@ class OpenLabService .gsub("\r\n", ' ').gsub("\n\r", ' ') .gsub("\n", ' ').gsub("\r", ' ').gsub("\t", ' ') - strip_tags(concatenated_steps).strip + ActionController::Base.helpers.strip_tags(concatenated_steps).strip end end end diff --git a/test/services/open_lab_service_test.rb b/test/services/open_lab_service_test.rb new file mode 100644 index 000000000..03de1a5bd --- /dev/null +++ b/test/services/open_lab_service_test.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'test_helper' + +# In the following tests, amounts are expressed in centimes, ie. 1000 = 1000 cts = 10,00 EUR +class OpenLabServiceTest < ActiveSupport::TestCase + test "do not raise any error" do + h = nil + + assert_nothing_raised do + h = OpenLabService.to_hash(projects(:project_1)) + end + + assert_instance_of Hash, h + end +end \ No newline at end of file From 73f30de587e447ab7a7458f9179725e2c0ed66cc Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Wed, 27 Sep 2023 15:39:00 +0200 Subject: [PATCH 4/8] Fix a bug: public availabilities (no user) was buggy (server error) --- CHANGELOG.md | 1 + app/services/availabilities/availabilities_service.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb635acb..4bc787985 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## next release - Fix a bug: unable to sync projects with openprojects +- Fix a bug: public availabilities (no user) was buggy (server error) - [TODO DEPLOY] `rails fablab:openlab:bulk_export` - [TODO DEPLOY] `rails fablab:openlab:bulk_update` diff --git a/app/services/availabilities/availabilities_service.rb b/app/services/availabilities/availabilities_service.rb index 8df177504..dc5c4671e 100644 --- a/app/services/availabilities/availabilities_service.rb +++ b/app/services/availabilities/availabilities_service.rb @@ -141,7 +141,7 @@ class Availabilities::AvailabilitiesService end def flag_or_remove_blocked_slots(slots, blocked_slots, user) - if user.admin? || user.manager? + if user && (user.admin? || user.manager?) blocked_slots.each do |slot| slot.is_blocked = true end From b11bb11968bdaa64faab8ccc2406dc7b9a0e07aa Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 28 Sep 2023 08:49:36 +0200 Subject: [PATCH 5/8] Fix a bug: rss/projects was failing with project without image --- CHANGELOG.md | 1 + app/views/rss/events/index.xml.builder | 4 +++- app/views/rss/projects/index.xml.builder | 4 +++- test/integration/rss/events_test.rb | 13 +++++++++++++ test/integration/rss/projects_test.rb | 13 +++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/integration/rss/events_test.rb create mode 100644 test/integration/rss/projects_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e5bf3c7..cf24fa613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix a bug: unable to sync projects with openprojects - Fix a bug: public availabilities (no user) was buggy (server error) - Fix a bug: unable to generate statistic +- Fix a bug: rss/projects was failing with project without image - [TODO DEPLOY] `rails fablab:openlab:bulk_export` - [TODO DEPLOY] `rails fablab:openlab:bulk_update` diff --git a/app/views/rss/events/index.xml.builder b/app/views/rss/events/index.xml.builder index b0a1942c6..1f03c90c1 100644 --- a/app/views/rss/events/index.xml.builder +++ b/app/views/rss/events/index.xml.builder @@ -22,7 +22,9 @@ xml.rss version: '2.0', 'xmlns:xCal' => 'urn:ietf:params:xml:ns:xcal' do xml.xCal :dtend do xml.text! event.availability.end_at.strftime('%FT%T%:z') end - xml.enclosure url: root_url + event.event_image.attachment.large.url, length: event.event_image.attachment.large.size, type: event.event_image.attachment.content_type if event.event_image + if event.event_image&.attachment? + xml.enclosure url: root_url + event.event_image.attachment.large.url, length: event.event_image.attachment.large.size, type: event.event_image.attachment.content_type + end xml.category event.category.name end end diff --git a/app/views/rss/projects/index.xml.builder b/app/views/rss/projects/index.xml.builder index 29e24057a..54525e2de 100644 --- a/app/views/rss/projects/index.xml.builder +++ b/app/views/rss/projects/index.xml.builder @@ -17,7 +17,9 @@ xml.rss version: '2.0' do xml.link root_url + '#!/projects/' + project.slug xml.author project.author&.user&.profile&.full_name xml.description project.description - xml.enclosure url: root_url + project.project_image.attachment.large.url, length: project.project_image.attachment.large.size, type: project.project_image.attachment.content_type if project.project_image + if project.project_image&.attachment? + xml.enclosure url: root_url + project.project_image.attachment.large.url, length: project.project_image.attachment.large.size, type: project.project_image.attachment.content_type + end end end end diff --git a/test/integration/rss/events_test.rb b/test/integration/rss/events_test.rb new file mode 100644 index 000000000..47972f271 --- /dev/null +++ b/test/integration/rss/events_test.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'test_helper' +module Rss; end + +class Rss::EventsTestTest < ActionDispatch::IntegrationTest + test '#index' do + get rss_events_path + + assert_response :success + assert Nokogiri::XML(response.body).errors.empty? + end +end \ No newline at end of file diff --git a/test/integration/rss/projects_test.rb b/test/integration/rss/projects_test.rb new file mode 100644 index 000000000..cf4945f2e --- /dev/null +++ b/test/integration/rss/projects_test.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'test_helper' +module Rss; end + +class Rss::ProjectsTestTest < ActionDispatch::IntegrationTest + test '#index' do + get rss_projects_path + + assert_response :success + assert Nokogiri::XML(response.body).errors.empty? + end +end \ No newline at end of file From d197f16cd92dfb79189965ed4b31bca2bb779026 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 28 Sep 2023 10:00:37 +0200 Subject: [PATCH 6/8] adds tests for public availabilities --- .../availabilities/availabilities_service.rb | 1 - .../availabilities/as_public_test.rb | 59 ++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/app/services/availabilities/availabilities_service.rb b/app/services/availabilities/availabilities_service.rb index dc5c4671e..c870fd1d3 100644 --- a/app/services/availabilities/availabilities_service.rb +++ b/app/services/availabilities/availabilities_service.rb @@ -40,7 +40,6 @@ class Availabilities::AvailabilitiesService if @level == 'slot' slots = availabilities.map(&:slots).flatten - blocked_slots = Slots::InterblockingService.new.blocked_slots_for_machines(machines, slots) flag_or_remove_blocked_slots(slots, blocked_slots, @current_user) else diff --git a/test/integration/availabilities/as_public_test.rb b/test/integration/availabilities/as_public_test.rb index 1b99204d9..5e5e8ea45 100644 --- a/test/integration/availabilities/as_public_test.rb +++ b/test/integration/availabilities/as_public_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class Availabilities::AsPublicTest < ActionDispatch::IntegrationTest - test 'get public machines availabilities if machines module is active' do + test "[level == 'availability'] get public machines availabilities if machines module is active" do start_date = Time.current.to_date end_date = 7.days.from_now.to_date @@ -24,6 +24,24 @@ class Availabilities::AsPublicTest < ActionDispatch::IntegrationTest end end + test "[level == 'slot'] get public machines availabilities if machines module is active" do + start_date = Time.current.to_date + end_date = start_date + 1.day + + get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_machines}" + + # Check response format & status + assert_equal 200, response.status + assert_match Mime[:json].to_s, response.content_type + + # Check the correct availabilities was returned + availabilities = json_response(response.body) + assert_not_empty availabilities, 'no availabilities were found' + availabilities.each do |a| + assert_not_empty a[:machine_ids] + end + end + test 'get anymore machines availabilities if machines module is inactive' do Setting.set('machines_module', false) start_date = Time.current.to_date @@ -61,6 +79,45 @@ class Availabilities::AsPublicTest < ActionDispatch::IntegrationTest end end + test "[level == 'availability'] get public spaces availabilities" do + start_date = Time.current.to_date + end_date = 7.days.from_now.to_date + + get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_spaces}" + + # Check response format & status + assert_equal 200, response.status + assert_match Mime[:json].to_s, response.content_type + + # Check the correct availabilities was returned + availabilities = json_response(response.body) + assert_not_empty availabilities, 'no availabilities were found' + availabilities.each_with_index do |a, index| + assert_not_nil a, "availability #{index} was unexpectedly nil" + assert_equal 'space', a[:available_type], "availability #{index} is not a space availability" + assert Time.zone.parse(a[:start]) > start_date, "availability #{index} starts before the requested period" + assert Time.zone.parse(a[:end]) < end_date, "availability #{index} ends after the requested period" + end + end + + test "[level == 'slot'] get public spaces availabilities" do + start_date = Time.current.to_date + end_date = start_date + 1.day + + get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_spaces}" + + # Check response format & status + assert_equal 200, response.status + assert_match Mime[:json].to_s, response.content_type + + # Check the correct availabilities was returned + availabilities = json_response(response.body) + assert_not_empty availabilities, 'no availabilities were found' + availabilities.each do |a| + assert_not_nil a[:space_id] + end + end + test 'get public spaces availabilities' do start_date = Time.current.to_date end_date = 7.days.from_now.to_date From d95e2ac56cedd1c95159a24454497abeafcac600 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 28 Sep 2023 15:57:30 +0200 Subject: [PATCH 7/8] improvement : performance of members#show and reservations#index --- CHANGELOG.md | 1 + app/controllers/api/reservations_controller.rb | 2 ++ app/views/api/members/show.json.jbuilder | 7 ++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf24fa613..3fd7063d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix a bug: public availabilities (no user) was buggy (server error) - Fix a bug: unable to generate statistic - Fix a bug: rss/projects was failing with project without image +- improvement : performance of members#show and reservations#index - [TODO DEPLOY] `rails fablab:openlab:bulk_export` - [TODO DEPLOY] `rails fablab:openlab:bulk_update` diff --git a/app/controllers/api/reservations_controller.rb b/app/controllers/api/reservations_controller.rb index 260fec568..495b95c9b 100644 --- a/app/controllers/api/reservations_controller.rb +++ b/app/controllers/api/reservations_controller.rb @@ -16,8 +16,10 @@ class API::ReservationsController < API::APIController where_clause[:reservable_id] = params[:reservable_id] if params[:reservable_id] @reservations = Reservation.where(where_clause) + .preload(:reservable, :booking_users, :tickets, { statistic_profile: { user: :profile }, slots_reservations: :slot }) elsif params[:reservable_id] && params[:reservable_type] && (current_user.admin? || current_user.manager?) @reservations = Reservation.where(params.permit(:reservable_id, :reservable_type)) + .preload(:reservable, :booking_users, :tickets, { statistic_profile: { user: :profile }, slots_reservations: :slot }) else @reservations = [] end diff --git a/app/views/api/members/show.json.jbuilder b/app/views/api/members/show.json.jbuilder index 0e7a44135..4313c1e38 100644 --- a/app/views/api/members/show.json.jbuilder +++ b/app/views/api/members/show.json.jbuilder @@ -10,7 +10,8 @@ json.trainings @member.trainings do |t| json.id t.id json.name t.name end -json.training_reservations @member.reservations.where(reservable_type: 'Training').map(&:slots_reservations).flatten do |sr| +reservations = @member.reservations.where(reservable_type: 'Training').preload(slots_reservations: [:slot, reservation: :reservable]) +json.training_reservations reservations.select { |r| r.reservable_type == "Training" }.map(&:slots_reservations).flatten do |sr| json.id sr.id json.start_at sr.slot.start_at json.end_at sr.slot.end_at @@ -19,7 +20,7 @@ json.training_reservations @member.reservations.where(reservable_type: 'Training json.is_valid @member.statistic_profile.training_ids.include?(sr.reservation.reservable_id) json.canceled_at sr.canceled_at end -json.machine_reservations @member.reservations.where(reservable_type: 'Machine').map(&:slots_reservations).flatten do |sr| +json.machine_reservations reservations.select { |r| r.reservable_type == "Machine" }.map(&:slots_reservations).flatten do |sr| json.id sr.id json.start_at sr.slot.start_at json.end_at sr.slot.end_at @@ -27,7 +28,7 @@ json.machine_reservations @member.reservations.where(reservable_type: 'Machine') json.reservable_type 'Machine' json.canceled_at sr.canceled_at end -json.space_reservations @member.reservations.where(reservable_type: 'Space').map(&:slots_reservations).flatten do |sr| +json.space_reservations reservations.select { |r| r.reservable_type == "Space" }.map(&:slots_reservations).flatten do |sr| json.id sr.id json.start_at sr.slot.start_at json.end_at sr.slot.end_at From d7e0d797c86f894db006d918442374579a8339c7 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 28 Sep 2023 16:03:32 +0200 Subject: [PATCH 8/8] Version X.Y.Z --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fd7063d7..fcbe38ffb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog Fab-manager -## next release +## v6.1.1 2023 September 28 - Fix a bug: unable to sync projects with openprojects - Fix a bug: public availabilities (no user) was buggy (server error) diff --git a/package.json b/package.json index 95f7b8ef0..024d9df00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fab-manager", - "version": "6.1.0", + "version": "6.1.1", "description": "Fab-manager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.", "keywords": [ "fablab",