Skip to content

Commit

Permalink
Merge pull request #113 from fgrehm/next
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
fgrehm authored Nov 6, 2021
2 parents c19a7f4 + 19955da commit e277c97
Show file tree
Hide file tree
Showing 71 changed files with 824 additions and 1,081 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/brakeman-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow integrates Brakeman with GitHub's Code Scanning feature
# Brakeman is a static analysis security vulnerability scanner for Ruby on Rails applications

name: Brakeman Scan

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '21 4 * * 4'

jobs:
brakeman-scan:
name: Brakeman Scan
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2

# Customize the ruby version depending on your needs
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: '2.7'

- name: Setup Brakeman
env:
BRAKEMAN_VERSION: '4.10' # SARIF support is provided in Brakeman version 4.10+
run: |
gem install brakeman --version $BRAKEMAN_VERSION
# Execute Brakeman CLI and generate a SARIF output with the security issues identified during the analysis
- name: Scan
continue-on-error: true
run: |
brakeman -f sarif -o output.sarif.json .
# Upload the SARIF file generated in the previous step
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: output.sarif.json
34 changes: 34 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Run tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master, next ]

jobs:
test:

runs-on: ubuntu-latest

strategy:
matrix:
ruby-version: [2.7, 3.0]

steps:
- uses: actions/checkout@v2

- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Install dependencies
run: bundle install

- name: Run tests
run: bundle exec rake

- name: Build gem
run: bundle exec rake build
32 changes: 32 additions & 0 deletions .github/workflows/release-gem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release gem

on:
push:
tags:
- 'v*'

jobs:
build:
name: Build + Publish
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Ruby 3.0
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0

- run: bundle install

- name: Publish to RubyGems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
bundle exec rake build
gem push pkg/*.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
17 changes: 4 additions & 13 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
---
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.5
NewCops: enable
TargetRubyVersion: 2.7
Exclude:
- "spec/dummy/bin/**/*"
- "tmp/**/*"
- "vendor/**/*"

Layout/HeredocIndentation:
Enabled: false

Style/Documentation:
Enabled: false

Style/ClassAndModuleChildren:
EnforcedStyle: nested

Style/SingleLineBlockParams:
Enabled: false

Metrics/BlockLength:
Exclude:
- spec/**/*_spec.rb
Expand Down
19 changes: 19 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-10-02 14:42:36 UTC using RuboCop version 1.22.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 5
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'app/controllers/letter_opener_web/letters_controller.rb'
- 'app/models/letter_opener_web/letter.rb'
- 'lib/letter_opener_web.rb'
- 'lib/letter_opener_web/delivery_method.rb'
- 'lib/letter_opener_web/engine.rb'
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## [v2.0.0](https://github.com/fgrehm/letter_opener_web/compare/v1.4.1...v2.0.0)

- Require Rails >= 5.2, run tests against Rails 6.1 [#113](https://github.com/fgrehm/letter_opener_web/pull/113)
- Inline CSS and Javascript, to avoid dependency on asset pipeline [#113](https://github.com/fgrehm/letter_opener_web/pull/113)
- Upgrade to Bootstrap 5.1.1 [#113](https://github.com/fgrehm/letter_opener_web/pull/113)
- Add rexml gem into dependency for Ruby 3.0 [#106](https://github.com/fgrehm/letter_opener_web/pull/106)
- Add routes for Rails API mode [#69](https://github.com/fgrehm/letter_opener_web/pull/69)
- Prevent name conflict with `Letter` class [#108](https://github.com/fgrehm/letter_opener_web/pull/108)
- Add Rails' built-in CSRF protection [#111](https://github.com/fgrehm/letter_opener_web/pull/111)
- Add Rails' CSP nonce to the script tag [#112](https://github.com/fgrehm/letter_opener_web/pull/112)
- Update dev dependencies [#113](https://github.com/fgrehm/letter_opener_web/pull/113)
- Switched to using GitHub actions as CI for the project [#113](https://github.com/fgrehm/letter_opener_web/pull/113)

## [1.4.1](https://github.com/fgrehm/letter_opener_web/compare/v1.4.0...v1.4.1) (Oct 5, 2021)

- Ensure letter is within letters base path [#110](https://github.com/fgrehm/letter_opener_web/pull/110)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013-2018 Fabio Rehm
Copyright (c) 2013-2021 Fabio Rehm

MIT License

Expand Down
49 changes: 29 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# letter_opener_web

[![Build Status](https://travis-ci.org/fgrehm/letter_opener_web.svg?branch=master)](https://travis-ci.org/fgrehm/letter_opener_web)
![Build Status](https://github.com/fgrehm/letter_opener_web/actions/workflows/main.yml/badge.svg)
[![Gem Version](https://badge.fury.io/rb/letter_opener_web.svg)](http://badge.fury.io/rb/letter_opener_web)
[![Code Climate](https://codeclimate.com/github/fgrehm/letter_opener_web.svg)](https://codeclimate.com/github/fgrehm/letter_opener_web)

Expand All @@ -15,7 +15,7 @@ First add the gem to your development environment and run the `bundle` command t

```ruby
group :development do
gem 'letter_opener_web', '~> 1.0'
gem 'letter_opener_web', '~> 2.0'
end
```

Expand All @@ -33,8 +33,9 @@ And make sure you have [`:letter_opener` delivery method](https://github.com/rya
configured for your app. Then visit `http://localhost:3000/letter_opener` after
sending an email and have fun.

If you are running the app from a [Vagrant](http://vagrantup.com) machine, you
might want to skip `letter_opener`'s `launchy` calls and avoid messages like these:
If you are running the app from a [Vagrant](http://vagrantup.com) machine or Docker
container, you might want to skip `letter_opener`'s `launchy` calls and avoid messages
like these:

```terminal
12:33:42 web.1 | Failure in opening /vagrant/tmp/letter_opener/1358825621_ba83a22/rich.html
Expand All @@ -43,31 +44,31 @@ environment variable LAUNCHY_DEBUG=true or the '-d' commandline option and file
https://github.com/copiousfreetime/launchy/issues/new
```

In that case (or if you just want to browse mails using the web interface), you
can set `:letter_opener_web` as your delivery method on your
`config/environments/development.rb`:
In that case (or if you really just want to browse mails using the web interface and
don't care about opening emails automatically), you can set `:letter_opener_web` as
your delivery method on your `config/environments/development.rb`:

```ruby
config.action_mailer.delivery_method = :letter_opener_web

# If not everyone on the team is using vagrant
config.action_mailer.delivery_method = ENV['USER'] == 'vagrant' ? :letter_opener_web : :letter_opener
```

If you're using `:letter_opener_web` as your delivery method, you can change the location of the letters by adding the
following to an initializer (or in development.rb):
If you're using `:letter_opener_web` as your delivery method, you can change the location of
the letters by adding the following to an initializer (or in development.rb):

```ruby
LetterOpenerWeb.configure do |config|
config.letters_location = Rails.root.join('your', 'new', 'path')
end
```

## Usage on Heroku
## Usage on pre-production environments

Some people use this gem on staging / pre-production environments to avoid having real emails
being sent out. To set that up you'll need to:

Some people use this gem on staging environments on Heroku and to set that up
is just a matter of moving the gem out of the `development` group and enabling
the route for all environments on your `routes.rb`.
1. Move the gem out of the `development` group in your `Gemfile`
2. Set `config.action_mailer.delivery_method` on the appropriate `config/environments/<env>.rb`
3. Enable the route for the environments on your `routes.rb`.

In other words, your `Gemfile` will have:

Expand All @@ -79,20 +80,28 @@ And your `routes.rb`:

```ruby
Your::Application.routes.draw do
mount LetterOpenerWeb::Engine, at: "/letter_opener"
# If you have a dedicated config/environments/staging.rb
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.staging?

# If you use RAILS_ENV=production in staging environments, you'll need another
# way to disable it in "real production"
mount LetterOpenerWeb::Engine, at: "/letter_opener" unless ENV["PRODUCTION_FOR_REAL"]
end
```

You might also want to have a look at the sources for the [demo](http://letter-opener-web.herokuapp.com)
available at https://github.com/fgrehm/letter_opener_web_demo.

**NOTICE: Using this gem on Heroku will only work if your app has just one Dyno and does not send emails from background jobs. For updates on this matter please subscribe to [GH-35](https://github.com/fgrehm/letter_opener_web/issues/35)**
**NOTICE: Using this gem on Heroku will only work if your app has just one Dyno
and does not send emails from background jobs. For updates on this matter please
subscribe to [GH-35](https://github.com/fgrehm/letter_opener_web/issues/35)**

## Acknowledgements

Special thanks to [@alexrothenberg](https://github.com/alexrothenberg) for some
ideas on [this pull request](https://github.com/ryanb/letter_opener/pull/12).

ideas on [this pull request](https://github.com/ryanb/letter_opener/pull/12) and
[@pseudomuto](https://github.com/pseudomuto) for keeping the project alive for a
few years.

## Contributing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

module LetterOpenerWeb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception, unless: -> { Rails.configuration.try(:api_only) }
end
end
11 changes: 7 additions & 4 deletions app/controllers/letter_opener_web/letters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LettersController < ApplicationController
before_action :load_letter, only: %i[show attachment destroy]

def index
@letters = Letter.search
@letters = LetterOpenerWeb::Letter.search
end

def show
Expand All @@ -31,13 +31,16 @@ def attachment
end

def clear
Letter.destroy_all
LetterOpenerWeb::Letter.destroy_all
redirect_to routes.letters_path
end

def destroy
@letter.delete
redirect_to routes.letters_path
respond_to do |format|
format.html { redirect_to routes.letters_path }
format.js { render js: "window.location='#{routes.letters_path}'" }
end
end

private
Expand All @@ -47,7 +50,7 @@ def check_style
end

def load_letter
@letter = Letter.find(params[:id])
@letter = LetterOpenerWeb::Letter.find(params[:id])

head :not_found unless @letter.valid?
end
Expand Down
Loading

0 comments on commit e277c97

Please # to comment.