From cac59e9de58d72380d814eda680b44742fb7c266 Mon Sep 17 00:00:00 2001
From: Will Bradley
Date: Sun, 2 Mar 2014 19:06:39 -0700
Subject: [PATCH] Finishing contracts, changing from s3.yml to .env
---
.gitignore | 1 +
Gemfile | 2 +
Gemfile.lock | 4 ++
README.rdoc | 6 ++-
app/controllers/contracts_controller.rb | 8 +++-
app/models/ability.rb | 3 +-
app/models/contract.rb | 7 ++--
app/models/resource.rb | 7 ++--
app/models/user.rb | 1 +
app/views/contracts/_form.html.erb | 27 +++++++------
app/views/contracts/edit.html.erb | 4 ++
app/views/contracts/index.html.erb | 38 +++++++++++++------
app/views/contracts/show.html.erb | 28 ++++++++++++++
app/views/resources/index.html.erb | 2 +-
app/views/users/show.html.erb | 8 +++-
config/s3.yml.example | 2 -
db/migrate/20140227095847_create_contracts.rb | 4 +-
db/schema.rb | 4 +-
env.example | 3 ++
19 files changed, 118 insertions(+), 41 deletions(-)
create mode 100644 app/views/contracts/edit.html.erb
create mode 100644 app/views/contracts/show.html.erb
delete mode 100755 config/s3.yml.example
create mode 100644 env.example
diff --git a/.gitignore b/.gitignore
index 0c6251b..ad40922 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,4 @@ tmp/
/config/s3.yml
/config/database.yml
/config/initializers/secret_token.rb
+.env
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index 2e9b84b..d1a9b27 100644
--- a/Gemfile
+++ b/Gemfile
@@ -4,6 +4,8 @@ ruby '1.9.3'
gem 'rails', '3.2.8'
+gem 'dotenv-rails', :groups => [:development, :test]
+
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
diff --git a/Gemfile.lock b/Gemfile.lock
index 68c7a92..e597316 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -53,6 +53,9 @@ GEM
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.2.1)
+ dotenv (0.10.0)
+ dotenv-rails (0.10.0)
+ dotenv (= 0.10.0)
erubis (2.7.0)
execjs (2.0.2)
gravtastic (3.2.6)
@@ -158,6 +161,7 @@ DEPENDENCIES
cancan
coffee-rails (~> 3.2.1)
devise
+ dotenv-rails
gravtastic
jquery-rails
json
diff --git a/README.rdoc b/README.rdoc
index e5d4882..99c1d84 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -5,16 +5,18 @@ via Ethernet ( see: https://github.com/zyphlar/Open_Access_Control_Ethernet )
https://github.com/zyphlar/Open-Source-Access-Control-Web-Interface
-Copyright Will Bradley, 2012-2013
+Copyright Will Bradley, 2012-2014
Distributed under a Creative Commons Attribution 3.0 license http://creativecommons.org/licenses/by/3.0/
+Contributions welcome! Simply send a pull request via Github.
+
To use:
* Install Imagemagick (for Paperclip / image uploads)
* Install arp-scan (for LAN Mac address scanning)
* Load into a Rails 3 environment
* Copy config/config.yml.example to config/config.yml and edit appropriately
* Copy config/database.yml.example to config/database.yml and edit appropriately
-* Copy config/s3.yml.example to config/s3.yml and edit appropriately OR adjust the resource.rb model settings to use different storage for picture attachments (via Paperclip)
+* Copy env.example to .env and edit appropriately for your Amazon S3 account OR adjust the resource.rb and contract.rb model settings to use different storage for picture attachments (via Paperclip)
* Copy config/initializers/secret_token.rb.example to config/config/initializers/secret_token.rb and edit appropriately
* See/edit db/seeds.rb for the initial admin account info.
* Run bundle install, rake db:migrate, rake db:seed, etc.
diff --git a/app/controllers/contracts_controller.rb b/app/controllers/contracts_controller.rb
index eb6a04c..fbb4905 100644
--- a/app/controllers/contracts_controller.rb
+++ b/app/controllers/contracts_controller.rb
@@ -1,6 +1,6 @@
class ContractsController < ApplicationController
load_and_authorize_resource :contract
- before_filter :authenticate_user!
+ before_filter :authenticate_user!, :load_users
layout 'resources'
def index
@@ -16,6 +16,8 @@ class ContractsController < ApplicationController
end
def create
+ Rails.logger.info "CONTRACT"
+ Rails.logger.info @contract.inspect
respond_to do |format|
if @contract.save
format.html { redirect_to Contract, :notice => 'Contract was successfully created.' }
@@ -47,4 +49,8 @@ class ContractsController < ApplicationController
format.json { head :no_content }
end
end
+
+ def load_users
+ @users = @users = User.accessible_by(current_ability).sort_by(&:name)
+ end
end
diff --git a/app/models/ability.rb b/app/models/ability.rb
index c47e640..55cfe63 100755
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -12,6 +12,7 @@ class Ability
# By default, users can only see their own stuff
can :read, Card, :user_id => user.id
can :read, Certification
+ can :read, Contract
can :read_details, Mac
can [:update], Mac, :user_id => nil
can [:create,:update], Mac, :user_id => user.id
@@ -54,7 +55,7 @@ class Ability
can :manage, :all
end
- # Prevent all destruction for now
+ # Prevent most destruction for now
#cannot :destroy, User
#cannot :destroy, Card
cannot :destroy, Certification
diff --git a/app/models/contract.rb b/app/models/contract.rb
index d7d58f4..3e5b357 100644
--- a/app/models/contract.rb
+++ b/app/models/contract.rb
@@ -1,12 +1,13 @@
class Contract < ActiveRecord::Base
belongs_to :user
- attr_accessible :user_id, :first_name, :last_name, :signed_at, :document_file_name, :document_content_type, :document_file_size, :document_updated_at
+ attr_accessible :user_id, :first_name, :last_name, :signed_at, :document, :document_file_name, :document_content_type, :document_file_size, :document_updated_at
validates_presence_of :first_name, :last_name, :signed_at
has_attached_file :document, { :styles => { :medium => "300x300>"},
:storage => :s3,
- :s3_credentials => Rails.root.join('config', 's3.yml'),
+ :s3_credentials => { :access_key_id => ENV['S3_KEY'],
+ :secret_access_key => ENV['S3_SECRET'] },
:path => ":attachment/:id/:style.:extension",
- :bucket => 'Toolshare' } #TODO: move to local storage
+ :bucket => ENV['S3_BUCKET'] }
end
diff --git a/app/models/resource.rb b/app/models/resource.rb
index 43448e1..854a75d 100755
--- a/app/models/resource.rb
+++ b/app/models/resource.rb
@@ -14,11 +14,12 @@ class Resource < ActiveRecord::Base
:thumb => "100x100>",
:tiny => "50x50>"},
:storage => :s3,
- :s3_credentials => Rails.root.join('config', 's3.yml'),
+ :s3_credentials => { :access_key_id => ENV['S3_KEY'],
+ :secret_access_key => ENV['S3_SECRET'] },
:path => ":attachment/:id/:style.:extension",
- :bucket => 'Toolshare' }
+ :bucket => ENV['S3_BUCKET'] }
- has_attached_file :picture, PICTURE_OPTIONS #TODO: move to local storage
+ has_attached_file :picture, PICTURE_OPTIONS
has_attached_file :picture2, PICTURE_OPTIONS
has_attached_file :picture3, PICTURE_OPTIONS
has_attached_file :picture4, PICTURE_OPTIONS
diff --git a/app/models/user.rb b/app/models/user.rb
index 0b4390b..ecfa34d 100755
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -14,6 +14,7 @@ class User < ActiveRecord::Base
has_many :cards
has_many :user_certifications
has_many :certifications, :through => :user_certifications
+ has_many :contracts
has_many :payments
has_many :macs
has_many :resources
diff --git a/app/views/contracts/_form.html.erb b/app/views/contracts/_form.html.erb
index e4a6f79..067737b 100644
--- a/app/views/contracts/_form.html.erb
+++ b/app/views/contracts/_form.html.erb
@@ -11,26 +11,31 @@
<% end %>
-
+
+
<%= f.label :last_name %>
<%= f.text_field :last_name, class: "form-control" %>
-
+
-
+
+ <%= f.label :user_id, "User" %>
+ <%= collection_select(:contract, :user_id, @users, :id, :name, :include_blank => true) %>
+
+
+
<%= f.label :signed_at %>
- <%= f.date_select :signed_at, class: "form-control" %>
-
+ <%= f.date_select :signed_at %>
+
-
+
<%= f.label :document %>
<%= f.file_field :document %>
-
+
-
+
<%= f.submit nil, class: "btn btn-primary" %>
-
+
<% end %>
diff --git a/app/views/contracts/edit.html.erb b/app/views/contracts/edit.html.erb
new file mode 100644
index 0000000..428c915
--- /dev/null
+++ b/app/views/contracts/edit.html.erb
@@ -0,0 +1,4 @@
+Edit Contract
+<%= link_to 'Back', contracts_path, class: "btn btn-default" %>
+
+<%= render 'form' %>
diff --git a/app/views/contracts/index.html.erb b/app/views/contracts/index.html.erb
index 05f4670..f0a99f1 100644
--- a/app/views/contracts/index.html.erb
+++ b/app/views/contracts/index.html.erb
@@ -4,18 +4,32 @@
-
- <% @contracts.sort_by{|r| [r.last_name] }.each do |contract| %>
-
-
-
- <%= contract.last_name %>
- <%= contract.first_name %>
-
-
-
- <% end %>
-
+
+
+ Name |
+ User |
+ Date |
+ |
+
+ <% @contracts.sort_by{|r| [r.last_name] }.each do |contract| %>
+
+
+ <%= contract.last_name %>,
+ <%= contract.first_name %>
+ |
+
+ <%= link_to contract.user.name, contract.user if contract.user %>
+ |
+
+ <%= contract.signed_at.to_date.to_s(:long) %>
+ |
+
+ <%= link_to "View", contract, class: "btn btn-primary" %>
+ <%= link_to "Edit", edit_contract_path(contract), class: "btn btn-default" %>
+ |
+
+ <% end %>
+
diff --git a/app/views/contracts/show.html.erb b/app/views/contracts/show.html.erb
new file mode 100644
index 0000000..4311350
--- /dev/null
+++ b/app/views/contracts/show.html.erb
@@ -0,0 +1,28 @@
+
+
+ Contract
+ <%= link_to 'Back', contracts_path, :class => "btn btn-default" %>
+ <%= link_to 'Delete', contract_path(@contract), {:confirm => 'Are you sure you want to delete this forever?', :method => :delete, :class => "btn btn-danger"} if can? :destroy, @contract %>
+
+
+
+
+
+ <%= @contract.full_name %>
+ <%= link_to "(#{@contract.user.name})", @contract.user if @contract.user %>
+
+ signed
+ <%= @contract.signed_at.to_date.to_s(:long) %>
+
+
+
+
+<%= link_to "Download Contract", @contract.document.url %>
+
+
+
+
+
+
+
+
diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb
index 56bd282..571bad5 100755
--- a/app/views/resources/index.html.erb
+++ b/app/views/resources/index.html.erb
@@ -7,7 +7,7 @@
Featured item:
- <%= render @featured_resource %>
+ <%= render @featured_resource unless @featured_resource.blank? %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index 8e573e8..40ff60b 100755
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -170,7 +170,13 @@ margin-right: auto;
Waiver?
- <%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %>
+ <%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %>
+ Contracts: <%= link_to "+ Add", new_contract_path, :class => 'btn' if can? :create, Contract %>
+
+ <% @user.contracts.each do |contract| %>
+ - <%= link_to contract.signed_at.strftime("%B %d %Y"), contract %>
+ <% end %>
+
diff --git a/config/s3.yml.example b/config/s3.yml.example
deleted file mode 100755
index 59cc44e..0000000
--- a/config/s3.yml.example
+++ /dev/null
@@ -1,2 +0,0 @@
-access_key_id: YOUR_PUBLIC_ACCESS_KEY
-secret_access_key: YOUR_SECRET_ACCESS_KEY
diff --git a/db/migrate/20140227095847_create_contracts.rb b/db/migrate/20140227095847_create_contracts.rb
index 28ed0ea..dea07f2 100644
--- a/db/migrate/20140227095847_create_contracts.rb
+++ b/db/migrate/20140227095847_create_contracts.rb
@@ -2,8 +2,8 @@ class CreateContracts < ActiveRecord::Migration
def change
create_table :contracts do |t|
t.integer :user_id
- t.datetime :first_name
- t.datetime :last_name
+ t.string :first_name
+ t.string :last_name
t.datetime :signed_at
t.string :document_file_name
t.string :document_content_type
diff --git a/db/schema.rb b/db/schema.rb
index ef73cd0..c980867 100755
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -66,8 +66,8 @@ ActiveRecord::Schema.define(:version => 20140227095847) do
create_table "contracts", :force => true do |t|
t.integer "user_id"
- t.datetime "first_name"
- t.datetime "last_name"
+ t.string "first_name"
+ t.string "last_name"
t.datetime "signed_at"
t.string "document_file_name"
t.string "document_content_type"
diff --git a/env.example b/env.example
new file mode 100644
index 0000000..cdbdd7d
--- /dev/null
+++ b/env.example
@@ -0,0 +1,3 @@
+S3_BUCKET =
+S3_KEY =
+S3_SECRET =
\ No newline at end of file