VRFS-1576 error handling; referral page; new admin menu
This commit is contained in:
parent
c81e581786
commit
6ee83f8dcc
|
|
@ -0,0 +1,31 @@
|
||||||
|
ActiveAdmin.register JamRuby::User, :as => 'Referrals' do
|
||||||
|
|
||||||
|
menu :label => 'Referrals', :parent => 'Affiliates'
|
||||||
|
|
||||||
|
config.batch_actions = false
|
||||||
|
config.clear_action_items!
|
||||||
|
config.filters = false
|
||||||
|
|
||||||
|
index do
|
||||||
|
column 'User' do |oo| link_to(oo.name, "http://www.jamkazam.com/client#/profile/#{oo.id}", {:title => oo.name}) end
|
||||||
|
column 'Email' do |oo| oo.email end
|
||||||
|
column 'Created' do |oo| oo.created_at end
|
||||||
|
column 'Partner' do |oo| oo.affiliate_referral.partner_name end
|
||||||
|
end
|
||||||
|
|
||||||
|
controller do
|
||||||
|
|
||||||
|
def scoped_collection
|
||||||
|
rel = end_of_association_chain
|
||||||
|
.includes([:affiliate_referral])
|
||||||
|
.order('created_at DESC')
|
||||||
|
if (ref_id = params[AffiliatePartner::PARAM_REFERRAL]).present?
|
||||||
|
qq = ['affiliate_referral_id = ?', ref_id]
|
||||||
|
else
|
||||||
|
qq = ['affiliate_referral_id IS NOT NULL']
|
||||||
|
end
|
||||||
|
@users ||= rel.where(qq)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
ActiveAdmin.register JamRuby::AffiliatePartner, :as => 'Affiliates' do
|
||||||
|
|
||||||
|
menu :label => 'Partners', :parent => 'Affiliates'
|
||||||
|
|
||||||
|
config.sort_order = 'created_at DESC'
|
||||||
|
config.batch_actions = false
|
||||||
|
# config.clear_action_items!
|
||||||
|
config.filters = false
|
||||||
|
|
||||||
|
form :partial => 'form'
|
||||||
|
|
||||||
|
index do
|
||||||
|
column 'User' do |oo| link_to(oo.partner_user.name, "http://www.jamkazam.com/client#/profile/#{oo.partner_user.id}", {:title => oo.partner_user.name}) end
|
||||||
|
column 'Email' do |oo| oo.partner_user.email end
|
||||||
|
column 'Name' do |oo| oo.partner_name end
|
||||||
|
column 'Code' do |oo| oo.partner_code end
|
||||||
|
column 'Referral Count' do |oo| oo.referral_user_count end
|
||||||
|
# column 'Referrals' do |oo| link_to('View', admin_referrals_path(AffiliatePartner::PARAM_REFERRAL => oo.id)) end
|
||||||
|
default_actions
|
||||||
|
end
|
||||||
|
|
||||||
|
controller do
|
||||||
|
|
||||||
|
def show
|
||||||
|
redirect_to admin_referrals_path(AffiliatePartner::PARAM_REFERRAL => resource.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
obj = AffiliatePartner.create_with_params(params[:jam_ruby_affiliate_partner])
|
||||||
|
if obj.errors.present?
|
||||||
|
set_resource_ivar(obj)
|
||||||
|
render active_admin_template('new')
|
||||||
|
else
|
||||||
|
redirect_to admin_affiliates_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
obj = resource
|
||||||
|
vals = params[:jam_ruby_affiliate_partner]
|
||||||
|
obj.partner_name = vals[:partner_name]
|
||||||
|
obj.user_email = vals[:user_email] if vals[:user_email].present?
|
||||||
|
obj.save!
|
||||||
|
redirect_to admin_affiliates_path
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
class AdminAuthorization < ActiveAdmin::AuthorizationAdapter
|
class AdminAuthorization < ActiveAdmin::AuthorizationAdapter
|
||||||
|
|
||||||
def authorized?(action, subject = nil)
|
def authorized?(action, subject = nil)
|
||||||
subject.is_a?(EmailBatch) && :update == action ? subject.can_run_batch? : true
|
if subject.is_a?(EmailBatch) && :update == action
|
||||||
|
subject.can_run_batch?
|
||||||
|
elsif subject.is_a?(AffiliatePartner) && :destroy == action
|
||||||
|
false
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<%= semantic_form_for([:admin, resource], :url => resource.new_record? ? admin_affiliates_path : "/admin/affiliates/#{resource.id}") do |f| %>
|
||||||
|
<%= f.semantic_errors *f.object.errors.keys %>
|
||||||
|
<%= f.inputs do %>
|
||||||
|
<%= f.input(:user_email, :input_html => {:maxlength => 255}) %>
|
||||||
|
<%= f.input(:partner_name, :input_html => {:maxlength => 128}) %>
|
||||||
|
<% if resource.new_record? %>
|
||||||
|
<%= f.input(:partner_code, :input_html => {:maxlength => 128}) %>
|
||||||
|
<% else %>
|
||||||
|
<%= f.input(:partner_code, :input_html => {:maxlength => 128, :readonly => 'readonly'}) %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<%= f.actions %>
|
||||||
|
<% end %>
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
class JamRuby::AffiliatePartner < ActiveRecord::Base
|
class JamRuby::AffiliatePartner < ActiveRecord::Base
|
||||||
has_one :partner_user, :class_name => "JamRuby::User", :foreign_key => :partner_user_id
|
belongs_to :partner_user, :class_name => "JamRuby::User", :foreign_key => :partner_user_id
|
||||||
has_many :user_referrals, :class_name => "JamRuby::User", :foreign_key => :affiliate_referral_id
|
has_many :user_referrals, :class_name => "JamRuby::User", :foreign_key => :affiliate_referral_id
|
||||||
|
|
||||||
attr_accessible :partner_name, :partner_code, :partner_user_id
|
attr_accessible :partner_name, :partner_code, :partner_user_id
|
||||||
|
|
||||||
|
PARAM_REFERRAL = :ref
|
||||||
|
PARAM_COOKIE = :affiliate_ref
|
||||||
|
|
||||||
PARTNER_CODE_REGEX = /^[#{Regexp.escape('abcdefghijklmnopqrstuvwxyz0123456789-._+,')}]+{2,128}$/i
|
PARTNER_CODE_REGEX = /^[#{Regexp.escape('abcdefghijklmnopqrstuvwxyz0123456789-._+,')}]+{2,128}$/i
|
||||||
|
|
||||||
validates :user_email, format: {with: JamRuby::User::VALID_EMAIL_REGEX}, :if => :user_email
|
validates :user_email, format: {with: JamRuby::User::VALID_EMAIL_REGEX}, :if => :user_email
|
||||||
|
|
@ -17,7 +20,7 @@ class JamRuby::AffiliatePartner < ActiveRecord::Base
|
||||||
oo.partner_code = params[:partner_code].try(:strip)
|
oo.partner_code = params[:partner_code].try(:strip)
|
||||||
oo.partner_user = User.where(:email => params[:user_email].try(:strip)).limit(1).first
|
oo.partner_user = User.where(:email => params[:user_email].try(:strip)).limit(1).first
|
||||||
oo.partner_user_id = oo.partner_user.try(:id)
|
oo.partner_user_id = oo.partner_user.try(:id)
|
||||||
oo.save!
|
oo.save
|
||||||
oo
|
oo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,17 @@ class ApplicationController < ActionController::Base
|
||||||
# inject username/email into bugsnag data
|
# inject username/email into bugsnag data
|
||||||
before_bugsnag_notify :add_user_info_to_bugsnag
|
before_bugsnag_notify :add_user_info_to_bugsnag
|
||||||
|
|
||||||
def affiliate_code
|
before_filter do
|
||||||
cookies[:affiliate_code]
|
if current_user.nil?
|
||||||
|
if (code = params[AffiliatePartner::PARAM_REFERRAL]).present? &&
|
||||||
|
cookies[AffiliatePartner::PARAM_COOKIE].blank?
|
||||||
|
cookies[AffiliatePartner::PARAM_COOKIE] = code
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def affiliate_code=(code)
|
def affiliate_code
|
||||||
cookies[:affiliate_code] = code if code.present?
|
cookies[AffiliatePartner::PARAM_COOKIE]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue