diff options
author | azul <azul@leap.se> | 2015-10-19 11:15:17 +0200 |
---|---|---|
committer | azul <azul@leap.se> | 2015-10-19 11:15:17 +0200 |
commit | c2cc1a48a4faeff4088cdf5f56e6b0382acfb346 (patch) | |
tree | 33b41304f30166182af2ff989b20d43efd75f183 | |
parent | fd55d71cd1cbadcc5378601c0c9dfa6292bd4725 (diff) | |
parent | 02c1e607bf8beb1f576307a7ad87f0cdbe3381c0 (diff) |
Merge pull request #196 from EvyW/develop
Admin - Ability to enable/disable user
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 7 | ||||
-rw-r--r-- | app/assets/stylesheets/leap.scss | 3 | ||||
-rw-r--r-- | app/controllers/sessions_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 6 | ||||
-rw-r--r-- | app/views/users/_user.html.haml | 34 | ||||
-rw-r--r-- | app/views/users/index.html.haml | 3 | ||||
-rw-r--r-- | config/locales/en/users.en.yml | 9 | ||||
-rw-r--r-- | config/locales/es.yml | 8 | ||||
-rw-r--r-- | test/functional/users_controller_test.rb | 1 |
10 files changed, 74 insertions, 7 deletions
@@ -79,6 +79,7 @@ end group :test, :development do gem 'thin' gem 'i18n-missing_translations' + gem 'pry' end group :production do diff --git a/Gemfile.lock b/Gemfile.lock index 5ffb0c8..894e062 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -159,6 +159,7 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) metaclass (0.0.4) + method_source (0.8.2) mime-types (1.25.1) mini_portile (0.6.1) minitest-stub-const (0.2) @@ -176,6 +177,10 @@ GEM multi_json (~> 1.0) websocket-driver (>= 0.2.0) polyglot (0.3.5) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) quiet_assets (1.0.3) railties (>= 3.1, < 5.0) rack (1.4.5) @@ -227,6 +232,7 @@ GEM rack (~> 1.4) rack-protection (~> 1.4) tilt (~> 1.3, >= 1.3.4) + slop (3.6.0) sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) @@ -295,6 +301,7 @@ DEPENDENCIES mocha (~> 0.13.0) phantomjs-binaries poltergeist + pry quiet_assets rails (~> 3.2.21) rails-i18n diff --git a/app/assets/stylesheets/leap.scss b/app/assets/stylesheets/leap.scss index dddcc1a..9fe2195 100644 --- a/app/assets/stylesheets/leap.scss +++ b/app/assets/stylesheets/leap.scss @@ -307,3 +307,6 @@ html, body { margin: 0 2px; } } +.modal-footer form{ + margin: 0; +} diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 66eba40..34d4f53 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -32,4 +32,13 @@ class SessionsController < ApplicationController # throw :warden, response.finish #end + Warden::Manager.after_set_user do |user, auth, opts| + scope = opts[:scope] + unless user.enabled? + auth.logout(scope) + throw(:warden, scope: scope, reason: "User not active") + end + end + + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3943afc..446b726 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -49,13 +49,15 @@ class UsersController < ApplicationController def deactivate @user.enabled = false @user.save - respond_with @user + flash[:notice] = I18n.t("actions.user_disabled_message", username: @user.username) + redirect_to :back end def enable @user.enabled = true @user.save - respond_with @user + flash[:notice] = I18n.t("actions.user_enabled_message", username: @user.username) + redirect_to :back end def destroy diff --git a/app/views/users/_user.html.haml b/app/views/users/_user.html.haml index 583d22f..1cabcf5 100644 --- a/app/views/users/_user.html.haml +++ b/app/views/users/_user.html.haml @@ -1,4 +1,32 @@ %tr - %td= link_to user.login, user - %td= l(user.created_at, :format => :short) - %td= l(user.updated_at, :format => :short) + %td + = link_to user.username, user + %td + = user.created_at.strftime("%d %b, %Y, %H:%M") + %td + = user.updated_at.strftime("%d %b, %Y, %H:%M") + %td + - if user.enabled + %button.btn.btn-default{:"data-toggle" => "modal", :"data-target" => "#user-form-#{user.id}", :type => "button"} + = t("actions.disable_user") + .modal.fade.hide{:id => "user-form-#{user.id}"} + .modal-dialog + .modal-content + .modal-header + %button.close{:"data-dismiss" => "modal"} × + = t("actions.confirm_user_deactivation", username: user.username) + .modal-footer + = form_tag deactivate_user_path(user) do + %input.btn.btn-default.btn-danger{:type => "submit", :value => "#{t("actions.disable_user")}"} + - else + %button.btn.btn-default{:"data-toggle" => "modal", :"data-target" => "#user-form-#{user.id}", :type => "button"} + = t("actions.enable_user") + .modal.fade.hide{:id => "user-form-#{user.id}"} + .modal-dialog + .modal-content + .modal-header + %button.close{:"data-dismiss" => "modal"} × + = t("actions.confirm_user_activation", username: user.username) + .modal-footer + = form_tag enable_user_path(user) do + %input.btn.btn-default.btn-danger{:type => "submit", :value => "#{t("actions.enable_user")}"} diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml index 3ed8835..e1136d8 100644 --- a/app/views/users/index.html.haml +++ b/app/views/users/index.html.haml @@ -1,4 +1,5 @@ - @show_navigation = false = search :users -= table @users, %w(username, created, updated) += table @users, %w(username, created, updated, actions.toggle_user) + diff --git a/config/locales/en/users.en.yml b/config/locales/en/users.en.yml index 4c6bbc0..bc8c19d 100644 --- a/config/locales/en/users.en.yml +++ b/config/locales/en/users.en.yml @@ -57,6 +57,14 @@ en: tickets: "Create and check support tickets." email: "Modify email settings." account: "Destroy your account." + actions: + toggle_user: "Enable / Disable User" + enable_user: "Enable User" + disable_user: "Disable User" + confirm_user_deactivation: "Are you sure you want to deactive user with username '%{username}'?" + confirm_user_activation: "Are you sure you want to activate user with username '%{username}'?" + user_disabled_message: "User with username '%{username}' has been disabled." + user_enabled_message: "User with username '%{username}' has been enabled." # # rails @@ -78,4 +86,3 @@ en: placeholders: user: email_forward: "my_other_email@domain.net" - diff --git a/config/locales/es.yml b/config/locales/es.yml index 2a36b6e..f745257 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -110,6 +110,14 @@ es: user: one: Usuario other: '%{count} usuarios' + actions: + toggle_user: "Activar / Desactivar Usuario" + enable_user: "Activar Usuario" + disable_user: "Desactivar Usuario" + confirm_user_deactivation: "Estás seguro que quieres desactivar al usuario con nombre '%{username}'?" + confirm_user_activation: "Estás seguro que quieres activar al usuario con nombre '%{username}'?" + user_disabled_message: "Usuario con nombre '%{username}' ha sido desactivado." + user_enabled_message: "Usuario con nombre '%{username}' ha sido activado." create_new_customer: Crear un nuevo Cliente de Braintree must_create_customer: Tiene que almacenar un cliente en Braintree antes de suscribirse a un plan subscribe: Suscribirse diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 7d1745c..70f483e 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -158,6 +158,7 @@ class UsersControllerTest < ActionController::TestCase login :is_admin? => true + @request.env['HTTP_REFERER'] = 'http://test.com/sessions/new' post :deactivate, :id => user.id assert !assigns(:user).enabled? end |