diff --git a/app/controllers/macs_controller.rb b/app/controllers/macs_controller.rb
index 29381f1..d26bc89 100644
--- a/app/controllers/macs_controller.rb
+++ b/app/controllers/macs_controller.rb
@@ -9,7 +9,7 @@ rescue_from CanCan::AccessDenied do |exception|
redirect_to main_app.root_url, :alert => "Nothing to see here!"
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]
#require "active_record"
@@ -80,26 +80,34 @@ end
end
# POST /macs
- # POST /user
def create
@mac = Mac.new(params[:mac])
- authorize! :update, @mac
-
- if can? :manage, Mac then
- @users = User.accessible_by(current_ability).sort_by(&:name)
- else
- @users = [current_user]
- end
-
- 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 }
+ @existing_mac = Mac.find_by_mac(@mac.mac)
+ if can? :manage, Mac then
+ @users = User.accessible_by(current_ability).sort_by(&:name)
+ else
+ @users = [current_user]
+ end
+
+ if @existing_mac.present?
+ if @existing_mac.user_id.nil?
+ redirect_to edit_mac_path(@existing_mac), :notice => 'This MAC already exists, edit it here:'
+ else
+@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
- 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
# PUT /macs/1
@@ -119,7 +127,7 @@ end
respond_to do |format|
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 }
else
format.html { render :action => "edit" }
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index a9ba487..b0025d6 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -42,6 +42,7 @@ class UsersController < ApplicationController
def activity
@user_logins = User.where(:last_sign_in_at => 1.month.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
# GET /users/1
diff --git a/app/views/macs/_form.html.erb b/app/views/macs/_form.html.erb
index a45e6e4..61586dd 100644
--- a/app/views/macs/_form.html.erb
+++ b/app/views/macs/_form.html.erb
@@ -1,7 +1,7 @@
<%= form_for(@mac) do |f| %>
<% if @mac.errors.any? %>
-
<%= pluralize(@mac.errors.count, "error") %> prohibited this Mac from being saved:
+
<%= pluralize(@mac.errors.count, "error") %> prohibited this MAC from being saved:
<% @mac.errors.full_messages.each do |msg| %>
diff --git a/app/views/macs/edit.html.erb b/app/views/macs/edit.html.erb
index 2765d61..18fc87f 100644
--- a/app/views/macs/edit.html.erb
+++ b/app/views/macs/edit.html.erb
@@ -1,4 +1,4 @@
-Editing Mac
+Editing MAC
<%= render 'form' %>
diff --git a/app/views/macs/index.html.erb b/app/views/macs/index.html.erb
index f579337..893f189 100644
--- a/app/views/macs/index.html.erb
+++ b/app/views/macs/index.html.erb
@@ -29,7 +29,7 @@ Rails.logger.info mac.inspect %>
<% end %>
<% if can? :manage, Mac %>
-All Macs
+All MACs
<% @all_macs.each do |mac| %>
>
diff --git a/app/views/macs/new.html.erb b/app/views/macs/new.html.erb
index 0b1d5c5..c15b502 100644
--- a/app/views/macs/new.html.erb
+++ b/app/views/macs/new.html.erb
@@ -1,4 +1,4 @@
-New Mac
+New MAC
<%= render 'form' %>
diff --git a/app/views/macs/show.html.erb b/app/views/macs/show.html.erb
index d8f503f..bf1e1f1 100644
--- a/app/views/macs/show.html.erb
+++ b/app/views/macs/show.html.erb
@@ -4,7 +4,7 @@
- Mac:
+ MAC:
<%= @mac.mac %>
diff --git a/app/views/users/activity.html.erb b/app/views/users/activity.html.erb
index 910ba04..49a5a4d 100644
--- a/app/views/users/activity.html.erb
+++ b/app/views/users/activity.html.erb
@@ -1,6 +1,10 @@
-Recent User Activity
+Member Onboarding/Activity
+New Users |
+Members Without Cards |
+Logins
-New Users
+
+New Users
Name |
@@ -42,7 +46,47 @@
<% end %>
-Logins
+Basic+ Members Without Cards
+
+
+ Name |
+ Account Created |
+ Member Level |
+ Payment |
+ Card |
+ |
+
+
+<% if !@cardless_users.blank? %>
+ <% @cardless_users.sort_by(&:created_at).reverse!.each do |user| %>
+ >
+ <%= link_to user.name, user %> |
+ <%= distance_of_time_in_words DateTime.now, user.created_at %> ago |
+ <%= user.member_level_string %> |
+ <% if user.payments.present? %>
+ <% last_payment = user.payments.maximum(:date) %>
+ <% if Date.today-last_payment > 60 %>
+
+ <% else %>
+
+ <% end %>
+ <%= distance_of_time_in_words(Date.today, user.payments.maximum(:date))+" ago" %>
+
+ <% else %>
+ ×
+ <% end %> |
+ <% if user.cards.present? %>
+ ✓
+ <% else %>
+ ×
+ <% end %> |
+
+ <% end %>
+<% end %>
+
+
+
+Logins