Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.0 #113

Merged
merged 48 commits into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9ed7285
[add]routes for rails api mode
ihatov08 Jul 25, 2017
734ef65
explicit letter class
shishi Mar 25, 2021
913c684
Begin the work on 2.0.0
fgrehm Oct 2, 2021
4cbba91
Update docs, changelog and license years
fgrehm Oct 2, 2021
66d7493
Modernize project and dummmy app for tests
fgrehm Oct 2, 2021
a231671
Fix tests
fgrehm Oct 2, 2021
ccb5de9
Upgrade rubocop and fix offenses
fgrehm Oct 2, 2021
6b02f8a
Moar rubocop stuff
fgrehm Oct 2, 2021
709b6fd
Add rexml gem into dependency
tricknotes Jan 1, 2021
a3596bd
Update changelog
fgrehm Oct 2, 2021
55f8b57
Major UI revamp, including bootstrap upgrade and better folder struct…
fgrehm Oct 6, 2021
88aa007
Merge branch 'explicit_letter' of github.com:shishi/letter_opener_web…
fgrehm Oct 6, 2021
57433f9
Add Rails' built-in CSRF protection
dee-see Oct 13, 2021
c535f35
Add Rails' CSP nonce to the script tag
dee-see Oct 13, 2021
b601109
Create brakeman-analysis.yml
fgrehm Oct 20, 2021
ed51f61
Remove travis configs
fgrehm Oct 20, 2021
086a0a0
Run tests in github actions
fgrehm Oct 20, 2021
76d88db
Fix ruby matrix on GH actions
fgrehm Oct 20, 2021
9546b79
Enable a bunch of new rubocops
fgrehm Oct 20, 2021
13565e3
Merge branch 'patch-1' of github.com:dee-see/letter_opener_web into next
fgrehm Oct 20, 2021
1a4a504
Merge branch 'patch-2' of github.com:dee-see/letter_opener_web into next
fgrehm Oct 20, 2021
2bb9982
Remove commented out code
fgrehm Oct 20, 2021
be45da5
Remove some padding from emails list on the sidebar
fgrehm Oct 20, 2021
c0a1a4c
Make refresh work when no emails have been sent yet
fgrehm Oct 20, 2021
5aba9a4
Merge branch 'add_routes_for_rails_api_mode' of github.com:ihatov08/l…
fgrehm Oct 20, 2021
1cd94cb
One way of doing things when it comes to routing
fgrehm Oct 20, 2021
4f05b27
Update CHANGELOG
fgrehm Oct 20, 2021
3801cc9
Update stub mail DOM structure
tricknotes Oct 20, 2021
70d1861
Fix headers for plain text
tricknotes Oct 20, 2021
dda7e55
Prefer reading header from rich style over plain one
tricknotes Oct 20, 2021
104bd2f
Run CI against next branch
tricknotes Oct 20, 2021
98165c8
Merge pull request #114 from tricknotes/correct-headers
fgrehm Oct 28, 2021
d8689f3
Merge branch 'master' of github.com:fgrehm/letter_opener_web into next
fgrehm Oct 28, 2021
871f49c
Release from GH actions, switch to alpha releases for now
fgrehm Oct 28, 2021
ba65ef1
Change readme build badge
fgrehm Oct 28, 2021
58d6353
Maybe adding inputs will do the trick here
fgrehm Oct 28, 2021
60739cb
Looks like this is the default for the repo already
fgrehm Oct 28, 2021
246c252
Switch to cutting releases based on tags
fgrehm Oct 28, 2021
c01c062
Bundler's release does more than we want
fgrehm Oct 28, 2021
31102c3
Gems are built to pkg/
fgrehm Oct 28, 2021
055c111
Fix PR number in CHANGELOG
tricknotes Oct 28, 2021
56bce37
Merge pull request #116 from tricknotes/fix-changelog
fgrehm Oct 28, 2021
3ab59e4
Simplest thing that could possibly work to bring back the ability to …
fgrehm Oct 30, 2021
3b4dc30
Skip protect_from_forgery if using rails api
fgrehm Nov 1, 2021
47b66eb
New beta release
fgrehm Nov 1, 2021
e2945af
Update README.md
fgrehm Nov 1, 2021
53640a8
Update CHANGELOG.md
fgrehm Nov 6, 2021
19955da
Bump version to 2.0.0 final
fgrehm Nov 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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