Finishing contracts, changing from s3.yml to .env

This commit is contained in:
Will Bradley 2014-03-02 19:06:39 -07:00
parent c74da562bc
commit cac59e9de5
19 changed files with 118 additions and 41 deletions

1
.gitignore vendored
View File

@ -24,3 +24,4 @@ tmp/
/config/s3.yml /config/s3.yml
/config/database.yml /config/database.yml
/config/initializers/secret_token.rb /config/initializers/secret_token.rb
.env

View File

@ -4,6 +4,8 @@ ruby '1.9.3'
gem 'rails', '3.2.8' gem 'rails', '3.2.8'
gem 'dotenv-rails', :groups => [:development, :test]
# Bundle edge Rails instead: # Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git' # gem 'rails', :git => 'git://github.com/rails/rails.git'

View File

@ -53,6 +53,9 @@ GEM
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (~> 3.1) railties (~> 3.1)
warden (~> 1.2.1) warden (~> 1.2.1)
dotenv (0.10.0)
dotenv-rails (0.10.0)
dotenv (= 0.10.0)
erubis (2.7.0) erubis (2.7.0)
execjs (2.0.2) execjs (2.0.2)
gravtastic (3.2.6) gravtastic (3.2.6)
@ -158,6 +161,7 @@ DEPENDENCIES
cancan cancan
coffee-rails (~> 3.2.1) coffee-rails (~> 3.2.1)
devise devise
dotenv-rails
gravtastic gravtastic
jquery-rails jquery-rails
json json

View File

@ -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 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/ 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: To use:
* Install Imagemagick (for Paperclip / image uploads) * Install Imagemagick (for Paperclip / image uploads)
* Install arp-scan (for LAN Mac address scanning) * Install arp-scan (for LAN Mac address scanning)
* Load into a Rails 3 environment * Load into a Rails 3 environment
* Copy config/config.yml.example to config/config.yml and edit appropriately * 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/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 * 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. * See/edit db/seeds.rb for the initial admin account info.
* Run bundle install, rake db:migrate, rake db:seed, etc. * Run bundle install, rake db:migrate, rake db:seed, etc.

View File

@ -1,6 +1,6 @@
class ContractsController < ApplicationController class ContractsController < ApplicationController
load_and_authorize_resource :contract load_and_authorize_resource :contract
before_filter :authenticate_user! before_filter :authenticate_user!, :load_users
layout 'resources' layout 'resources'
def index def index
@ -16,6 +16,8 @@ class ContractsController < ApplicationController
end end
def create def create
Rails.logger.info "CONTRACT"
Rails.logger.info @contract.inspect
respond_to do |format| respond_to do |format|
if @contract.save if @contract.save
format.html { redirect_to Contract, :notice => 'Contract was successfully created.' } format.html { redirect_to Contract, :notice => 'Contract was successfully created.' }
@ -47,4 +49,8 @@ class ContractsController < ApplicationController
format.json { head :no_content } format.json { head :no_content }
end end
end end
def load_users
@users = @users = User.accessible_by(current_ability).sort_by(&:name)
end
end end

View File

@ -12,6 +12,7 @@ class Ability
# By default, users can only see their own stuff # By default, users can only see their own stuff
can :read, Card, :user_id => user.id can :read, Card, :user_id => user.id
can :read, Certification can :read, Certification
can :read, Contract
can :read_details, Mac can :read_details, Mac
can [:update], Mac, :user_id => nil can [:update], Mac, :user_id => nil
can [:create,:update], Mac, :user_id => user.id can [:create,:update], Mac, :user_id => user.id
@ -54,7 +55,7 @@ class Ability
can :manage, :all can :manage, :all
end end
# Prevent all destruction for now # Prevent most destruction for now
#cannot :destroy, User #cannot :destroy, User
#cannot :destroy, Card #cannot :destroy, Card
cannot :destroy, Certification cannot :destroy, Certification

View File

@ -1,12 +1,13 @@
class Contract < ActiveRecord::Base class Contract < ActiveRecord::Base
belongs_to :user 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 validates_presence_of :first_name, :last_name, :signed_at
has_attached_file :document, { :styles => { :medium => "300x300>"}, has_attached_file :document, { :styles => { :medium => "300x300>"},
:storage => :s3, :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", :path => ":attachment/:id/:style.:extension",
:bucket => 'Toolshare' } #TODO: move to local storage :bucket => ENV['S3_BUCKET'] }
end end

View File

@ -14,11 +14,12 @@ class Resource < ActiveRecord::Base
:thumb => "100x100>", :thumb => "100x100>",
:tiny => "50x50>"}, :tiny => "50x50>"},
:storage => :s3, :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", :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 :picture2, PICTURE_OPTIONS
has_attached_file :picture3, PICTURE_OPTIONS has_attached_file :picture3, PICTURE_OPTIONS
has_attached_file :picture4, PICTURE_OPTIONS has_attached_file :picture4, PICTURE_OPTIONS

View File

@ -14,6 +14,7 @@ class User < ActiveRecord::Base
has_many :cards has_many :cards
has_many :user_certifications has_many :user_certifications
has_many :certifications, :through => :user_certifications has_many :certifications, :through => :user_certifications
has_many :contracts
has_many :payments has_many :payments
has_many :macs has_many :macs
has_many :resources has_many :resources

View File

@ -11,26 +11,31 @@
</div> </div>
<% end %> <% end %>
<p> <div class="form-group">
<%= f.label :first_name %><br /> <%= f.label :first_name %><br />
<%= f.text_field :first_name, class: "form-control" %> <%= f.text_field :first_name, class: "form-control" %>
</p> </div>
<p> <div class="form-group">
<%= f.label :last_name %><br /> <%= f.label :last_name %><br />
<%= f.text_field :last_name, class: "form-control" %> <%= f.text_field :last_name, class: "form-control" %>
</p> </div>
<p> <div class="form-group">
<%= f.label :user_id, "User" %><br />
<%= collection_select(:contract, :user_id, @users, :id, :name, :include_blank => true) %>
</div>
<div class="form-group">
<%= f.label :signed_at %><br /> <%= f.label :signed_at %><br />
<%= f.date_select :signed_at, class: "form-control" %> <%= f.date_select :signed_at %>
</p> </div>
<p> <div class="form-group">
<%= f.label :document %><br /> <%= f.label :document %><br />
<%= f.file_field :document %> <%= f.file_field :document %>
</p> </div>
<p> <div class="form-group">
<%= f.submit nil, class: "btn btn-primary" %> <%= f.submit nil, class: "btn btn-primary" %>
</p> </div>
<% end %> <% end %>

View File

@ -0,0 +1,4 @@
<h1>Edit Contract
<%= link_to 'Back', contracts_path, class: "btn btn-default" %>
</h1>
<%= render 'form' %>

View File

@ -4,18 +4,32 @@
</h1> </h1>
</div> </div>
<div class="row"> <table class="table">
<% @contracts.sort_by{|r| [r.last_name] }.each do |contract| %> <tr>
<div class="panel panel-default"> <th>Name</th>
<div class="panel-heading"> <th>User</th>
<h4 class="panel-title"> <th>Date</th>
<%= contract.last_name %> <th></th>
<%= contract.first_name %> </tr>
</h4>
</div>
</div>
<% end %>
</div>
<% @contracts.sort_by{|r| [r.last_name] }.each do |contract| %>
<tr>
<td>
<%= contract.last_name %>,
<%= contract.first_name %>
</td>
<td>
<%= link_to contract.user.name, contract.user if contract.user %>
</td>
<td>
<%= contract.signed_at.to_date.to_s(:long) %>
</td>
<td>
<%= link_to "View", contract, class: "btn btn-primary" %>
<%= link_to "Edit", edit_contract_path(contract), class: "btn btn-default" %>
</td>
</tr>
<% end %>
</table>
<br /> <br />

View File

@ -0,0 +1,28 @@
<div class="row">
<h1 class="col-md-8">
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 %>
</h1>
</div>
<h2>
<%= @contract.full_name %>
<%= link_to "(#{@contract.user.name})", @contract.user if @contract.user %>
<small>
signed
<%= @contract.signed_at.to_date.to_s(:long) %>
</small>
</h2>
<p><%= link_to "Download Contract", @contract.document.url %>
<div class="col-xs-12">
<iframe src="<%= @contract.document.url %>" width="100%" height="600"></iframe>
</div>
</p>
<br />

View File

@ -7,7 +7,7 @@
<span class="col-md-2 col-xs-6"> <span class="col-md-2 col-xs-6">
<h3>Featured item:</h3> <h3>Featured item:</h3>
<%= render @featured_resource %> <%= render @featured_resource unless @featured_resource.blank? %>
</span> </span>
</div> </div>

View File

@ -170,7 +170,13 @@ margin-right: auto;
<p> <p>
<b>Waiver?</b> <b>Waiver?</b>
<%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %> <%= @user.waiver.strftime("%B %d %Y") unless @user.waiver.blank? %><br/>
<b>Contracts:</b> <%= link_to "+ Add", new_contract_path, :class => 'btn' if can? :create, Contract %>
<ul>
<% @user.contracts.each do |contract| %>
<li><%= link_to contract.signed_at.strftime("%B %d %Y"), contract %></li>
<% end %>
</ul>
</p> </p>
<p> <p>

View File

@ -1,2 +0,0 @@
access_key_id: YOUR_PUBLIC_ACCESS_KEY
secret_access_key: YOUR_SECRET_ACCESS_KEY

View File

@ -2,8 +2,8 @@ class CreateContracts < ActiveRecord::Migration
def change def change
create_table :contracts do |t| create_table :contracts do |t|
t.integer :user_id t.integer :user_id
t.datetime :first_name t.string :first_name
t.datetime :last_name t.string :last_name
t.datetime :signed_at t.datetime :signed_at
t.string :document_file_name t.string :document_file_name
t.string :document_content_type t.string :document_content_type

View File

@ -66,8 +66,8 @@ ActiveRecord::Schema.define(:version => 20140227095847) do
create_table "contracts", :force => true do |t| create_table "contracts", :force => true do |t|
t.integer "user_id" t.integer "user_id"
t.datetime "first_name" t.string "first_name"
t.datetime "last_name" t.string "last_name"
t.datetime "signed_at" t.datetime "signed_at"
t.string "document_file_name" t.string "document_file_name"
t.string "document_content_type" t.string "document_content_type"

3
env.example Normal file
View File

@ -0,0 +1,3 @@
S3_BUCKET =
S3_KEY =
S3_SECRET =