Finishing contracts, changing from s3.yml to .env
This commit is contained in:
		
							parent
							
								
									c74da562bc
								
							
						
					
					
						commit
						cac59e9de5
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -24,3 +24,4 @@ tmp/
 | 
			
		||||
/config/s3.yml
 | 
			
		||||
/config/database.yml
 | 
			
		||||
/config/initializers/secret_token.rb
 | 
			
		||||
.env
 | 
			
		||||
							
								
								
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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.
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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  
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -11,26 +11,31 @@
 | 
			
		||||
    </div>
 | 
			
		||||
  <% end %>
 | 
			
		||||
 | 
			
		||||
  <p>
 | 
			
		||||
  <div class="form-group">
 | 
			
		||||
    <%= f.label :first_name %><br />
 | 
			
		||||
    <%= f.text_field :first_name, class: "form-control" %>
 | 
			
		||||
  </p>
 | 
			
		||||
  <p>
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="form-group">
 | 
			
		||||
    <%= f.label :last_name %><br />
 | 
			
		||||
    <%= 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.date_select :signed_at, class: "form-control"  %>
 | 
			
		||||
  </p>
 | 
			
		||||
    <%= f.date_select :signed_at  %>
 | 
			
		||||
  </div>
 | 
			
		||||
 | 
			
		||||
  <p>
 | 
			
		||||
  <div class="form-group">
 | 
			
		||||
    <%= f.label :document %><br />
 | 
			
		||||
    <%= f.file_field :document %>
 | 
			
		||||
  </p>
 | 
			
		||||
  </div>
 | 
			
		||||
 | 
			
		||||
  <p>
 | 
			
		||||
  <div class="form-group">
 | 
			
		||||
    <%= f.submit nil, class: "btn btn-primary" %>
 | 
			
		||||
  </p>
 | 
			
		||||
  </div>
 | 
			
		||||
<% end %>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								app/views/contracts/edit.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/views/contracts/edit.html.erb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
			
		||||
<h1>Edit Contract
 | 
			
		||||
<%= link_to 'Back', contracts_path, class: "btn btn-default" %>
 | 
			
		||||
</h1>
 | 
			
		||||
<%= render 'form' %>
 | 
			
		||||
@ -4,18 +4,32 @@
 | 
			
		||||
  </h1>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div class="row">
 | 
			
		||||
  <% @contracts.sort_by{|r| [r.last_name] }.each do |contract| %>
 | 
			
		||||
    <div class="panel panel-default">
 | 
			
		||||
      <div class="panel-heading">
 | 
			
		||||
        <h4 class="panel-title">
 | 
			
		||||
            <%= contract.last_name %>
 | 
			
		||||
            <%= contract.first_name %>
 | 
			
		||||
        </h4>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  <% end %>
 | 
			
		||||
</div>
 | 
			
		||||
<table class="table">
 | 
			
		||||
  <tr>
 | 
			
		||||
    <th>Name</th>
 | 
			
		||||
    <th>User</th>
 | 
			
		||||
    <th>Date</th>
 | 
			
		||||
    <th></th>
 | 
			
		||||
  </tr>
 | 
			
		||||
 | 
			
		||||
  <% @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 />
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										28
									
								
								app/views/contracts/show.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								app/views/contracts/show.html.erb
									
									
									
									
									
										Normal 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 />
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,7 @@
 | 
			
		||||
  
 | 
			
		||||
  <span class="col-md-2 col-xs-6">
 | 
			
		||||
    <h3>Featured item:</h3>
 | 
			
		||||
    <%= render @featured_resource %>
 | 
			
		||||
    <%= render @featured_resource unless @featured_resource.blank? %>
 | 
			
		||||
  </span>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -170,7 +170,13 @@ margin-right: auto;
 | 
			
		||||
 | 
			
		||||
<p>
 | 
			
		||||
  <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>
 | 
			
		||||
 | 
			
		||||
@ -1,2 +0,0 @@
 | 
			
		||||
access_key_id: YOUR_PUBLIC_ACCESS_KEY
 | 
			
		||||
secret_access_key: YOUR_SECRET_ACCESS_KEY
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								env.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								env.example
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
S3_BUCKET = 
 | 
			
		||||
S3_KEY = 
 | 
			
		||||
S3_SECRET = 
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user