Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Release 0.2.0 (#9)
Browse files Browse the repository at this point in the history
Add delete feature to announcements
Add gpl3 license
Store user IP addresses for submitted quotes
Database migration for original PHP Rash -> Rash on Rails
Don't add unnecessary seeds in production
  • Loading branch information
bplunkert authored Jan 7, 2019
1 parent e180780 commit 72bd722
Show file tree
Hide file tree
Showing 15 changed files with 805 additions and 20 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ group :test do
gem 'chromedriver-helper'
end

group :legacy_migration, optional: true do
gem 'mysql2'
gem 'OptionParser'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
OptionParser (0.5.1)
actioncable (5.2.2)
actionpack (= 5.2.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -92,7 +93,7 @@ GEM
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (1.4.0)
i18n (1.5.1)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
jbuilder (2.8.0)
Expand Down Expand Up @@ -132,6 +133,7 @@ GEM
minitest (5.11.3)
msgpack (1.2.4)
multi_json (1.13.1)
mysql2 (0.5.2)
nio4r (2.3.1)
nokogiri (1.10.0)
mini_portile2 (~> 2.4.0)
Expand Down Expand Up @@ -240,6 +242,7 @@ PLATFORMS
ruby

DEPENDENCIES
OptionParser
bootsnap (>= 1.1.0)
bootstrap
byebug
Expand All @@ -251,6 +254,7 @@ DEPENDENCIES
jquery-rails
kaminari
listen (>= 3.0.5, < 3.2)
mysql2
pg
puma (~> 3.11)
rails (~> 5.2.0)
Expand Down
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
[![Build Status](https://travis-ci.org/bplunkert/rqdb.svg?branch=development)](https://travis-ci.org/bplunkert/rqdb)
[![Heroku Status](https://heroku-badge.herokuapp.com/?app=rqdb)](https://rqdb.herokuapp.com)


## Introduction:
Rash/Rails Quote Database is a simple web application for publishing, sharing, and ranking quotes. It's a ground-up rebuild of the [Rash Quote Management System (RQMS)](http://rqms.sourceforge.net), originally written in PHP by Tom Cuchta. RQDB is written in Ruby on Rails instead of PHP and does not share any common code with the original version.

Depedendencies:
## Installation
### Depedendencies:
Install [RVM](https://rvm.io) and Ruby 2.5.1:
* ```curl -sSL https://rvm.io/mpapis.asc | gpg --import -```
* ```curl -sSL https://get.rvm.io | bash -s stable --ruby=2.5.1```
Expand All @@ -14,14 +15,22 @@ Install bundled ruby gems:
* ```bundle install```
* Note: if bundle install fails due to postgres errors, you can safely skip this for development and testing by running: ```bundle install --without production```

Installation:
### Main Installation:
* ```bundle exec rake db:migrate```
* ```bundle exec rake db:seed```

Start the service:
### Migration from older PHP versions of Rash:
This step will connect to a legacy Rash MySQL database and copy all existing data into the Currently only Rash 2.0 Beta version is supported. A MySQL client will be required. The example installs into the production database but set RAILS_ENV and other options as needed.
* ```bundle install --with legacy_migration```
* ```RAILS_ENV=production bundle exec rake legacy:migrate_database --host SERVER --username USERNAME --database DATABASE --password PASSWORD```

For more options, you can pass the --help flag:
```bundle exec rake legacy:migrate_database --help```

### Start the service:
* ```bundle exec rails server```

Login:
### Login:
* Browse to http://localhost:3000
* Default username: admin@admin.admin
* Default password: password
* Default password: password
5 changes: 4 additions & 1 deletion app/controllers/quotes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def random1
# POST /quotes
# POST /quotes.json
def create
@quote = Quote.new(quote_params)
all_params = quote_params
all_params['submitterip'] = request.ip

@quote = Quote.new(all_params)

respond_to do |format|
if @quote.score != 0 or @quote.approved
Expand Down
3 changes: 2 additions & 1 deletion app/views/announcements/_show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<strong><%= announcement.created_at.strftime("%Y.%m.%d %H:%M:%S %Z") %></strong>
<strong><%= announcement.created_at.strftime("%Y.%m.%d %H:%M:%S %Z") %></strong> <% if user_signed_in? %><%= link_to 'Delete', announcement, method: :delete, data: { confirm: 'Are you sure you want to delete this announcement?' } %><% end %>

<pre>
<%= announcement.text %>
</pre>
4 changes: 3 additions & 1 deletion app/views/quotes/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<%= link_to 'Delete', quote, method: :delete, data: { confirm: 'Are you sure you want to delete this quote?' } %>
<% if quote.flagged == true -%>
<%= link_to 'Unflag', "/quotes/#{quote.id}/unflag", method: :get, data: { confirm: 'Are you sure you want to unflag this quote?' } %>
<% end %>
<% end %>
<% if quote.approved == false -%>
<%= link_to 'Approve', "/quotes/#{quote.id}/approve", method: :get, data: { confirm: 'Are you sure you want to approve this quote?' } %>
<% end %>
<br />
Submitter IP: <%= quote.submitterip %>
<% else -%>
<%= link_to '[X]', "/quotes/#{quote.id}/flag", method: :get, data: { confirm: 'Are you sure you want to flag this quote for review?' } %>
<% end -%>
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.

config.version = "0.1.2"
config.version = "0.2.0"
end
end
5 changes: 5 additions & 0 deletions db/migrate/20190107010750_add_submitterip_to_quotes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSubmitteripToQuotes < ActiveRecord::Migration[5.2]
def change
add_column :quotes, :submitterip, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_05_23_022941) do
ActiveRecord::Schema.define(version: 2019_01_07_010750) do

create_table "announcements", force: :cascade do |t|
t.string "text", null: false
Expand All @@ -25,6 +25,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "flagged"
t.string "submitterip"
end

create_table "searches", force: :cascade do |t|
Expand Down
17 changes: 9 additions & 8 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

Announcement.create(text: 'Hello!!!!! second announcement!!')
Announcement.create(text: 'Hello!!!!!!! First announcement!!!')

User.create!([
{email: 'admin@admin.admin', password: 'password'}
])

99.times do
Quote.create(approved: true, text: 'This quote has been approved. It is possibly awesome!')
Quote.create(approved: false, text: 'This quote has been submitted, but not yet reviewed for approval/deletion.')
Quote.create(approved: true, flagged: true, text: 'This quote has been approved, but it has been flagged for admin review.')
end
unless Rails.env == 'production'
Announcement.create(text: 'Hello!!!!! second announcement!!')
Announcement.create(text: 'Hello!!!!!!! First announcement!!!')

99.times do
Quote.create(approved: true, text: 'This quote has been approved. It is possibly awesome!')
Quote.create(approved: false, text: 'This quote has been submitted, but not yet reviewed for approval/deletion.')
Quote.create(approved: true, flagged: true, text: 'This quote has been approved, but it has been flagged for admin review.')
end
end
57 changes: 57 additions & 0 deletions lib/tasks/legacy.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace :legacy do
desc 'Migrate data from RQMS legacy (Beta 2.0) database and copy to current environment'
task migrate_database: :environment do
require 'mysql2'
require 'optparse'

options = {'tableprefix': 'rash'}

o = OptionParser.new do |opts|
opts.banner = 'Usage: rake legacy:migrate_database [options]'
opts.on('-h HOST', '--host HOST') { |host| options['host'] = host }
opts.on('-s SOCKET', '--socket SOCKET') { |socket| options['socket'] = socket }
opts.on('-d DATABASE', '--database DATABASE') { |database| options['database'] = database }
opts.on('-u USERNAME', '--username USERNAME') { |username| options['username'] = username }
opts.on('-p PASSWORD', '--password PASSWORD') { |password| options['password'] = password }
opts.on('-t TABLEPREFIX', '--tableprefix TABLEPREFIX') { |tableprefix| options['tableprefix'] = tableprefix }
opts.on_tail('--help', 'Show this message') do
puts opts
exit
end
end

args = o.order!(ARGV) {}
o.parse!(args)

legacy_mysql = Mysql2::Client.new({:host => options['host'], :username => options['username'], :database => options['database'], :password => options['password']})

legacy_news = legacy_mysql.query("SELECT * FROM #{options[:tableprefix]}_news")
legacy_queue = legacy_mysql.query("SELECT * FROM #{options[:tableprefix]}_queue")
legacy_quotes = legacy_mysql.query("SELECT * FROM #{options[:tableprefix]}_quotes")

legacy_news.each do |legacy_announcement|
puts "Migrating legacy announcement #{legacy_announcement['id']}"
announcement = Announcement.new(text: legacy_announcement['news'], created_at: Time.at(legacy_quote['date']))
announcement.save
end

legacy_queue.each do |legacy_quote|
puts "Migrating legacy queued quote #{legacy_quote['id']}"
quote = Quote.new(text: legacy_quote['quote'], created_at: Time.at(legacy_quote['date']))
quote.save
end

legacy_quotes.each do |legacy_quote|
puts "Migrating legacy quote #{legacy_quote['id']}"
is_flagged = case legacy_quote['flag']
when 1
true
else
false
end
quote = Quote.new(text: legacy_quote['quote'], score: legacy_quote['rating'], flagged: legacy_quote['flag'], approved: true, created_at: Time.at(legacy_quote['date']))
quote.save
end

end
end
4 changes: 4 additions & 0 deletions test/controllers/announcements_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest
end

test 'unauthenticated user should not destroy announcement' do
get '/'
assert_no_match /Delete/, response.parsed_body, 'Authenticated user is not seeing link to delete announcement'
assert_no_difference('Announcement.count') do
delete announcement_url(@announcement)
end
Expand All @@ -45,6 +47,8 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest

test 'authenticated user should destroy announcement' do
sign_in users(:one)
get '/'
assert_match /Delete/, response.parsed_body, 'Authenticated user is not seeing link to delete announcement'
assert_difference('Announcement.count', -1) do
delete announcement_url(@announcement)
end
Expand Down
17 changes: 17 additions & 0 deletions test/controllers/quotes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest
end
end

test 'should store user IP address when creating quote' do
post quotes_url, params: { quote: { text: 'this is a unique quote guaranteed not to be in any fixtures' } }
sign_in users(:one)
post search_url, params: { pattern: 'this is a unique quote guaranteed not to be in any fixtures' }
assert_match(/Submitter IP: 127\.0\.0\.1/, response.parsed_body)
end

test 'should show quote' do
get quote_url(@quote)
assert_response :success
Expand Down Expand Up @@ -97,4 +104,14 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to quote_url(@quote)
end

test 'unauthenticated user should not see submitter IPs for quotes' do
get quote_url(@quote)
assert_no_match(/Submitter IP:/, response.parsed_body)
end

test 'authenticated user should see submitter IPs for quotes' do
sign_in users(:one)
get quote_url(@quote)
assert_match(/Submitter IP: 255\.255\.255\.255/, response.parsed_body)
end
end
2 changes: 2 additions & 0 deletions test/fixtures/quotes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ one:
id: 1
text: MyString1
score: 5
submitterip: 255.255.255.255

two:
id: 2
text: MyString2
flagged: true
score: 0
submitterip: 255.255.255.255

0 comments on commit 72bd722

Please sign in to comment.