New domain Web (rails engine) with the following features extracted from the main app:

- cookies banner
- cookies policy page
- cookies policy and privacy policy links in the footer
This commit is contained in:
luisramos0
2018-08-07 15:25:47 +01:00
parent ce7be68fac
commit d170a4d489
32 changed files with 157 additions and 63 deletions

View File

@@ -16,6 +16,8 @@ AllCops:
- !ruby/regexp /old_and_unused\.rb$/
# The parser gem fails to parse this file with out current Ruby version.
- 'spec/factories.rb'
# Excluding: inadequate Naming/FileName rule rejects GemFile name with camelcase
- 'engines/web/Gemfile'
# OFN SETTINGS
# Cop settings that have been agreed upon by the OFN community

View File

@@ -10,6 +10,8 @@ gem 'i18n-js', '~> 3.0.0'
# Patched version. See http://rubysec.com/advisories/CVE-2015-5312/.
gem 'nokogiri', '>= 1.6.7.1'
gem 'web', path: './engines/web'
gem 'pg'
gem 'spree', github: 'openfoodfoundation/spree', branch: 'step-6a', ref: '69db1c090f3711088d84b524f1b94d25e6d21616'
gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable'

View File

@@ -133,6 +133,11 @@ GIT
activemodel (>= 3.0)
railties (>= 3.0)
PATH
remote: engines/web
specs:
web (0.0.1)
GEM
remote: https://rubygems.org/
specs:
@@ -767,6 +772,7 @@ DEPENDENCIES
capybara (>= 2.15.4)
coffee-rails (~> 3.2.1)
compass-rails
web!
custom_error_message!
daemons
dalli

View File

@@ -1,26 +0,0 @@
module Api
class CookiesConsentController < BaseController
include ActionController::Cookies
respond_to :json
def show
render json: { cookies_consent: cookies_consent.exists? }
end
def create
cookies_consent.set
show
end
def destroy
cookies_consent.destroy
show
end
private
def cookies_consent
@cookies_consent ||= CookiesConsent.new(cookies, request.host)
end
end
end

View File

@@ -1,29 +0,0 @@
class CookiesConsent
COOKIE_NAME = 'cookies_consent'.freeze
def initialize(cookies, domain)
@cookies = cookies
@domain = domain
end
def exists?
cookies.key?(COOKIE_NAME)
end
def destroy
cookies.delete(COOKIE_NAME, domain: domain)
end
def set
cookies[COOKIE_NAME] = {
value: COOKIE_NAME,
expires: 1.year.from_now,
domain: domain,
httponly: true
}
end
private
attr_reader :cookies, :domain
end

View File

@@ -19,6 +19,8 @@
%script{src: "//maps.googleapis.com/maps/api/js?libraries=places,geometry#{ ENV['GOOGLE_MAPS_API_KEY'] ? '&key=' + ENV['GOOGLE_MAPS_API_KEY'] : ''} "}
= stylesheet_link_tag "darkswarm/all"
= javascript_include_tag "darkswarm/all"
= stylesheet_link_tag "web/all"
= javascript_include_tag "web/all"
= render "layouts/i18n_script"
= render "layouts/bugherd_script"

View File

@@ -140,7 +140,7 @@
= t '.footer_legal_text_html', {content_license: link_to('CC BY-SA 3.0', 'https://creativecommons.org/licenses/by-sa/3.0/'), code_license: link_to('AGPL 3', 'https://tldrlegal.com/license/gnu-affero-general-public-license-v3-(agpl-3.0)' )}
%p.text-small
%div
- cookies_policy_link = link_to( t( '.footer_data_cookies_policy' ), '', 'cookies-policy-modal' => true, 'cookies-banner' => !CookiesConsent.new(cookies, request.host).exists? && Spree::Config.cookies_consent_banner_toggle)
- cookies_policy_link = link_to( t( '.footer_data_cookies_policy' ), '', 'cookies-policy-modal' => true, 'cookies-banner' => !Web::CookiesConsent.new(cookies, request.host).exists? && Spree::Config.cookies_consent_banner_toggle)
- privacy_policy_link = link_to( t( '.footer_data_privacy_policy' ), Spree::Config.privacy_policy_url, :target => '_blank' )
- if Spree::Config.privacy_policy_url.present?
= t '.footer_data_text_with_privacy_policy_html', {cookies_policy: cookies_policy_link.html_safe, privacy_policy: privacy_policy_link.html_safe }

View File

@@ -109,10 +109,6 @@ Openfoodnetwork::Application.routes.draw do
get :job_queue
end
scope '/cookies' do
resource :consent, only: [:show, :create, :destroy], :controller => "cookies_consent"
end
resources :customers, only: [:index, :update]
post '/product_images/:product_id', to: 'product_images#update_product_image'
@@ -120,6 +116,9 @@ Openfoodnetwork::Application.routes.draw do
get 'sitemap.xml', to: 'sitemap#index', defaults: { format: 'xml' }
# Mount Web engine routes
mount Web::Engine, :at => '/'
# Mount Spree's routes
mount Spree::Core::Engine, :at => '/'
end

5
engines/web/README.md Normal file
View File

@@ -0,0 +1,5 @@
# Web
This is the rails engine for the Web domain.
See our wiki for [more info about domains and engines in OFN](https://github.com/openfoodfoundation/openfoodnetwork/wiki/Tech-Doc:-How-OFN-is-organized-in-Domains-using-Rails-Engines).

View File

@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require_tree .

View File

@@ -4,7 +4,7 @@ Darkswarm.factory "CookiesBannerService", (Navigation, $modal, $location, Redire
modalMessage: null
isEnabled: false
open: (path, template = 'darkswarm/cookies_banner/cookies_banner.html') =>
open: (path, template = 'angular-templates/cookies_banner.html') =>
return unless @isEnabled
@modalInstance = $modal.open
templateUrl: template

View File

@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@@ -0,0 +1,13 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/

View File

@@ -1,4 +1,4 @@
@import '../branding';
@import '../../../../../../../app/assets/stylesheets/darkswarm/branding';
.cookies-banner {
background: $dark-grey;

View File

@@ -1,4 +1,4 @@
@import '../branding';
@import '../../../../../../../app/assets/stylesheets/darkswarm/branding';
.cookies-policy-modal {
background: $disabled-light;

View File

@@ -0,0 +1,30 @@
require_dependency 'web/cookies_consent'
module Web
module Api
class CookiesConsentController < BaseController
include ActionController::Cookies
respond_to :json
def show
render json: { cookies_consent: cookies_consent.exists? }
end
def create
cookies_consent.set
show
end
def destroy
cookies_consent.destroy
show
end
private
def cookies_consent
@cookies_consent ||= Web::CookiesConsent.new(cookies, request.host)
end
end
end
end

View File

@@ -0,0 +1,5 @@
module Web
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
end

View File

@@ -0,0 +1,7 @@
Web::Engine.routes.draw do
namespace :api do
scope '/cookies' do
resource :consent, only: [:show, :create, :destroy], controller: "cookies_consent"
end
end
end

4
engines/web/lib/web.rb Normal file
View File

@@ -0,0 +1,4 @@
require "web/engine"
module Web
end

View File

@@ -0,0 +1,31 @@
module Web
class CookiesConsent
COOKIE_NAME = 'cookies_consent'.freeze
def initialize(cookies, domain)
@cookies = cookies
@domain = domain
end
def exists?
cookies.key?(COOKIE_NAME)
end
def destroy
cookies.delete(COOKIE_NAME, domain: domain)
end
def set
cookies[COOKIE_NAME] = {
value: COOKIE_NAME,
expires: 1.year.from_now,
domain: domain,
httponly: true
}
end
private
attr_reader :cookies, :domain
end
end

View File

@@ -0,0 +1,4 @@
module Web
class Engine < ::Rails::Engine
end
end

View File

@@ -0,0 +1,3 @@
module Web
VERSION = "0.0.1".freeze
end

View File

@@ -0,0 +1,8 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path("dummy/config/environment.rb", __dir__)
require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

13
engines/web/web.gemspec Normal file
View File

@@ -0,0 +1,13 @@
$LOAD_PATH.push File.expand_path('lib', __dir__)
require "web/version"
Gem::Specification.new do |s|
s.name = "web"
s.version = Web::VERSION
s.authors = ["developers@ofn"]
s.summary = "Web domain of the OFN solution."
s.files = Dir["{app,config,db,lib}/**/*"] + ["LICENSE.txt", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
end