diff --git a/Gemfile b/Gemfile index 05c604a..d5ad53a 100644 --- a/Gemfile +++ b/Gemfile @@ -2,14 +2,14 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '2.5.3' +ruby '2.7.2' gem 'bootsnap', '>= 1.4.2', require: false gem 'dotenv' gem 'graphql-client' gem 'jbuilder', '~> 2.7' gem 'pg' -gem 'puma', '~> 4.3' +gem 'puma' gem 'rack-attack' gem 'rails', '~> 6.0.2', '>= 6.0.2.1' gem 'sidekiq' @@ -22,6 +22,9 @@ gem 'webpacker', '~> 4.0' # but today is not that day. gem 'coffee-rails' +# Transactional email service +gem 'postmark-rails' + group :development, :test do gem 'dotenv-rails' gem 'pry' diff --git a/Gemfile.lock b/Gemfile.lock index b053ecb..de571c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,6 +89,7 @@ GEM concurrent-ruby (~> 1.0) jbuilder (2.9.1) activesupport (>= 4.2.0) + json (2.5.1) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -110,10 +111,15 @@ GEM nokogiri (1.10.8) mini_portile2 (~> 2.4.0) pg (1.2.2) + postmark (1.21.3) + json + postmark-rails (0.20.0) + actionmailer (>= 3.0.0) + postmark (~> 1.15) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) - puma (4.3.5) + puma (5.1.1) nio4r (~> 2.0) rack (2.2.3) rack-attack (6.2.2) @@ -229,8 +235,9 @@ DEPENDENCIES jbuilder (~> 2.7) listen (>= 3.0.5, < 3.2) pg + postmark-rails pry - puma (~> 4.3) + puma rack-attack rails (~> 6.0.2, >= 6.0.2.1) rspec-rails @@ -241,7 +248,7 @@ DEPENDENCIES webpacker (~> 4.0) RUBY VERSION - ruby 2.5.3p105 + ruby 2.7.2p137 BUNDLED WITH 2.1.4 diff --git a/README.md b/README.md index 45d919c..9e0ff17 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,25 @@ Challenge OSS maintainers to re-license with an ethical license so that Palantir # Local dev -To create junk data, run `bin/rake defaults:sample_data` +## Setup + +`bundle` + +`bundle exec rails db:create` + +`bundle exec rails db:schema:load` + +`cp .env.example .env` + +## Seed data + +To create junk data, run `bin/rake defaults:junk_data` + +## Real Data To set up your local environment with real data: -* Copy `.env.example` to `.env` -* Set the `GITHUB_TOKEN` in `.env` to any GitHub token with org and repo read permissions -* Set defaults: `bin/rake defaults:init` -* Fetch projects and their dependencies using the background job queue: `bin/rake scheduled_tasks:update +- Copy `.env.example` to `.env` +- Set the `GITHUB_TOKEN` in `.env` to any GitHub token with org and repo read permissions +- Set defaults: `bin/rake defaults:init` +- Fetch projects and their dependencies using the background job queue: `bin/rake scheduled_tasks:update diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..d7e52af 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: 'notifications@icebreaker.dev' layout 'mailer' end diff --git a/app/mailers/hippocratic_alert_mailer.rb b/app/mailers/hippocratic_alert_mailer.rb new file mode 100644 index 0000000..8cb1e24 --- /dev/null +++ b/app/mailers/hippocratic_alert_mailer.rb @@ -0,0 +1,10 @@ +class HippocraticAlertMailer < ApplicationMailer + def alert(dependency_name) + @dependency_name = dependency_name + mail( + subject: 'Hippocratic License Alert', + to: ENV['ALERT_EMAIL_ADDRESSES'], + html_body: "'#{dependency_name}' is using the Hippocratic License!", + message_stream: 'notifications') + end +end diff --git a/app/models/dependency.rb b/app/models/dependency.rb index 0b549e3..d5de5be 100644 --- a/app/models/dependency.rb +++ b/app/models/dependency.rb @@ -11,9 +11,11 @@ class Dependency < ApplicationRecord def update_with_details details = DependencyDetailsFetcher.new(self).fetch - license_name = details[:license] || "Unknown" - license = License.find_or_create_by(name: license_name) self.source_repo_url = details[:url] - self.license = license + license_name = details[:license] || "Unknown" + self.license = License.find_or_create_by(name: license_name) + if license_name == "MIT-Hippocratic-1.2" + HippocraticAlertMailer.alert(name) + end end end diff --git a/app/models/package_manager.rb b/app/models/package_manager.rb index 8c036e5..baefed4 100644 --- a/app/models/package_manager.rb +++ b/app/models/package_manager.rb @@ -11,6 +11,6 @@ class PackageManager < ApplicationRecord private def set_language - self.language = Language.find_or_create_by(name: MANAGERS[self.name]) + self.language = Language.find_or_create_by(name: MANAGERS[name]) end end diff --git a/app/models/project.rb b/app/models/project.rb index d1a53c5..fb5605a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -6,7 +6,7 @@ class Project < ApplicationRecord validates :name, uniqueness: true, presence: true def github_identifier - "#{self.org_name}/#{self.name}" + "#{org_name}/#{name}" end end diff --git a/app/views/hippocratic_alert_mailer/alert.html.erb b/app/views/hippocratic_alert_mailer/alert.html.erb new file mode 100644 index 0000000..435ecc8 --- /dev/null +++ b/app/views/hippocratic_alert_mailer/alert.html.erb @@ -0,0 +1 @@ +'<%= @dependency_name %>' is using the Hippocratic License! \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index ab25405..af77e90 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,5 +11,11 @@ class Application < Rails::Application config.load_defaults 6.0 config.autoload_paths << "#{Rails.root}/app/services/*" config.active_job.queue_adapter = :sidekiq + + config.action_mailer.delivery_method = :postmark + + config.action_mailer.postmark_settings = { + api_token: Rails.application.credentials.postmark_api_token + } end end diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000..4a38820 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +mSk7HEcfdczw+naGIebobwZB1n1pPPettZOtBpSHJ/qvbkXYNn+BjVH9ZJLzXD7q3AlKLptOsuNTU8K+4piwflBsVmBFFzus28DP+vc0XFRXaLBeL3OVFUb2rpBqDvYBoNdQaA/11XJz4fZ+TroNgGXAdG7oD3YerE7qBdIx9PpVef/19l6S9eAX5W3Ljt5AlazDvc4jXd6fdjZPaL8qVyvSnoO9yuYOjAdeauR2Ow5TcwRd1t5qWf2Z5W3+Mt8tV2znhL/5rs0QwUXfjCpVRyKjh4SCwlSKGJ+WSf/FURQ30yqoqcI3C544af5W3GjJRorstds0XDZMan5zZfh/DDeK+Mr3KkUxZo3arCcepZ9jeiGQYbNjdm9SR0fC/K6ppdUNE0fE3lcelczkHbrhn0OCdNSvjCRYc8wPzmEfMSOeE0gpsVZbQzDV3L0Vsy8j5E6+q1r97yHOoCi1cmosfTxUuWMhQeKXuimoU2b+sM7Y--bqaAhpt+XCcZP/cM--qErv/AUFYTF21+QGe7Fbdw== \ No newline at end of file diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 38f73bf..7274fc5 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -8,6 +8,5 @@ # - Use digests to stop length information leaking (see also ActiveSupport::SecurityUtils.variable_size_secure_compare) ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_USERNAME"])) & ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_PASSWORD"])) - end Sidekiq::Web.set :sessions, false diff --git a/config/routes.rb b/config/routes.rb index 7ab91be..5abc3bc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,6 @@ Rails.application.routes.draw do mount Sidekiq::Web => '/sidekiq' - resources :projects, only: [:index, :show] root "home#show"