All Projects → piotrmurach → Rack Policy

piotrmurach / Rack Policy

Licence: mit
Rack middleware for the EU ePrivacy Directive compliance in Ruby Web Apps

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Rack Policy

Bugsnag Ruby
Bugsnag error monitoring & reporting software for rails, sinatra, rack and ruby
Stars: ✭ 211 (+41.61%)
Mutual labels:  rails, sinatra
Recaptcha
ReCaptcha helpers for ruby apps
Stars: ✭ 1,819 (+1120.81%)
Mutual labels:  rails, sinatra
Draftsman
Ruby gem that lets you create draft versions of your database records.
Stars: ✭ 159 (+6.71%)
Mutual labels:  rails, sinatra
Timber Ruby
🌲 Great Ruby logging made easy.
Stars: ✭ 154 (+3.36%)
Mutual labels:  rails, sinatra
Will paginate
Pagination library for Rails, Sinatra, Merb, DataMapper, and more
Stars: ✭ 5,621 (+3672.48%)
Mutual labels:  rails, sinatra
Config
Easiest way to add multi-environment yaml settings to Rails, Sinatra, Pandrino and other Ruby projects.
Stars: ✭ 1,821 (+1122.15%)
Mutual labels:  rails, sinatra
Rack Reducer
Declaratively filter data via URL params, in any Rack app, with any ORM.
Stars: ✭ 241 (+61.74%)
Mutual labels:  rails, sinatra
Pluck to hash
Extend ActiveRecord pluck to return array of hashes
Stars: ✭ 275 (+84.56%)
Mutual labels:  rails, sinatra
Dawnscanner
Dawn is a static analysis security scanner for ruby written web applications. It supports Sinatra, Padrino and Ruby on Rails frameworks.
Stars: ✭ 642 (+330.87%)
Mutual labels:  rails, sinatra
Pagy
🏆 The Best Pagination Ruby Gem 🥇
Stars: ✭ 3,340 (+2141.61%)
Mutual labels:  rails, sinatra
Daru View
daru-view is for easy and interactive plotting in web application & IRuby notebook. daru-view is a plugin gem to the existing daru gem.
Stars: ✭ 65 (-56.38%)
Mutual labels:  rails, sinatra
Simple Navigation
A ruby gem for creating navigations (with multiple levels) for your Rails, Sinatra or Padrino applications. Render your navigation as html list, link list or breadcrumbs.
Stars: ✭ 868 (+482.55%)
Mutual labels:  rails, sinatra
Redis dashboard
Sinatra app to monitor Redis servers.
Stars: ✭ 141 (-5.37%)
Mutual labels:  rails, sinatra
Stimulus reflex
Build reactive applications with the Rails tooling you already know and love.
Stars: ✭ 1,928 (+1193.96%)
Mutual labels:  rails
Rails api auth
Lightweight Rails Engine that implements the "Resource Owner Password Credentials Grant" OAuth 2.0 flow as well as Facebook authentication
Stars: ✭ 143 (-4.03%)
Mutual labels:  rails
I18n Debug
Ever wondered which translations are being looked up by Rails, a gem, or simply your app? Wonder no more!
Stars: ✭ 143 (-4.03%)
Mutual labels:  rails
Font awesome5 rails
font_awesome_5_rails is font awesome 5 gem bundled for rails asset pipeline
Stars: ✭ 148 (-0.67%)
Mutual labels:  rails
Doorkeeper Provider App
An example OAuth 2 provider application using the Doorkeeper gem, Rails and Devise
Stars: ✭ 146 (-2.01%)
Mutual labels:  rails
Rails admin theme
rails_admin theme flat theme
Stars: ✭ 142 (-4.7%)
Mutual labels:  rails
Dry Rails
The official dry-rb railtie
Stars: ✭ 142 (-4.7%)
Mutual labels:  rails

Rack-Policy

Gem Version Build Status Code Climate Dependency Status Coverage Status Inline docs

This is Rack middleware that makes your app compliant with the 'EU ePrivacy Directive' whereby a user needs to provide implied consent before any data can be stored on his machine.

Installation

Add this line to your application's Gemfile:

gem 'rack-policy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-policy

Usage

By default when the Rack application is loaded no cookies will be set(provided no session cookies already exist), and any existing session cookies will be destroyed. Throughout the request cycle cookies now won't be set until the user has given explicit consent. This can be controlled by setting consent token

Rack::Policy::CookieLimiter, consent_token: 'allow_me'

The very same consent_token is used to toggle the limiter behaviour.

The cookies_accepted? view helper method is automatically loaded for Rails, Sinatra & Padrino apps.

Examples

Adding Rack::Policy::CookieLimiter to Rack applications

Rails 3.x

# config/application.rb
require 'rack/policy'

class Application < Rails::Application
  config.middleware.insert_before ActionDispatch::Cookies, Rack::Policy::CookieLimiter, consent_token: 'rack.policy'
end

And then in your custom controller create actions responsible for setting and unsetting cookie policy

class CookiePolicyController < ApplicationController

  def allow
    response.set_cookie 'rack.policy', {
      value: 'true',
      path: '/',
      expires: 1.year.from_now.utc
    }
    render nothing: true
  end

  def deny
    response.delete_cookie 'rack.policy'
    render nothing: true
  end
end

Finally, in your view you can use helper method cookies_accepted? to display/toggle cookie information

<% cookies_accepted? do %>
  Accepted Cookies!
<% end %>

or

<% if cookies_accepted? %>
  Accepted Cookies!
<% else %>
  Cookies Not Accepted!
<% end %>

Rails 2.x

# config/environment

Rails::Initializer.run do |config|
  require 'rack/policy'
  config.middleware.insert_before Rack::Lock, Rack::Policy::CookieLimiter, consent_token: 'rack.policy'
end

Set and unset cookie consent in your controller and modify views logic in similar way to Rails 3.x example.

Sinatra

For classic style sinatra application do

#!/usr/bin/env ruby -rubygems
require 'sinatra'
require 'rack/policy'

configure do
  use Rack::Policy::CookieLimiter, consent_token: 'rack.policy'
end

get('/') { "Allow cookies to be set? <a href='/allow'>Allow</a>" }

get('/allow') { response.set_cookie 'rack.policy' }

get('/deny') { response.delete_cookie 'rack.policy' }

Similiar to Rails 3.x example you can use cookies_accpeted? helper to manage view logic related to cookie policy information.

Padrino

#!/usr/bin/env ruby -rubygems
require 'padrino'
require 'rack/policy'

class MyApp < Padrino::Application
  use Rack::Policy::CookieLimiter, consent_token: 'rack.policy'
end

Rackup

#!/usr/bin/env rackup
require 'rack/policy'

use Rack::Policy::CookieLimiter, consent_token: 'rack.policy'

run lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, world!\n"] }

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Copyright

Copyright (c) 2012-2016 Piotr Murach. See LICENSE for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].