Skip to content

Commit

Permalink
Fixed a few wording issues, tweaked how users sign in / show suspende…
Browse files Browse the repository at this point in the history
…d / show approved and fixed password reset feature that Devise 3.1 broke
  • Loading branch information
scouttyg committed Dec 3, 2014
1 parent 8392a45 commit 0ba54f2
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 115 deletions.
174 changes: 87 additions & 87 deletions app/assets/javascripts/admin/admin.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,126 +9,126 @@ DENY_BTN_CSS = "btn-danger"
ALLOW_BTN_CSS = "btn-success"

$(document).ready ->
$(document).on("click", ".waiting-for-approval-users .status-action.approve", {action : APPROVE_ACTION }, act_on_user)
$(document).on("click", ".approved-users .status-action.suspend", {action : SUSPEND_ACTION }, act_on_user)
$(document).on("click", ".approved-users .status-action.activate", {action : ACTIVATE_ACTION }, act_on_user)
$(document).on("click", ".waiting-for-approval-users .status-action.approve", {action : APPROVE_ACTION }, act_on_user)
$(document).on("click", ".approved-users .status-action.suspend", {action : SUSPEND_ACTION }, act_on_user)
$(document).on("click", ".approved-users .status-action.activate", {action : ACTIVATE_ACTION }, act_on_user)

$(document).on("click", ".approved-users .admin-action.grant", { action: GRANT_ACTION }, toggleAdminOnUser)
$(document).on("click", ".approved-users .admin-action.revoke", { action: REVOKE_ACTION }, toggleAdminOnUser)
$(document).on("click", ".approved-users .admin-action.grant", { action: GRANT_ACTION }, toggleAdminOnUser)
$(document).on("click", ".approved-users .admin-action.revoke", { action: REVOKE_ACTION }, toggleAdminOnUser)

return
return

act_on_user = (obj) ->
$el = $(this)
$user = $el.closest("li")
$el = $(this)
$user = $el.closest("li")

user_id = $user.data("user-id")
action_taken = obj.data.action
user_id = $user.data("user-id")
action_taken = obj.data.action

request = $.post '/admin/update_user',
user_id: user_id
action_taken: action_taken
request = $.post '/admin/update_user',
user_id: user_id
action_taken: action_taken

request.success (data) ->
# We will set the new and old css actions depending on the action that was taken because this method
# is used by 3 different buttons
if action_taken == SUSPEND_ACTION
old_btn_class = SUSPEND_ACTION
old_css_class = DENY_BTN_CSS
new_btn_class = ALLOW_BTN_CSS
new_css_class = ACTIVATE_ACTION
else
# Approve and activate will be almost the same except for the original css class
if action_taken == ACTIVATE_ACTION
old_css_class = ACTIVATE_ACTION
else
old_css_class = APPROVE_ACTION
request.success (data) ->
# We will set the new and old css actions depending on the action that was taken because this method
# is used by 3 different buttons
if action_taken == SUSPEND_ACTION
old_btn_class = SUSPEND_ACTION
old_css_class = DENY_BTN_CSS
new_btn_class = ALLOW_BTN_CSS
new_css_class = ACTIVATE_ACTION
else
# Approve and activate will be almost the same except for the original css class
if action_taken == ACTIVATE_ACTION
old_css_class = ACTIVATE_ACTION
else
old_css_class = APPROVE_ACTION

old_btn_class = ALLOW_BTN_CSS
new_btn_class = DENY_BTN_CSS
new_css_class = SUSPEND_ACTION
old_btn_class = ALLOW_BTN_CSS
new_btn_class = DENY_BTN_CSS
new_css_class = SUSPEND_ACTION

btn_text = _.str.titleize(new_css_class)
btn_text = _.str.titleize(new_css_class)

badge_class = 'badge-success' if data.registration_status == 'active'
badge_class = 'badge-success' if data.registration_status == 'active'

$user.find(".registration-status")
.text(_.str.titleize(data.registration_status))
.removeClass('badge-success')
.addClass(badge_class)
$user.find(".registration-status")
.text(_.str.titleize(data.registration_status))
.removeClass('badge-success')
.addClass(badge_class)

# 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}")
# 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}")

# Check if the user was an approval. If so, move the user out of the waiting for approval table and add it to the approved table
if action_taken == APPROVE_ACTION
$user.remove()
$(".approved-users .users").append($user)
# Check if the user was an approval. If so, move the user out of the waiting for approval table and add it to the approved table
if action_taken == APPROVE_ACTION
$user.remove()
$(".approved-users .users").append($user)

checkList $(".waiting-for-approval-users")
checkList $(".approved-users")
checkList $(".waiting-for-approval-users")
checkList $(".approved-users")

# Show the admin row that is hidden on the waiting for approval users table
$user.find(".admin-action").show()
# Show the admin row that is hidden on the waiting for approval users table
$user.find(".admin-action").show()

return
return

request.error (data, textStatus, jqXHR) ->
alert('Something went wrong while trying to get change user status')
request.error (data, textStatus, jqXHR) ->
alert('Something went wrong while trying to get change user status')

return
return

toggleAdminOnUser = (obj) ->
$el = $(this)
$user = $el.closest("li")
$el = $(this)
$user = $el.closest("li")

user_id = $user.data("user-id")
user_id = $user.data("user-id")

action_taken = obj.data.action
# checked = $el.prop("checked");
action_taken = obj.data.action
# checked = $el.prop("checked");

full_name = $user.data("full-name")
full_name = $user.data("full-name")

# Generate the message based on the check of the user admin flag
message = if action_taken == GRANT_ACTION
"make #{full_name} an administrator?"
else
"remove #{full_name} from the administrators?"
# Generate the message based on the check of the user admin flag
message = if action_taken == GRANT_ACTION
"make #{full_name} an administrator?"
else
"remove #{full_name} from the administrators group?"

message = "Are you sure " + message
message = "Are you sure " + message

# Return if the user didnt confirm
return unless confirm(message)
# Return if the user didnt confirm
return unless confirm(message)

request = $.post '/admin/toggle_admin',
user_id: user_id
request = $.post '/admin/toggle_admin',
user_id: user_id

request.success (data) ->
if action_taken == GRANT_ACTION
action_text = "Remove from administrators"
old_class = [GRANT_ACTION, ALLOW_BTN_CSS].join ' '
new_class = [REVOKE_ACTION, DENY_BTN_CSS].join ' '
else
action_text = "Make an administrator"
old_class = [REVOKE_ACTION, DENY_BTN_CSS].join ' '
new_class = [GRANT_ACTION, ALLOW_BTN_CSS].join ' '
request.success (data) ->
if action_taken == GRANT_ACTION
action_text = "Remove from administrators"
old_class = [GRANT_ACTION, ALLOW_BTN_CSS].join ' '
new_class = [REVOKE_ACTION, DENY_BTN_CSS].join ' '
else
action_text = "Make an administrator"
old_class = [REVOKE_ACTION, DENY_BTN_CSS].join ' '
new_class = [GRANT_ACTION, ALLOW_BTN_CSS].join ' '

$el.text(action_text).removeClass(old_class).addClass(new_class)
$el.text(action_text).removeClass(old_class).addClass(new_class)

return
return

request.error (data, textStatus, jqXHR) ->
alert("Something went wrong while trying to make #{full_name} an administrator")
return
request.error (data, textStatus, jqXHR) ->
alert("Something went wrong while trying to make #{full_name} an administrator")
return

# Toggles a list item that says there are no users if needed
checkList = ($container) ->
$list = $container.find(".users")
$no_user_el = $list.find(".no-users")
$list = $container.find(".users")
$no_user_el = $list.find(".no-users")

if $list.find("li").length == 0
$list.append '<li class="no-users">There are no users. Invite others to join Kandan!</li>'
else
$no_user_el.remove()
if $list.find("li").length == 0
$list.append '<li class="no-users">There are no users. Invite others to join Kandan!</li>'
else
$no_user_el.remove()

return
return
14 changes: 10 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ 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.registration_status.waiting_approval?

redirect_to approval_path if redirect
if redirect
flash[:notice] = "Your account needs to be approved by an administrator before you can start using the Kandan app."
sign_out current_user
new_user_session_path
end
end

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

redirect_to suspended_path if redirect
if redirect
flash[:notice] = "Sorry, the administrator of this site has suspended your account."
sign_out current_user
new_user_session_path
end
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/admin/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<h3>Users waiting for approval</h3>
<ul class="users">
<%= render(:collection => @waiting_for_approval_users, :as => :user, :partial => "user") ||\
content_tag(:li, "There are no users. Invite others to join Kandan!", class: 'no-users') %>
content_tag(:li, "There are no users needing approval right now. Invite others to join Kandan!", class: 'no-users') %>
</ul>
</div>
<div class="approved-users">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p>Someone has requested a link to change your password, and you can do this through the link below.</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token) %></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
16 changes: 9 additions & 7 deletions app/views/devise/passwords/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>

<p><%= f.label :password, "New password" %><br />
<%= f.password_field :password %></p>

<p><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></p>

<p><%= f.submit "Change my password" %></p>
<div class="form-group">
<%= f.label :password, "New password", :class => "control-label" %>
<%= f.password_field :password, :class => "form-control" %>
</div>
<div class="form-group">
<%= f.label :password_confirmation, "Confirm new password", :class => "control-label" %>
<%= f.password_field :password_confirmation, :class => "form-control" %>
</div>
<p><%= f.submit "Change my password", :class => "btn btn-primary" %></p>
<% end %>

<p><%= render :partial => "devise/shared/links" %></p>
37 changes: 22 additions & 15 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@
devise_for :users, :controllers => {
:sessions => "sessions"
}
devise_scope :user do
authenticated :user do
root :to => "main#index"

root :to => "main#index"
get '/search' => "main#search"

get '/search' => "main#search"
resources :channels do
resources :activities
resources :attachments
end

resources :channels do
resources :activities
resources :attachments
end
resources :users, :only => [:index, :show]

resources :users, :only => [:index, :show]
get "/active_users" => "apis#active_users"
get "/me" => "apis#me"

get "/active_users" => "apis#active_users"
get "/me" => "apis#me"
get "/users/edit" =>"main#users_edit"

get "/users/edit" =>"main#users_edit"
namespace :admin do
root :to => "admin#index"
post "/update", :to => "admin#update", :as => "update"
post "/update_user", :to => "admin#update_user", :as => "update_user"
post "/toggle_admin", :to => "admin#toggle_admin"
end
end

namespace :admin do
root :to => "admin#index"
post "/update", :to => "admin#update", :as => "update"
post "/update_user", :to => "admin#update_user", :as => "update_user"
post "/toggle_admin", :to => "admin#toggle_admin"
unauthenticated do
root to: "sessions#new"
end
end

# Pages Controller
Expand Down

0 comments on commit 0ba54f2

Please sign in to comment.