├── log └── .keep ├── app ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── concerns │ │ ├── .keep │ │ └── rearrangeable.rb │ ├── application_record.rb │ ├── setting.rb │ ├── consumer.rb │ ├── user.rb │ ├── consumer_event.rb │ ├── subscription_user.rb │ ├── notification.rb │ └── push_device.rb ├── assets │ ├── images │ │ └── .keep │ ├── config │ │ └── manifest.js │ └── stylesheets │ │ ├── preferences.scss │ │ ├── users.scss │ │ ├── articles.scss │ │ ├── subscriptions.scss │ │ ├── administration.scss │ │ ├── notifications.scss │ │ └── application.css ├── controllers │ ├── concerns │ │ └── .keep │ ├── administration_controller.rb │ ├── analytics_controller.rb │ ├── subscriptions_controller.rb │ └── users_controller.rb ├── views │ ├── notifications │ │ ├── _notification.html.erb │ │ ├── subscribe.json.erb │ │ ├── unsubscribe.json.erb │ │ ├── resubscribe.html.erb │ │ ├── cert_upload.html.erb │ │ ├── admin.html.erb │ │ ├── index.html.erb │ │ ├── show.html.erb │ │ ├── new.html.erb │ │ └── fcm.html.erb │ ├── articles │ │ ├── index.html.erb │ │ ├── search.json.erb │ │ ├── article.json.erb │ │ └── index.json.erb │ ├── devise │ │ ├── mailer │ │ │ ├── password_change.html.erb │ │ │ ├── confirmation_instructions.html.erb │ │ │ ├── unlock_instructions.html.erb │ │ │ └── reset_password_instructions.html.erb │ │ ├── unlocks │ │ │ └── new.html.erb │ │ ├── confirmations │ │ │ └── new.html.erb │ │ ├── passwords │ │ │ ├── new.html.erb │ │ │ └── edit.html.erb │ │ ├── sessions │ │ │ └── new.html.erb │ │ ├── shared │ │ │ └── _links.html.erb │ │ └── registrations │ │ │ ├── new.html.erb │ │ │ └── edit.html.erb │ ├── administration │ │ └── index.html.erb │ ├── subscriptions │ │ └── authenticate.json.erb │ ├── preferences │ │ ├── _category.html.erb │ │ ├── index_snworks.html.erb │ │ └── index.html.erb │ ├── users │ │ ├── index.html.erb │ │ ├── show.html.erb │ │ ├── edit.html.erb │ │ └── new.html.erb │ ├── analytics │ │ └── index.html.erb │ └── layouts │ │ └── application.html.erb ├── helpers │ ├── users_helper.rb │ ├── articles_helper.rb │ ├── administration_helper.rb │ ├── notifications_helper.rb │ ├── subscriptions_helper.rb │ └── application_helper.rb ├── jobs │ ├── application_job.rb │ └── scheduled_tasks │ │ ├── caching │ │ └── warm_cache_job.rb │ │ └── scheduled_task.rb └── javascript │ ├── controllers │ ├── index.js │ └── category_list_controller.js │ └── packs │ └── application.js ├── lib ├── assets │ └── .keep └── tasks │ ├── .keep │ └── scheduled_tasks.rb ├── public ├── favicon.ico ├── robots.txt ├── packs │ └── manifest.json ├── 500.html ├── 422.html └── 404.html ├── test ├── helpers │ └── .keep ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── user_test.rb │ ├── consumer_test.rb │ ├── push_device_test.rb │ ├── notification_test.rb │ ├── consumer_event_test.rb │ ├── subscription_user_test.rb │ ├── sn_works_ceo_test.rb │ └── wordpress_test.rb ├── controllers │ ├── .keep │ ├── users_controller_test.rb │ ├── articles_controller_test.rb │ ├── notifications_controller_test.rb │ ├── administration_controller_test.rb │ └── subscriptions_controller_test.rb ├── fixtures │ ├── .keep │ ├── users.yml │ ├── consumers.yml │ ├── consumer_events.yml │ ├── notifications.yml │ ├── push_devices.yml │ ├── sn_works_ceos.yml │ └── subscription_users.yml ├── integration │ └── .keep ├── jobs │ └── warm_cache_job_test.rb └── test_helper.rb ├── .docker ├── backups │ └── .keep ├── .DS_Store ├── data │ └── .DS_Store └── nginx │ ├── .DS_Store │ ├── dev │ └── nginx.conf │ └── nginx.conf ├── .ruby-version ├── .browserslistrc ├── vendor └── assets │ ├── javascripts │ └── .keep │ └── stylesheets │ └── .keep ├── Procfile ├── config ├── initializers │ ├── time_formats.rb │ ├── session_store.rb │ ├── mime_types.rb │ ├── content_security_policy.rb │ ├── filter_parameter_logging.rb │ ├── application_controller_renderer.rb │ ├── cookies_serializer.rb │ ├── sidekiq.rb │ ├── backtrace_silencers.rb │ ├── wrap_parameters.rb │ ├── inflections.rb │ ├── assets.rb │ ├── figaro.rb │ ├── new_framework_defaults_5_2.rb │ └── scheduler.rb ├── webpack │ ├── environment.js │ ├── test.js │ ├── production.js │ └── development.js ├── boot.rb ├── environment.rb ├── sidekiq.yml ├── app.yml ├── cable.yml ├── database.yml ├── application.rb ├── locales │ ├── en.yml │ └── devise.en.yml ├── secrets.yml ├── puma.rb ├── storage.yml ├── routes.rb ├── environments │ ├── test.rb │ ├── development.rb │ └── production.rb └── webpacker.yml ├── bin ├── rake ├── bundle ├── rails ├── yarn ├── webpack ├── webpack-dev-server ├── spring ├── update └── setup ├── config.ru ├── db ├── migrate │ ├── 20160710185334_add_push_time_to_notification.rb │ ├── 20200417030553_add_headline_to_notification.rb │ ├── 20160712130648_add_article_id_to_notification.rb │ ├── 20190217052137_create_sn_works_ceos.rb │ ├── 20161104181227_add_status_to_push_device.rb │ ├── 20180116215137_create_subscription_users.rb │ ├── 20160708161758_create_push_devices.rb │ ├── 20160708160654_create_notifications.rb │ ├── 20170213215532_create_consumers.rb │ ├── 20160710162055_create_settings.rb │ ├── 20170213220839_create_consumer_events.rb │ ├── 20160719172629_add_confirmable_to_devise.rb │ └── 20160708160653_devise_create_users.rb ├── seeds.rb └── schema.rb ├── .gitmodules ├── entrypoint_sidekiq.sh ├── entrypoint_webpacker.sh ├── Cheffile ├── Rakefile ├── entrypoint_scheduled_jobs.sh ├── postcss.config.js ├── package.json ├── githooks ├── pre-commit └── README.md ├── scheduler.rb ├── README.rdoc ├── Vagrantfile ├── Dockerfile ├── LICENSE ├── Cheffile.lock ├── maintence-scripts ├── setup-databases.sh ├── setup.sh ├── upgrade.sh ├── renew-lets_encrypt.sh ├── includes.sh ├── export.sh └── setup-lets_encrypt.sh ├── app.json ├── .rubocop.yml ├── .gitignore ├── babel.config.js ├── entrypoint.sh ├── secrets.env.template ├── docker-compose-no-nginx.yml ├── letsencrypt-docker-compose.yml ├── Gemfile ├── docker-compose-no-nginx-dev.yml └── data └── appendonly.aof /log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.docker/backups/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.6.6 2 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.browserslistrc: -------------------------------------------------------------------------------- 1 | defaults 2 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/views/notifications/_notification.html.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: bundle exec puma -C config/puma.rb 2 | -------------------------------------------------------------------------------- /app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link application.css 2 | -------------------------------------------------------------------------------- /app/helpers/users_helper.rb: -------------------------------------------------------------------------------- 1 | module UsersHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/articles_helper.rb: -------------------------------------------------------------------------------- 1 | module ArticlesHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/administration_helper.rb: -------------------------------------------------------------------------------- 1 | module AdministrationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/notifications_helper.rb: -------------------------------------------------------------------------------- 1 | module NotificationsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/subscriptions_helper.rb: -------------------------------------------------------------------------------- 1 | module SubscriptionsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/assets/stylesheets/preferences.scss: -------------------------------------------------------------------------------- 1 | .categories { 2 | width: 50%; 3 | } 4 | -------------------------------------------------------------------------------- /app/views/articles/index.html.erb: -------------------------------------------------------------------------------- 1 | <%= raw(JSON.pretty_generate @response) %> 2 | -------------------------------------------------------------------------------- /config/initializers/time_formats.rb: -------------------------------------------------------------------------------- 1 | Time::DATE_FORMATS[:number_date] = "%Y%m%d" 2 | -------------------------------------------------------------------------------- /.docker/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PushOCCRP/Push-Backend/HEAD/.docker/.DS_Store -------------------------------------------------------------------------------- /.docker/data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PushOCCRP/Push-Backend/HEAD/.docker/data/.DS_Store -------------------------------------------------------------------------------- /.docker/nginx/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PushOCCRP/Push-Backend/HEAD/.docker/nginx/.DS_Store -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /config/webpack/environment.js: -------------------------------------------------------------------------------- 1 | const { environment } = require('@rails/webpacker') 2 | 3 | module.exports = environment 4 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /app/models/setting.rb: -------------------------------------------------------------------------------- 1 | # RailsSettings Model 2 | class Setting < RailsSettings::Base 3 | source Rails.root.join("config/app.yml") 4 | namespace Rails.env 5 | end 6 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../config/application', __dir__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /test/models/user_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class UserTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/views/devise/mailer/password_change.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

We're contacting you to notify you that your password has been changed.

4 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path("../config/environment", __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /test/models/consumer_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ConsumerTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/controllers/administration_controller.rb: -------------------------------------------------------------------------------- 1 | class AdministrationController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def index 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /test/jobs/warm_cache_job_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class WarmCacheJobTest < ActiveJob::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/push_device_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class PushDeviceTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/models/consumer.rb: -------------------------------------------------------------------------------- 1 | class Consumer < ActiveRecord::Base 2 | has_many :consumer_events 3 | 4 | before_save do |consumer| 5 | consumer.last_seen = Time.now 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/notification_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class NotificationTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path("../application", __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: "_Push-Backend_session" 4 | -------------------------------------------------------------------------------- /test/models/consumer_event_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ConsumerEventTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /config/webpack/test.js: -------------------------------------------------------------------------------- 1 | process.env.NODE_ENV = process.env.NODE_ENV || 'development' 2 | 3 | const environment = require('./environment') 4 | 5 | module.exports = environment.toWebpackConfig() 6 | -------------------------------------------------------------------------------- /test/models/subscription_user_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class SubscriptionUserTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /config/webpack/production.js: -------------------------------------------------------------------------------- 1 | process.env.NODE_ENV = process.env.NODE_ENV || 'production' 2 | 3 | const environment = require('./environment') 4 | 5 | module.exports = environment.toWebpackConfig() 6 | -------------------------------------------------------------------------------- /test/controllers/users_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class UsersControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /test/controllers/articles_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ArticlesControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /db/migrate/20160710185334_add_push_time_to_notification.rb: -------------------------------------------------------------------------------- 1 | class AddPushTimeToNotification < ActiveRecord::Migration[4.2] 2 | def change 3 | add_column :notifications, :push_time, :date 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20200417030553_add_headline_to_notification.rb: -------------------------------------------------------------------------------- 1 | class AddHeadlineToNotification < ActiveRecord::Migration[5.2] 2 | def change 3 | add_column :notifications, :headline, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160712130648_add_article_id_to_notification.rb: -------------------------------------------------------------------------------- 1 | class AddArticleIdToNotification < ActiveRecord::Migration[4.2] 2 | def change 3 | add_column :notifications, :article_id, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/controllers/notifications_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class NotificationsControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/assets/stylesheets/users.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Users controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /config/sidekiq.yml: -------------------------------------------------------------------------------- 1 | development: 2 | :concurrency: 5 3 | production: 4 | :concurrency: 6 5 | :queues: 6 | - [urgent, 2] 7 | - default 8 | - scheduled_tasks 9 | 10 | :verbose: false 11 | :timeout: 8 12 | -------------------------------------------------------------------------------- /db/migrate/20190217052137_create_sn_works_ceos.rb: -------------------------------------------------------------------------------- 1 | class CreateSnWorksCeos < ActiveRecord::Migration[5.2] 2 | def change 3 | create_table :sn_works_ceos do |t| 4 | t.timestamps 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/administration_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class AdministrationControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/subscriptions_controller_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class SubscriptionsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/assets/stylesheets/articles.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the articles controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | Rails.application.config.content_security_policy do |policy| 2 | policy.connect_src :self, :http, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? 3 | end 4 | -------------------------------------------------------------------------------- /db/migrate/20161104181227_add_status_to_push_device.rb: -------------------------------------------------------------------------------- 1 | class AddStatusToPushDevice < ActiveRecord::Migration[4.2] 2 | def change 3 | add_column :push_devices, :status, :Integer, default: 0, null: false 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /app/assets/stylesheets/subscriptions.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Subscriptions controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "docker-uniqush"] 2 | path = docker-uniqush 3 | url = https://git.occrp.org/libre/docker-uniqush.git 4 | [submodule "uniqush-push"] 5 | path = uniqush-push 6 | url = https://github.com/uniqush/uniqush-push.git 7 | -------------------------------------------------------------------------------- /app/assets/stylesheets/administration.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the administration controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /config/app.yml: -------------------------------------------------------------------------------- 1 | # config/app.yml for rails-settings-cached 2 | defaults: &defaults 3 | foo: "Foo" 4 | bar: 123 5 | 6 | development: 7 | <<: *defaults 8 | 9 | test: 10 | <<: *defaults 11 | 12 | production: 13 | <<: *defaults 14 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: async 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: push_backend_production 11 | -------------------------------------------------------------------------------- /app/views/notifications/subscribe.json.erb: -------------------------------------------------------------------------------- 1 | { 2 | "status": "<%= @status %>", 3 | "status_id": "<%= @status_id %>", 4 | "uniqush_code": "<%= @uniqush_code %>", 5 | "uniqush_message": "<%= @uniqush_message %>", 6 | "uniqush_reponse": "<%= @uniqush_reponse %>" 7 | } -------------------------------------------------------------------------------- /app/views/notifications/unsubscribe.json.erb: -------------------------------------------------------------------------------- 1 | { 2 | "status": "<%= @status %>", 3 | "status_id": "<%= @status_id %>", 4 | "uniqush_code": "<%= @uniqush_code %>", 5 | "uniqush_message": "<%= @uniqush_message %>", 6 | "uniqush_reponse": "<%= @uniqush_reponse %>" 7 | } -------------------------------------------------------------------------------- /entrypoint_sidekiq.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "" 4 | echo "Running Bundler... 🎁" 5 | 6 | bundle config build.nokogiri --use-system-libraries 7 | bundle install --path vendor/bundle 8 | 9 | echo "" 10 | echo "Starting Sidekiq...⚙️🦵" 11 | 12 | exec $@ 13 | -------------------------------------------------------------------------------- /app/views/devise/mailer/confirmation_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Welcome <%= @email %>!

2 | 3 |

You can confirm your account email through the link below:

4 | 5 |

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

6 | -------------------------------------------------------------------------------- /entrypoint_webpacker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "" 4 | echo "Running Bundler... 🎁" 5 | 6 | bundle config build.nokogiri --use-system-libraries 7 | bundle install --path vendor/bundle 8 | 9 | echo "" 10 | echo "Starting Webpacker... 🕸️📦" 11 | 12 | exec $@ 13 | -------------------------------------------------------------------------------- /Cheffile: -------------------------------------------------------------------------------- 1 | site "http://community.opscode.com/api/v1" 2 | 3 | cookbook "apt" 4 | cookbook "build-essential" 5 | cookbook "mysql", "5.5.3" 6 | cookbook "ruby_build" 7 | cookbook "nodejs" 8 | cookbook "rbenv", git: "https://github.com/aminin/chef-rbenv" 9 | cookbook "vim" 10 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path("../config/application", __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/stylesheets/notifications.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Notifications controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | 5 | .action_button { 6 | min-width: 100%; 7 | } -------------------------------------------------------------------------------- /entrypoint_scheduled_jobs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "" 4 | echo "Running Bundler... 🎁" 5 | 6 | bundle config build.nokogiri --use-system-libraries 7 | bundle install --path vendor/bundle 8 | 9 | echo "" 10 | echo "Starting Clockwork Job Scheduler... 🕰️ 🗓️" 11 | 12 | exec $@ 13 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | # Include default devise modules. Others available are: 3 | # :confirmable, :lockable, :timeoutable and :omniauthable 4 | devise :database_authenticatable, :rememberable, :trackable, :validatable 5 | 6 | has_many :notifications 7 | end 8 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ActiveSupport::Reloader.to_prepare do 4 | # ApplicationController.renderer.defaults.merge!( 5 | # http_host: 'example.org', 6 | # https: false 7 | # ) 8 | # end 9 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require('postcss-import'), 4 | require('postcss-flexbugs-fixes'), 5 | require('postcss-preset-env')({ 6 | autoprefixer: { 7 | flexbox: 'no-2009' 8 | }, 9 | stage: 3 10 | }) 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /app/javascript/controllers/index.js: -------------------------------------------------------------------------------- 1 | import { Application } from "stimulus" 2 | import { definitionsFromContext } from "stimulus/webpack-helpers" 3 | 4 | const application = Application.start() 5 | const context = require.context(".", true, /\.js$/) 6 | application.load(definitionsFromContext(context)) 7 | -------------------------------------------------------------------------------- /app/views/administration/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 |
10 |
11 | -------------------------------------------------------------------------------- /config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /db/migrate/20180116215137_create_subscription_users.rb: -------------------------------------------------------------------------------- 1 | class CreateSubscriptionUsers < ActiveRecord::Migration[5.1] 2 | def change 3 | create_table :subscription_users do |t| 4 | t.string :username, null: false 5 | t.string :api_key 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /config/webpack/development.js: -------------------------------------------------------------------------------- 1 | process.env.NODE_ENV = process.env.NODE_ENV || 'development' 2 | 3 | const environment = require('./environment') 4 | 5 | module.exports = environment.toWebpackConfig() 6 | 7 | // devServer: { host: '0.0.0.0', port: '7654', hot: true, inline: true, disableHostCheck: true, public: '0.0.0.0:0' }, 8 | -------------------------------------------------------------------------------- /app/models/consumer_event.rb: -------------------------------------------------------------------------------- 1 | class ConsumerEvent < ActiveRecord::Base 2 | belongs_to :consumer 3 | has_one :article 4 | has_one :notification 5 | 6 | module EventType 7 | ARTICLES_LIST = 0 8 | ARTICLE_VIEW = 1 9 | SEARCH = 2 10 | NOTIFICATION_CLICK = 3 11 | SOCIAL_MEDIA_SHARE = 4 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/views/subscriptions/authenticate.json.erb: -------------------------------------------------------------------------------- 1 | <% if @authenticated == true %> 2 | { 3 | "status": "authenticated", 4 | "code": "1", 5 | "api_key": "<%= @subscription_user.api_key %>", 6 | "username": "<%= @subscription_user.username %>" 7 | } 8 | <% else %> 9 | { 10 | "status": "error", 11 | "code": "0" 12 | } 13 | <% end %> -------------------------------------------------------------------------------- /app/views/devise/mailer/unlock_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

4 | 5 |

Click the link below to unlock your account:

6 | 7 |

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

8 | -------------------------------------------------------------------------------- /bin/yarn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_ROOT = File.expand_path('..', __dir__) 3 | Dir.chdir(APP_ROOT) do 4 | begin 5 | exec "yarnpkg", *ARGV 6 | rescue Errno::ENOENT 7 | $stderr.puts "Yarn executable was not detected in the system." 8 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" 9 | exit 1 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20160708161758_create_push_devices.rb: -------------------------------------------------------------------------------- 1 | class CreatePushDevices < ActiveRecord::Migration[4.2] 2 | def change 3 | create_table :push_devices do |t| 4 | t.string :dev_token 5 | t.string :dev_id 6 | 7 | t.string :language 8 | 9 | t.string :platform 10 | 11 | t.timestamps null: false 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@rails/activestorage": "^6.0.2-1", 4 | "@rails/ujs": "^6.0.2-1", 5 | "@rails/webpacker": "4.2.2", 6 | "jquery": "^3.4.1", 7 | "stimulus": "^1.1.1", 8 | "turbolinks": "^5.2.0", 9 | "uuid": "^8.3.0" 10 | }, 11 | "devDependencies": { 12 | "webpack-dev-server": "^3.10.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] ||= "test" 2 | require File.expand_path("../../config/environment", __FILE__) 3 | require "rails/test_help" 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 7 | fixtures :all 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | -------------------------------------------------------------------------------- /config/initializers/sidekiq.rb: -------------------------------------------------------------------------------- 1 | require "sidekiq/web" 2 | 3 | Concurrent.use_stdlib_logger(Logger::DEBUG) 4 | 5 | Sidekiq.configure_client do |config| 6 | config.redis = { url: ENV["REDIS_URL"] } 7 | end 8 | 9 | Sidekiq.configure_server do |config| 10 | config.redis = { url: ENV["REDIS_URL"] } 11 | end 12 | 13 | Sidekiq.default_worker_options = { "backtrace" => true } 14 | -------------------------------------------------------------------------------- /db/migrate/20160708160654_create_notifications.rb: -------------------------------------------------------------------------------- 1 | class CreateNotifications < ActiveRecord::Migration[4.2] 2 | def change 3 | create_table :notifications do |t| 4 | add_reference :users, index: true, foreign_key: true 5 | 6 | t.text :message 7 | t.string :language 8 | 9 | t.integer :reach 10 | 11 | t.timestamps null: false 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /test/fixtures/users.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | # one: {} 8 | # column: value 9 | # 10 | # two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/fixtures/consumers.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | # one: {} 8 | # column: value 9 | # 10 | # two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/fixtures/consumer_events.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | # one: {} 8 | # column: value 9 | # 10 | # two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/fixtures/notifications.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | # one: {} 8 | # column: value 9 | # 10 | # two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/fixtures/push_devices.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | # one: {} 8 | # column: value 9 | # 10 | # two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/fixtures/sn_works_ceos.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | # one: {} 8 | # column: value 9 | # 10 | # two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/fixtures/subscription_users.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | # one: {} 8 | # column: value 9 | # 10 | # two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /db/migrate/20170213215532_create_consumers.rb: -------------------------------------------------------------------------------- 1 | class CreateConsumers < ActiveRecord::Migration[4.2] 2 | def change 3 | create_table :consumers do |t| 4 | t.string :uuid, null: false 5 | t.datetime :last_seen, null: false 6 | t.integer :times_seen, null: false, default: 0 7 | t.timestamps null: false 8 | end 9 | 10 | add_index :consumers, :uuid, unique: true 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /public/packs/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "application.js": "/packs/js/application-98ad9879f11716ff1bb8.js", 3 | "application.js.map": "/packs/js/application-98ad9879f11716ff1bb8.js.map", 4 | "entrypoints": { 5 | "application": { 6 | "js": [ 7 | "/packs/js/application-98ad9879f11716ff1bb8.js" 8 | ], 9 | "js.map": [ 10 | "/packs/js/application-98ad9879f11716ff1bb8.js.map" 11 | ] 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /app/models/subscription_user.rb: -------------------------------------------------------------------------------- 1 | class SubscriptionUser < ApplicationRecord 2 | before_create :generate_api_key 3 | 4 | def self.authenticate(username, api_key) 5 | user = self.find(username: username) 6 | return false, User.new if user.nil? 7 | 8 | authenticated = user.api_key == api_key 9 | return authenticated, user 10 | end 11 | 12 | def generate_api_key 13 | self.api_key = SecureRandom.hex(12) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /app/views/devise/mailer/reset_password_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

Someone has requested a link to change your password. You can do this through the link below.

4 | 5 |

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

6 | 7 |

If you didn't request this, please ignore this email.

8 |

Your password won't change until you access the link above and create a new one.

9 | -------------------------------------------------------------------------------- /app/views/notifications/resubscribe.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 | Successes: <%= @devices[:successful].count %>
10 | Errors 11 |
12 | <% @devices[:error].each do |device| %> 13 | <%= device.inspect %>
14 | <% end %> 15 |
16 |
-------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | 9 | User.create!({ 10 | email: "admin@pushapp.press", 11 | password: "changemenow" 12 | }) 13 | -------------------------------------------------------------------------------- /.docker/nginx/dev/nginx.conf: -------------------------------------------------------------------------------- 1 | events { worker_connections 1024; } 2 | http { 3 | upstream myapp1 { 4 | server web:3000; 5 | } 6 | 7 | server { 8 | listen 80; 9 | 10 | location / { 11 | proxy_pass http://myapp1; 12 | proxy_set_header Host $host; 13 | proxy_set_header X-Forwarded-For $remote_addr; 14 | proxy_set_header X-Forwarded-Proto $scheme; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /bin/webpack: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" 4 | ENV["NODE_ENV"] ||= "development" 5 | 6 | require "pathname" 7 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 8 | Pathname.new(__FILE__).realpath) 9 | 10 | require "bundler/setup" 11 | 12 | require "webpacker" 13 | require "webpacker/webpack_runner" 14 | 15 | APP_ROOT = File.expand_path("..", __dir__) 16 | Dir.chdir(APP_ROOT) do 17 | Webpacker::WebpackRunner.run(ARGV) 18 | end 19 | -------------------------------------------------------------------------------- /bin/webpack-dev-server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" 4 | ENV["NODE_ENV"] ||= "development" 5 | 6 | require "pathname" 7 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 8 | Pathname.new(__FILE__).realpath) 9 | 10 | require "bundler/setup" 11 | 12 | require "webpacker" 13 | require "webpacker/dev_server_runner" 14 | 15 | APP_ROOT = File.expand_path("..", __dir__) 16 | Dir.chdir(APP_ROOT) do 17 | Webpacker::DevServerRunner.run(ARGV) 18 | end 19 | -------------------------------------------------------------------------------- /app/views/devise/unlocks/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend unlock instructions

2 | 3 | <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> 4 | <%= devise_error_messages! %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true %> 9 |
10 | 11 |
12 | <%= f.submit "Resend unlock instructions" %> 13 |
14 | <% end %> 15 | 16 | <%= render "devise/shared/links" %> 17 | -------------------------------------------------------------------------------- /db/migrate/20160710162055_create_settings.rb: -------------------------------------------------------------------------------- 1 | class CreateSettings < ActiveRecord::Migration[4.2] 2 | def self.up 3 | create_table :settings do |t| 4 | t.string :var, null: false 5 | t.text :value, null: true 6 | t.integer :thing_id, null: true 7 | t.string :thing_type, null: true, limit: 30 8 | t.timestamps 9 | end 10 | 11 | add_index :settings, %i(thing_type thing_id var), unique: true 12 | end 13 | 14 | def self.down 15 | drop_table :settings 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" } 12 | if spring 13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 14 | gem 'spring', spring.version 15 | require 'spring/binstub' 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /githooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # require 'english' 4 | require "rubocop" 5 | 6 | ADDED_OR_MODIFIED = /A|AM|^M/.freeze 7 | 8 | changed_files = `git status --porcelain`.split(/\n/). 9 | select { |file_name_with_status| 10 | file_name_with_status =~ ADDED_OR_MODIFIED 11 | }. 12 | map { |file_name_with_status| 13 | file_name_with_status.split(" ")[1] 14 | }. 15 | select { |file_name| 16 | File.extname(file_name) == ".rb" 17 | }.join(" ") 18 | 19 | system("rubocop #{changed_files}") unless changed_files.empty? 20 | 21 | exit $?.to_s[-1].to_i 22 | -------------------------------------------------------------------------------- /scheduler.rb: -------------------------------------------------------------------------------- 1 | # Set up jobs and allow us to capture exceptions in them 2 | # Borrowed from https://medium.com/carwow-product-engineering/moving-from-heroku-scheduler-to-clockwork-and-sidekiq-7b05f63d0d24 3 | 4 | require File.expand_path("../config/boot", __FILE__) 5 | require File.expand_path("../config/environment", __FILE__) 6 | require "clockwork" 7 | 8 | module Clockwork 9 | every(30.seconds, "Caching: Warm caches") do 10 | ScheduledTasks::Caching::WarmCacheJob.perform_unique_later 11 | end 12 | 13 | error_handler do |error| 14 | puts "Error: #{error}" 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | == README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | 26 | 27 | Please feel free to use a different markup language if you do not plan to run 28 | rake doc:app. 29 | -------------------------------------------------------------------------------- /app/views/devise/confirmations/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend confirmation instructions

2 | 3 | <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> 4 | <%= devise_error_messages! %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> 9 |
10 | 11 |
12 | <%= f.submit "Resend confirmation instructions" %> 13 |
14 | <% end %> 15 | 16 | <%= render "devise/shared/links" %> 17 | -------------------------------------------------------------------------------- /app/views/preferences/_category.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | " value="<%= name if defined?(name) %>"> 4 | <% if defined?(valid) && !valid %> 5 |
6 | Category not found, did you misspell it? 7 |
8 | <% end %> 9 |
10 |
11 | 12 |
13 |
14 | -------------------------------------------------------------------------------- /db/migrate/20170213220839_create_consumer_events.rb: -------------------------------------------------------------------------------- 1 | class CreateConsumerEvents < ActiveRecord::Migration[4.2] 2 | def change 3 | create_table :consumer_events do |t| 4 | t.integer :consumer_id, null: false 5 | t.integer :event_type_id, null: false 6 | t.integer :article_id 7 | t.integer :notification_id 8 | t.string :language 9 | t.string :search_phrase 10 | t.integer :length 11 | t.timestamps null: false 12 | end 13 | 14 | add_index :consumer_events, :consumer_id 15 | add_index :consumer_events, :event_type_id 16 | add_index :consumer_events, :article_id 17 | add_index :consumer_events, :notification_id 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /app/models/notification.rb: -------------------------------------------------------------------------------- 1 | class Notification < ActiveRecord::Base 2 | has_one :user 3 | 4 | validates :headline, presence: true 5 | validates :message, presence: true 6 | validates :language, presence: true 7 | validates :article_id, presence: true 8 | 9 | def display_language 10 | case self.language 11 | when "en" 12 | language = "English" 13 | when "bg" 14 | language = "Bulgarian" 15 | when "ru" 16 | language = "Russian" 17 | when "az" 18 | language = "Azerbaijani" 19 | when "sr" 20 | language = "Serbian" 21 | when "ro" 22 | language = "Romanian" 23 | else 24 | language = "Not Found" 25 | end 26 | 27 | language 28 | end 29 | 30 | private 31 | end 32 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | # Add Yarn node_modules folder to the asset load path. 9 | Rails.application.config.assets.paths << Rails.root.join("node_modules") 10 | 11 | # Precompile additional assets. 12 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 13 | # Rails.application.config.assets.precompile += %w( search.js ) 14 | Rails.application.config.assets.precompile += %w( manifest.js ) 15 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /app/views/users/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 6 |
7 | 8 |
9 |
10 | <% @users.each do |user| %> 11 |
12 |
<%= link_to user.email, user %>
13 |
<%= link_to 'Edit', edit_user_path(user) if current_user == user %>
14 |
<%= link_to "Delete", user_path(user), method: :delete, data: {confirm: "Are you sure?"} %>
15 |
16 | <% end %> 17 |
18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /app/javascript/packs/application.js: -------------------------------------------------------------------------------- 1 | /* eslint no-console:0 */ 2 | // This file is automatically compiled by Webpack, along with any other files 3 | // present in this directory. You're encouraged to place your actual application logic in 4 | // a relevant structure within app/javascript and only use these pack files to reference 5 | // that code so it'll be compiled. 6 | // 7 | // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate 8 | // layout file, like app/views/layouts/application.html.erb 9 | 10 | import "core-js/stable"; 11 | import "regenerator-runtime/runtime"; 12 | 13 | require("@rails/ujs").start() 14 | require("turbolinks").start() 15 | require("@rails/activestorage").start() 16 | 17 | console.log('Hello World from Webpacker') 18 | 19 | import 'controllers' 20 | -------------------------------------------------------------------------------- /app/views/users/show.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 6 |
7 | 8 |
9 |
10 |
11 |
Created On: <%= @user.created_at %>
12 |
13 |
14 |
15 | <% if current_user == @user %> 16 | <%= link_to "Edit", edit_user_path(@user) %> | 17 | <% end %> 18 | 19 | <%= link_to "Delete", user_path(@user), method: :delete, data: {confirm: "Are you sure?"} %>
20 |
21 |
22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /app/models/concerns/rearrangeable.rb: -------------------------------------------------------------------------------- 1 | module Rearrangeable 2 | extend ActiveSupport::Concern 3 | 4 | module ClassMethods 5 | # Rearrange articles so the first has an image. If none do, then return the original array 6 | def rearrange_articles_for_images(articles) 7 | article_with_image = articles.find do |article| 8 | logger.debug "Checking article #{article} for images" 9 | article["images"].count > 0 || article[:header_image].nil? == false 10 | end 11 | 12 | # Because I'm a good CS student I make sure we don't do unncessary array modification 13 | return articles if article_with_image.nil? || article_with_image == articles.first 14 | 15 | articles.delete(article_with_image) 16 | articles.unshift(article_with_image) 17 | 18 | articles 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /app/views/notifications/cert_upload.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 6 |
7 | 8 |
9 |
10 | <%= form_tag({action: :process_cert}, multipart: true) do %> 11 | 12 |
13 | <%= label_tag "APNS Cert" %> 14 | <%= file_field_tag 'cert', class: "form-control" %> 15 |
16 |
17 | <%= label_tag "APNS Key" %> 18 | <%= file_field_tag 'key', class: "form-control" %> 19 |
20 | 21 | <%= submit_tag "Save", class:"btn btn-default" %> 22 | <% end %> 23 |
24 |
25 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: postgresql 9 | encoding: unicode 10 | pool: 5 11 | database: postgresql 12 | username: postgres 13 | password: postgres 14 | host: db 15 | 16 | development: 17 | <<: *default 18 | database: development 19 | 20 | # Warning: The database defined as "test" will be erased and 21 | # re-generated from your development database when you run "rake". 22 | # Do not set this db to the same as development or production. 23 | test: 24 | <<: *default 25 | database: test 26 | 27 | production: 28 | adapter: postgresql 29 | encoding: unicode 30 | pool: 5 31 | username: postgres 32 | password: postgres 33 | host: db 34 | database: production 35 | -------------------------------------------------------------------------------- /githooks/README.md: -------------------------------------------------------------------------------- 1 | # Git Hooks 2 | 3 | Git hooks are scripts that are automatically run at various points in the Git cycle. You can do things 4 | such as automatically format code, send notifications etc. 5 | 6 | We use one, a `pre-commit` which does what it sounds like. 7 | 8 | ## Overview 9 | 10 | ### Pre-Commit 11 | 12 | This script automatically runs the ruby linter `rubocop` against all changed files and won't let you 13 | proceed if it can't automatically fix them 14 | 15 | ## Setup 16 | 17 | ### Set up the Git hook 18 | 1. Run bundler to make sure all of our prerequisites are installed `bundle install` 19 | 1. After cloning this repository copy all the files, except this README over to the `./.git/hooks` folder 20 | 1. Set them all to executable `sudo chmod 777 ./.git/hooks/*` 21 | 22 | That's it! From now on everything should be running fine. 23 | -------------------------------------------------------------------------------- /lib/tasks/scheduled_tasks.rb: -------------------------------------------------------------------------------- 1 | # Borrowed from https://medium.com/carwow-product-engineering/moving-from-heroku-scheduler-to-clockwork-and-sidekiq-7b05f63d0d24 2 | # Allows us to run scheduled tasks from the command line for testing and maintence 3 | 4 | namespace :scheduled_tasks do 5 | require "./app/jobs/scheduled_tasks/scheduled_task" 6 | Dir[File.join(".", "app/jobs/scheduled_tasks/**/*.rb")].each { |f| require f } 7 | 8 | classes = ObjectSpace.each_object(Class).select { |klass| klass < ScheduledTasks::ScheduledTask } 9 | 10 | classes.each do |klass| 11 | class_name = klass.to_s 12 | task_name = class_name.gsub("ScheduledTasks::", "").gsub("::", ":").underscore 13 | 14 | desc "Runs #{class_name}" 15 | task task_name => :environment do 16 | puts "Executing job #{class_name}" 17 | klass.perform_now 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path("../boot", __FILE__) 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module PushBackend 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 5.0 13 | 14 | # Settings in config/environments/* take precedence over those specified here. 15 | # Application configuration can go into files in config/initializers 16 | # -- all .rb files in that directory are automatically loaded after loading 17 | # the framework and any gems in your application. 18 | config.eager_load_paths << Rails.root.join("lib") 19 | config.middleware.use Rack::Deflater 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure("2") do |config| 5 | config.vm.box = "bento/ubuntu-20.04" 6 | 7 | config.vm.network(:forwarded_port, guest: 3000, host: 3000) 8 | config.vm.network(:forwarded_port, guest: 9898, host: 9898) 9 | 10 | $script = <<-SCRIPT 11 | echo "Updating sources..." 12 | apt-get update 13 | echo "Installing Docker..." 14 | apt-get install -qq docker.io 15 | curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 16 | chmod +x /usr/local/bin/docker-compose 17 | 18 | echo "Building Docker dev containers..." 19 | docker-compose --file=/docker/docker-compose-no-nginx-dev.yml build 20 | 21 | SCRIPT 22 | 23 | config.vm.synced_folder ".", "/docker" 24 | config.vm.provision "shell", inline: $script 25 | end 26 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.6.6-stretch 2 | 3 | RUN apt-get update 4 | RUN apt-get -y install apt-transport-https ca-certificates libmagic-dev 5 | 6 | RUN wget https://dl.yarnpkg.com/debian/pubkey.gpg 7 | RUN apt-key add pubkey.gpg 8 | 9 | RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list 10 | RUN curl --silent --location https://deb.nodesource.com/setup_14.x | bash - 11 | 12 | RUN apt-get install -y build-essential libpq-dev nodejs yarn 13 | 14 | # This is for a work around in SEOWorks where some image's dimensions are returned as null 15 | # We don't want that to happen, so we need to determine them ourselves 16 | # This can be removed later if we get that bug fixed 17 | RUN apt-get install -y libmagickwand-dev 18 | 19 | RUN gem install bundler 20 | RUN RAILS_ENV=development 21 | WORKDIR /push 22 | CMD ["rails", "s", "-b", "0.0.0.0", "-p", "80"] 23 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | def display_name_for_language(language) 3 | case language 4 | when "en" 5 | "English" 6 | when "bg" 7 | "Bulgarian" 8 | when "ru" 9 | "Russian" 10 | when "az" 11 | "Azerbaijani" 12 | when "sr" 13 | "Serbian" 14 | when "ro" 15 | "Romanian" 16 | else 17 | "Not Found" 18 | end 19 | end 20 | 21 | def check_for_valid_cms_mode 22 | case ENV["cms_mode"] 23 | when "occrp-joomla" 24 | :occrp_joomla 25 | when "wordpress" 26 | :wordpress 27 | when "newscoop" 28 | :newscoop 29 | when "cins-codeigniter" 30 | :cins_codeigniter 31 | when "blox" 32 | :blox 33 | when "snworks" 34 | :snworks 35 | else 36 | raise "CMS type #{ENV['cms_mode']} not valid for this version of Push." 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /app/views/devise/passwords/new.html.erb: -------------------------------------------------------------------------------- 1 | 2 |
3 | 6 |
7 | 8 |
9 |
10 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> 11 | <%= devise_error_messages! %> 12 |
13 | <%= f.label :email %>
14 | <%= f.email_field :email, autofocus: true, class: "form-control" %> 15 |
16 | 17 |
18 |
19 | <%= f.submit "Send me reset password instructions", class:"btn btn-default" %> 20 |
21 | <% end %> 22 | 23 |
24 | <%= render "devise/shared/links" %> 25 |
26 | 27 |
28 |
29 | -------------------------------------------------------------------------------- /app/views/devise/passwords/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Change your password

2 | 3 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> 4 | <%= devise_error_messages! %> 5 | <%= f.hidden_field :reset_password_token %> 6 | 7 |
8 | <%= f.label :password, "New password" %>
9 | <% if @minimum_password_length %> 10 | (<%= @minimum_password_length %> characters minimum)
11 | <% end %> 12 | <%= f.password_field :password, autofocus: true, autocomplete: "off" %> 13 |
14 | 15 |
16 | <%= f.label :password_confirmation, "Confirm new password" %>
17 | <%= f.password_field :password_confirmation, autocomplete: "off" %> 18 |
19 | 20 |
21 | <%= f.submit "Change my password" %> 22 |
23 | <% end %> 24 | 25 | <%= render "devise/shared/links" %> 26 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | # path to your application root. 6 | APP_ROOT = File.expand_path('..', __dir__) 7 | 8 | def system!(*args) 9 | system(*args) || abort("\n== Command #{args} failed ==") 10 | end 11 | 12 | chdir APP_ROOT do 13 | # This script is a way to update your development environment automatically. 14 | # Add necessary update steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies if using Yarn 21 | # system('bin/yarn') 22 | 23 | puts "\n== Updating database ==" 24 | system! 'bin/rails db:migrate' 25 | 26 | puts "\n== Removing old logs and tempfiles ==" 27 | system! 'bin/rails log:clear tmp:clear' 28 | 29 | puts "\n== Restarting application server ==" 30 | system! 'bin/rails restart' 31 | end 32 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at http://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /app/javascript/controllers/category_list_controller.js: -------------------------------------------------------------------------------- 1 | import { Controller } from 'stimulus'; 2 | import { v4 as uuidv4 } from 'uuid'; 3 | 4 | export default class extends Controller { 5 | static targets = [ "categories" ] 6 | 7 | connect() { 8 | console.log("hello from StimulusJS") 9 | } 10 | 11 | add() { 12 | let uuid = uuidv4() 13 | let categoryInput = ` 14 |
15 | 16 | 17 |
18 |
19 | ` 20 | 21 | this.categoriesTarget.innerHTML += categoryInput 22 | } 23 | 24 | remove() { 25 | this.event.target.parent.remove() 26 | } 27 | 28 | update() { 29 | let updatedCategories = this.categories 30 | updatedCategories[this.event.target.data.id] = this.event.target.value 31 | this.data.set('categories', updatedCategories) 32 | } 33 | 34 | categories() { 35 | this.data.get('categories') 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: b7814806acfd5986ac5cb15cc8b0c9f2ee42081fe961fd518c44d90ec23a1e3267003db5917cbad917ca19ee7a400a50a52e4d8ac214142c64d8eac5aea30414 15 | 16 | test: 17 | secret_key_base: 01f314df8b2089dedfc692866f67031898d0dacd26921e3c7a0d12b0994051008d2ed2ad0f1ab0afb3d3851e4bdefaedd579b23e5b0f91b80319ec5132e158ab 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | # path to your application root. 6 | APP_ROOT = File.expand_path('..', __dir__) 7 | 8 | def system!(*args) 9 | system(*args) || abort("\n== Command #{args} failed ==") 10 | end 11 | 12 | chdir APP_ROOT do 13 | # This script is a starting point to setup your application. 14 | # Add necessary setup steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies if using Yarn 21 | # system('bin/yarn') 22 | 23 | # puts "\n== Copying sample files ==" 24 | # unless File.exist?('config/database.yml') 25 | # cp 'config/database.yml.sample', 'config/database.yml' 26 | # end 27 | 28 | puts "\n== Preparing database ==" 29 | system! 'bin/rails db:setup' 30 | 31 | puts "\n== Removing old logs and tempfiles ==" 32 | system! 'bin/rails log:clear tmp:clear' 33 | 34 | puts "\n== Restarting application server ==" 35 | system! 'bin/rails restart' 36 | end 37 | -------------------------------------------------------------------------------- /app/views/notifications/admin.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 |

Devices

10 | Total Devices: <%= @devices %>
11 | iOS Devices: <%= @ios_devices %>
12 | Android Devices: <%= @android_devices %>
13 |
14 | <%= link_to 'Resubscribe all devices', notifications_resubscribe_url %>
15 |
16 |
17 |

Certificates

18 |

iOS APNS

19 | Production: <%= @status_check[:apns_prod] %>
20 | Sandbox: <%= @status_check[:apns_sandbox] %>
21 |

Android FCM

22 | FCM: <%= @status_check[:fcm] %>
23 |
24 | <%= link_to 'APNS Cert Upload', notifications_cert_upload_url %>
25 | <%= link_to 'FCM Management', notifications_fcm_url %>
26 |
27 |
28 | -------------------------------------------------------------------------------- /app/views/notifications/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 6 |
7 | 8 |
9 |
10 | <% @notifications.each do |notification| %> 11 |
12 |
13 |
14 |

<%= notification.headline %>

15 |
16 |

<%= notification.message %>

17 |
18 |
19 |

<%= notification.display_language %>

<%= notification.created_at %>

20 |
21 |
22 | <%= link_to "View", notification %> 23 |
24 |
25 |
26 |
27 | <% end %> 28 |
29 |
30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Christopher Guess 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.docker/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | events { worker_connections 1024; } 2 | http { 3 | upstream myapp1 { 4 | server web:3000; 5 | } 6 | 7 | server { 8 | listen 80; 9 | listen 443 ssl; 10 | 11 | 12 | ssl_certificate /srv/data/ssl/keys/fullchain.pem; 13 | ssl_certificate_key /srv/data/ssl/keys/privkey.pem; 14 | ssl_session_timeout 5m; 15 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 16 | ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; 17 | ssl_prefer_server_ciphers on; 18 | ssl_session_cache shared:SSL:10m; 19 | ssl_dhparam /etc/ssl/nginx/dhparam.pem; 20 | 21 | location ~ ^/assets/ { 22 | expires 1y; 23 | add_header Cache-Control public; 24 | gzip_static on; 25 | root /var/public; 26 | add_header ETag ""; 27 | } 28 | 29 | location / { 30 | proxy_pass http://myapp1; 31 | proxy_set_header Host $host; 32 | proxy_set_header X-Forwarded-For $remote_addr; 33 | proxy_set_header X-Forwarded-Proto $scheme; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Cheffile.lock: -------------------------------------------------------------------------------- 1 | SITE 2 | remote: http://community.opscode.com/api/v1 3 | specs: 4 | 7-zip (1.0.2) 5 | windows (>= 1.2.2) 6 | apt (2.9.2) 7 | ark (0.9.0) 8 | 7-zip (>= 0.0.0) 9 | windows (>= 0.0.0) 10 | build-essential (2.2.4) 11 | chef_handler (1.2.0) 12 | homebrew (2.0.3) 13 | build-essential (>= 2.1.2) 14 | mysql (5.5.3) 15 | yum-mysql-community (>= 0.0.0) 16 | nodejs (2.4.4) 17 | apt (>= 0.0.0) 18 | ark (>= 0.0.0) 19 | build-essential (>= 0.0.0) 20 | homebrew (>= 0.0.0) 21 | yum-epel (>= 0.0.0) 22 | ruby_build (0.8.0) 23 | vim (2.0.0) 24 | windows (1.38.4) 25 | chef_handler (>= 0.0.0) 26 | yum (3.8.2) 27 | yum-epel (0.6.5) 28 | yum (~> 3.2) 29 | yum-mysql-community (0.1.21) 30 | yum (>= 3.2) 31 | 32 | GIT 33 | remote: https://github.com/aminin/chef-rbenv 34 | ref: master 35 | sha: 9c8688dbffb79269385581b6aa518c5ba456f154 36 | specs: 37 | rbenv (0.7.3) 38 | 39 | DEPENDENCIES 40 | apt (>= 0) 41 | build-essential (>= 0) 42 | mysql (= 5.5.3) 43 | nodejs (>= 0) 44 | rbenv (>= 0) 45 | ruby_build (>= 0) 46 | vim (>= 0) 47 | 48 | -------------------------------------------------------------------------------- /app/views/devise/sessions/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 | <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 10 |
11 | <%= f.label :email %>
12 | <%= f.email_field :email, autofocus: true, class: "form-control" %> 13 |
14 | 15 |
16 | <%= f.label :password %>
17 | <%= f.password_field :password, autocomplete: "off", class: "form-control" %> 18 |
19 | 20 | <% if devise_mapping.rememberable? -%> 21 |
22 | <%= f.check_box :remember_me %> 23 | <%= f.label :remember_me %> 24 |
25 | <% end -%> 26 | 27 |
28 | <%= f.submit "Log in", class:"btn btn-default"%> 29 |
30 | <% end %> 31 |
32 | <%= render "devise/shared/links" %> 33 |
34 |
35 |
-------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | workers Integer(ENV["WEB_CONCURRENCY"] || 1) 2 | threads_count = Integer(ENV["MAX_THREADS"] || 1) 3 | threads threads_count, threads_count 4 | 5 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 6 | # 7 | port ENV.fetch("PORT") { 3000 } 8 | 9 | rackup DefaultRackup 10 | port ENV["PORT"] || 3000 11 | environment ENV["RACK_ENV"] || "development" 12 | 13 | # Specifies the number of `workers` to boot in clustered mode. 14 | # Workers are forked webserver processes. If using threads and workers together 15 | # the concurrency of the application would be max `threads` * `workers`. 16 | # Workers do not work on JRuby or Windows (both of which do not support 17 | # processes). 18 | # 19 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 20 | 21 | # Use the `preload_app!` method when specifying a `workers` number. 22 | # This directive tells Puma to first boot the application and load code 23 | # before forking the application. This takes advantage of Copy On Write 24 | # process behavior so workers use less memory. 25 | # 26 | # preload_app! 27 | 28 | # Allow puma to be restarted by `rails restart` command. 29 | plugin :tmp_restart 30 | -------------------------------------------------------------------------------- /app/jobs/scheduled_tasks/caching/warm_cache_job.rb: -------------------------------------------------------------------------------- 1 | module ScheduledTasks 2 | module Caching 3 | class WarmCacheJob < ScheduledTask 4 | def perform 5 | # Get the CMS mode that's set up for this instance 6 | cms_mode = ApplicationController.helpers.check_for_valid_cms_mode 7 | 8 | # Go through and get the articles for the current method. We throw away the response 9 | # because this will just set the cache keys 10 | 11 | # We're not passing in params, which means multiple pages and such won't be cached. What we care 12 | # about is speed right now. So that's fine for the moment. We could conceive of caching a few 13 | # pages at anytime, but that's for another time. 14 | case cms_mode 15 | when :occrp_joomla 16 | JoomlaOccrp.articles({}) 17 | when :wordpress 18 | Wordpress.articles({}) 19 | when :newscoop 20 | Newscoop.articles({}) 21 | when :cins_codeigniter 22 | CinsCodeigniter.articles({}) 23 | when :blox 24 | Blox.articles({}) 25 | when :snworks 26 | SNWorksCEO.articles({}) 27 | end 28 | end 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /maintence-scripts/setup-databases.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="${BASH_SOURCE%/*}" 3 | if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi 4 | . "$DIR/includes.sh" 5 | 6 | # Stop any possible docker-compose containers that might be sticking around 7 | kill_docker_containers 8 | 9 | # Migrate the database (does nothing if database already exists) 10 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 11 | echoc "Migrating the Push app database" $LIGHT_BLUE 12 | echoc "\n-------------------------------------------------------------------------------------------------------------\n\n" $LIGHT_BLUE 13 | 14 | docker-compose run web rake db:create 15 | docker-compose run web rake db:migrate 16 | docker-compose run web rake db:seed 17 | 18 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 19 | echoc "Everything should be set up properly now." 20 | echoc "Try running" 21 | echoc "docker-compose up" $YELLOW 22 | echoc "to make sure it works" 23 | echoc "\n-------------------------------------------------------------------------------------------------------------\n\n" $LIGHT_BLUE 24 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Push Backend", 3 | "description": "A backend middleware to communicate between CMS and mobile app for the Push ecosystem.", 4 | "website": "https://small-sharp-tool.com/", 5 | "repository": "https://github.com/PushOCCRP/Push-Backend", 6 | "success_url": "/notifications", 7 | "scripts": { 8 | "postdeploy": "bash entrypoint.sh" 9 | }, 10 | "env": { 11 | "cms_mode": { 12 | "value": "occrp-joomla" 13 | }, 14 | "force_https": { 15 | "value": "true" 16 | }, 17 | "occrp_joomla_url": { 18 | "value": "https://www.occrp.org/index.html?option=com_push&format=json&view=articles" 19 | }, 20 | 21 | }, 22 | "formation": { 23 | "web": { 24 | "quantity": 2, 25 | "size": "Performance-M" 26 | } 27 | }, 28 | "image": "heroku/ruby", 29 | "addons": [ 30 | "openredis", 31 | { 32 | "plan": "mongolab:shared-single-small", 33 | "as": "MONGO" 34 | }, 35 | { 36 | "plan": "heroku-postgresql", 37 | "options": { 38 | "version": "9.5" 39 | } 40 | } 41 | ], 42 | "buildpacks": [ 43 | { 44 | "url": "https://github.com/stomita/heroku-buildpack-phantomjs" 45 | } 46 | ] 47 | } -------------------------------------------------------------------------------- /config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket 23 | 24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /app/jobs/scheduled_tasks/scheduled_task.rb: -------------------------------------------------------------------------------- 1 | # Borrowed from https://medium.com/carwow-product-engineering/moving-from-heroku-scheduler-to-clockwork-and-sidekiq-7b05f63d0d24 2 | # Helps us managed scheduled taks so that they don't overlap each other mostly 3 | require "sidekiq/api" 4 | 5 | module ScheduledTasks 6 | class ScheduledTask < ApplicationJob 7 | queue_as :scheduled_tasks 8 | 9 | rescue_from(Exception) do |e| 10 | # Bugsnag.notify(e) 11 | end 12 | 13 | def self.perform_unique_later(*args) 14 | if self.task_already_scheduled? 15 | logger.warn "Task #{self} already enqueued/running." 16 | return 17 | end 18 | 19 | self.perform_later(*args) 20 | end 21 | 22 | def self.task_already_scheduled? 23 | job_type = self.to_s 24 | queue_name = "quotes_site_scheduled_tasks" 25 | q = Sidekiq::Queue.new(queue_name) 26 | is_enqueued = q.any? { |j| j["args"][0]["job_class"] == job_type } 27 | 28 | workers = Sidekiq::Workers.new 29 | is_running = workers.any? do |x, y, work| 30 | work["queue"] == queue_name && 31 | work["payload"]["args"][0]["job_class"] == job_type 32 | end 33 | 34 | is_enqueued || is_running 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /app/views/users/edit.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 | <%= form_for(@user, url: {action: "update"}) do |f| %> 10 | <%= @devise_error_messages %> 11 |
12 | <%= f.label :email %>
13 | <%= f.email_field :email, autofocus: true, class: "form-control" %> 14 |
15 |
16 | <%= f.label :password %> 17 | <% if @minimum_password_length %> 18 | (<%= @minimum_password_length %> characters minimum) 19 | <% end %>
20 | <%= f.password_field :password, autocomplete: "off", class: "form-control" %> 21 |
22 | 23 |
24 | <%= f.label :password_confirmation %>
25 | <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %> 26 |
27 | 28 |
29 |
30 | <%= f.submit "Edit", class:"btn btn-default" %> 31 |
32 | <% end %> 33 | 34 |
35 |
-------------------------------------------------------------------------------- /app/views/devise/shared/_links.html.erb: -------------------------------------------------------------------------------- 1 | <%- if controller_name != 'sessions' %> 2 | <%= link_to "Log in", new_session_path(resource_name) %>
3 | <% end -%> 4 | 5 | <%- if devise_mapping.registerable? && controller_name != 'registrations' %> 6 | <%= link_to "Sign up", new_registration_path(resource_name) %>
7 | <% end -%> 8 | 9 | <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> 10 | <%= link_to "Forgot your password?", new_password_path(resource_name) %>
11 | <% end -%> 12 | 13 | <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> 14 | <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
15 | <% end -%> 16 | 17 | <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> 18 | <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
19 | <% end -%> 20 | 21 | <%- if devise_mapping.omniauthable? %> 22 | <%- resource_class.omniauth_providers.each do |provider| %> 23 | <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
24 | <% end -%> 25 | <% end -%> 26 | -------------------------------------------------------------------------------- /test/models/sn_works_ceo_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class SnWorksCEOTest < ActiveSupport::TestCase 4 | test "Bearer key should be generated" do 5 | bearer_token = SNWorksCEO.send(:bearer_token) 6 | assert_not_nil bearer_token, "SNWorks bearer token must not be nil." 7 | end 8 | 9 | test "Bearer key should have 'pk' in payload" do 10 | bearer_token = SNWorksCEO.send(:bearer_token) 11 | decoded_token = JWT.decode bearer_token, Figaro.env.snworks_private_api_key, true, { algorithm: "HS256" } 12 | pk = decoded_token.find { |x| x.keys.include?("pk") } 13 | assert_not_nil pk, "SNWorks bearer token must include 'pk' in the payload." 14 | end 15 | 16 | test "Getting articles should return an array" do 17 | articles = SNWorksCEO.articles nil 18 | assert_not_nil articles, "SNWorks should return an array of articles." 19 | end 20 | 21 | test "Get url should accept options" do 22 | SNWorksCEO.get_url("/test", { test: "key" }) 23 | assert_equal "#{ENV["snworks_url"]}/test?test=key", "#{ENV["snworks_url"]}/test?test=key" 24 | end 25 | 26 | test "Searching should return an aray" do 27 | articles = SNWorksCEO.search({ "q": "wisconsin" }) 28 | assert_not_nil articles, "SNWorks should allow searching" 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/views/users/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 | <%= form_for(@user, url: {action: "create"}) do |f| %> 10 | <%= @devise_error_messages %> 11 |
12 | <%= f.label :email %>
13 | <%= f.email_field :email, autofocus: true, class: "form-control" %> 14 |
15 |
16 | <%= f.label :password %> 17 | <% if @minimum_password_length %> 18 | (<%= @minimum_password_length %> characters minimum) 19 | <% end %>
20 | <%= f.password_field :password, autocomplete: "off", class: "form-control" %> 21 |
22 | 23 |
24 | <%= f.label :password_confirmation %>
25 | <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %> 26 |
27 |
28 |
29 | <%= f.submit "Sign up", class:"btn btn-default" %> 30 |
31 |
32 | <% end %> 33 | 34 |
35 |
36 | -------------------------------------------------------------------------------- /app/views/notifications/show.html.erb: -------------------------------------------------------------------------------- 1 | 2 |
3 | 7 |
8 | 9 |
10 |
11 | Headline: <%= @notification.headline %>
12 | Message: <%= @notification.message %>
13 | Language: <%= display_name_for_language @notification.language %>
14 | Article ID: <%= @notification.article_id %> 15 |
16 |
17 |
18 |
19 |

Actions

20 |
21 |
22 | <%= link_to "Push to production", push_path(@notification), data:{:confirm => 'Are you sure?'}, class:"btn btn-success action_button" %>

23 | <%= link_to "Push to test", push_path(@notification, :sandbox => "true"), data:{:confirm => 'Are you sure?'}, class:"btn btn-info action_button" %> 24 |
25 |
26 |
27 |
28 | -------------------------------------------------------------------------------- /app/controllers/analytics_controller.rb: -------------------------------------------------------------------------------- 1 | class AnalyticsController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def index 5 | @consumer_count = Consumer.all.count 6 | @consumer_count_last_day = Consumer.where(last_seen: 1.day.ago..Time.now).count 7 | @consumer_count_last_week = Consumer.where(last_seen: 1.week.ago..Time.now).count 8 | @consumer_count_last_month = Consumer.where(last_seen: 1.month.ago..Time.now).count 9 | 10 | @articles_request_count_last_day = ConsumerEvent.where(event_type_id: ConsumerEvent::EventType::ARTICLES_LIST, created_at: 1.day.ago..Time.now).count 11 | @articles_request_count_last_week = ConsumerEvent.where(event_type_id: ConsumerEvent::EventType::ARTICLES_LIST, created_at: 1.week.ago..Time.now).count 12 | @articles_request_count_last_month = ConsumerEvent.where(event_type_id: ConsumerEvent::EventType::ARTICLES_LIST, created_at: 1.month.ago..Time.now).count 13 | 14 | @earliest_consumer_date = Consumer.first.nil? ? Time.now : Consumer.first.created_at 15 | @earliest_consumer_event_date = ConsumerEvent.first.nil? ? Time.now : ConsumerEvent.first.created_at 16 | 17 | @most_recent_search_phrases = ConsumerEvent.where("event_type_id = #{ConsumerEvent::EventType::SEARCH} AND search_phrase <> ''").order(:created_at).limit(10) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/views/devise/registrations/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 10 | <%= devise_error_messages! %> 11 |
12 | <%= f.label :email %>
13 | <%= f.email_field :email, autofocus: true, class: "form-control" %> 14 |
15 | 16 |
17 | <%= f.label :password %> 18 | <% if @minimum_password_length %> 19 | (<%= @minimum_password_length %> characters minimum) 20 | <% end %>
21 | <%= f.password_field :password, autocomplete: "off", class: "form-control" %> 22 |
23 | 24 |
25 | <%= f.label :password_confirmation %>
26 | <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %> 27 |
28 |
29 |
30 | <%= f.submit "Sign up", class:"btn btn-default" %> 31 |
32 | <% end %> 33 | 34 |
35 | <%= render "devise/shared/links" %> 36 |
37 |
38 |
39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /db/migrate/20160719172629_add_confirmable_to_devise.rb: -------------------------------------------------------------------------------- 1 | class AddConfirmableToDevise < ActiveRecord::Migration[4.2] 2 | # Note: You can't use change, as User.update_all will fail in the down migration 3 | def up 4 | add_column :users, :confirmation_token, :string 5 | add_column :users, :confirmed_at, :datetime 6 | add_column :users, :confirmation_sent_at, :datetime 7 | add_column :users, :unconfirmed_email, :string 8 | # add_column :users, :unconfirmed_email, :string # Only if using reconfirmable 9 | add_index :users, :confirmation_token, unique: true 10 | # User.reset_column_information # Need for some types of updates, but not for update_all. 11 | # To avoid a short time window between running the migration and updating all existing 12 | # users as confirmed, do the following 13 | execute("UPDATE users SET confirmed_at = NOW()") 14 | # All existing user accounts should be able to log in after this. 15 | # Remind: Rails using SQLite as default. And SQLite has no such function :NOW. 16 | # Use :date('now') instead of :NOW when using SQLite. 17 | # => execute("UPDATE users SET confirmed_at = date('now')") 18 | # Or => User.all.update_all confirmed_at: Time.now 19 | end 20 | 21 | def down 22 | remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at 23 | # remove_columns :users, :unconfirmed_email # Only if using reconfirmable 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/controllers/subscriptions_controller.rb: -------------------------------------------------------------------------------- 1 | class SubscriptionsController < ApplicationController 2 | skip_before_action :verify_authenticity_token 3 | 4 | def authenticate 5 | username = params["username"] 6 | password = params["password"] 7 | 8 | @authenticated = false 9 | 10 | case @cms_mode 11 | when :occrp_joomla 12 | render plain: "Not Implemented" 13 | return 14 | when :wordpress 15 | render plain: "Not Implemented" 16 | return 17 | when :newscoop 18 | render plain: "Not Implemented" 19 | return 20 | when :cins_codeigniter 21 | render plain: "Not Implemented" 22 | return 23 | when :blox 24 | @authenticated = Blox.authenticate(username, password, params) 25 | end 26 | 27 | # If the user is properly authenticated against the server then we either return the previous api_key or 28 | # make the user anew and return that. 29 | @subscription_user = SubscriptionUser.where(username: username).first_or_create! 30 | 31 | respond_to do |format| 32 | format.json 33 | end 34 | end 35 | 36 | def logout 37 | render json: return_error("username missing") unless params.has_key("username") 38 | render json: return_error("api_key missing") unless params.has_key("api_key") 39 | 40 | user = SubscriptionUser.find(username: params["username"], api_key: ["api_key"]) 41 | user.generate_api_key 42 | user.save! 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /app/views/notifications/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 6 |
7 | 8 |
9 |
10 | <%= form_for @notification, url: {action: "create"} do |f| %> 11 |
12 | <%= f.label :headline %> 13 | <%= f.text_field :headline, class: "form-control" %>
14 |
15 |
16 | <%= f.label :message %> 17 | <%= f.text_area :message, size: "60x5", class: "form-control" %>
18 |
19 | <% if @languages.count > 1 %> 20 |
21 | <%= f.label :language_for_notification %>
22 | <% options = [] 23 | @languages.each{|language| options << [display_name_for_language(language), language]} %> 24 | <%= f.select :language, options_for_select(options) %> 25 |
26 | <% else %> 27 | <%= f.hidden_field :language, value: @languages.first %> 28 | <% end %> 29 |
30 | <%= f.label :article_id %> 31 | <%= f.select :article_id, options_for_select(@articles), {class: "form-control"} %> 32 |
33 | 34 | <%= f.submit "Create", class:"btn btn-primary" %> 35 | <% end %> 36 |
37 |
38 | -------------------------------------------------------------------------------- /config/initializers/figaro.rb: -------------------------------------------------------------------------------- 1 | Figaro.require_keys("cms_mode", "title") 2 | 3 | Figaro.require_keys("host") if !ENV["proxy_images"].blank? 4 | auth = ENV["auth_enabled"].downcase == true if !ENV["auth_enabled"].blank? 5 | 6 | case ENV["cms_mode"] 7 | when "occrp-joomla" 8 | Figaro.require_keys("occrp_joomla_url") 9 | when "wordpress" 10 | Figaro.require_keys("wordpress_url") 11 | when "newscoop" 12 | Figaro.require_keys("newscoop_url") 13 | Figaro.require_keys("newscoop_client_id") 14 | Figaro.require_keys("newscoop_client_secret") 15 | when "cins-codeigniter" 16 | Figaro.require_keys("codeigniter_url") 17 | when "blox" 18 | Figaro.require_keys("blox_url") 19 | Figaro.require_keys("blox_publication_name") 20 | Figaro.require_keys("blox_eedition_key") 21 | Figaro.require_keys("blox_eedition_secret") 22 | Figaro.require_keys("blox_editorial_key") 23 | Figaro.require_keys("blox_editorial_secret") 24 | if auth == true 25 | Figaro.require_keys("blox_user_key") 26 | Figaro.require_keys("blox_user_secret") 27 | end 28 | 29 | # Blox seems to only support one language at a time. 30 | languages = ENV["languages"].delete('"').split(",") 31 | raise "Blox only supports one language at a time right now" if languages.count > 1 32 | when "snworks" 33 | # Figaro.require_keys["xxxxx"] 34 | else 35 | raise "No valid cms mode, please fix the environment variable \"cms_mode\"" 36 | end 37 | 38 | if !ENV["developer_mode"] || ENV["developer_mode"].length > 0 39 | ENV["developer_mode"] = "false" 40 | end 41 | -------------------------------------------------------------------------------- /db/migrate/20160708160653_devise_create_users.rb: -------------------------------------------------------------------------------- 1 | class DeviseCreateUsers < ActiveRecord::Migration[4.2] 2 | def change 3 | create_table :users do |t| 4 | ## Database authenticatable 5 | t.string :email, null: false, default: "" 6 | t.string :encrypted_password, null: false, default: "" 7 | 8 | ## Recoverable 9 | t.string :reset_password_token 10 | t.datetime :reset_password_sent_at 11 | 12 | ## Rememberable 13 | t.datetime :remember_created_at 14 | 15 | ## Trackable 16 | t.integer :sign_in_count, default: 0, null: false 17 | t.datetime :current_sign_in_at 18 | t.datetime :last_sign_in_at 19 | t.inet :current_sign_in_ip 20 | t.inet :last_sign_in_ip 21 | 22 | ## Confirmable 23 | # t.string :confirmation_token 24 | # t.datetime :confirmed_at 25 | # t.datetime :confirmation_sent_at 26 | # t.string :unconfirmed_email # Only if using reconfirmable 27 | 28 | ## Lockable 29 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 30 | # t.string :unlock_token # Only if unlock strategy is :email or :both 31 | # t.datetime :locked_at 32 | 33 | 34 | t.timestamps null: false 35 | end 36 | 37 | add_index :users, :email, unique: true 38 | add_index :users, :reset_password_token, unique: true 39 | # add_index :users, :confirmation_token, unique: true 40 | # add_index :users, :unlock_token, unique: true 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /app/views/notifications/fcm.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 10 |
11 | 12 |
13 |
14 | <%= form_tag({action: :process_fcm}) do %> 15 |
16 | <%= label_tag "Project ID" %> This is a unique identifier for your Firebase project and looks similar to "push-test-f8ea2" 17 | <%= text_field_tag 'project_id', @gcm_project_id, class: "form-control" %>
18 |
19 | 23 |
24 | <%= label_tag "Production FCM API Key" %> hthttps://console.firebase.google.com/project 25 | <%= text_field_tag 'fcm_api_key', @fcm_api_key_production, class: "form-control" %> 26 |
27 | <%= submit_tag "Save", class:"btn btn-default" %> 28 | <% end %> 29 |
30 |
31 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | # require "sidekiq/web" # Uncomment if testing or debugging Sidekiq 2 | 3 | Rails.application.routes.draw do 4 | devise_for :users 5 | 6 | # mount Sidekiq::Web => "/sidekiq" # Uncomment if testing or debugging Sidekiq 7 | 8 | root to: "home#index" 9 | 10 | get "admin" => "administration#index" 11 | 12 | get "notifications" => "notifications#index" 13 | get "notifications/admin" => "notifications#admin" 14 | 15 | post "notifications/subscribe" => "notifications#subscribe" 16 | post "notifications/unsubscribe" => "notifications#unsubscribe" 17 | get "notifications/resubscribe" => "notifications#resubscribe" 18 | 19 | get "notifications/cert_upload" => "notifications#cert_upload" 20 | post "notifications/cert_upload" => "notifications#process_cert" 21 | 22 | get "notifications/fcm" => "notifications#fcm" 23 | post "notifications/fcm" => "notifications#process_fcm" 24 | 25 | get "notifications/:id/push" => "notifications#push", as: :push 26 | resources :notifications 27 | 28 | resources :users 29 | 30 | get "articles" => "articles#index", defaults: { format: "json" } 31 | get "article" => "articles#article", defaults: { format: "json" } 32 | get "search" => "articles#search", defaults: { format: "json" } 33 | post "authenticate" => "subscriptions#authenticate", defaults: { format: "json" } 34 | post "logout" => "subscriptions#logout", defaults: { format: "json" } 35 | 36 | get "preferences" => "preferences#index" 37 | put "preferences" => "preferences#update" 38 | 39 | get "passthrough" => "application#passthrough" 40 | 41 | get "heartbeat" => "application#heartbeat" 42 | 43 | get "analytics" => "analytics#index" 44 | end 45 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /app/views/articles/search.json.erb: -------------------------------------------------------------------------------- 1 | 2 | <%= raw(JSON.pretty_generate @response) %> 3 | 4 | <%# keeping this for reference %> 5 | <% if true == false %> 6 | { 7 | "query":"Khadija Ismayilova", 8 | "start_date":20150501, 9 | "end_date":20150505, 10 | "total_results":10, 11 | "total_pages":2, 12 | "page":2, 13 | 14 | "results": [ 15 | { 16 | "headline": "Macedonia's Snap Election: The Tale of Two Skopjes", 17 | "description": "Picture the scene. A mass of people sprawl around the base of a stage. Bare-armed, they sit, stand, drink from water bottles in the lazy heat. It's May 19th.", 18 | "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit...", 19 | "publish_date": 20150413, 20 | "author": "John C. Doe", 21 | "organization": "ICFJ", 22 | "language": "en", 23 | "id": 12, 24 | "image_urls": ["https://www.occrp.org/images/MacedoniaAlbania1.jpg", "https://www.occrp.org/occrp/images/stories/indepth/azerbaijani-family.jpg"] 25 | }, 26 | { 27 | "headline": "Romania on Brink as Prime Minister Urged to Quit Over Corruption Claims", 28 | "description": "Romania’s president has urged Prime Minister Victor Ponta to resign after prosecutors named Ponta in connection with allegations of corruption.", 29 | "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit...", 30 | "publish_date": 20150413, 31 | "author": "John C. Doe", 32 | "organization": "ICFJ", 33 | "language": "en", 34 | "id": 12, 35 | "image_urls": ["https://www.occrp.org/images/MacedoniaAlbania1.jpg", "https://www.occrp.org/occrp/images/stories/indepth/azerbaijani-family.jpg"] 36 | } 37 | ] 38 | } 39 | <% end %> 40 | -------------------------------------------------------------------------------- /app/views/preferences/index_snworks.html.erb: -------------------------------------------------------------------------------- 1 | 15 | 16 |
17 | 20 |
21 |
22 | 23 |
24 | <%= form_with(url: "/preferences", method: "put") do %> 25 |
26 |
27 | 28 |
29 |

30 |

31 | <%= render partial: "category", locals: { language: @language } if @categories.empty? || @categories[@language].empty? %> 32 | <% @categories[@language].each do |category| %> 33 | <%= render partial: "category", locals: { language: @language, name: category[0], valid: category[1] != "invalid" } %> 34 | <% end %> 35 |
36 |

37 | 38 |
39 |
40 |
41 | <%= submit_tag "Save", class: "btn btn-success" %> 42 |
43 | <% end %> 44 |
45 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /app/views/articles/article.json.erb: -------------------------------------------------------------------------------- 1 | <%= raw(JSON.pretty_generate @response) %> 2 | 3 | <%# keeping this for reference %> 4 | <% if true == false %> 5 | { 6 | "start_date": 19700501, 7 | "end_date": 20150505, 8 | "total_results": 10, 9 | "total_pages": 2, 10 | "page": 2, 11 | "results": [ 12 | { 13 | "headline": "Macedonia's Snap Election: The Tale of Two Skopjes", 14 | "description": "Picture the scene. A mass of people sprawl around the base of a stage. Bare-armed, they sit, stand, drink from water bottles in the lazy heat. It's May 19th.", 15 | "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit...", 16 | "publish_date": 20150413, 17 | "author": "John C. Doe", 18 | "organization": "ICFJ", 19 | "language": "en", 20 | "id": 12, 21 | "image_urls": [ 22 | "https://www.occrp.org/images/MacedoniaAlbania1.jpg", 23 | "https://www.occrp.org/occrp/images/stories/indepth/azerbaijani-family.jpg" 24 | ] 25 | }, 26 | { 27 | "headline": "Romania on Brink as Prime Minister Urged to Quit Over Corruption Claims", 28 | "description": "Romania’s president has urged Prime Minister Victor Ponta to resign after prosecutors named Ponta in connection with allegations of corruption.", 29 | "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit...", 30 | "publish_date": 20150413, 31 | "author": "John C. Doe", 32 | "organization": "ICFJ", 33 | "language": "en", 34 | "id": 12, 35 | "image_urls": [ 36 | "https://www.occrp.org/images/MacedoniaAlbania1.jpg", 37 | "https://www.occrp.org/occrp/images/stories/indepth/azerbaijani-family.jpg" 38 | ] 39 | } 40 | ] 41 | } 42 | <% end %> 43 | -------------------------------------------------------------------------------- /app/views/articles/index.json.erb: -------------------------------------------------------------------------------- 1 | <%= raw(JSON.pretty_generate @response) %> 2 | 3 | <%# keeping this for reference %> 4 | <% if true == false %> 5 | { 6 | "start_date": 19700501, 7 | "end_date": 20150505, 8 | "total_results": 10, 9 | "total_pages": 2, 10 | "page": 2, 11 | "results": [ 12 | { 13 | "headline": "Macedonia's Snap Election: The Tale of Two Skopjes", 14 | "description": "Picture the scene. A mass of people sprawl around the base of a stage. Bare-armed, they sit, stand, drink from water bottles in the lazy heat. It's May 19th.", 15 | "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit...", 16 | "publish_date": 20150413, 17 | "author": "John C. Doe", 18 | "organization": "ICFJ", 19 | "language": "en", 20 | "id": 12, 21 | "image_urls": [ 22 | "https://www.occrp.org/images/MacedoniaAlbania1.jpg", 23 | "https://www.occrp.org/occrp/images/stories/indepth/azerbaijani-family.jpg" 24 | ] 25 | }, 26 | { 27 | "headline": "Romania on Brink as Prime Minister Urged to Quit Over Corruption Claims", 28 | "description": "Romania’s president has urged Prime Minister Victor Ponta to resign after prosecutors named Ponta in connection with allegations of corruption.", 29 | "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit...", 30 | "publish_date": 20150413, 31 | "author": "John C. Doe", 32 | "organization": "ICFJ", 33 | "language": "en", 34 | "id": 12, 35 | "image_urls": [ 36 | "https://www.occrp.org/images/MacedoniaAlbania1.jpg", 37 | "https://www.occrp.org/occrp/images/stories/indepth/azerbaijani-family.jpg" 38 | ] 39 | } 40 | ] 41 | } 42 | <% end %> 43 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | # inherit_from: .rubocop_todo.yml 2 | 3 | inherit_gem: 4 | rubocop-rails_config: 5 | - config/rails.yml 6 | 7 | AllCops: 8 | Exclude: 9 | - db/schema.rb 10 | - 'node_modules/**/*' 11 | - 'redis-stable/**/*' 12 | - 'bin/**/*' 13 | - 'vendor/**/*' 14 | - 'cookbooks/**/*' 15 | - 'tmp/**/*' 16 | - 'log/**/*' 17 | TargetRubyVersion: 2.5 18 | 19 | # Join tables don't really need timestamps 20 | Rails/CreateTableWithTimestamps: 21 | Exclude: 22 | 23 | # Rails generates this file 24 | Style/BlockComments: 25 | Exclude: 26 | - 'db/seeds.rb' 27 | 28 | # This sets us to use the standard Rails format instead of Rubocop's 29 | # opinionated Ruby style. 30 | Style/FrozenStringLiteralComment: 31 | Enabled: false 32 | 33 | # This sets us to use the standard Rails format instead of Rubocop's 34 | # opinionated Ruby style. 35 | Style/ClassAndModuleChildren: 36 | Enabled: false 37 | 38 | # Rails generates this file 39 | Layout/IndentationStyle: 40 | Exclude: 41 | - 'db/seeds.rb' 42 | 43 | # Temporarily turn this off 44 | Metrics/AbcSize: 45 | Enabled: false 46 | 47 | Metrics/ClassLength: 48 | Enabled: false 49 | 50 | Lint/RescueException: 51 | Enabled: false 52 | 53 | Lint/Debugger: 54 | Enabled: true 55 | 56 | Rails/HasManyOrHasOneDependent: 57 | Enabled: false 58 | 59 | Rails/HasAndBelongsToMany: 60 | Enabled: false 61 | 62 | Style/NumericPredicate: 63 | Enabled: false 64 | 65 | # This sets us to use the standard Rails format instead of Rubocop's 66 | # opinionated Ruby style. 67 | Layout/EmptyLinesAroundAccessModifier: 68 | Enabled: true 69 | EnforcedStyle: 'around' 70 | 71 | Naming/MethodName: 72 | Exclude: 73 | - 'app/serializers/participant_serializer.rb' 74 | 75 | # Regex sort of sucks 76 | Style/RegexpLiteral: 77 | Exclude: 78 | - 'config/application.rb' 79 | - 'config/initializers/route_downcaser.rb' 80 | Enabled: false 81 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # ignore the docker-compose.yml symlink 11 | docker-compose.yml 12 | 13 | # Ignore the default SQLite database. 14 | /db/*.sqlite3 15 | /db/*.sqlite3-journal 16 | 17 | # Ignore all logfiles and tempfiles. 18 | /log/* 19 | !/log/.keep 20 | /tmp 21 | tmp/* 22 | 23 | # Ignore application configuration 24 | /config/application.yml 25 | 26 | # Ignore the installed gems 27 | /vendor/bundle 28 | /vendor/cache 29 | 30 | secrets.env* 31 | /.docker/postgres/* 32 | /.docker/data/live/* 33 | /.docker/data/secrets/* 34 | /.docker/redis/* 35 | docker/postgres/* 36 | .docker/postgres/* 37 | .docker/nginx/dhparam.pem 38 | secrets/certs/* 39 | /secrets/certs/* 40 | public/assets 41 | secrets.env 42 | /cookbooks/* 43 | .env 44 | <<<<<<< HEAD 45 | 46 | data/dump.rdb 47 | ======= 48 | .byebug_history 49 | 50 | node_modules/ 51 | /actionview/log 52 | 53 | /activerecord/sqlnet.log 54 | 55 | /activemodel/test/fixtures/fixture_database.sqlite3 56 | /activesupport/test/fixtures/isolation_test 57 | /activestorage/test/service/configurations.yml 58 | /railties/test/500.html 59 | /railties/test/fixtures/tmp 60 | /railties/test/initializer/root/log 61 | /railties/doc 62 | /railties/tmp 63 | /guides/output 64 | 65 | data/dump.rdb 66 | 67 | /.docker/logs/* 68 | 69 | # Backups 70 | /.docker/backups/* 71 | !/.docker/backups/.keep 72 | 73 | 74 | /.vagrant 75 | /.idea 76 | 77 | # Because macOS 78 | .DS_Store 79 | >>>>>>> eb10494aa57787440b8395433b5ca965da570fea 80 | 81 | /public/packs 82 | /public/packs-test 83 | /node_modules 84 | /yarn-error.log 85 | yarn-debug.log* 86 | .yarn-integrity 87 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static file server for tests with Cache-Control for performance. 16 | config.serve_static_files = true 17 | config.static_cache_control = "public, max-age=3600" 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Store uploaded files on the local file system in a temporary directory 30 | config.active_storage.service = :test 31 | 32 | config.action_mailer.perform_caching = false 33 | 34 | # Tell Action Mailer not to deliver emails to the real world. 35 | # The :test delivery method accumulates sent emails in the 36 | # ActionMailer::Base.deliveries array. 37 | config.action_mailer.delivery_method = :test 38 | 39 | # Print deprecation notices to the stderr. 40 | config.active_support.deprecation = :stderr 41 | 42 | # Raises error for missing translations 43 | # config.action_view.raise_on_missing_translations = true 44 | end 45 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function(api) { 2 | var validEnv = ['development', 'test', 'production'] 3 | var currentEnv = api.env() 4 | var isDevelopmentEnv = api.env('development') 5 | var isProductionEnv = api.env('production') 6 | var isTestEnv = api.env('test') 7 | 8 | if (!validEnv.includes(currentEnv)) { 9 | throw new Error( 10 | 'Please specify a valid `NODE_ENV` or ' + 11 | '`BABEL_ENV` environment variables. Valid values are "development", ' + 12 | '"test", and "production". Instead, received: ' + 13 | JSON.stringify(currentEnv) + 14 | '.' 15 | ) 16 | } 17 | 18 | return { 19 | presets: [ 20 | isTestEnv && [ 21 | '@babel/preset-env', 22 | { 23 | targets: { 24 | node: 'current' 25 | } 26 | } 27 | ], 28 | (isProductionEnv || isDevelopmentEnv) && [ 29 | '@babel/preset-env', 30 | { 31 | forceAllTransforms: true, 32 | useBuiltIns: 'entry', 33 | corejs: 3, 34 | modules: false, 35 | exclude: ['transform-typeof-symbol'] 36 | } 37 | ] 38 | ].filter(Boolean), 39 | plugins: [ 40 | 'babel-plugin-macros', 41 | '@babel/plugin-syntax-dynamic-import', 42 | isTestEnv && 'babel-plugin-dynamic-import-node', 43 | '@babel/plugin-transform-destructuring', 44 | [ 45 | '@babel/plugin-proposal-class-properties', 46 | { 47 | loose: true 48 | } 49 | ], 50 | [ 51 | '@babel/plugin-proposal-object-rest-spread', 52 | { 53 | useBuiltIns: true 54 | } 55 | ], 56 | [ 57 | '@babel/plugin-transform-runtime', 58 | { 59 | helpers: false, 60 | regenerator: true, 61 | corejs: false 62 | } 63 | ], 64 | [ 65 | '@babel/plugin-transform-regenerator', 66 | { 67 | async: false 68 | } 69 | ] 70 | ].filter(Boolean) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /config/initializers/new_framework_defaults_5_2.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 5.2 upgrade. 4 | # 5 | # Once upgraded flip defaults one by one to migrate to the new default. 6 | # 7 | # Read the Guide for Upgrading Ruby on Rails for more info on each option. 8 | 9 | # Make Active Record use stable #cache_key alongside new #cache_version method. 10 | # This is needed for recyclable cache keys. 11 | # Rails.application.config.active_record.cache_versioning = true 12 | 13 | # Use AES-256-GCM authenticated encryption for encrypted cookies. 14 | # Also, embed cookie expiry in signed or encrypted cookies for increased security. 15 | # 16 | # This option is not backwards compatible with earlier Rails versions. 17 | # It's best enabled when your entire app is migrated and stable on 5.2. 18 | # 19 | # Existing cookies will be converted on read then written with the new scheme. 20 | # Rails.application.config.action_dispatch.use_authenticated_cookie_encryption = true 21 | 22 | # Use AES-256-GCM authenticated encryption as default cipher for encrypting messages 23 | # instead of AES-256-CBC, when use_authenticated_message_encryption is set to true. 24 | # Rails.application.config.active_support.use_authenticated_message_encryption = true 25 | 26 | # Add default protection from forgery to ActionController::Base instead of in 27 | # ApplicationController. 28 | # Rails.application.config.action_controller.default_protect_from_forgery = true 29 | 30 | # Store boolean values are in sqlite3 databases as 1 and 0 instead of 't' and 31 | # 'f' after migrating old data. 32 | # Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true 33 | 34 | # Use SHA-1 instead of MD5 to generate non-sensitive digests, such as the ETag header. 35 | # Rails.application.config.active_support.use_sha1_digests = true 36 | 37 | # Make `form_with` generate id attributes for any generated HTML tags. 38 | # Rails.application.config.action_view.form_with_generates_ids = true 39 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "" 3 | echo "Running Bundler... 🎁" 4 | 5 | bundle config build.nokogiri --use-system-libraries 6 | bundle install --path vendor/bundle 7 | 8 | # Write the logrotate file 9 | cat >/etc/logrotate.conf < language, "categories" => boolean }) 25 | when :wordpress 26 | response = Wordpress.articles({ "language" => language, "categories" => boolean }) 27 | when :newscoop 28 | response = Newscoop.articles({ "language" => language, "categories" => boolean }) 29 | when :cins_codeigniter 30 | response = CinsCodeigniter.articles({ "language" => language, "categories" => boolean }) 31 | when :blox 32 | response = Blox.articles({ "language" => language, "categories" => boolean }) 33 | end 34 | 35 | application_controller = ApplicationController.new 36 | 37 | response[:results].keys.each do |key| 38 | # go through each image 39 | response[:results][key].each do |article| 40 | article["images"].each { |image| application_controller.passthrough_image(image["url"]) } 41 | end unless response[:results][key].nil? 42 | end if response[:results].class == Hash 43 | 44 | response[:results].each do |article| 45 | article["images"].each { |image| application_controller.passthrough_image(image["url"]) } 46 | end if response[:results].class == Array 47 | end 48 | end 49 | end 50 | 51 | unless defined?(Rails::Console) || File.split($0).last == "rake" 52 | s.every "1m" do 53 | # run_update 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /app/views/devise/registrations/edit.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 10 | <%= devise_error_messages! %> 11 |
12 | <%= f.label :email %>
13 | <%= f.email_field :email, autofocus: true, class: "form-control" %> 14 |
15 | 16 | <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 17 |
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
18 | <% end %> 19 | 20 |
21 | <%= f.label :password %> (leave blank if you don't want to change it)
22 | <%= f.password_field :password, autocomplete: "off", class: "form-control" %> 23 | 24 | <% if @minimum_password_length %>. 25 |
26 | (<%= @minimum_password_length %> characters minimum) 27 | <% end %> 28 |
29 | 30 |
31 | <%= f.label :password_confirmation %>
32 | <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %> 33 |
34 | 35 |
36 | <%= f.label :current_password %> (we need your current password to confirm your changes)
37 | <%= f.password_field :current_password, autocomplete: "off", class: "form-control" %> 38 |
39 | 40 |
41 |
42 | <%= f.submit "Update", class:"btn btn-default" %> 43 |
44 | <% end %> 45 | 46 |
47 | <%= render "devise/shared/links" %> 48 |
49 | 50 |

Cancel my account

51 | 52 |

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

53 | 54 | <%= link_to "Back", :back %> 55 | 56 |
57 |
-------------------------------------------------------------------------------- /secrets.env.template: -------------------------------------------------------------------------------- 1 | ########## 2 | # To be filled out properly 3 | ########## 4 | 5 | ############### 6 | # Wordpress 7 | ############## 8 | 9 | #title=Meydan TV 10 | #cms_mode=wordpress 11 | #DEVISE_SECRET_KEY=******************************* 12 | #SECRET_KEY_BASE=******************************* 13 | #proxy_images='true' 14 | #host=https://meydan.pushapp.press 15 | #languages="en,ru,ge,az,sr,bg" 16 | #default_language="en" 17 | 18 | ############### 19 | # Joomla 20 | ############## 21 | 22 | #cms_mode=occrp-joomla 23 | #occrp_joomla_url=https://www.occrp.org/index.html?option=com_push&format=json 24 | #DEVISE_SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxx 25 | #SECRET_KEY_BASE=xxxxxxxxxxxxxxxxxxxxxxxxx 26 | #language="en,ru,ge,az,sr,bg" 27 | #default_language="en" 28 | 29 | ############### 30 | # Newscoop 31 | ############## 32 | 33 | #title=Meydan TV 34 | #cms_mode=newscoop 35 | #newscoop_client_id=******************************* 36 | #newscoop_client_secret=******************************* 37 | #newscoop_url=https://www.example.com 38 | #DEVISE_SECRET_KEY=******************************* 39 | #SECRET_KEY_BASE=******************************* 40 | #proxy_images='true' 41 | #host=https://meydan.pushapp.press 42 | #language="en,ru,ge,az,sr,bg" 43 | #default_language="en" 44 | 45 | ############### 46 | # Cins-Codeignitor 47 | ############## 48 | 49 | #title=Meydan TV 50 | #cms_mode=newscoop 51 | #newscoop_client_id=******************************* 52 | #newscoop_client_secret=******************************* 53 | #newscoop_url=https://www.example.com 54 | #DEVISE_SECRET_KEY=******************************* 55 | #SECRET_KEY_BASE=******************************* 56 | #proxy_images='true' 57 | #host=https://example.pushapp.press 58 | #language="en,ru,ge,az,sr,bg" 59 | #default_language="en" 60 | 61 | ############### 62 | # SEO Works CEO 63 | ############### 64 | title="Sample Organization" 65 | cms_mode=snworks 66 | 67 | # `snworks_url` is always the same, no matter what the organization 68 | snworks_url=https://car.ceo.getsnworks.com 69 | snworks_public_api_key=******************************* 70 | snworks_private_api_key==******************************* 71 | # Url of the main site 72 | host_url=https://example.com 73 | 74 | force_https=true 75 | #DEVISE_SECRET_KEY=******************************* 76 | #SECRET_KEY_BASE=******************************* 77 | #SENTRY_DSN=**********************************y 78 | -------------------------------------------------------------------------------- /config/webpacker.yml: -------------------------------------------------------------------------------- 1 | # Note: You must restart bin/webpack-dev-server for changes to take effect 2 | 3 | default: &default 4 | source_path: app/javascript 5 | source_entry_path: packs 6 | public_root_path: public 7 | public_output_path: packs 8 | cache_path: tmp/cache/webpacker 9 | check_yarn_integrity: false 10 | webpack_compile_output: true 11 | 12 | # Additional paths webpack should lookup modules 13 | # ['app/assets', 'engine/foo/app/assets'] 14 | resolved_paths: [] 15 | 16 | # Reload manifest.json on all requests so we reload latest compiled packs 17 | cache_manifest: false 18 | 19 | # Extract and emit a css file 20 | extract_css: false 21 | 22 | static_assets_extensions: 23 | - .jpg 24 | - .jpeg 25 | - .png 26 | - .gif 27 | - .tiff 28 | - .ico 29 | - .svg 30 | - .eot 31 | - .otf 32 | - .ttf 33 | - .woff 34 | - .woff2 35 | 36 | extensions: 37 | - .mjs 38 | - .js 39 | - .sass 40 | - .scss 41 | - .css 42 | - .module.sass 43 | - .module.scss 44 | - .module.css 45 | - .png 46 | - .svg 47 | - .gif 48 | - .jpeg 49 | - .jpg 50 | 51 | development: 52 | <<: *default 53 | compile: true 54 | 55 | # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules 56 | check_yarn_integrity: true 57 | 58 | # Reference: https://webpack.js.org/configuration/dev-server/ 59 | dev_server: 60 | https: false 61 | host: webpack 62 | port: 3035 63 | public: webpack:3035 64 | hmr: false 65 | # Inline should be set to true if using HMR 66 | inline: true 67 | overlay: true 68 | compress: true 69 | disable_host_check: true 70 | use_local_ip: false 71 | quiet: false 72 | pretty: false 73 | headers: 74 | 'Access-Control-Allow-Origin': '*' 75 | watch_options: 76 | ignored: '**/node_modules/**' 77 | 78 | 79 | test: 80 | <<: *default 81 | compile: true 82 | 83 | # Compile test packs to a separate directory 84 | public_output_path: packs-test 85 | 86 | production: 87 | <<: *default 88 | 89 | # Production depends on precompilation of packs prior to booting for performance. 90 | compile: false 91 | 92 | # Extract and emit a css file 93 | extract_css: true 94 | 95 | # Cache manifest.json for performance 96 | cache_manifest: true 97 | -------------------------------------------------------------------------------- /maintence-scripts/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="${BASH_SOURCE%/*}" 4 | if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi 5 | . "$DIR/includes.sh" 6 | 7 | function kill_docker_containers { 8 | echo -e "\n\e[94mStopping any errantly running docker containers\e[0m" 9 | echo -e "\e[94m---------------------------------\e[0m\n" 10 | docker stop $(docker ps -a -q) 11 | docker rm $(docker ps -a -q) 12 | } 13 | 14 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 15 | echoc "Setting up a new Push server..." $LIGHT_BLUE 16 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 17 | 18 | # making sure a docker-compose.yml file exists 19 | # if not, let's use some sane defaults 20 | if basename "$PWD" | grep 'maintence-scripts' > /dev/null; then 21 | [ -f ../docker-compose.yml ] || ln -s docker-compose-with-nginx.yml ../docker-compose.yml 22 | else 23 | [ -f docker-compose.yml ] || ln -s docker-compose-with-nginx.yml docker-compose.yml 24 | fi 25 | 26 | if basename "$PWD" | grep 'maintence-scripts' > /dev/null; then 27 | path='./setup-cms_env.sh' 28 | else 29 | path='./maintence-scripts/setup-cms_env.sh' 30 | fi 31 | 32 | #bash $path 33 | 34 | #echoc '\n---------------------------------------------------------\n' $LIGHT_BLUE 35 | #echoc ' Moving on to generating SSL keys \n' $LIGHT_BLUE 36 | #echoc '---------------------------------------------------------\n\n' $LIGHT_BLUE 37 | 38 | #if basename "$PWD" | grep 'maintence-scripts' > /dev/null; then 39 | # path='./setup-lets_encrypt.sh' 40 | #else 41 | # path='./maintence-scripts/setup-lets_encrypt.sh' 42 | #fi 43 | 44 | #bash $path 45 | 46 | if [ "$?" = 0 ]; then 47 | echoc '\n---------------------------------------------------------\n' $LIGHT_BLUE 48 | echoc " Theoretically you\'re done!!! \n" $LIGHT_BLUE 49 | echoc '---------------------------------------------------------\n\n' $LIGHT_BLUE 50 | else 51 | echoc '\n---------------------------------------------------------' $RED 52 | echoc "It looks like there were some errors. I'm sorry about that, I know it can be frustrating" 53 | echoc "Please review any messages and post bug reports if you believe it's an inapproriate error." 54 | echoc '---------------------------------------------------------' $RED 55 | fi 56 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable/disable caching. By default caching is disabled. 16 | # Run rails dev:cache to toggle caching. 17 | if Rails.root.join("tmp", "caching-dev.txt").exist? 18 | config.action_controller.perform_caching = true 19 | config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"] } 20 | config.public_file_server.headers = { 21 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 22 | } 23 | else 24 | config.action_controller.perform_caching = false 25 | 26 | config.cache_store = :null_store 27 | end 28 | 29 | # Store uploaded files on the local file system (see config/storage.yml for options) 30 | config.active_storage.service = :local 31 | 32 | # Don't care if the mailer can't send. 33 | config.action_mailer.raise_delivery_errors = false 34 | 35 | config.action_mailer.perform_caching = false 36 | 37 | # Print deprecation notices to the Rails logger. 38 | config.active_support.deprecation = :log 39 | 40 | # Raise an error on page load if there are pending migrations. 41 | config.active_record.migration_error = :page_load 42 | 43 | # Highlight code that triggered database queries in logs. 44 | config.active_record.verbose_query_logs = true 45 | 46 | # Debug mode disables concatenation and preprocessing of assets. 47 | # This option may cause significant delays in view rendering with a large 48 | # number of complex assets. 49 | config.assets.debug = true 50 | 51 | # Suppress logger output for asset requests. 52 | config.assets.quiet = true 53 | 54 | # Raises error for missing translations 55 | # config.action_view.raise_on_missing_translations = true 56 | # config.force_ssl = true 57 | config.cache_store = :null_store 58 | 59 | config.action_mailer.default_url_options = { host: "localhost", port: 3000 } 60 | 61 | config.middleware.insert_before 0, Rack::Cors do 62 | allow do 63 | origins "*" 64 | resource "*", headers: :any, methods: [:get, :post, :options] 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | rescue_from ActiveRecord::RecordNotFound, with: :user_not_found 3 | 4 | before_action :authenticate_user! 5 | before_action :set_minimum_password_length, only: [:new, :edit] 6 | 7 | def index 8 | @users = User.all 9 | @devise_error_messages = [] 10 | end 11 | 12 | def new 13 | @user = User.new 14 | end 15 | 16 | def create 17 | u = User.new(email: params[:user][:email], password: params[:user][:password], password_confirmation: params[:user][:password_confirmation]) 18 | 19 | if u == false 20 | @devise_error_messages = u.errors 21 | redirect_to new_user_path(u) 22 | end 23 | u.save! 24 | 25 | flash[:notice] = "#{u.email} successfully created." 26 | 27 | redirect_to u 28 | end 29 | 30 | 31 | def show 32 | @user = User.find(params[:id]) 33 | end 34 | 35 | def edit 36 | @user = User.find(params[:id]) 37 | 38 | if current_user != @user 39 | flash[:alert] = "You can only edit yourself. Please contact the administrator with questions." 40 | redirect_to :users 41 | end 42 | end 43 | 44 | def update 45 | @user = User.find(params[:id]) 46 | 47 | if current_user != @user 48 | flash[:alert] = "You can only edit yourself. Please contact the administrator with questions." 49 | redirect_to :users 50 | end 51 | 52 | if params[:user][:password] != params[:user][:password_confirmation] 53 | flash[:alert] = "Passwords must match." 54 | redirect_back(fallback_location: users_path) 55 | end 56 | 57 | @user.email = params[:user][:email] 58 | if !params[:user][:password].blank? 59 | @user.password = params[:user][:password] 60 | end 61 | 62 | @user.save! 63 | 64 | sign_in(@user, bypass: true) 65 | 66 | flash[:notice] = "Successfully updated user." 67 | redirect_to @user 68 | end 69 | 70 | def destroy 71 | user = User.find(params[:id]) 72 | 73 | email = user.email 74 | user.destroy! 75 | 76 | flash[:notice] = "#{email} deleted" 77 | redirect_back(fallback_location: users_path) 78 | end 79 | 80 | private 81 | 82 | def redirect_to_default 83 | redirect_to users_path 84 | end 85 | 86 | def user_not_found 87 | flash[:alert] = "User not found with id #{params[:id]}" 88 | begin 89 | redirect_back(fallback_location: users_path) 90 | rescue ActionController::RedirectBackError 91 | redirect_to_default 92 | end 93 | end 94 | 95 | def set_minimum_password_length 96 | @minimum_password_length = 10 97 | end 98 | end 99 | -------------------------------------------------------------------------------- /maintence-scripts/upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="${BASH_SOURCE%/*}" 3 | if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi 4 | . "$DIR/includes.sh" 5 | 6 | # This script will pull the newest version of Push from the git repository. 7 | # If Push wasn't set up with git this will break pretty fantastically. 8 | 9 | check_if_docker_is_running 10 | 11 | # Pull the Git repository 12 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 13 | echoc "Updating the Push software from the git repository" $GREEN 14 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 15 | 16 | # error=$(git pull --rebase | tee /dev/tty | grep 'error') 17 | 18 | # if ! [[ -z "${error// }" ]]; then 19 | 20 | if ! [ "$(git pull --rebase)" ]; then 21 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 22 | echoc "There was an error in upgrading from Git.\n" $RED 23 | echoc "Please review the console output and submit a bug report if you think it's necessary." 24 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 25 | exit 100 26 | else 27 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 28 | echoc "Successfully pulled new code!" $LIGHT_BLUE 29 | echoc "\n-------------------------------------------------------------------------------------------------------------\n\n" $LIGHT_BLUE 30 | fi 31 | 32 | # Stop the cert docker-compose containers 33 | kill_docker_containers 34 | 35 | if basename "$PWD" | grep 'maintence-scripts' > /dev/null; then 36 | command='docker-compose -f ../docker-compose-with-nginx.yml up -d' 37 | else 38 | command='docker-compose -f docker-compose-with-nginx.yml up -d' 39 | fi 40 | 41 | error=$($command | tee /dev/tty | grep 'The following errors were reported by the server') 42 | 43 | if ! [[ -z "${error// }" ]]; then 44 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 45 | echoc "There was an error in restarting your production containers.\n" $RED 46 | echoc "Please review the console output and submit a bug report if you think it's necessary." 47 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 48 | exit 100 49 | else 50 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 51 | echoc "Successfully booted up the production servers!" $LIGHT_BLUE 52 | echoc "\n-------------------------------------------------------------------------------------------------------------\n\n" $LIGHT_BLUE 53 | fi -------------------------------------------------------------------------------- /app/views/analytics/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 |
10 |
11 |
12 | Consumers since <%= @earliest_consumer_date.strftime('%B %y, %Y %H:%M %Z') %> 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
Active Users In the Last Day:<%= @consumer_count_last_day %>
Active Users In the Last Week:<%= @consumer_count_last_week %>
Active Users In the Last Month:<%= @consumer_count_last_month %>
Total Users All Time:<%= @consumer_count %>
31 |
32 |
33 |
34 |
35 |
36 |
37 | Types of Requests since <%= @earliest_consumer_date.strftime('%B %y, %Y %H:%M %Z') %> 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
Articles Load/Reload (last day):<%= @articles_request_count_last_day %>
Articles Load/Reload (last week):<%= @articles_request_count_last_week %>
Articles Load/Reload (last month):<%= @articles_request_count_last_month %>
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | Recent Searches since <%= @earliest_consumer_date.strftime('%B %y, %Y %H:%M %Z') %> 61 | 62 | <% @most_recent_search_phrases.each do |search| %> 63 | 64 | 65 | 66 | <% end %> 67 |
<%= link_to search.search_phrase, controller: 'articles', action: 'search', format: 'json', language: search.language, q: search.search_phrase %>
68 |
69 |
70 |
71 |
-------------------------------------------------------------------------------- /maintence-scripts/renew-lets_encrypt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="${BASH_SOURCE%/*}" 3 | if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi 4 | . "$DIR/includes.sh" 5 | 6 | # This script will renew the let's encrypt ssl certs, if needed 7 | 8 | if basename "$PWD" | grep 'maintence-scripts' > /dev/null; then 9 | path='../.env' 10 | else 11 | path='./.env' 12 | fi 13 | 14 | if [ ! -f $path ]; then 15 | echoc "No .env file found, please run the 'setup-lets_encrypt.sh' script first." $YELLOW 16 | exit 17 | fi 18 | 19 | # Stop the production docker-compose containers 20 | kill_docker_containers 21 | 22 | # Renew the ssl certs 23 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 24 | echoc "Renewing SSL certificates" $GREEN 25 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 26 | 27 | if basename "$PWD" | grep 'maintence-scripts' > /dev/null; then 28 | command='docker-compose -f ../letsencrypt-docker-compose.yml up' 29 | else 30 | command='docker-compose -f letsencrypt-docker-compose.yml up' 31 | fi 32 | 33 | error=$($command | tee /dev/tty | grep 'The following errors were reported by the server') 34 | 35 | 36 | if ! [[ -z "${error// }" ]]; then 37 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 38 | echoc "There was an error in renewing your certificates.\n" $RED 39 | echoc "Please review the console output and submit a bug report if you think it's necessary." 40 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 41 | exit 100 42 | else 43 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 44 | echoc "Successfully renewed your SSL keys!" $LIGHT_BLUE 45 | echoc "\n-------------------------------------------------------------------------------------------------------------\n\n" $LIGHT_BLUE 46 | fi 47 | 48 | # Stop the cert docker-compose containers 49 | kill_docker_containers 50 | 51 | if basename "$PWD" | grep 'maintence-scripts' > /dev/null; then 52 | command='docker-compose -f ../docker-compose-with-nginx.yml up -d' 53 | else 54 | command='docker-compose -f docker-compose-with-nginx.yml up -d' 55 | fi 56 | 57 | error=$($command | tee /dev/tty | grep 'The following errors were reported by the server') 58 | 59 | if ! [[ -z "${error// }" ]]; then 60 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 61 | echoc "There was an error in restarting your production containers.\n" $RED 62 | echoc "Please review the console output and submit a bug report if you think it's necessary." 63 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 64 | exit 100 65 | else 66 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 67 | echoc "Successfully booted up the production servers!" $LIGHT_BLUE 68 | echoc "\n-------------------------------------------------------------------------------------------------------------\n\n" $LIGHT_BLUE 69 | fi -------------------------------------------------------------------------------- /docker-compose-no-nginx.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | # nginx, working as a front-end proxy for uniqush 5 | # we need it for only allowing certain endpoints to be available 6 | db: 7 | image: postgres:9.6 8 | volumes: 9 | - "./.docker/postgres:/data/postgres" 10 | environment: 11 | - POSTGRES_USER=postgres 12 | - POSTGRES_PASSWORD=postgres 13 | - PGDATA=/data/postgres 14 | 15 | web: 16 | build: . 17 | command: bundle exec rails s -p 3000 -b '0.0.0.0' 18 | volumes: 19 | - ".:/push:cached" 20 | - "rails_cache:/app/tmp/cache" 21 | - "node_modules:/app/node_modules" 22 | - "packs:/app/public/packs" 23 | expose: 24 | - "3000" 25 | depends_on: 26 | - db 27 | - uniqush 28 | - redis 29 | env_file: 30 | - ./secrets.env 31 | environment: 32 | - RAILS_ENV=${RAILS_ENV} 33 | - proxy_images=true 34 | entrypoint: /push/entrypoint.sh 35 | tty: true 36 | stdin_open: true 37 | networks: 38 | - default 39 | 40 | # Run ActiveJobs on a schedule using the Clockwork gem 41 | scheduled_jobs: 42 | build: . 43 | command: bundle exec clockwork ./scheduler.rb 44 | volumes: 45 | - ".:/push:cached" 46 | env_file: 47 | - ./secrets.env 48 | environment: 49 | - RAILS_ENV=production 50 | - proxy_images=true 51 | - REDIS_URL=redis://redis:6379/0 52 | - FORCE_SSL=false 53 | depends_on: 54 | - db 55 | - redis 56 | - sidekiq 57 | entrypoint: /push/entrypoint_scheduled_jobs.sh 58 | tty: true 59 | stdin_open: true 60 | networks: 61 | - default 62 | 63 | # uniqush itself 64 | uniqush: 65 | build: https://github.com/beevelop/docker-uniqush.git 66 | environment: 67 | # this is the default, but let's be explicit here 68 | UNIQUSH_DATABASE_HOST: "redis" 69 | # UNIQUSH_LOGFILE: "/srv/logs/gurac/uniqush.log" 70 | UNIQUSH_LOGLEVEL: "verbose" 71 | UNIQUSH_GID: "60001" 72 | UNIQUSH_UID: "60001" 73 | depends_on: 74 | - redis 75 | volumes: 76 | - "./secrets:/secrets" 77 | #- "/srv/logs/gurac/:/srv/logs/gurac/" 78 | 79 | # The Redis server. This is used for both Sidekiq and Uniqush 80 | redis: 81 | image: redis:buster 82 | restart: always 83 | volumes: 84 | - "./.docker/redis:/data:cached" 85 | command: ["redis-server", "--appendonly", "yes"] 86 | expose: 87 | - "6379" 88 | logging: 89 | driver: "json-file" 90 | options: 91 | max-size: "10m" 92 | max-file: "3" 93 | 94 | # Sidekiq is used for the ActiveJob backend 95 | sidekiq: 96 | build: . 97 | command: bundle exec sidekiq -C config/sidekiq.yml 98 | volumes: 99 | - ".:/push:cached" 100 | depends_on: 101 | - db 102 | - redis 103 | env_file: 104 | - ./secrets.env 105 | environment: 106 | - RAILS_ENV=production 107 | - proxy_images=true 108 | - FORCE_SSL=false 109 | - REDIS_URL=redis://redis:6379/0 110 | tty: true 111 | stdin_open: true 112 | entrypoint: /push/entrypoint_sidekiq.sh 113 | networks: 114 | - default 115 | 116 | volumes: 117 | rails_cache: 118 | node_modules: 119 | packs: 120 | -------------------------------------------------------------------------------- /maintence-scripts/includes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Common includes for bash scripts 4 | # Author: Christopher Guess 5 | # Date: December 15, 2016 6 | # Contact: cguess@gmail.com 7 | 8 | # To use this in your script add the following lines to the top of the script (uncommented) 9 | # 10 | # DIR="${BASH_SOURCE%/*}" 11 | # if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi 12 | # . "$DIR/includes.sh" 13 | # 14 | 15 | 16 | 17 | # A list of color constants that can be used 18 | # NOTE: Most of these are very wrong 19 | BLACK='\033[0;30m' 20 | RED='\033[0;31m' 21 | GREEN='\033[0;32m' 22 | ORANGE='\033[0;33m' 23 | BLUE='\033[0;34m' 24 | PURPLE='\033[0;35m' 25 | CYAN='\033[0;36m' 26 | LIGHT_GRAY='\033[0;37m' 27 | DARK_GRAY='\033[0;38m' 28 | LIGHT_RED='\033[0;39m' 29 | LIGHT_GREEN='\033[1;30m' 30 | YELLOW='\033[1;31m' 31 | LIGHT_BLUE='\033[1;32m' 32 | LIGHT_PURPLE='\033[1;33m' 33 | LIGHT_CYAN='\033[1;34m' 34 | WHITE='\033[1;35m' 35 | NC='\033[0m' 36 | 37 | # echos a string with a given color constant 38 | # ex: echoc "Hello World!" $RED 39 | function echoc { 40 | printf "$2$1${NC}\n" 41 | } 42 | 43 | function timestamp { 44 | date +"%Y%m%d-%H:%M:%S" 45 | } 46 | 47 | # asks a yes or no question, echos 'true' for yes, 'false' for no 48 | # ex: answer=$(askyn 'Are you a god?') 49 | # ex: askyn 'Are you a god?' $answer 50 | function askyn { 51 | local __resultvar=$2 52 | while true 53 | do 54 | read -p "$1 [y/n] " choice 55 | if [[ $choice =~ ^(yes|y|YES|Y|N|NO|no|n| ) ]]; then 56 | break 57 | fi 58 | done 59 | 60 | case "$choice" in 61 | y|Y|yes|YES ) 62 | answer=true; 63 | ;; 64 | n|N|no|NO ) 65 | answer=false; 66 | ;; 67 | * ) echo "Please answer y or n";; 68 | esac 69 | 70 | if [[ "$__resultvar" ]]; then 71 | eval $__resultvar=$answer 72 | else 73 | echo $answer 74 | fi 75 | } 76 | 77 | # Borrow from https://stackoverflow.com/questions/1527049/bash-join-elements-of-an-array 78 | # Joins an array by a delimiter 79 | # ex: join_by , a "b c" d #a,b c,d 80 | # join_by / var local tmp #var/local/tmp 81 | # join_by , "${FOO[@]}" #a,b,c 82 | function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; } 83 | 84 | # This is the setup script for Lets Encrypt on a new Push Backend Server. 85 | 86 | function kill_docker_containers { 87 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $BLUE 88 | echoc "Stopping any errantly running docker containers" $BLUE 89 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $BLUE 90 | if [ -n "$(docker ps -a -q)" ]; then 91 | docker stop $(docker ps -a -q) 92 | docker rm $(docker ps -a -q) 93 | fi 94 | } 95 | 96 | function check_if_docker_is_running { 97 | if [ ! "$(docker ps)" ]; then 98 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 99 | echoc "ERROR: The Docker engine doesn't seem to be running.\n" $RED 100 | echoc "Please review the console output and submit a bug report if you think it's necessary." 101 | echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 102 | exit 100 103 | fi 104 | } 105 | -------------------------------------------------------------------------------- /maintence-scripts/export.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="${BASH_SOURCE%/*}" 3 | if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi 4 | . "$DIR/includes.sh" 5 | 6 | # This script is for exporting various parts of the app 7 | 8 | function export_full_db { 9 | echoc "Exporting full database..." $GREEN 10 | name="push_production_$(timestamp).sql" 11 | $(docker-compose exec --user postgres db pg_dump -Fc production > $name) 12 | 13 | error=$(grep 'failed' $name) 14 | if ! [[ -z "${error// }" ]]; then 15 | echoc "\n-------------------------------------------------------------" $RED 16 | echoc "There was an error in your export:\n" $RED 17 | cat $name 18 | echoc "\n-------------------------------------------------------------" $RED 19 | echoc "Please review the console output and submit a bug report if you think it's necessary." 20 | echoc "-------------------------------------------------------------" $RED 21 | rm $name 22 | exit 100 23 | else 24 | echoc "\n-------------------------------------------------------------"n" $LIGHT_BLUE 25 | echoc "Successfully generated your SSL keys!" $LIGHT_BLUE 26 | echoc "\n-------------------------------------------------------------"n\n" $LIGHT_BLUE 27 | fi 28 | 29 | } 30 | 31 | function export_analytics { 32 | echoc "Exporting backend analytics..." $GREEN 33 | command="..." 34 | export_from_db 35 | } 36 | 37 | function export_notifications { 38 | echoc "Exporting push notifications history..." $GREEN 39 | command="..." 40 | export_from_db 41 | } 42 | 43 | function export_devices { 44 | echoc "Exporting user devices..." $GREEN 45 | export_from_db '', 46 | } 47 | 48 | echoc "\nPush Project Backend Export Utility\n" 49 | 50 | # When I figure out how to do commands we'll skip this if something's put in. 51 | # bash options list? 52 | PS3='Please choose what you would like to export: ' 53 | options=("Full Database" "Analytics" "Push Notifications" "Devices") 54 | select opt in "${options[@]}" 55 | do 56 | case $opt in 57 | "Full Database") 58 | export_type='full' 59 | export_full_db 60 | break 61 | ;; 62 | "Analytics") 63 | export_type='analytics'; 64 | break 65 | ;; 66 | "Push Notifications") 67 | export_type='notifications'; 68 | break 69 | ;; 70 | "Devices") 71 | export_type='devices'; 72 | break 73 | ;; 74 | *) echo invalid option;; 75 | esac 76 | done 77 | 78 | echoc "Export completed" 79 | 80 | # echoc "Setting up a $cms installation" $GREEN 81 | 82 | # if [[ -z "${error// }" ]]; then 83 | # echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 84 | # echoc "There was an error in generating your certificates.\n" $RED 85 | # echoc "Please review the console output and submit a bug report if you think it's necessary." 86 | # echoc "\n-------------------------------------------------------------------------------------------------------------" $RED 87 | # exit 100 88 | # else 89 | # echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 90 | # echoc "Successfully generated your SSL keys!" $LIGHT_BLUE 91 | # echoc "\n-------------------------------------------------------------------------------------------------------------\n\n" $LIGHT_BLUE 92 | # fi -------------------------------------------------------------------------------- /letsencrypt-docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | 4 | # Adopted from https://git.occrp.org/tech/letsencrypt/blob/master/docker-compose-with-nginx.yml 5 | # 6 | # relevant: 7 | # - https://community.letsencrypt.org/t/nginx-docker-setup-for-le/2621 8 | # - https://github.com/mbrugger/letsencrypt-nginx-docker 9 | # 10 | # nginx container config has to contain: 11 | # - "/srv/data/live/letsencrypt/:/srv/data/live/letsencrypt/:ro" # letsencrypt verificaton webroot 12 | # - "/srv/data/secrets/letsencrypt/archive/:/srv/data/secrets/letsencrypt/archive/:ro" # letsencrypt certificate store 13 | # - "/srv/data/secrets/letsencrypt/live/:/srv/data/secrets/letsencrypt/live/:ro" # letsencrypt live certificate store 14 | # 15 | # nginx site config -- each server for each domain handled by letsencrypt should contain this config: 16 | # location /.well-known/acme-challenge { 17 | # alias /srv/data/live/letsencrypt/; 18 | # } 19 | # 20 | # nginx certificate config (say, for www.example.com domain): 21 | # ssl_certificate /srv/data/secrets/letsencrypt/live/www.example.com/fullchain.pem; 22 | # ssl_certificate_key /srv/data/secrets/letsencrypt/live/www.example.com/privkey.pem; 23 | # 24 | # if using docker-compose < 1.7.0, remember to run: 25 | # export $( cat your-env-file.env ) 26 | # ...before running docker-compose 27 | # 28 | # if running docker-compose >= 1.7.0, put your env vars in .env file 29 | # 30 | letsencrypt: 31 | image: quay.io/letsencrypt/letsencrypt 32 | # this file should contain at least two envvars defined 33 | # - LETSENCRYPT_EMAIL 34 | # - LETSENCRYPT_DOMAINS (comma-separated list; first domain used as the name of the cert) 35 | # it might additionally contain: 36 | # - LETSENCRYPT_STAGING (set to "--staging" to make the letsencrypt tool hit LE testing servers, instead of production -- for testing obviously) 37 | # an example settings file is available in (surprise, surprise) settings.example file 38 | ports: 39 | - "80:80" 40 | - "443:443" 41 | volumes: 42 | - "./.docker/data/secrets/keys/:/etc/letsencrypt/" # config, certs, etc 43 | - "./.docker/data/live/letsencrypt/:/var/www/.well-known/acme-challenge/" # directory used for webroot verification 44 | - "./.docker/logs/letsencrypt/:/var/log/letsencrypt/" # logs 45 | # help available via --help all 46 | #depends_on: 47 | #- nginx_letsencrypt 48 | entrypoint: certbot 49 | command: certonly --text --authenticator standalone --webroot-path /var/www/ --keep $LETSENCRYPT_STAGING --domains "$LETSENCRYPT_DOMAINS" --email "$LETSENCRYPT_EMAIL" --agree-tos 50 | 51 | nginx: 52 | build: https://github.com/PushOCCRP/watchful-nginx.git 53 | env_file: 54 | - ./secrets.env 55 | volumes: 56 | - "./.docker/nginx/:/etc/nginx/" # config 57 | - "./.docker/nginx/:/etc/ssl/nginx" 58 | - "./.docker/data/secrets/keys:/srv/data" # dhpram and certs are here 59 | - "./.docker/data/secrets/keys/archive/:/etc/letsencrypt/archive" 60 | - "./.docker/data/secrets/keys/live/$LETSENCRYPT_DOMAINS:/srv/data/ssl/keys" 61 | - "./public/:/var/public/" 62 | 63 | devencrypt: 64 | image: paulczar/omgwtfssl 65 | volumes: 66 | - "./.docker/data/secrets/keys/ssl/keys/:/certs/" # config, certs, etc 67 | environment: 68 | - SSL_SUBJECT=dev.pushapp.press 69 | - SSL_CERT=fullchain.pem 70 | - SSL_KEY=privkey.pem 71 | 72 | -------------------------------------------------------------------------------- /test/models/wordpress_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class WordpressTest < ActiveSupport::TestCase 4 | test "Clean up of Wordpress HTML entities should work" do 5 | input_text = '"body": "wp:paragraph -->

Svetlana Stojanović, sudija Osnovnog suda u

Lazarevcu, osuđena je danas na pet godina zatvora jer je primila 2000 evra

mita, saopštio je Viši sud u Beogradu. Stojanović je mito uzela od muškarca

kome je sudila uz obećanje da ga neće osuditi na zatvorsku, već na uslovnu kaznu.


/wp:paragraph -->

wp:paragraph -->

Piše: Milica Vojinović

/wp:paragraph -->

wp:paragraph -->

Sudiji Stojanović, uz zatvorsku kaznu, izrečena

je i petogodišnja zabrana obavljanja javne funkcije, tako da ona u tom periodu

ne može da bude sudija. Osim nje, osuđen je i njen suprug Miroljub Stojanović na

četiri i po godine zatvora jer je bio posrednik u uzimanju mita.

/wp:paragraph -->

wp:paragraph -->

Presudu je izreklo veće Višeg suda u

Beogradu na čelu sa sudijom Zoranom Trajković. Ona nije pravosnažna, jer

osuđeni imaju pravo da se žale Apelacionom sudu u Beogradu.

/wp:paragraph -->

wp:paragraph -->

Stojanović je, kako je utvrđeno, kao sudija

u Osnovnom sudu u Lazarevcu uzela 2000 evra mita od Marinković Radiše kome je sudila

za krijumčarenje ljudi.

/wp:paragraph -->

wp:paragraph -->

Naime, sudijin suprug Miroljub pozvao je u

oktobru 2018. godine Marinkovića da dođe u njihovu porodičnu kuću. Tokom sastanka

sudija i suprug tražili su od Marinkovića 2000 evra. Sudija je obećala da će ga,

ukoliko joj preda ovaj iznos, osuditi na uslovnu, a ne zatvorsku kaznu.

/wp:paragraph -->

wp:paragraph -->

Marinković to nije učinio, pa ga je Stojanović

osudila na godinu i po dana zatvora.

/wp:paragraph -->

wp:paragraph -->

Bračni par Stojanović mu je, međutim, dao

još jednu šansu, piše u optužnici, s obzirom da sudija u to vreme još nije

napisala presudu i postupak nije bio gotov. Ponovo su tražili od Marinkovića 2000

evra, kako bi ga spasili zatvora.

/wp:paragraph -->

wp:paragraph -->

Sudija mu je objasnila da će napisati presudu

„na koju će ljudi da se krste“, odnosno da će da napravi grešku zbog koje će viši

sud da je ukine i da naloži novo suđenje. U ponovljenom postupku Stojanović će Marinkovića

da osudi na uslovnu kaznu, piše u optužnici.

/wp:paragraph -->

wp:paragraph -->

Ovaj put Marinković je pristao. Pre nego što

je predao mito, međutim, kontaktirao je svog advokata i protiv sudije i njenog

supruga podneo krivičnu prijavu, piše u optužnici. Potom je početkom novembra

2018. novac odneo do porodične kuće Stojanovića i u dvorištu ga predao Miroljubu.

/wp:paragraph -->

wp:paragraph -->

Istog dana policija je upala u kuću sudije i

njenog supruga i pronašla kovertu sa 2000 evra, piše u optužnici Tužilaštva za

organizovani kriminal.

/wp:paragraph -->

wp:paragraph -->

Stojanovići su uhapšeni, a potom i optuženi u

martu 2019. godine.

/wp:paragraph -->"' 6 | cleaned_input_text = Wordpress.handle_paragraph_tags input_text 7 | assert_match "wp:paragraph -->", input_text 8 | assert_no_match "wp:paragraph -->", cleaned_input_text 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | ruby "2.6.6" 4 | 5 | source "https://rubygems.org" 6 | 7 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 8 | gem "rails", "~>5" 9 | # Use SCSS for stylesheets 10 | gem "sass-rails" 11 | # Use Uglifier as compressor for JavaScript assets 12 | # gem "uglifier" 13 | # Use CoffeeScript for .coffee assets and views 14 | # gem "coffee-rails" 15 | # See https://github.com/rails/execjs#readme for more supported runtimes 16 | # gem 'therubyracer', platforms: :ruby 17 | 18 | # Use jquery as the JavaScript library 19 | # gem "jquery-rails" 20 | # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 21 | gem "turbolinks" 22 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 23 | gem "jbuilder" 24 | # bundle exec rake doc:rails generates the API under doc/api. 25 | gem "sdoc" 26 | 27 | # Filemagic to check content type of images or whatever we need 28 | gem "ruby-filemagic" 29 | 30 | # Postgres, for databases 31 | gem "pg" 32 | 33 | # Rake, because it's what Ruby and Rails uses for all automation. 34 | gem "rake" 35 | 36 | # Elasticsearch integration 37 | gem "dalli" 38 | 39 | # Figaro is used to insure that environment variables exist on boot instead of silently failing later 40 | gem "figaro" 41 | 42 | # Not sure 43 | gem "htmlentities" 44 | 45 | # For making HTTP calls 46 | gem "httparty" 47 | 48 | # Memcache is used for caching our requests and such 49 | gem "memcachier" 50 | 51 | # Binding for ImageMagick for manipulating images, resizing etc. 52 | gem "mini_magick" 53 | 54 | # Nokogiri is an XML/HTML parser used for cleaning up the html 55 | gem "nokogiri" 56 | 57 | # The server we use 58 | gem "puma" 59 | 60 | # Not sure 61 | gem "rails_12factor" 62 | 63 | # Not Sure 64 | gem "addressable" 65 | 66 | # Authentication gem to handle users 67 | gem "devise" 68 | 69 | # Unsure 70 | gem "rails-settings-cached", git: "https://github.com/huacnlee/rails-settings-cached", branch: "0.x" 71 | 72 | # Unsure 73 | gem "fcm" 74 | 75 | # Unsure. 76 | gem "rufus-scheduler" 77 | 78 | # Rubocop is used as a linter 79 | gem "rubocop", "~> 0.78.0", require: false 80 | # Use Rails's default rubocop rulse 81 | gem "rubocop-rails_config" 82 | 83 | # Use ActiveModel has_secure_password 84 | # gem 'bcrypt', '~> 3.1.7' 85 | 86 | # We're using modern Webpacker to handle our Javascript assets now 87 | gem "webpacker", "~> 5" 88 | 89 | # Sprockets for asset management 90 | gem "sprockets-rails" 91 | 92 | # JWT is used by SNWorks for authentication 93 | gem "jwt" 94 | 95 | # This is for a work around in SEOWorks to determine image size if it's not returned 96 | # If the bug for this is fixed, this can be removed 97 | gem "rmagick" 98 | 99 | # This allows us to schedule jobs to keep the caches hot specifically 100 | gem "clockwork" 101 | 102 | # Sidekiq is great for running background jobs 103 | gem "sidekiq" 104 | 105 | # Redis is good for caching, we're already using it for Sidekiq and Uniqush 106 | gem "redis" 107 | 108 | # Add error handling and monitoring 109 | gem "sentry-raven" 110 | 111 | group :development do 112 | # Access an IRB console on exception pages or by using <%= console %> in views 113 | gem "web-console" 114 | end 115 | 116 | group :development, :test do 117 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 118 | gem "byebug" 119 | 120 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 121 | gem "spring" 122 | 123 | # Allow connections for the webpack-dev-server 124 | gem "rack-cors", require: "rack/cors" 125 | 126 | end 127 | -------------------------------------------------------------------------------- /app/models/push_device.rb: -------------------------------------------------------------------------------- 1 | class PushDevice < ActiveRecord::Base 2 | module Status 3 | ACTIVE = 0 4 | DISABLED = 1 5 | SANDBOX = 2 6 | UNIQUSH = 3 7 | end 8 | 9 | module UniqushServiceType 10 | GCM = "fcm" 11 | FCM = "fcm" 12 | APNS = "apns" 13 | ANDROID = "fcm" 14 | IOS = "ios" 15 | end 16 | 17 | def self.service_name(platform, sandbox = false) 18 | service_name = PushDevice.push_id() 19 | 20 | if platform == "android" 21 | service_name += "-#{PushDevice::UniqushServiceType::ANDROID}" 22 | # All Android devices will use the same credentials, we seperate sandboxed later as a naming convention 23 | else 24 | service_name += "-#{PushDevice::UniqushServiceType::IOS}" 25 | # iOS has seperate protocols for sandbox and production 26 | service_name += "-sandbox" if sandbox == true 27 | end 28 | 29 | service_name 30 | end 31 | 32 | def self.push_id 33 | push_id = ENV["push_id"] 34 | if !push_id || push_id.length == 0 35 | push_id = "push_app" 36 | end 37 | 38 | push_id 39 | end 40 | 41 | # Subscribe a new device, sandbox is for testing 42 | def subscribe_to_push(sandbox = true) 43 | subscribe_unsubscribe_to_push false, sandbox 44 | end 45 | 46 | # Subscribe a new device, sandbox is for testing 47 | def unsubscribe_to_push(sandbox = true) 48 | # response_json = subscribe_unsubscribe_to_push true, sandbox 49 | # language = "" 50 | # dev_token = "" 51 | save! 52 | end 53 | 54 | # This performs the actual call to subscribe or unsubscribe 55 | private def subscribe_unsubscribe_to_push(unsubscribe, sandbox = true) 56 | # build up the service name based on the platform 57 | # This is set up in the ENV variables 58 | service_name = PushDevice.service_name platform, sandbox 59 | 60 | 61 | # Build up the options that Uniqush needs 62 | # Subscriber has their language attached to the end of it so we can seperate it out 63 | options = { "service": service_name, 64 | "subscriber": dev_id + "." + language, 65 | } 66 | 67 | # Uniqush expects Android to use the "regid", iOS use the "devtoken" 68 | # We store them both under the same field in the database, and seperate them here 69 | case platform 70 | when "android" 71 | options["regid"] = dev_token 72 | options["pushservicetype"] = PushDevice::UniqushServiceType::GCM 73 | # For Android, since there's not a built in sandbox, we just segregate it by naming convention 74 | options[:subscriber] += ".sandbox" if sandbox == true 75 | when "ios" 76 | options["devtoken"] = dev_token 77 | options["pushservicetype"] = PushDevice::UniqushServiceType::APNS 78 | end 79 | 80 | # Here we set the verb that's being used subscribe, or unsubscribe 81 | verb = unsubscribe == true ? "unsubscribe" : "subscribe" 82 | 83 | # Make the call to the Uniqush server 84 | logger.debug("#{unsubscribe == true ? "Unsubscribing" : "Subscribing"} to Uniqush with options: #{options}") 85 | response = HTTParty.post("http://uniqush:9898/#{verb}?#{options.to_query}", options) 86 | response_json = JSON.parse(response.body) 87 | 88 | logger.debug("*************************************") 89 | logger.debug("Device: #{self.inspect}") 90 | logger.debug("Uniqush response: #{response_json}") 91 | logger.debug("*************************************") 92 | 93 | # Parse through the message returned, building the JSON response 94 | if response_json["status"] == 1 95 | response = { status: "FAILURE", uniqush_message: response_json["details"]["errorMsg"], status_id: 1 } 96 | else 97 | response = { status: "SUCCESS", status_id: 0 } 98 | end 99 | 100 | # Add in the Uniqush raw data for debugging purposes. 101 | response[:uniqush_code] = response_json["details"]["code"] 102 | response[:uniqush_response] = response_json 103 | 104 | # Send it all back up the chain 105 | response 106 | end 107 | end 108 | -------------------------------------------------------------------------------- /maintence-scripts/setup-lets_encrypt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="${BASH_SOURCE%/*}" 3 | if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi 4 | . "$DIR/includes.sh" 5 | 6 | # I have no idea how to pass in variables to a bash function, figure that out. 7 | # This will just stub otherwise 8 | function check_host_resolution { 9 | echoc "Check that" 10 | echoc $host $YELLOW 11 | echoc "resolves properly..." 12 | curl -H $host 13 | #check that headers are 200, 404, 502 (maybe 500?) everything that's not 'did not resolve' 14 | } 15 | 16 | echoc "So I guess we're going to make your server secure with Lets Encrypt (good choice)...\n" $GREEN 17 | 18 | # Ask the email of the main user 19 | 20 | while true 21 | do 22 | echo -en "First, What is your email address? " 23 | read email 24 | if [[ "$OSTYPE" == "darwin"* ]]; then 25 | # MacOS uses BSD's grep, which doesn't have the -P flag 26 | if ! echo "$email" | grep -qiE "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$" ;then 27 | echoc "Sorry, I can't seem to parse your email becuase it's not a valid email address. Please try again." $RED 28 | else 29 | break 30 | fi 31 | else 32 | if ! echo "$email" | grep -qiP "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$" ;then 33 | echo "Sorry, I can't seem to parse your email becuase it's not a valid email address. Please try again." $RED 34 | else 35 | break 36 | fi 37 | fi 38 | done 39 | 40 | # Ask the name of the site 41 | 42 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 43 | echo "Next we're going to create the SSL certificates that will encrypt your server data." 44 | echo "This requires that your host name resolves to this server." 45 | echo "Please see the README.md if you need more info or you're not sure what that means.\n" 46 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 47 | 48 | while true 49 | do 50 | echo -en "What is the host name for this installation (e.g. testapp.pushapp.press)? " 51 | read host 52 | if [[ "$OSTYPE" == "darwin"* ]]; then 53 | if ! echo "$host" | egrep -qiE "^[A-z0-9-]*[\.]*[A-z0-9]+[\.][A-z]{2,}$" ;then 54 | echo "Sorry, I can't seem to parse your url because it's not a valid URL format. Please try again." $RED 55 | else 56 | break 57 | fi 58 | else 59 | if ! echo "$host" | grep -qiP "^[A-z0-9-]*[\.]*[A-z0-9]+[\.][A-z]{2,}$" ;then 60 | echoc "Sorry, I can't seem to parse your url because it's not a valid URL format. Please try again." $RED 61 | else 62 | break 63 | fi 64 | fi 65 | done 66 | 67 | # Write the .env file for the LetsEncrypt variables 68 | # This overwrites the current file 69 | 70 | # If there's no .env, create it. 71 | 72 | if basename "$PWD" | grep 'maintence-scripts' > /dev/null; then 73 | path='../.env' 74 | else 75 | path='./.env' 76 | fi 77 | 78 | if [ ! -f $path ]; then 79 | echoc "No .env file found, creating it." $YELLOW 80 | else 81 | echoc "Removing current .env file" $YELLOW 82 | rm $path 83 | fi 84 | 85 | touch $path 86 | 87 | # Write the .env file 88 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 89 | echoc "Creating .env file for $email and $host" $GREEN 90 | echoc "\n-------------------------------------------------------------------------------------------------------------\n" $LIGHT_BLUE 91 | 92 | cat <> $path 93 | ########################################################################################### 94 | # Environmental variables for LetsEncrypt and Push 95 | # 96 | # This file is automatically generated and is overwritten by maintence-scripts/setup.sh 97 | # Since that script will only usually be automatically written to once feel free to edit. 98 | ########################################################################################### 99 | 100 | LETSENCRYPT_EMAIL=$email 101 | LETSENCRYPT_DOMAINS=$host 102 | LETSENCRYPT_STAGING= 103 | RAILS_ENV=production 104 | EOT 105 | 106 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your email address has been successfully confirmed." 7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." 8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." 9 | failure: 10 | already_authenticated: "You are already signed in." 11 | inactive: "Your account is not activated yet." 12 | invalid: "Invalid %{authentication_keys} or password." 13 | locked: "Your account is locked." 14 | last_attempt: "You have one more attempt before your account is locked." 15 | not_found_in_database: "Invalid %{authentication_keys} or password." 16 | timeout: "Your session expired. Please sign in again to continue." 17 | unauthenticated: "You need to sign in or sign up before continuing." 18 | unconfirmed: "You have to confirm your email address before continuing." 19 | mailer: 20 | confirmation_instructions: 21 | subject: "Confirmation instructions" 22 | reset_password_instructions: 23 | subject: "Reset password instructions" 24 | unlock_instructions: 25 | subject: "Unlock instructions" 26 | password_change: 27 | subject: "Password Changed" 28 | omniauth_callbacks: 29 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 30 | success: "Successfully authenticated from %{kind} account." 31 | passwords: 32 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." 33 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." 34 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." 35 | updated: "Your password has been changed successfully. You are now signed in." 36 | updated_not_active: "Your password has been changed successfully." 37 | registrations: 38 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." 39 | signed_up: "Welcome! You have signed up successfully." 40 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 41 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 42 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." 43 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." 44 | updated: "Your account has been updated successfully." 45 | sessions: 46 | signed_in: "Signed in successfully." 47 | signed_out: "Signed out successfully." 48 | already_signed_out: "Signed out successfully." 49 | unlocks: 50 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." 51 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." 52 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 53 | errors: 54 | messages: 55 | already_confirmed: "was already confirmed, please try signing in" 56 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 57 | expired: "has expired, please request a new one" 58 | not_found: "not found" 59 | not_locked: "was not locked" 60 | not_saved: 61 | one: "1 error prohibited this %{resource} from being saved:" 62 | other: "%{count} errors prohibited this %{resource} from being saved:" 63 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like 20 | # NGINX, varnish or squid. 21 | # config.action_dispatch.rack_cache = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.serve_static_files = ENV["RAILS_SERVE_STATIC_FILES"].present? 26 | 27 | # Compress JavaScripts and CSS. 28 | # config.assets.js_compressor = :uglifier 29 | # config.assets.css_compressor = :sass 30 | 31 | # Do not fallback to assets pipeline if a precompiled asset is missed. 32 | config.assets.compile = false 33 | 34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 35 | # yet still be able to expire them through the digest params. 36 | config.assets.digest = true 37 | 38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 39 | 40 | # Specifies the header that your server uses for sending files. 41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 43 | 44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 45 | # config.force_ssl = true 46 | 47 | # Prepend all log lines with the following tags. 48 | # config.log_tags = [ :subdomain, :uuid ] 49 | 50 | # Use a different logger for distributed setups. 51 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 52 | 53 | # Use a different cache store in production. 54 | # config.cache_store = :mem_cache_store 55 | 56 | if ENV["REDIS_URL"] 57 | config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"] } 58 | else 59 | config.cache_store = :memory_store 60 | end 61 | 62 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 63 | # config.action_controller.asset_host = 'http://assets.example.com' 64 | 65 | # Ignore bad email addresses and do not raise email delivery errors. 66 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 67 | # config.action_mailer.raise_delivery_errors = false 68 | 69 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 70 | # the I18n.default_locale when a translation cannot be found). 71 | config.i18n.fallbacks = true 72 | 73 | # Send deprecation notices to registered listeners. 74 | config.active_support.deprecation = :notify 75 | 76 | # Use default logging formatter so that PID and timestamp are not suppressed. 77 | # config.log_formatter = ::Logger::Formatter.new 78 | config.logger = ActiveSupport::Logger.new(config.paths["log"].first, 100, 104857600) 79 | # Use the lowest log level to ensure availability of diagnostic information 80 | # when problems arise. 81 | config.log_level = :debug 82 | 83 | # Do not dump schema after migrations. 84 | config.active_record.dump_schema_after_migration = false 85 | 86 | # For testing purposes we probably want to disable FORCE_SSL, but let's make it explicit 87 | # Set `FORCE_SSL` in the docker-compose `web` section to override 88 | # config.force_ssl = ENV["FORCE_SSL"].nil? ? true : ENV["FORCE_SSL"] 89 | config.force_ssl = false 90 | 91 | # Active job is used for caches, we'll use Sidekiq, since we already have Redis setup 92 | config.active_job.queue_adapter = :sidekiq 93 | end 94 | -------------------------------------------------------------------------------- /docker-compose-no-nginx-dev.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | # This configuration excludes NGINX for development purposes so you don't accidently run a full 5 | # web server on your own machine and accidently screw up your ports or what have you. 6 | # 7 | # If you're running in production and don't need NGINX (for instance, if you're on a multi-Docker setup) 8 | # then use `docker-compose-no-ngix.yml`. Otherwise, you probably want `docker-compose-with-nginx.yml` 9 | 10 | db: 11 | image: postgres:12-alpine 12 | volumes: 13 | - "postgres:/data/postgres" 14 | environment: 15 | - POSTGRES_USER=postgres 16 | - POSTGRES_PASSWORD=postgres 17 | - PGDATA=/data/postgres 18 | 19 | web: 20 | build: . 21 | command: bundle exec rails s -p 3000 -b '0.0.0.0' 22 | volumes: 23 | - ".:/push:cached" 24 | # - "rails_cache:/app/tmp/cache" 25 | # - "node_modules:/app/node_modules" 26 | # - "packs:/app/public/packs" 27 | expose: 28 | - "3000" 29 | ports: 30 | - "3000:3000" 31 | depends_on: 32 | - db 33 | - uniqush 34 | - redis 35 | # - sidekiq 36 | # - scheduled_jobs 37 | env_file: 38 | - ./secrets.env 39 | environment: 40 | - RAILS_ENV=development 41 | - proxy_images=true 42 | - FORCE_SSL=false 43 | - REDIS_URL=redis://redis:6379/0 44 | entrypoint: /push/entrypoint.sh 45 | tty: true 46 | stdin_open: true 47 | networks: 48 | - default 49 | 50 | # Since this is the dev setup this starts the webpack-dev-server. It shouldn't be in any of the 51 | # production configurations. 52 | webpack: 53 | build: . 54 | command: bin/webpack-dev-server 55 | volumes: 56 | - ".:/push:cached" 57 | ports: 58 | - "3035:3035" 59 | expose: 60 | - "3035" 61 | env_file: 62 | - ./secrets.env 63 | environment: 64 | - RAILS_ENV=development # This should always be development for this config, even if web is set to production. 65 | - proxy_images=true 66 | - WEBPACKER_DEV_SERVER_HOST=0.0.0.0 67 | tty: true 68 | stdin_open: true 69 | entrypoint: /push/entrypoint_webpacker.sh 70 | networks: 71 | - default 72 | 73 | # Run ActiveJobs on a schedule using the Clockwork gem 74 | # scheduled_jobs: 75 | # build: . 76 | # command: bundle exec clockwork ./scheduler.rb 77 | # volumes: 78 | # - ".:/push:cached" 79 | # env_file: 80 | # - ./secrets.env 81 | # environment: 82 | # - RAILS_ENV=production 83 | # - proxy_images=true 84 | # - FORCE_SSL=false 85 | # - REDIS_URL=redis://redis:6379 86 | # depends_on: 87 | # - db 88 | # - redis 89 | # - sidekiq 90 | # entrypoint: /push/entrypoint_scheduled_jobs.sh 91 | # tty: true 92 | # stdin_open: true 93 | # networks: 94 | # - default 95 | 96 | # Uniqush is used for managing push notifications ourselves 97 | uniqush: 98 | build: https://github.com/PushOCCRP/docker-uniqush.git 99 | environment: 100 | # this is the default, but let's be explicit here 101 | UNIQUSH_DATABASE_HOST: "redis" 102 | UNIQUSH_LOGFILE: "/srv/logs/gurac/uniqush.log" 103 | UNIQUSH_LOGLEVEL: "verbose" 104 | UNIQUSH_GID: "60001" 105 | UNIQUSH_UID: "60001" 106 | ports: 107 | - "9898:9898" 108 | depends_on: 109 | - redis 110 | volumes: 111 | - "./secrets:/secrets" 112 | - "./log/uniqush/:/srv/logs/gurac/" 113 | 114 | # The Redis server. This is used for both Sidekiq and Uniqush 115 | redis: 116 | image: redis 117 | expose: 118 | - "6379" 119 | volumes: 120 | - "./.docker/redis:/data" 121 | command: ["redis-server", "--appendonly", "yes"] 122 | 123 | # Sidekiq is used for the ActiveJob backend 124 | # sidekiq: 125 | # build: . 126 | # command: bundle exec sidekiq -C config/sidekiq.yml 127 | # volumes: 128 | # - ".:/push:cached" 129 | # depends_on: 130 | # - db 131 | # - redis 132 | # env_file: 133 | # - ./secrets.env 134 | # environment: 135 | # - RAILS_ENV=production 136 | # - proxy_images=true 137 | # - FORCE_SSL=false 138 | # - REDIS_URL=redis://redis:6379/0 139 | # tty: true 140 | # stdin_open: true 141 | # entrypoint: /push/entrypoint_sidekiq.sh 142 | # networks: 143 | # - default 144 | 145 | volumes: 146 | rails_cache: 147 | node_modules: 148 | packs: 149 | postgres: 150 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 2020_04_17_030553) do 14 | 15 | # These are extensions that must be enabled in order to support this database 16 | enable_extension "plpgsql" 17 | 18 | create_table "consumer_events", id: :serial, force: :cascade do |t| 19 | t.integer "consumer_id", null: false 20 | t.integer "event_type_id", null: false 21 | t.integer "article_id" 22 | t.integer "notification_id" 23 | t.string "language" 24 | t.string "search_phrase" 25 | t.integer "length" 26 | t.datetime "created_at", null: false 27 | t.datetime "updated_at", null: false 28 | t.index ["article_id"], name: "index_consumer_events_on_article_id" 29 | t.index ["consumer_id"], name: "index_consumer_events_on_consumer_id" 30 | t.index ["event_type_id"], name: "index_consumer_events_on_event_type_id" 31 | t.index ["notification_id"], name: "index_consumer_events_on_notification_id" 32 | end 33 | 34 | create_table "consumers", id: :serial, force: :cascade do |t| 35 | t.string "uuid", null: false 36 | t.datetime "last_seen", null: false 37 | t.integer "times_seen", default: 0, null: false 38 | t.datetime "created_at", null: false 39 | t.datetime "updated_at", null: false 40 | t.index ["uuid"], name: "index_consumers_on_uuid", unique: true 41 | end 42 | 43 | create_table "notifications", id: :serial, force: :cascade do |t| 44 | t.text "message" 45 | t.string "language" 46 | t.integer "reach" 47 | t.datetime "created_at", null: false 48 | t.datetime "updated_at", null: false 49 | t.date "push_time" 50 | t.string "article_id" 51 | t.string "headline" 52 | end 53 | 54 | create_table "push_devices", id: :serial, force: :cascade do |t| 55 | t.string "dev_token" 56 | t.string "dev_id" 57 | t.string "language" 58 | t.string "platform" 59 | t.datetime "created_at", null: false 60 | t.datetime "updated_at", null: false 61 | t.integer "status", default: 0, null: false 62 | end 63 | 64 | create_table "settings", id: :serial, force: :cascade do |t| 65 | t.string "var", null: false 66 | t.text "value" 67 | t.integer "thing_id" 68 | t.string "thing_type", limit: 30 69 | t.datetime "created_at" 70 | t.datetime "updated_at" 71 | t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true 72 | end 73 | 74 | create_table "sn_works_ceos", force: :cascade do |t| 75 | t.datetime "created_at", null: false 76 | t.datetime "updated_at", null: false 77 | end 78 | 79 | create_table "subscription_users", force: :cascade do |t| 80 | t.string "username", null: false 81 | t.string "api_key" 82 | t.datetime "created_at", null: false 83 | t.datetime "updated_at", null: false 84 | end 85 | 86 | create_table "users", id: :serial, force: :cascade do |t| 87 | t.string "email", default: "", null: false 88 | t.string "encrypted_password", default: "", null: false 89 | t.string "reset_password_token" 90 | t.datetime "reset_password_sent_at" 91 | t.datetime "remember_created_at" 92 | t.integer "sign_in_count", default: 0, null: false 93 | t.datetime "current_sign_in_at" 94 | t.datetime "last_sign_in_at" 95 | t.inet "current_sign_in_ip" 96 | t.inet "last_sign_in_ip" 97 | t.datetime "created_at", null: false 98 | t.datetime "updated_at", null: false 99 | t.integer "{:index=>true, :foreign_key=>true}_id" 100 | t.string "confirmation_token" 101 | t.datetime "confirmed_at" 102 | t.datetime "confirmation_sent_at" 103 | t.string "unconfirmed_email" 104 | t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true 105 | t.index ["email"], name: "index_users_on_email", unique: true 106 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 107 | t.index ["{:index=>true, :foreign_key=>true}_id"], name: "index_users_on_{:index=>true, :foreign_key=>true}_id" 108 | end 109 | 110 | end 111 | -------------------------------------------------------------------------------- /app/views/preferences/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 |
9 | <% if(!@categories.nil?) %> 10 | <%= form_tag({action: :update}, method: :put) do %> 11 | <% @categories.keys.each do |language| %> 12 |
13 |

<%= language %>

14 |
15 |
16 | 17 | <% categories = @categories[language] %> 18 | <% selected_categories = @selected_categories[language].nil? ? nil : @selected_categories[language][0] %> 19 | <%= select_tag "category[#{language}][]", options_for_select(categories, selected_categories), {include_blank: true, class: "form-control"} %> 20 |
21 |
22 |
23 | 24 | <% category_names = @category_names[language].nil? ? nil : @category_names[language][0] %> 25 | <%= text_field_tag "category_name[#{language}][]", category_names, {class: "form-control"} %> 26 |
27 |
28 |
29 |
30 |
31 | 32 | <% selected_category = @selected_categories[language].nil? ? nil : @selected_categories[language][1] %> 33 | <%= select_tag "category[#{language}][]", options_for_select(categories, selected_category), {include_blank: true, class: "form-control"} %> 34 | 35 |
36 |
37 |
38 | 39 | <% category_names = @category_names[language].nil? ? nil : @category_names[language][1] %> 40 | <%= text_field_tag "category_name[#{language}][]",category_names, {class: "form-control"} %> 41 |
42 |
43 |
44 |
45 |
46 | 47 | <% selected_category = @selected_categories[language].nil? ? nil : @selected_categories[language][2] %> 48 | <%= select_tag "category[#{language}][]", options_for_select(categories, selected_category), {include_blank: true, class: "form-control"} %> 49 | 50 |
51 |
52 |
53 | 54 | <% category_names = @category_names[language].nil? ? nil : @category_names[language][2] %> 55 | <%= text_field_tag "category_name[#{language}][]",category_names, {class: "form-control"} %> 56 |
57 |
58 |
59 |
60 |
61 | 62 | <% selected_category = @selected_categories[language].nil? ? nil : @selected_categories[language][3] %> 63 | <%= select_tag "category[#{language}][]", options_for_select(categories, selected_category), {include_blank: true, class: "form-control"} %> 64 | 65 |
66 |
67 |
68 | 69 | <% category_names = @category_names[language].nil? ? nil : @category_names[language][3] %> 70 | <%= text_field_tag "category_name[#{language}][]",category_names, {class: "form-control"} %> 71 |
72 |
73 | <% end %> 74 | 75 |
76 |
77 | 78 | <%= check_box_tag 'show_most_recent', "1", !@show_most_recent.nil?, {class: "form-control"} %> 79 |
80 |
81 | 82 |
83 |
84 | 85 | <%= check_box_tag 'consolidated', "1", !@consolidated.nil?, {class: "form-control"} %> 86 |
87 |
88 | 89 |
90 |
91 | <%= submit_tag "Save Categories", {class: "btn btn-primary"} %> 92 |
93 |
94 | <% end %> 95 | <% end %> 96 |
97 |
98 | -------------------------------------------------------------------------------- /data/appendonly.aof: -------------------------------------------------------------------------------- 1 | *2 2 | $6 3 | SELECT 4 | $1 5 | 0 6 | *3 7 | $3 8 | SET 9 | $67 10 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 11 | $176 12 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 13 | *3 14 | $4 15 | SADD 16 | $11 17 | services{0} 18 | $20 19 | push_app-ios-sandbox 20 | *3 21 | $4 22 | SADD 23 | $30 24 | srv-2-psp:push_app-ios-sandbox 25 | $45 26 | apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 27 | *3 28 | $3 29 | SET 30 | $67 31 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 32 | $176 33 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 34 | *3 35 | $3 36 | SET 37 | $67 38 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 39 | $176 40 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 41 | *2 42 | $6 43 | SELECT 44 | $1 45 | 0 46 | *3 47 | $3 48 | SET 49 | $67 50 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 51 | $176 52 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 53 | *3 54 | $3 55 | SET 56 | $67 57 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 58 | $176 59 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 60 | *3 61 | $3 62 | SET 63 | $67 64 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 65 | $176 66 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 67 | *3 68 | $3 69 | SET 70 | $67 71 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 72 | $176 73 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 74 | *3 75 | $3 76 | SET 77 | $67 78 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 79 | $176 80 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 81 | *3 82 | $3 83 | SET 84 | $67 85 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 86 | $176 87 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 88 | *3 89 | $3 90 | SET 91 | $67 92 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 93 | $176 94 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 95 | *3 96 | $3 97 | SET 98 | $67 99 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 100 | $176 101 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 102 | *2 103 | $6 104 | SELECT 105 | $1 106 | 0 107 | *3 108 | $3 109 | SET 110 | $67 111 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 112 | $176 113 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 114 | *2 115 | $6 116 | SELECT 117 | $1 118 | 0 119 | *3 120 | $3 121 | SET 122 | $60 123 | delivery.point:apns:6bac28e93b315e4ffbcd58195ec665a0801949f0 124 | $177 125 | apns:[{"devtoken":"32E51D1DF410AE668723FC16013FFEF53FD6664841F97F5F92D08FBC147693F0","service":"push_app-ios-sandbox","subscriber":"8464F0BA-DE14-47DC-9945-39447DBE828D.en"},{}] 126 | *3 127 | $4 128 | SADD 129 | $73 130 | srv.sub-2-dp:push_app-ios-sandbox:8464F0BA-DE14-47DC-9945-39447DBE828D.en 131 | $45 132 | apns:6bac28e93b315e4ffbcd58195ec665a0801949f0 133 | *2 134 | $4 135 | INCR 136 | $68 137 | delivery.point.counter:apns:6bac28e93b315e4ffbcd58195ec665a0801949f0 138 | *3 139 | $3 140 | SET 141 | $79 142 | srv.dp-2-psp:push_app-ios-sandbox:apns:6bac28e93b315e4ffbcd58195ec665a0801949f0 143 | $45 144 | apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 145 | *3 146 | $3 147 | SET 148 | $67 149 | push.service.provider:apns:64788c990cfb2f1a72c4ddf53b0e4b409c931e30 150 | $176 151 | apns:[{"cert":"secrets/certs/push_app-sandbox-cert.pem","key":"secrets/certs/push_app-sandbox-key.pem","service":"push_app-ios-sandbox"},{"addr":"gateway.push.apple.com:2195"}] 152 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= ENV["title"] %> Push Backend 5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 6 | <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 82 | 83 |
84 | 85 | <% if notice || alert %> 86 |
87 |
88 | <% if notice %> 89 |
<%= content_tag :div, "Success: #{notice}".html_safe %>
90 | <% end %> 91 | 92 | <% if alert %> 93 |
<%= content_tag :div, "Error: #{alert}".html_safe %>
94 | <% end %> 95 |
96 |
97 | <% end %> 98 | 99 | <%= yield %> 100 | 101 | 102 | --------------------------------------------------------------------------------