Skip to content

Commit 9c08223

Browse files
committed
Rake Task and UI changes
- Add rake task to check and update user status to Subscribe and Unsubscribed - UI fix the navigation bar, paignation and button alignments - Fix the rake task for Blocked users and web subscription status
1 parent 0e6bf7b commit 9c08223

File tree

6 files changed

+109
-22
lines changed

6 files changed

+109
-22
lines changed

app/assets/stylesheets/light/home.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,25 @@
22
Place all the styles related to the matching controller here.
33
They will automatically be included in application.css.
44
*/
5+
6+
.badge-users-count {
7+
margin-top: 10px;
8+
}
9+
10+
.btn-mail {
11+
margin-top: 5px;
12+
}
13+
14+
#users_per_page {
15+
width: 50px;
16+
height: 30px;
17+
}
18+
19+
#searchbox {
20+
height: 30px;
21+
}
22+
23+
.brand {
24+
font-weight: bold !important;
25+
margin-top: 5px !important;
26+
}

app/controllers/light/users_controller.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,16 @@ def auto_opt_in
111111
def opt_in
112112
@user = Light::User.where(email_id: params[:email]).first
113113
if @user.present?
114-
if @user.is_subscribed.eql?(false)
115-
Light::UserMailer.auto_opt_in(@user.email_id, @user.slug, @user.token).deliver
116-
#send email
117-
end
114+
@user.update_attributes(is_subscribed: true,
115+
sidekiq_status: 'Subscribed',
116+
subscribed_at: DateTime.now)
118117
else
119118
u_name = params[:username].blank? ? params[:email] : params[:username]
120-
@user= Light::User.new(username: u_name,
121-
email_id: params[:email],
122-
source: 'web subscription request',
123-
sidekiq_status: 'new user')
124-
if @user.save
125-
Light::UserMailer.auto_opt_in(@user.email_id, @user.slug, @user.token).deliver
126-
end
119+
@user = Light::User.new(username: u_name,
120+
email_id: params[:email],
121+
source: 'web subscription request',
122+
subscribed_at: DateTime.now,
123+
sidekiq_status: 'Subscribed')
127124
end
128125
respond_to do |format|
129126
format.json { head :no_content }

app/models/light/user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class User
3939
end
4040
end
4141

42-
scope :subscribed_users, -> { where is_subscribed: true }
43-
scope :unsubscribed_users, -> { where is_subscribed: false }
42+
scope :subscribed_users, -> { where(is_subscribed: true, sidekiq_status: 'Subscribed') }
43+
scope :unsubscribed_users, -> { where(is_subscribed: false, sidekiq_status: 'Unsubscribed') }
4444
scope :new_users, -> { where(is_subscribed: false, sidekiq_status: NEW_USER) }
4545
scope :blocked_users, -> { where(is_subscribed: false, sidekiq_status: 'Block') }
4646
scope :bounced_users, -> { where(is_subscribed: false, sidekiq_status: 'Bounced') }

app/views/light/newsletters/_top_navbar.html.haml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= nav_bar :brand => "Newsletters", :responsive => true, :static => :top, :fluid => :true do
1+
= nav_bar :brand => 'Newsletters', :responsive => true, :static => :top, :fluid => :true do
22
= menu_group do
33
= menu_item "Add Newsletter", new_newsletter_path
44
= menu_item "Opt in letters", opt_in_newsletters_path
@@ -10,6 +10,7 @@
1010

1111
= menu_item "Show Users", users_path, ({:method => 'get'} if params[:controller] == 'light/users' && params[:action].in?(['new', 'create']))
1212
= menu_group :pull => :right do
13-
= content_tag :a, "Send Mail", :href => sendmailer_path, :class => 'btn btn-danger', :data => { :confirm => 'Are you sure ?'}
14-
= content_tag :a, "Test Mail", :href => testmail_path, :class => "btn btn-success"
13+
.btn-mail
14+
= content_tag :a, "Send Mail", :href => sendmailer_path, :class => 'btn btn-danger', :data => { :confirm => 'Are you sure ?'}
15+
= content_tag :a, "Test Mail", :href => testmail_path, :class => 'btn btn-success'
1516
%br

app/views/light/users/index.html.haml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
%option{:value => 'Opt in mail sent'} Opt in Mail Sent: #{Light::User.opt_in_users.count}
2525

2626
%ul.nav.navbar-nav.pull-right
27-
%li
28-
%h5= raw ("Subscribers: #{badge(Light::User.subscribed_users.count)}")
27+
%li.badge-users-count
28+
%h5= raw ("Subscribed users: #{badge(Light::User.subscribed_users.count)}")
2929

30-
%li
30+
%li.badge-users-count
3131
%h5= raw ("New users: #{badge(Light::User.new_users.count)}")
3232

3333
.row
@@ -55,13 +55,13 @@
5555

5656
%a{ :href => "/newsletter/users/{{_id.$oid}}", data:{ :confirm => 'Are you sure?', method: 'delete'}, :class => 'btn btn-sm btn-danger' } Delete
5757

58-
.col-lg-12.padding_none.text-center
58+
.col-lg-12.padding_none.pull-right
5959
#user_pagination.col-lg-12
6060
.col-lg-6.content
6161

6262
:javascript
6363
var users_data = #{@users.to_json}
6464
var total_count = #{@users.count}
65-
$('#searchbox').css('height',30)
66-
$('.per-page').css('width',90)
6765
initialize_filterjs_table('#users tbody', users_data, '#user-template', '', [], '#user_pagination', '#users_per_page')
66+
$('.per-page').css('width',90)
67+
$('.per-page').css('height',30)

lib/tasks/update_user_status.rake

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace :light do
2+
desc 'Checking and updating the User status (Subscribed and Unsubscribed)'
3+
task :update_user_status => :environment do
4+
5+
print "\n\n Update the flag is_subscribed for status: "
6+
['Bounced', 'Spam', 'Opt in mail sent', 'Invalid'].each do |status|
7+
print "\n #{status} : "
8+
print Light::User.where(sidekiq_status: status)
9+
.update_all(is_subscribed: false)[:n]
10+
# Keeping is_blocked as is, because we have code sit in there depending on it.
11+
end
12+
13+
print "\n\n Fix the data for Blocked Users : "
14+
print "\n Update flags for Block user : "
15+
print Light::User.where(sidekiq_status: 'Block')
16+
.update_all(is_subscribed: false, is_blocked: true)[:n]
17+
18+
print "\n Update status for new_users who are blocked : "
19+
print Light::User.where(is_subscribed: false, sidekiq_status: 'new user', is_blocked: true)
20+
.update_all(sidekiq_status: 'Block')[:n]
21+
22+
23+
print "\n\n Update one who dones't have sidekiq_status : "
24+
print "\n Unsubscribed : "
25+
print Light::User.where(is_subscribed: false, sidekiq_status: nil, :is_blocked.in => [false, nil])
26+
.update_all(sidekiq_status: 'Unsubscribed', unsubscribed_at: DateTime.now)[:n]
27+
28+
print "\n Block (is_subscribed: false) : "
29+
print Light::User.where(is_subscribed: false, is_blocked: true, sidekiq_status: nil)
30+
.update_all(sidekiq_status: 'Block')[:n]
31+
32+
print "\n Block (is_subscribed: true) : "
33+
print Light::User.where(is_subscribed: true, is_blocked: true, sidekiq_status: nil)
34+
.update_all(is_subscribed: false, sidekiq_status: 'Block')[:n]
35+
36+
print "\n Subscribed : "
37+
print Light::User.where(is_subscribed: true, sidekiq_status: nil)
38+
.update_all(sidekiq_status: 'Subscribed')[:n]
39+
40+
print "\n\n Updated flag value for is_blocked: nil to flase : "
41+
print Light::User.where(is_blocked: nil)
42+
.update_all(is_blocked: false)[:n]
43+
44+
print "\n\n Updated Status for Web Subscription Request : "
45+
print Light::User.where(sidekiq_status: 'web subscription request')
46+
.update_all(source: 'web subscription request',
47+
is_subscribed: false,
48+
sidekiq_status: 'Unsubscribed',
49+
unsubscribed_at: DateTime.now)[:n]
50+
51+
def check_status(status)
52+
Light::User.where(sidekiq_status: status).count
53+
end
54+
55+
# Status wise count of User
56+
print "\n\n Total no of User Status : " +
57+
"\n Subscribed : #{check_status('Subscribed')}" +
58+
"\n Unsubscribed : #{check_status('Unsubscribed')}" +
59+
"\n New User : #{check_status('new user')}" +
60+
"\n Invalid : #{check_status('Invalid')}" +
61+
"\n Spam : #{check_status('Spam')}" +
62+
"\n Blocked : #{check_status('Block')}" +
63+
"\n Bounced : #{check_status('Bounced')}" +
64+
"\n Opt in User: #{check_status('Opt in mail sent')} \n\n"
65+
end
66+
end
67+

0 commit comments

Comments
 (0)