Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a1ef8a5fd5 | |||
| 75e4907a9c | |||
| 20a007cac5 |
@@ -10,12 +10,16 @@ class CardsController < ApplicationController
|
|||||||
@cards = @cards.sort_by{|e| e[:id]}
|
@cards = @cards.sort_by{|e| e[:id]}
|
||||||
|
|
||||||
if can? :read, DoorLog then
|
if can? :read, DoorLog then
|
||||||
|
Rails.logger.info "CARD STATS:"
|
||||||
most_active_count = 0
|
most_active_count = 0
|
||||||
@most_active_card = nil
|
@most_active_card = nil
|
||||||
@cards.each do |card|
|
@cards.each do |card|
|
||||||
card_num_R = card.card_number.to_i(16)%32767
|
card_num_R = card.card_number.to_i(16)%32767
|
||||||
card[:accesses_this_week] = DoorLog.where('key = "R" AND data =? AND created_at > ?', card_num_R, DateTime.now - 7.days).order("created_at DESC").count
|
Rails.logger.info card_num_R
|
||||||
|
card[:accesses_this_week] = DoorLog.where('key = "G" AND data =? AND created_at > ?', card_num_R, DateTime.now - 7.days).order("created_at DESC").count
|
||||||
|
Rails.logger.info card[:accesses_this_week]
|
||||||
if(card[:accesses_this_week] > most_active_count) then
|
if(card[:accesses_this_week] > most_active_count) then
|
||||||
|
Rails.logger.info "ACTIVE"
|
||||||
most_active_count = card[:accesses_this_week]
|
most_active_count = card[:accesses_this_week]
|
||||||
@most_active_card = card
|
@most_active_card = card
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class PaymentsController < ApplicationController
|
|||||||
|
|
||||||
# Load users and certs based on current ability
|
# Load users and certs based on current ability
|
||||||
before_filter do
|
before_filter do
|
||||||
@users = User.accessible_by(current_ability).sort_by(&:name_with_payee_and_member_level)
|
@users = User.where(:hidden => false).where("member_level > 10").accessible_by(current_ability).sort_by(&:name_with_payee_and_member_level)
|
||||||
end
|
end
|
||||||
|
|
||||||
before_filter :only => [:create, :update] do
|
before_filter :only => [:create, :update] do
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class UserCertificationsController < ApplicationController
|
|||||||
|
|
||||||
# Load users and certs based on current ability
|
# Load users and certs based on current ability
|
||||||
before_filter :only => [:new, :edit, :create, :update] do
|
before_filter :only => [:new, :edit, :create, :update] do
|
||||||
@users = User.accessible_by(current_ability).sort_by(&:name)
|
@users = User.where(:hidden => false).accessible_by(current_ability).sort_by(&:name)
|
||||||
@certifications = Certification.accessible_by(current_ability).sort_by(&:name)
|
@certifications = Certification.accessible_by(current_ability).sort_by(&:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /user_summary/1
|
||||||
|
def user_summary
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :partial => "user_summary" } # show.html.erb
|
||||||
|
format.json { render :json => @user }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# GET /users/new
|
# GET /users/new
|
||||||
# GET /users/new.json
|
# GET /users/new.json
|
||||||
def new
|
def new
|
||||||
@@ -84,6 +92,37 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /users/merge
|
||||||
|
def merge_view
|
||||||
|
@users = @users.sort_by(&:name)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # merge_view.html.erb
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /users/merge
|
||||||
|
def merge_action
|
||||||
|
@user_to_keep = User.find(params[:user][:to_keep])
|
||||||
|
Rails.logger.info "USER TO KEEP:"
|
||||||
|
Rails.logger.info @user_to_keep.inspect
|
||||||
|
@user_to_merge = User.find(params[:user][:to_merge])
|
||||||
|
Rails.logger.info "USER TO MERGE:"
|
||||||
|
Rails.logger.info @user_to_merge.inspect
|
||||||
|
|
||||||
|
@user_to_keep.absorb_user(@user_to_merge)
|
||||||
|
|
||||||
|
Rails.logger.info "RESULT:"
|
||||||
|
Rails.logger.info @user_to_keep.inspect
|
||||||
|
Rails.logger.info @user_to_keep.cards.inspect
|
||||||
|
Rails.logger.info @user_to_keep.user_certifications.inspect
|
||||||
|
Rails.logger.info @user_to_keep.payments.inspect
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to @user_to_keep, :notice => 'Users successfully merged.' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# DELETE /users/1
|
# DELETE /users/1
|
||||||
# DELETE /users/1.json
|
# DELETE /users/1.json
|
||||||
def destroy
|
def destroy
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ class Ability
|
|||||||
if user.instructor?
|
if user.instructor?
|
||||||
can :manage, Certification
|
can :manage, Certification
|
||||||
can [:create,:read], User, :hidden => [nil,false]
|
can [:create,:read], User, :hidden => [nil,false]
|
||||||
can :manage, UserCertification
|
can [:create,:read], UserCertification
|
||||||
|
can [:update,:destroy], UserCertification, :created_by => user.id
|
||||||
end
|
end
|
||||||
# Users can see others' stuff if they've been oriented
|
# Users can see others' stuff if they've been oriented
|
||||||
unless user.orientation.blank?
|
unless user.orientation.blank?
|
||||||
@@ -39,12 +40,12 @@ class Ability
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Prevent all destruction for now
|
# Prevent all destruction for now
|
||||||
cannot :destroy, User
|
#cannot :destroy, User
|
||||||
cannot :destroy, Card
|
#cannot :destroy, Card
|
||||||
cannot :destroy, Certification
|
cannot :destroy, Certification
|
||||||
cannot :destroy, Mac
|
cannot :destroy, Mac
|
||||||
cannot :destroy, MacLog
|
cannot :destroy, MacLog
|
||||||
cannot :destroy, UserCertification
|
#cannot :destroy, UserCertification
|
||||||
cannot :destroy, DoorLog
|
cannot :destroy, DoorLog
|
||||||
# no exception for destroying payments
|
# no exception for destroying payments
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,48 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
after_create :send_new_user_email
|
after_create :send_new_user_email
|
||||||
|
|
||||||
|
def absorb_user(user_to_absorb)
|
||||||
|
# copy all attributes except email, password, name, and anything that isn't blank on the destination
|
||||||
|
user_to_absorb.attributes.each_pair {|k,v|
|
||||||
|
unless (v.nil? || k == :id || k == :email || k == :password || k == :name || k == :password_confirmation || k == :hidden || k == 'hidden' || k == :encrypted_password || !self.attributes[k].blank? )
|
||||||
|
Rails.logger.info "Updating "+k.to_s+" from "+self[k].to_s
|
||||||
|
self[k] = v
|
||||||
|
Rails.logger.info "Updated "+k.to_s+" to "+self[k].to_s
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
self.save!
|
||||||
|
|
||||||
|
user_to_absorb.cards.each {|card|
|
||||||
|
Rails.logger.info "CARD BEFORE: "+card.inspect
|
||||||
|
card.user_id = self.id
|
||||||
|
card.save!
|
||||||
|
Rails.logger.info "CARD AFTER: "+card.inspect
|
||||||
|
}
|
||||||
|
user_to_absorb.user_certifications.each {|user_cert|
|
||||||
|
Rails.logger.info "CERT BEFORE: "+user_cert.inspect
|
||||||
|
user_cert.user_id = self.id
|
||||||
|
user_cert.save!
|
||||||
|
Rails.logger.info "CERT AFTER: "+user_cert.inspect
|
||||||
|
}
|
||||||
|
user_to_absorb.payments.each {|payment|
|
||||||
|
Rails.logger.info "PAYMENT BEFORE: "+payment.inspect
|
||||||
|
payment.user_id = self.id
|
||||||
|
payment.save!
|
||||||
|
Rails.logger.info "PAYMENT AFTER: "+payment.inspect
|
||||||
|
}
|
||||||
|
|
||||||
|
user_to_absorb.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
def name_with_email_and_visibility
|
||||||
|
if hidden then
|
||||||
|
"#{name} (#{email}) HIDDEN"
|
||||||
|
else
|
||||||
|
"#{name} (#{email})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def name_with_payee_and_member_level
|
def name_with_payee_and_member_level
|
||||||
if payee.blank? then
|
if payee.blank? then
|
||||||
"#{name} - #{member_level_string}"
|
"#{name} - #{member_level_string}"
|
||||||
|
|||||||
@@ -5,4 +5,12 @@ class UserCertification < ActiveRecord::Base
|
|||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :certification
|
belongs_to :certification
|
||||||
|
|
||||||
|
def user_name
|
||||||
|
if user.blank?
|
||||||
|
return "n/a (user ##{user_id} missing)"
|
||||||
|
else
|
||||||
|
return self.user.name
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,7 +28,13 @@
|
|||||||
<% if !@cards.blank? %>
|
<% if !@cards.blank? %>
|
||||||
<% @cards.each do |card| %>
|
<% @cards.each do |card| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= link_to card.user.name, card %></td>
|
<td>
|
||||||
|
<% if card.user.nil? %>
|
||||||
|
n/a
|
||||||
|
<% else %>
|
||||||
|
<%= link_to card.user.name , card %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
<td><%= card.name %></td>
|
<td><%= card.name %></td>
|
||||||
<td><%= card.id %></td>
|
<td><%= card.id %></td>
|
||||||
<td><%= card.card_number %></td>
|
<td><%= card.card_number %></td>
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :user_id, "User" %><br />
|
<%= f.label :user_id, "User" %><br />
|
||||||
<%= collection_select(:payment, :user_id, @users, :id, :name_with_payee_and_member_level) %>
|
<%= collection_select(:payment, :user_id, @users, :id, :name_with_payee_and_member_level) %> (inactive members are not shown.)
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :date, "Paid for month beginning" %><br />
|
<%= f.label :date, "Paid for month beginning" %><br />
|
||||||
<%= f.date_select :date %>
|
<%= f.date_select :date, :default => (DateTime.now - 1.month) %>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<%= f.submit %>
|
<%= f.submit %>
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
<% @grouped_user_certs.sort.each do |cert, user_certifications| %>
|
<% @grouped_user_certs.sort.each do |cert, user_certifications| %>
|
||||||
<dl class="collapsible">
|
<dl class="collapsible">
|
||||||
<dt><%= cert.name %></dt>
|
<dt><%= cert.name %></dt>
|
||||||
<% user_certifications.sort{|a,b| a.user.name <=> b.user.name}.each do |user_certification| %>
|
<% user_certifications.sort{|a,b| a.user_name <=> b.user_name}.each do |user_certification| %>
|
||||||
<dd>
|
<dd>
|
||||||
<%= link_to user_certification.user.name, user_certification %>
|
<%= link_to user_certification.user_name, user_certification %>
|
||||||
</dd>
|
</dd>
|
||||||
<% end %>
|
<% end %>
|
||||||
</dl>
|
</dl>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<p>
|
<p>
|
||||||
<b>User:</b>
|
<b>User:</b>
|
||||||
<%= @user_certification.user.name %>
|
<%= @user_certification.user_name %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@@ -14,12 +14,23 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Updated:</b> by <%= link_to @updated_by.name, @updated_by unless @updated_by.blank? %>
|
<b>Updated:</b> by
|
||||||
|
<% if @updated_by.blank? %>
|
||||||
|
#<%= @user_certification.updated_by ||= "nil" %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to @updated_by.name, @updated_by %>
|
||||||
|
<% end %>
|
||||||
at <%= @user_certification.updated_at %>
|
at <%= @user_certification.updated_at %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<%= link_to 'Edit', edit_user_certification_path(@user_certification) %> |
|
|
||||||
<%= link_to 'Back', user_certifications_path %>
|
|
||||||
<p>
|
<p>
|
||||||
<%= link_to 'Destroy', @user_certification, :confirm => "Are you sure you want to destroy this user's certification?", :method => :delete if can? :destroy, @user_certification %>
|
<% if can? :update, @user_certification %>
|
||||||
|
<%= link_to 'Edit', edit_user_certification_path(@user_certification) %> |
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if can? :destroy, @user_certification %>
|
||||||
|
<%= link_to 'Delete', @user_certification, :confirm => "Are you sure you want to destroy this user's certification?", :method => :delete %> |
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', user_certifications_path %>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
95
app/views/users/_user_summary.html.erb
Normal file
95
app/views/users/_user_summary.html.erb
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<% user ||= @user #unless @user.blank? %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Name:</b>
|
||||||
|
<%= user.name %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<p>
|
||||||
|
<b>Email:</b>
|
||||||
|
<%= user.email %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Orientation?</b>
|
||||||
|
<%= user.orientation.strftime("%B %d %Y") unless user.orientation.blank? %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Waiver?</b>
|
||||||
|
<%= user.waiver.strftime("%B %d %Y") unless user.waiver.blank? %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>Current Member?</b>
|
||||||
|
<%= raw(user.member_status_symbol) %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<p>
|
||||||
|
<b>Desired Member Level:</b>
|
||||||
|
<%= user.member_level %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Payment Method:</b>
|
||||||
|
<%= user.payment_method %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Payee:</b>
|
||||||
|
<%= user.payee %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Phone:</b>
|
||||||
|
<%= user.phone %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
<p>
|
||||||
|
<b>Current Skills:</b>
|
||||||
|
<%= simple_format user.current_skills %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Desired Skills:</b>
|
||||||
|
<%= simple_format user.desired_skills %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Card:</b>
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<% user.cards.each do |c| %>
|
||||||
|
<%= link_to c.card_number, c %><%= "," unless c == user.cards.last %>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= unless user.cards.blank? then raw("✓") end %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<b>Certifications:</b>
|
||||||
|
<ul>
|
||||||
|
<% user.certifications.each do |certification| %>
|
||||||
|
<li><%= link_to certification.name, certification %></li>
|
||||||
|
<% end %>
|
||||||
|
<% if user.certifications.blank? %><li>n/a</li><% end %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<p>
|
||||||
|
<b>Payments:</b>
|
||||||
|
<ul>
|
||||||
|
<% user.payments.each do |payment| %>
|
||||||
|
<li><%= payment.date %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if current_user.admin? then %>
|
||||||
|
<p>
|
||||||
|
<b>Created:</b>
|
||||||
|
<%= user.created_at %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Last signed in:</b>
|
||||||
|
<%= user.current_sign_in_at %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
<% if can? :create, User %>
|
<% if can? :create, User %>
|
||||||
<%= link_to 'New User', new_user_path %>
|
<%= link_to 'New User', new_user_path %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if can? :manage, User %>
|
||||||
|
| <%= link_to 'Merge Users', users_merge_path %>
|
||||||
|
<% end %>
|
||||||
<table>
|
<table>
|
||||||
<col />
|
<col />
|
||||||
<col />
|
<col />
|
||||||
|
|||||||
48
app/views/users/merge_view.html.erb
Normal file
48
app/views/users/merge_view.html.erb
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<style type="text/css">
|
||||||
|
#user_to_merge_details, #user_to_keep_details,
|
||||||
|
#user_to_merge_details p, #user_to_keep_details p {
|
||||||
|
font-size: 12px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<h1>Merging users</h1>
|
||||||
|
|
||||||
|
<%= form_tag('/users/merge', :method => :post) do %>
|
||||||
|
<b>Everything except the email, password, name, id, hidden, and blank values will be moved to the "user to keep" UNLESS there is a value already there. The "user to merge" will be deleted.</b>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="field">
|
||||||
|
<%= label_tag :user_to_keep, "User to Keep" %><br />
|
||||||
|
<%= collection_select(:user, :to_keep, @users, :id, :name_with_email_and_visibility, :include_blank => true) %>
|
||||||
|
</div>
|
||||||
|
<div id="user_to_keep_details"></div>
|
||||||
|
</td>
|
||||||
|
<td style="font-size: 16px">◀◀</td>
|
||||||
|
<td>
|
||||||
|
<div class="field">
|
||||||
|
<%= label_tag :user_to_merge, "User to Merge" %><br />
|
||||||
|
<%= collection_select(:user, :to_merge, @users, :id, :name_with_email_and_visibility, :include_blank => true) %>
|
||||||
|
</div>
|
||||||
|
<div id="user_to_merge_details"></div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
<div class="actions">
|
||||||
|
<%= submit_tag "Merge" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', users_path %>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$("#user_to_keep").change(function(event,handler){
|
||||||
|
$("#user_to_keep_details").load("/user_summary/"+event.target.value);
|
||||||
|
});
|
||||||
|
$("#user_to_merge").change(function(event,handler){
|
||||||
|
$("#user_to_merge_details").load("/user_summary/"+event.target.value);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -108,6 +108,10 @@
|
|||||||
<b>Created:</b>
|
<b>Created:</b>
|
||||||
<%= @user.created_at %>
|
<%= @user.created_at %>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Last signed in:</b>
|
||||||
|
<%= @user.current_sign_in_at %>
|
||||||
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if can? :update, @user then %><%= link_to 'Edit', edit_user_path(@user) %> |<% end %>
|
<% if can? :update, @user then %><%= link_to 'Edit', edit_user_path(@user) %> |<% end %>
|
||||||
|
|||||||
@@ -23,3 +23,9 @@ production:
|
|||||||
database: db/production.sqlite3
|
database: db/production.sqlite3
|
||||||
pool: 5
|
pool: 5
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
|
# adapter: postgresql
|
||||||
|
# encoding: unicode
|
||||||
|
# database: members
|
||||||
|
# pool: 5
|
||||||
|
# username: postgres
|
||||||
|
# password:
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ Dooraccess::Application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
match 'user_summary/:id' => 'users#user_summary' # User summary view
|
||||||
|
match 'users/merge' => 'users#merge_view', :via => :get # Merge view
|
||||||
|
match 'users/merge' => 'users#merge_action', :via => :post # Merge action
|
||||||
resources :users
|
resources :users
|
||||||
match 'users/create' => 'users#create', :via => :post # Use POST users/create instead of POST users to avoid devise conflict
|
match 'users/create' => 'users#create', :via => :post # Use POST users/create instead of POST users to avoid devise conflict
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user