IPN improvements

This commit is contained in:
Will Bradley 2013-08-28 03:18:47 -07:00
parent 0be2834a5d
commit c662be6dc0
10 changed files with 48 additions and 15 deletions

View File

@ -20,6 +20,7 @@ font-size: 13px;
line-height: 18px;
color: #333;
text-align: center;
text-decoration: none;
text-shadow: 0 1px 1px rgba(255,255,255,.75);
vertical-align: middle;
background-color: #f5f5f5;

View File

@ -24,6 +24,16 @@ class IpnsController < ApplicationController
#end
end
def import
@ipn = Ipn.new_from_dynamic_params(params)
@ipn.data = params.to_json
@ipn.save
redirect_to ipn_path(@ipn)
#unless @ipn.validate!
# Rails.logger.error "Unable to validate IPN: #{@ipn.inspect}"
#end
end
def validate
if @ipn.validate!
redirect_to ipns_url, :notice => 'Valid!'

View File

@ -1,5 +1,15 @@
class MacsController < ApplicationController
load_and_authorize_resource :mac, :except => [:index, :scan, :import]
rescue_from CanCan::AccessDenied do |exception|
today = Date.today
event = Date.new(2013,9,1)
if today == event
redirect_to main_app.root_url, :alert => "CryptoParty today; no MAC scanning. Sorry, NSA!"
else
redirect_to main_app.root_url, :alert => "Nothing to see here!"
end
end
load_and_authorize_resource :mac
load_and_authorize_resource :user, :through => :mac, :except => [:index, :show, :scan, :import]
#require "active_record"

View File

@ -69,7 +69,7 @@ class UsersController < ApplicationController
def create
respond_to do |format|
if @user.save
format.html { redirect_to users_url, :notice => 'User was successfully created.' }
format.html { redirect_to @user, :notice => 'User was successfully created.' }
format.json { render :json => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
@ -83,7 +83,7 @@ class UsersController < ApplicationController
def update
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to users_url, :notice => 'User was successfully updated.' }
format.html { redirect_to @user, :notice => 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }

View File

@ -3,14 +3,20 @@ class Ability
def initialize(user)
# Anonymous can read mac
can :read, Mac
today = Date.today
event = Date.new(2013,9,1)
unless today == event
can :read, Mac
can :scan, Mac # Need anonymous so CRON can scan
end
if !user.nil?
# By default, users can only see their own stuff
can :read, Card, :user_id => user.id
can :read, Certification
can :read_details, Mac
can :read_details, Mac unless today == event
can [:update], Mac, :user_id => nil
can [:create,:update], Mac, :user_id => user.id
can :read, User, :id => user.id #TODO: why can users update themselves?

View File

@ -86,7 +86,7 @@ class User < ActiveRecord::Base
end
def self.member_levels
{25 => "Associate", 50 => "Basic", 100 => "Plus"}
{25 => "Associate", 50 => "Basic", 75 => "Basic", 100 => "Plus"}
end
def member_status
@ -144,7 +144,7 @@ class User < ActiveRecord::Base
# There are payments
if self.payments.count > 0 then
# They're on time
if self.payments.last.date > (DateTime.now - 45.days)
if self.payments.last.date > (DateTime.now - 60.days)
flair = "-paid"
else
message = "Last Payment #{(DateTime.now - self.payments.last.date).to_i/30} months ago"

View File

@ -8,10 +8,11 @@
<% end %>
<p>
<% if @ipn.payment.present? %>
<%= link_to "Payment", @ipn.payment %>
<%= link_to "Linked Payment", @ipn.payment %>
<% else %>
Couldn't link '<%= @ipn.payer_email %>' or payment amount '<%= @ipn.payment_gross.to_i %>' not a valid membership level. Please create payment manually.
<span class="alert">Couldn't link automatically. Please create payment manually or adjust the user account and try again to <%= link_to "link email '#{@ipn.payer_email}' at membership level '#{@ipn.payment_gross.to_i}'", link_ipn_path(@ipn) %>.</span>
<% end %>
</p>
<%= link_to "Back", ipns_path %>
<%= link_to "Back", ipns_path %>

View File

@ -1,5 +1,7 @@
Scanning...
<% @log.each do |log| %>
<% if can? :read_details, Mac
@log.each do |log| %>
<%= log.mac %> =
<%= log.ip %><br/>
<% end %>
<% end
end %>

View File

@ -74,17 +74,19 @@
</p>
<% end %>
<p>
<b>Card:</b><%= link_to "+ Add", (new_card_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, Card %>
<b>Card: </b><%= link_to "+ Add", (new_card_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, Card %>
<% if current_user.admin? then %>
<ul>
<% @user.cards.each do |c| %>
<%= link_to c.card_number, c %><%= "," unless c == @user.cards.last %>
<li><%= link_to c.card_number, c %><%= "," unless c == @user.cards.last %></li>
<% end %>
</ul>
<% else %>
<%= unless @user.cards.blank? then raw("&#x2713;") end %>
<% end %>
</p>
<b>Certifications:</b><%= link_to "+ Add", (new_user_certification_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, UserCertification %>
<b>Certifications: </b><%= link_to "+ Add", (new_user_certification_path+"?user="+@user.id.to_s), :class => 'btn' if can? :create, UserCertification %>
<ul>
<% @user.certifications.each do |certification| %>
<li><%= link_to certification.name, certification %></li>

View File

@ -1,4 +1,5 @@
Dooraccess::Application.routes.draw do
match 'ipns/import' => 'ipns#import', :as => :import_ipn
resources :ipns
match 'ipns/:id/link' => 'ipns#link', :as => :link_ipn
match 'ipns/:id/validate' => 'ipns#validate', :as => :validate_ipn