summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorazul <azul@leap.se>2015-10-19 11:15:17 +0200
committerazul <azul@leap.se>2015-10-19 11:15:17 +0200
commitc2cc1a48a4faeff4088cdf5f56e6b0382acfb346 (patch)
tree33b41304f30166182af2ff989b20d43efd75f183 /app
parentfd55d71cd1cbadcc5378601c0c9dfa6292bd4725 (diff)
parent02c1e607bf8beb1f576307a7ad87f0cdbe3381c0 (diff)
Merge pull request #196 from EvyW/develop
Admin - Ability to enable/disable user
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/leap.scss3
-rw-r--r--app/controllers/sessions_controller.rb9
-rw-r--r--app/controllers/users_controller.rb6
-rw-r--r--app/views/users/_user.html.haml34
-rw-r--r--app/views/users/index.html.haml3
5 files changed, 49 insertions, 6 deletions
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)
+