From c4087c7a630c53e40cd733bd06db15fbc45f4a27 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Fri, 10 Nov 2017 12:08:13 +0100 Subject: [PATCH] def log_activity functions #802 --- app/controllers/dmsf_controller.rb | 11 ----------- app/controllers/dmsf_files_controller.rb | 9 --------- app/controllers/dmsf_files_copy_controller.rb | 19 ------------------- .../dmsf_folders_copy_controller.rb | 11 ----------- 4 files changed, 50 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 6894ffd0..fb31f17b 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -339,10 +339,6 @@ class DmsfController < ApplicationController private - def log_activity(file, action) - Rails.logger.info "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}@#{request.remote_ip}/#{request.env['HTTP_X_FORWARDED_FOR']}: #{action} dmsf://#{file.project.identifier}/#{file.id}" - end - def email_entries(selected_folders, selected_files) begin zip = DmsfZip.new @@ -363,7 +359,6 @@ class DmsfController < ApplicationController end zip.files.each do |f| - log_activity(f, 'emailing zip') audit = DmsfFileRevisionAccess.new audit.user = User.current audit.dmsf_file_revision = f.last_revision @@ -390,16 +385,13 @@ class DmsfController < ApplicationController begin zip = DmsfZip.new zip_entries(zip, selected_folders, selected_files) - zip.files.each do |f| - log_activity(f, 'download zip') audit = DmsfFileRevisionAccess.new audit.user = User.current audit.dmsf_file_revision = f.last_revision audit.action = DmsfFileRevisionAccess::DownloadAction audit.save! end - send_file(zip.finish, :filename => filename_for_content_disposition("#{@project.name}-#{DateTime.now.strftime('%y%m%d%H%M%S')}.zip"), :type => 'application/zip', @@ -508,9 +500,6 @@ class DmsfController < ApplicationController end # Activities if !deleted_files.empty? - deleted_files.each do |f| - log_activity(f, 'deleted') - end begin recipients = DmsfMailer.get_notify_users(@project, deleted_files) recipients.each do |u| diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index 6778fec9..784f5751 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -53,7 +53,6 @@ class DmsfFilesController < ApplicationController end check_project(@revision.dmsf_file) raise ActionController::MissingFile if @file.deleted? - log_activity('downloaded') access = DmsfFileRevisionAccess.new access.user = User.current access.dmsf_file_revision = @revision @@ -164,7 +163,6 @@ class DmsfFilesController < ApplicationController if @file.save @file.set_last_revision revision flash[:notice] = (flash[:notice].nil? ? '' : flash[:notice]) + l(:notice_file_revision_created) - log_activity('new revision') begin recipients = DmsfMailer.get_notify_users(@project, [@file]) recipients.each do |u| @@ -197,7 +195,6 @@ class DmsfFilesController < ApplicationController if @file.delete(commit) flash[:notice] = l(:notice_file_deleted) unless commit - log_activity('deleted') begin recipients = DmsfMailer.get_notify_users(@project, [@file]) recipients.each do |u| @@ -235,7 +232,6 @@ class DmsfFilesController < ApplicationController @file.save end flash[:notice] = l(:notice_revision_deleted) - log_activity('deleted') else flash[:error] = @revision.errors.full_messages.join(', ') end @@ -297,7 +293,6 @@ class DmsfFilesController < ApplicationController def restore if @file.restore - log_activity('restored') flash[:notice] = l(:notice_dmsf_file_restored) else flash[:error] = @file.errors.full_messages.to_sentence @@ -320,10 +315,6 @@ class DmsfFilesController < ApplicationController private - def log_activity(action) - Rails.logger.info "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}@#{request.remote_ip}/#{request.env['HTTP_X_FORWARDED_FOR']}: #{action} dmsf://#{@file.project.identifier}/#{@file.id}/#{@revision.id if @revision}" - end - def find_file @file = DmsfFile.find params[:id] @project = @file.project diff --git a/app/controllers/dmsf_files_copy_controller.rb b/app/controllers/dmsf_files_copy_controller.rb index b9741ca7..65f3689d 100644 --- a/app/controllers/dmsf_files_copy_controller.rb +++ b/app/controllers/dmsf_files_copy_controller.rb @@ -60,25 +60,19 @@ class DmsfFilesCopyController < ApplicationController if @target_folder && (@target_folder.project != @target_project) raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) end - if (@target_folder && @target_folder == @file.dmsf_folder) || (@target_folder.nil? && @file.dmsf_folder.nil? && @target_project == @file.project) flash[:error] = l(:error_target_folder_same) redirect_to :action => 'new', :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder return end - new_file = @file.copy_to(@target_project, @target_folder) - unless new_file.errors.empty? flash[:error] = "#{l(:error_file_cannot_be_copied)}: #{new_file.errors.full_messages.join(', ')}" redirect_to :action => 'new', :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder return end - flash[:notice] = l(:notice_file_copied) - log_activity(new_file, 'was copied (is copy)') - redirect_to dmsf_file_path(new_file) end @@ -92,37 +86,24 @@ class DmsfFilesCopyController < ApplicationController if @target_folder && @target_folder.project != @target_project raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) end - if (@target_folder && @target_folder == @file.dmsf_folder) || (@target_folder.nil? && @file.dmsf_folder.nil? && @target_project == @file.project) flash[:error] = l(:error_target_folder_same) redirect_to :action => 'new', :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder return end - unless @file.move_to(@target_project, @target_folder) flash[:error] = "#{l(:error_file_cannot_be_moved)}: #{@file.errors.full_messages.join(', ')}" redirect_to :action => 'new', :id => @file, :target_project_id => @target_project, :target_folder_id => @target_folder return end - @file.reload - flash[:notice] = l(:notice_file_moved) - log_activity(@file, 'was moved (is copy)') - redirect_to dmsf_file_path(@file) end private - def log_activity(file, action) - if file && file.last_revision - Rails.logger.info - "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}@#{request.remote_ip}/#{request.env['HTTP_X_FORWARDED_FOR']}: #{action} dmsf://#{file.project.identifier}/#{file.id}/#{file.last_revision.id}" - end - end - def find_file @file = DmsfFile.visible.find_by_id params[:id] @project = @file.project if @file diff --git a/app/controllers/dmsf_folders_copy_controller.rb b/app/controllers/dmsf_folders_copy_controller.rb index cbe3e326..975628a0 100644 --- a/app/controllers/dmsf_folders_copy_controller.rb +++ b/app/controllers/dmsf_folders_copy_controller.rb @@ -55,36 +55,25 @@ class DmsfFoldersCopyController < ApplicationController if !@target_folder.nil? && @target_folder.project != @target_project raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) end - if (@target_folder && @target_folder == @folder.dmsf_folder) || (@target_folder.nil? && @folder.dmsf_folder.nil? && @target_project == @folder.project) flash[:error] = l(:error_target_folder_same) redirect_to :action => 'new', :id => @folder, :target_project_id => @target_project, :target_folder_id => @target_folder return end - new_folder = @folder.copy_to(@target_project, @target_folder) - unless new_folder.errors.empty? flash[:error] = "#{l(:error_folder_cannot_be_copied)}: #{new_folder.errors.full_messages.join(', ')}" redirect_to :action => 'new', :id => @folder, :target_project_id => @target_project, :target_folder_id => @target_folder return end - new_folder.reload - flash[:notice] = l(:notice_folder_copied) - log_activity(new_folder, 'was copied (is copy)') - redirect_to dmsf_folder_path(:id => @target_project, :folder_id => new_folder) end private - def log_activity(folder, action) - Rails.logger.info "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}@#{request.remote_ip}/#{request.env['HTTP_X_FORWARDED_FOR']}: #{action} dmsf://#{folder.project.identifier}/#{folder.id}" - end - def find_folder @folder = DmsfFolder.visible.find_by_id(params[:id]) @project = @folder.project if @folder