diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 81427015b..67364efb4 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -5,7 +5,7 @@ class TeamsController < ApplicationController before_action :check_create_samples_permissions, only: %i(parse_sheet import_samples) before_action :check_view_samples_permission, only: [:export_samples] - before_action :check_export_projects_permissions, only: [:export_projects] + before_action :check_export_projects_permissions, only: :export_projects def parse_sheet session[:return_to] ||= request.referer @@ -228,8 +228,9 @@ class TeamsController < ApplicationController def export_projects if export_projects_params[:project_ids] # Check if user has enough requests for the day - limit = ENV['EXPORT_ALL_LIMIT_24_HOURS'].to_i || 3 - if current_user.export_vars['num_of_export_all_last_24_hours'] >= limit + limit = (ENV['EXPORT_ALL_LIMIT_24_HOURS'] || 3).to_i + if limit.zero? \ + || current_user.export_vars['num_of_export_all_last_24_hours'] >= limit render json: { html: render_to_string( partial: 'projects/export/error.html.erb', @@ -254,11 +255,7 @@ class TeamsController < ApplicationController title: t('projects.export_projects.modal_title_success') } end - return - else - flash[:alert] = t('zip_export.export_error') end - redirect_back(fallback_location: root_path) end def routing_error(error = 'Routing error', status = :not_found, exception=nil) diff --git a/app/views/projects/export/_error.html.erb b/app/views/projects/export/_error.html.erb index 2f1bd5365..58896de9c 100644 --- a/app/views/projects/export/_error.html.erb +++ b/app/views/projects/export/_error.html.erb @@ -2,5 +2,5 @@ It looks like you have exceeded your daily export limit. The number of exports is limited to <%= limit %> requests per day - you currently have 0 export requests left.

-

Please repeat the desired action tomorrow, when your daily limit will rise back to <%= limit %> export requests. +

Please repeat the desired action tomorrow, when your daily limit will reset back to <%= limit %> export requests.

diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index 0a57952b4..706004343 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -88,7 +88,7 @@ diff --git a/lib/tasks/exportable_items.rake b/lib/tasks/exportable_items.rake index 2f9946b6e..04f9130f3 100644 --- a/lib/tasks/exportable_items.rake +++ b/lib/tasks/exportable_items.rake @@ -9,7 +9,7 @@ namespace :exportable_items do desc 'Resets export project counter to 0' task reset_export_projects_counter: :environment do - User.all.each do |user| + User.find_each do |user| User.transaction do begin user.export_vars['num_of_export_all_last_24_hours'] = 0 @@ -17,7 +17,8 @@ namespace :exportable_items do rescue ActiveRecord::ActiveRecordError, ArgumentError, ActiveRecord::RecordNotSaved => e - puts "Error creating user, transaction reverted: #{e}" + puts "Error resetting users num_of_export_all_last_24_hours " \ + "variable to 0, transaction reverted: #{e}" end end end