Adding users without cards report, fixing mac registration for existing macs

This commit is contained in:
Will Bradley 2013-09-23 18:34:18 -07:00
parent 377170d47c
commit cad46e45c5
8 changed files with 79 additions and 26 deletions

View File

@ -9,7 +9,7 @@ rescue_from CanCan::AccessDenied do |exception|
redirect_to main_app.root_url, :alert => "Nothing to see here!" redirect_to main_app.root_url, :alert => "Nothing to see here!"
end end
end end
load_and_authorize_resource :mac load_and_authorize_resource :mac, :except => :create
load_and_authorize_resource :user, :through => :mac, :except => [:index, :show, :scan, :import] load_and_authorize_resource :user, :through => :mac, :except => [:index, :show, :scan, :import]
#require "active_record" #require "active_record"
@ -80,26 +80,34 @@ end
end end
# POST /macs # POST /macs
# POST /user
def create def create
@mac = Mac.new(params[:mac]) @mac = Mac.new(params[:mac])
authorize! :update, @mac @existing_mac = Mac.find_by_mac(@mac.mac)
if can? :manage, Mac then
if can? :manage, Mac then @users = User.accessible_by(current_ability).sort_by(&:name)
@users = User.accessible_by(current_ability).sort_by(&:name) else
else @users = [current_user]
@users = [current_user] end
end
if @existing_mac.present?
respond_to do |format| if @existing_mac.user_id.nil?
if @mac.save redirect_to edit_mac_path(@existing_mac), :notice => 'This MAC already exists, edit it here:'
format.html { redirect_to macs_path, :notice => 'Mac was successfully created.' } else
format.json { render :json => @mac, :status => :created, :location => @mac } @mac.errors.add(:user,"for this MAC is already set to #{@existing_mac.user.name} -- please contact them or an admin if this is incorrect.")
render :action => "new"
end
else else
format.html { render :action => "new" }
format.json { render :json => @mac.errors, :status => :unprocessable_entity } respond_to do |format|
if @mac.save
format.html { redirect_to macs_path, :notice => 'MAC was successfully created.' }
format.json { render :json => @mac, :status => :created, :location => @mac }
else
format.html { render :action => "new" }
format.json { render :json => @mac.errors, :status => :unprocessable_entity }
end
end
end end
end
end end
# PUT /macs/1 # PUT /macs/1
@ -119,7 +127,7 @@ end
respond_to do |format| respond_to do |format|
if @mac.save if @mac.save
format.html { redirect_to macs_path, :notice => 'Mac was successfully updated.' } format.html { redirect_to macs_path, :notice => 'MAC was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render :action => "edit" } format.html { render :action => "edit" }

View File

@ -42,6 +42,7 @@ class UsersController < ApplicationController
def activity def activity
@user_logins = User.where(:last_sign_in_at => 1.month.ago..Date.today) @user_logins = User.where(:last_sign_in_at => 1.month.ago..Date.today)
@new_users = User.where(:created_at => 3.months.ago..Date.today) @new_users = User.where(:created_at => 3.months.ago..Date.today)
@cardless_users = User.includes('cards').where(['users.member_level >= ?','50']).where('cards.id IS NULL')
end end
# GET /users/1 # GET /users/1

View File

@ -1,7 +1,7 @@
<%= form_for(@mac) do |f| %> <%= form_for(@mac) do |f| %>
<% if @mac.errors.any? %> <% if @mac.errors.any? %>
<div id="error_explanation"> <div id="error_explanation">
<h2><%= pluralize(@mac.errors.count, "error") %> prohibited this Mac from being saved:</h2> <h2><%= pluralize(@mac.errors.count, "error") %> prohibited this MAC from being saved:</h2>
<ul> <ul>
<% @mac.errors.full_messages.each do |msg| %> <% @mac.errors.full_messages.each do |msg| %>

View File

@ -1,4 +1,4 @@
<h1>Editing Mac</h1> <h1>Editing MAC</h1>
<%= render 'form' %> <%= render 'form' %>

View File

@ -29,7 +29,7 @@ Rails.logger.info mac.inspect %>
<% end %> <% end %>
<% if can? :manage, Mac %> <% if can? :manage, Mac %>
<h3>All Macs</h3> <h3>All MACs</h3>
<table> <table>
<% @all_macs.each do |mac| %> <% @all_macs.each do |mac| %>
<tr <%= raw('class="hidden"') if mac.hidden? %>> <tr <%= raw('class="hidden"') if mac.hidden? %>>

View File

@ -1,4 +1,4 @@
<h1>New Mac</h1> <h1>New MAC</h1>
<%= render 'form' %> <%= render 'form' %>

View File

@ -4,7 +4,7 @@
</p> </p>
<p> <p>
<b>Mac:</b> <b>MAC:</b>
<%= @mac.mac %> <%= @mac.mac %>
</p> </p>

View File

@ -1,6 +1,10 @@
<h1>Recent User Activity</h1> <h1>Member Onboarding/Activity</h1>
<a href="#new_users">New Users</a> |
<a href="#members_without_cards">Members Without Cards</a> |
<a href="#logins">Logins</a>
<h2>New Users</h2>
<h2><a name="new_users"></a>New Users</h2>
<table> <table>
<tr> <tr>
<th>Name</th> <th>Name</th>
@ -42,7 +46,47 @@
<% end %> <% end %>
</table> </table>
<h2>Logins</h2> <h2><a name="members_without_cards"></a>Basic+ Members Without Cards</h2>
<table>
<tr>
<th>Name</th>
<th>Account Created</th>
<th>Member Level</th>
<th>Payment</th>
<th>Card</th>
<th></th>
</tr>
<% if !@cardless_users.blank? %>
<% @cardless_users.sort_by(&:created_at).reverse!.each do |user| %>
<tr<%= " class='hidden'" if user.hidden? %>>
<td><%= link_to user.name, user %></td>
<td><%= distance_of_time_in_words DateTime.now, user.created_at %> ago</td>
<td><%= user.member_level_string %></td>
<td><% if user.payments.present? %>
<% last_payment = user.payments.maximum(:date) %>
<% if Date.today-last_payment > 60 %>
<span class="alert">
<% else %>
<span class="notice">
<% end %>
<%= distance_of_time_in_words(Date.today, user.payments.maximum(:date))+" ago" %>
</span>
<% else %>
<span class="alert">&times;</span>
<% end %></td>
<td><% if user.cards.present? %>
<span class="notice">&check;</span>
<% else %>
<span class="alert">&times;</span>
<% end %></td>
</tr>
<% end %>
<% end %>
</table>
<h2><a name="logins"></a>Logins</h2>
<table> <table>
<tr> <tr>
<th>Name</th> <th>Name</th>