Skip to content

Commit

Permalink
Status is now registration_status all over the app
Browse files Browse the repository at this point in the history
  • Loading branch information
gabceb committed Feb 25, 2013
1 parent 7896ffe commit f8b1a39
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/admin/admin.js.coffee
Expand Up @@ -43,7 +43,7 @@ act_on_user = (obj)->

btn_text = _.str.titleize(new_css_class)

$row.find("td.status").text(_.str.titleize(data.status))
$row.find("td.registration_status").text(_.str.titleize(data.registration_status))

# Change the look of the buttons by removing and adding classes
$el.text(btn_text).removeClass("#{old_btn_class} #{old_css_class}").addClass("#{new_btn_class} #{new_css_class}")
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/admin/admin_controller.rb
Expand Up @@ -9,7 +9,7 @@ def index
@approved_users = []

# Iterate over the array to get approved and non-approved users
@all_users.each{|user| user.status.waiting_approval? ? @waiting_for_approval_users.push(user) : @approved_users.push(user) }
@all_users.each{|user| user.registration_status.waiting_approval? ? @waiting_for_approval_users.push(user) : @approved_users.push(user) }
end

def update
Expand All @@ -30,9 +30,9 @@ def update_user

case action
when "activate", "approve"
user.status = "active"
user.registration_status = "active"
when "suspend"
user.status = "suspended"
user.registration_status = "suspended"
end

user.save! if user.changed?
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Expand Up @@ -6,14 +6,14 @@ class ApplicationController < ActionController::Base

def force_approved_account
# We will redirect to the approval page if a user is signed in, is not an admin and is marked as waiting for approval
redirect = user_signed_in? && !current_user.is_admin? && current_user.status.waiting_approval?
redirect = user_signed_in? && !current_user.is_admin? && current_user.registration_status.waiting_approval?

redirect_to approval_path if redirect
end

def redirect_suspended_account
# We will redirect to suspended if a user is singed in and its marked as suspended
redirect = user_signed_in? && current_user.status.suspended?
redirect = user_signed_in? && current_user.registration_status.suspended?

redirect_to suspended_path if redirect
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/pages_controller.rb
Expand Up @@ -6,11 +6,11 @@ class PagesController < ApplicationController
skip_filter :redirect_suspended_account, :only => :suspended

def approval
redirect_to(root_path) && return unless current_user.status.waiting_approval?
redirect_to(root_path) && return unless current_user.registration_status.waiting_approval?
end

def suspended
redirect_to(root_path) && return unless current_user.status.suspended?
redirect_to(root_path) && return unless current_user.registration_status.suspended?
end

def about
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/admin/admin_helper.rb
@@ -1,12 +1,12 @@
module Admin::AdminHelper
def user_status user
"<div class='#{user.status}'>#{user.status.titlecase}</div>".html_safe
def user_registration_status user
"<div class='#{user.registration_status}'>#{user.registration_status.titlecase}</div>".html_safe
end

def user_action user
action, css = if user.status.waiting_approval?
action, css = if user.registration_status.waiting_approval?
["Approve", "btn-success"]
elsif user.status.suspended?
elsif user.registration_status.suspended?
["Activate", "btn-success"]
else
["Suspend", "btn-danger"]
Expand Down
12 changes: 6 additions & 6 deletions app/models/user.rb
Expand Up @@ -2,12 +2,12 @@ class User < ActiveRecord::Base
extend Enumerize

# Being pesimistic here and making the default waiting for approval for security reasons
enumerize :status, in: [:active, :suspended, :waiting_approval], :default => :waiting_approval
enumerize :registration_status, in: [:active, :suspended, :waiting_approval], :default => :waiting_approval

has_many :activities
before_save :ensure_authentication_token
before_save :ensure_gravatar_hash
before_create :mark_status_depending_on_app_settings
before_create :mark_registration_status_depending_on_app_settings

after_create :ensure_at_least_one_admin
after_destroy :ensure_at_least_one_admin
Expand All @@ -21,7 +21,7 @@ class User < ActiveRecord::Base
devise devise *Kandan.devise_modules

# Setup accessible (or protected) attributes for your model
attr_accessible :id, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :locale, :gravatar_hash, :status
attr_accessible :id, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :locale, :gravatar_hash, :registration_status

def full_name
"#{self.first_name.to_s} #{self.last_name.to_s}".titlecase
Expand All @@ -38,10 +38,10 @@ def cloudfuji_extra_attributes(extra_attributes)
self.locale = extra_attributes["locale"]
end

# Callback to mark the user status depending on the settings of the app
def mark_status_depending_on_app_settings
# Callback to mark the user registration status depending on the settings of the app
def mark_registration_status_depending_on_app_settings
# If the site is public we will make the user active. Otherwise we will make the user as waiting_approval
self.status = Setting.my_settings.public_site? ? :active : :waiting_approval
self.registration_status = Setting.my_settings.public_site? ? :active : :waiting_approval
end

def ensure_gravatar_hash
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/admin/_user_table.html.erb
Expand Up @@ -27,7 +27,7 @@
<%= user.email %>
</td>
<td class="status">
<%= user_status(user) %>
<%= user_registration_status(user) %>
</td>
<td class="action">
<%= user_action(user) %>
Expand Down
6 changes: 4 additions & 2 deletions db/migrate/20130224150724_add_status_as_default_for_users.rb
@@ -1,9 +1,11 @@
class AddStatusAsDefaultForUsers < ActiveRecord::Migration
def up
change_column :users, :status, :string, :default => "active"
rename_column :users, :status, :registration_status
change_column :users, :registration_status, :string, :default => "active"
end

def down
change_column :users, :status, :string, :default => nil
change_column :users, :registration_status, :string, :default => nil
rename_column :users, :registration_status, :status
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -78,7 +78,7 @@
t.boolean "active", :default => true
t.string "username"
t.boolean "is_admin"
t.string "status", :default => "active"
t.string "registration_status", :default => "active"
end

add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true
Expand Down

0 comments on commit f8b1a39

Please sign in to comment.