diff --git a/.env.sample b/.env.sample index 9df289ce7..75211a527 100644 --- a/.env.sample +++ b/.env.sample @@ -1,3 +1,8 @@ GCS_CREDENTIALS_FILE= GCS_BUCKET= MQ_BETA_ENABLED=true + +# SMTP API +SMTP_API_KEY= +SMTP_API_SECRET= +SMTP_DEFAULT_FROM= diff --git a/Gemfile b/Gemfile index 9c0436d25..22c6bc915 100644 --- a/Gemfile +++ b/Gemfile @@ -44,6 +44,7 @@ gem 'react-rails' gem 'appsignal' gem 'roo' gem 'caxlsx' +gem 'mailjet' group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index bd1c07330..397d68a14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -291,6 +291,11 @@ GEM net-imap net-pop net-smtp + mailjet (1.8.0) + activesupport (>= 5.0.0) + faraday (~> 2.1) + rack (>= 1.4.0) + yajl-ruby marcel (1.0.4) matrix (0.4.2) memoist (0.16.2) @@ -547,6 +552,7 @@ GEM rails (>= 3.2.16) xpath (3.2.0) nokogiri (~> 1.8) + yajl-ruby (1.4.3) zeitwerk (2.6.18) PLATFORMS @@ -589,6 +595,7 @@ DEPENDENCIES image_processing language_list listen (>= 3.0.5, < 3.2) + mailjet pg (>= 0.18, < 2.0) pg_search (= 2.3.2) pry diff --git a/app/assets/stylesheets/tpi/_mq_beta_scores.scss b/app/assets/stylesheets/tpi/_mq_beta_scores.scss index d7078a942..b550309c9 100644 --- a/app/assets/stylesheets/tpi/_mq_beta_scores.scss +++ b/app/assets/stylesheets/tpi/_mq_beta_scores.scss @@ -64,6 +64,9 @@ &__download-button { flex-grow: 4; text-align: right; + display: flex; + gap: 5px; + justify-content: end; .button { background-color: $blue; @@ -73,4 +76,4 @@ margin-bottom: 10px; } } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/tpi/pages/company.scss b/app/assets/stylesheets/tpi/pages/company.scss index b985cf308..b5615106f 100644 --- a/app/assets/stylesheets/tpi/pages/company.scss +++ b/app/assets/stylesheets/tpi/pages/company.scss @@ -243,10 +243,6 @@ border-left: 2px solid $hawkes-blue; - &.level5 { - background-color: rgba($tpi-level5-background-color, 0.15); - } - &__header { font-size: 16px; font-weight: bold; diff --git a/app/controllers/concerns/tpi/user_download.rb b/app/controllers/concerns/tpi/user_download.rb index 72bfb1089..61cd878de 100644 --- a/app/controllers/concerns/tpi/user_download.rb +++ b/app/controllers/concerns/tpi/user_download.rb @@ -12,10 +12,8 @@ def send_tpi_user_file(mq_assessments:, cp_assessments:, filename:) .includes(sector: [:cp_units]) mq_assessments_files = mq_assessments_by_methodology.map do |methodology, assessments| - is_beta_methodology = MQ::Assessment::BETA_METHODOLOGIES.include? methodology - name = is_beta_methodology ? "#{methodology}_BETA_#{timestamp}" : "#{methodology}_#{timestamp}" { - "MQ_Assessments_Methodology_#{name}.csv" => CSVExport::User::MQAssessments.new(assessments).call + "MQ_Assessments_Methodology_#{methodology}_#{timestamp}.csv" => CSVExport::User::MQAssessments.new(assessments).call } end.reduce(&:merge) @@ -28,17 +26,15 @@ def send_tpi_user_file(mq_assessments:, cp_assessments:, filename:) cp_assessments_csv = CSVExport::User::CompanyCPAssessments.new(cp_assessments).call cp_assessments_regional_csv = CSVExport::User::CompanyCPAssessmentsRegional.new(cp_assessments).call sector_benchmarks_csv = CSVExport::User::CPBenchmarks.new(cp_benchmarks).call - user_guide = File.binread(Rails.root.join('public', 'tpi', 'export_support', 'User guide TPI files.xlsx')) files = (mq_assessments_files || {}).merge( 'Company_Latest_Assessments.csv' => latest_cp_assessments_csv, "CP_Assessments_#{timestamp}.csv" => cp_assessments_csv, "CP_Assessments_Regional_#{timestamp}.csv" => cp_assessments_regional_csv, - "Sector_Benchmarks_#{timestamp}.csv" => sector_benchmarks_csv, - 'User guide TPI files.xlsx' => user_guide + "Sector_Benchmarks_#{timestamp}.csv" => sector_benchmarks_csv ) if ENV['MQ_BETA_ENABLED'].to_s == 'true' - files = files.merge 'Company_Latest_Assessments_BETA_5.0.csv' => latest_cp_assessments_beta_csv + files = files.merge 'Company_Latest_Assessments_5.0.csv' => latest_cp_assessments_beta_csv end render zip: files.compact, filename: "#{filename} - #{timestamp}" end diff --git a/app/controllers/tpi/companies_controller.rb b/app/controllers/tpi/companies_controller.rb index d2724d22b..0d6b53856 100644 --- a/app/controllers/tpi/companies_controller.rb +++ b/app/controllers/tpi/companies_controller.rb @@ -2,6 +2,7 @@ module TPI class CompaniesController < TPIController include UserDownload + before_action :enable_beta_mq_assessments before_action :fetch_company before_action :redirect_if_numeric_or_historic_slug, only: [:show] before_action :fetch_cp_assessment, only: [:show, :cp_assessment, :emissions_chart_data] diff --git a/app/controllers/tpi/sectors_controller.rb b/app/controllers/tpi/sectors_controller.rb index 2e6cd22c5..086105b29 100644 --- a/app/controllers/tpi/sectors_controller.rb +++ b/app/controllers/tpi/sectors_controller.rb @@ -2,6 +2,7 @@ module TPI class SectorsController < TPIController include UserDownload + before_action :enable_beta_mq_assessments before_action :fetch_companies, only: [:show, :index] before_action :fetch_sectors, only: [:show, :index, :user_download_all] before_action :fetch_sector, only: [:show, :user_download] @@ -77,6 +78,11 @@ def cp_performance_chart_data render json: data.chart_json end + def send_download_file_info_email + DataDownloadMailer.send_download_file_info_email(permitted_email_params).deliver_now + head :ok + end + def user_download_all send_user_download_file( Company.published.select(:id).where(sector_id: @sectors.pluck(:id)), @@ -91,6 +97,13 @@ def user_download ) end + def user_download_methodology + user_guide = File.binread(Rails.root.join('public', 'tpi', 'export_support', 'User guide TPI files.xlsx')) + render zip: { + 'User guide TPI files.xlsx' => user_guide + }, filename: "TPI Methodology - #{Time.now.strftime('%d%m%Y')}" + end + private def any_cp_assessment? @@ -155,5 +168,9 @@ def companies_scope(params) Company.published.active end end + + def permitted_email_params + params.permit(:email, :job_title, :forename, :surname, :location, :organisation, purposes: []) + end end end diff --git a/app/controllers/tpi/tpi_controller.rb b/app/controllers/tpi/tpi_controller.rb index c0893c6ec..d4add55b1 100644 --- a/app/controllers/tpi/tpi_controller.rb +++ b/app/controllers/tpi/tpi_controller.rb @@ -6,6 +6,10 @@ class TPIController < ApplicationController protected + def enable_beta_mq_assessments + session[:enable_beta_mq_assessments] = true unless session.key?(:enable_beta_mq_assessments) + end + def fixed_navbar(admin_panel_section_title, admin_panel_link) @admin_panel_section_title = admin_panel_section_title @link = admin_panel_link diff --git a/app/javascript/components/tpi/charts/mq-level/options.js b/app/javascript/components/tpi/charts/mq-level/options.js index a76a505dd..ea28b5fb6 100644 --- a/app/javascript/components/tpi/charts/mq-level/options.js +++ b/app/javascript/components/tpi/charts/mq-level/options.js @@ -58,10 +58,7 @@ export function getOptions({ chartData }) { fontSize: '12px' }, useHTML: true, - stagger: 0, - formatter() { - return this.value === 5 ? '5 [BETA]' : this.value; - } + stagger: 0 }, title: { text: 'Level', diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239d..4ca5b1428 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' + default from: ENV.fetch('SMTP_DEFAULT_FROM', 'from@example.com') layout 'mailer' end diff --git a/app/mailers/data_download_mailer.rb b/app/mailers/data_download_mailer.rb new file mode 100644 index 000000000..ce03a868f --- /dev/null +++ b/app/mailers/data_download_mailer.rb @@ -0,0 +1,6 @@ +class DataDownloadMailer < ApplicationMailer + def send_download_file_info_email(data) + @data = data + mail(to: 'tpi@lse.ac.uk', subject: 'TPI data has been downloaded') + end +end diff --git a/app/models/mq/assessment.rb b/app/models/mq/assessment.rb index 2e3b46082..291ddd2aa 100644 --- a/app/models/mq/assessment.rb +++ b/app/models/mq/assessment.rb @@ -22,7 +22,7 @@ class Assessment < ApplicationRecord LEVELS = %w[0 1 2 3 4 4STAR 5 5STAR].freeze BETA_METHODOLOGIES = { # taken into account only when beta is enabled - 5 => {levels: %w[5], highlight_questions: %w[18]} + 5 => {levels: %w[5], highlight_questions: %w[]} }.freeze BETA_LEVELS = BETA_METHODOLOGIES.map { |_k, v| v[:levels] }.flatten.freeze diff --git a/app/views/data_download_mailer/send_download_file_info_email.html.erb b/app/views/data_download_mailer/send_download_file_info_email.html.erb new file mode 100644 index 000000000..3fd2a9a18 --- /dev/null +++ b/app/views/data_download_mailer/send_download_file_info_email.html.erb @@ -0,0 +1,15 @@ +

Following user downloaded data from TPI website

+ +

Email: <%= @data[:email] %>

+

Job Title: <%= @data[:job_title] %>

+

Forename: <%= @data[:forename] %>

+

Surname: <%= @data[:surname] %>

+

Location: <%= @data[:location] %>

+

Organisation: <%= @data[:organisation] %>

+ +

Purposes

+ diff --git a/app/views/tpi/companies/_mq_assessment.html.erb b/app/views/tpi/companies/_mq_assessment.html.erb index 11ef814f4..b0855b95a 100644 --- a/app/views/tpi/companies/_mq_assessment.html.erb +++ b/app/views/tpi/companies/_mq_assessment.html.erb @@ -31,7 +31,7 @@ <% assessment.questions_by_level.each do |level, questions| %>

- Level <%= level.in?(assessment.beta_levels) ? "#{level} [BETA]" : level %>: <%= t("tpi.company.level_description.#{level}") %> + Level <%= "#{level}: #{t("tpi.company.level_description.#{level}")}" %>

diff --git a/app/views/tpi/companies/show.html.erb b/app/views/tpi/companies/show.html.erb index 88b4e7a9b..af7c13109 100644 --- a/app/views/tpi/companies/show.html.erb +++ b/app/views/tpi/companies/show.html.erb @@ -1,11 +1,6 @@ <% content_for :page_title, "#{@company.name} - Transition Pathway Initiative" %> <% content_for :page_description, "Assess how prepared #{@company.name} is for the transition to a low-carbon economy – its Management Quality and Carbon Performance." %> -<%= react_component('MqBetaModal', { - enabled: session[:enable_beta_mq_assessments], - page: "companies" -}) %> - <% regional_view = @company.cp_alignment_region.present? && params[:view] == 'regional' %>
@@ -16,22 +11,14 @@
<%= render 'tpi/shared/mq_beta_scores', has_data: @company.beta_mq_assessments? %> -
- - arrow down - Go to Management Quality - - <% if @company_presenter.cp_assessments.any? %> - - arrow down - Go to Carbon Performance - - <% end %> -
+ <%= link_to user_download_methodology_tpi_sectors_path, class: 'button is-primary is-pulled-right with-icon with-border' do %> + download icon + Download Methodology + <% end %> <%= link_to user_download_all_tpi_sectors_path, class: 'button is-primary is-pulled-right with-icon with-border' do %> download icon - Download data + Download CP & MQ Data <% end %>
@@ -39,16 +26,6 @@
<%= render 'tpi/shared/mq_beta_scores', has_data: @company.beta_mq_assessments? %> -
- - Management Quality - - <% if @company_presenter.cp_assessments.any? %> - - Carbon Performance - - <% end %> -
@@ -242,6 +219,7 @@
<% end %> + <% if @company.latest_information.present? %> <%= react_component("LatestInformation", { name: @company.name, latestInformation: @company.latest_information }) %> <% end %> diff --git a/app/views/tpi/sectors/index.html.erb b/app/views/tpi/sectors/index.html.erb index 1fb91630f..0d07715c9 100644 --- a/app/views/tpi/sectors/index.html.erb +++ b/app/views/tpi/sectors/index.html.erb @@ -1,11 +1,6 @@ <% content_for :page_title, "Tool - Transition Pathway Initiative" %> <% content_for :page_description, "The TPI tool is a corporate climate action benchmark which assesses how prepared companies are for the transition to a low-carbon economy." %> -<%= react_component('MqBetaModal', { - enabled: session[:enable_beta_mq_assessments], - page: "company" -}) %> -