Implemented to switch back to old user.

This commit is contained in:
Martin Edenhofer 2014-09-15 22:55:06 +02:00
parent 00ac0636a0
commit ec18cbd58b
7 changed files with 118 additions and 14 deletions

View file

@ -23,6 +23,7 @@ class Index extends App.Controller
switchTo = (id,e) => switchTo = (id,e) =>
e.preventDefault() e.preventDefault()
@disconnectClient() @disconnectClient()
$('#app').hide().attr('style', 'display: none!important')
App.Auth._logout() App.Auth._logout()
window.location = App.Config.get('api_path') + '/sessions/switch/' + id window.location = App.Config.get('api_path') + '/sessions/switch/' + id

View file

@ -0,0 +1,37 @@
class Widget extends App.Controller
events:
'click .close': 'switchBack'
constructor: ->
super
# start widget
@bind 'app:ready', =>
@render()
# remove widget
@bind 'auth:logout', =>
App.Config.set('switch_back_to_possible', false)
@render()
render: (user) ->
# if no switch to user is active
if !App.Config.get('switch_back_to_possible') || _.isEmpty( App.Session.all() )
@el.html('')
$('#app').removeClass('switch-back-to-user-space')
return
# show switch back widget
@html App.view('widget/switch_back_to_user')()
$('#app').addClass('switch-back-to-user-space')
switchBack: (e) =>
e.preventDefault()
@disconnectClient()
$('#app').hide().attr('style', 'display: none!important')
App.Auth._logout()
window.location = App.Config.get('api_path') + '/sessions/switch_back'
App.Config.set( 'switch_back_to_user', Widget, 'Widgets' )

View file

@ -0,0 +1,4 @@
<div class="switch-back-to-user fit">
<%- @T('Zammad looks like this for "%s"', @S('firstname') + ' ' + @S('lastname') ) %>
<a href="#" class="close icon "></a>
</div>

View file

@ -1922,7 +1922,7 @@ footer {
.sidebar { .sidebar {
width: 32%; width: 32%;
max-width: 300px; max-width: 300px;
padding: 20px; padding: 8px 20px 20px 20px;
background: white; background: white;
border-right: 1px solid #e6e6e6; border-right: 1px solid #e6e6e6;
overflow: auto; overflow: auto;
@ -2186,7 +2186,7 @@ footer {
.activity-avatar { .activity-avatar {
padding-top: 16px; padding-top: 16px;
padding-left: 14px; padding-left: 2px;
padding-right: 2px; padding-right: 2px;
margin-right: 10px; margin-right: 10px;
} }
@ -2196,7 +2196,7 @@ footer {
.activity-body { .activity-body {
color: #444a4f; color: #444a4f;
padding: 16px 26px 16px 2px; padding: 16px 0 16px 2px;
position: relative; position: relative;
} }
@ -2219,7 +2219,7 @@ footer {
} }
.activity-message { .activity-message {
padding-right: 20px; padding-right: 0;
} }
.activity-time { .activity-time {
@ -3114,6 +3114,19 @@ footer {
display: block; display: block;
} }
.switch-back-to-user {
position: absolute;
background-color: #389ed9;
color: #fff;
height: 34px;
z-index: 1;
padding: 8px 9px;
top: -34px;
}
.switch-back-to-user-space {
top: 34px;
}
/* /*
---------------- ----------------
@ -3123,7 +3136,7 @@ footer {
*/ */
@media only screen and (max-width: 1280px) { @media only screen and (max-width: 1280px) {
.sidebar-optional.sidebar { .sidebar.optional {
display: none; display: none;
} }
} }

View file

@ -246,7 +246,11 @@ class ApplicationController < ActionController::Base
config['timezones'][ t.name ] = diff config['timezones'][ t.name ] = diff
} }
return config if session[:switched_from_user_id]
config['switch_back_to_possible'] = true
end
config
end end
# model helper # model helper

View file

@ -5,6 +5,9 @@ class SessionsController < ApplicationController
# "Create" a login, aka "log the user in" # "Create" a login, aka "log the user in"
def create def create
# in case, remove switched_from_user_id
session[:switched_from_user_id] = nil
# authenticate user # authenticate user
user = User.authenticate( params[:username], params[:password] ) user = User.authenticate( params[:username], params[:password] )
@ -128,6 +131,10 @@ class SessionsController < ApplicationController
end end
def create_omniauth def create_omniauth
# in case, remove switched_from_user_id
session[:switched_from_user_id] = nil
auth = request.env['omniauth.auth'] auth = request.env['omniauth.auth']
if !auth if !auth
@ -158,6 +165,10 @@ class SessionsController < ApplicationController
end end
def create_sso def create_sso
# in case, remove switched_from_user_id
session[:switched_from_user_id] = nil
user = User.sso(params) user = User.sso(params)
# Log the authorizing user in. # Log the authorizing user in.
@ -199,6 +210,9 @@ class SessionsController < ApplicationController
return false return false
end end
# remember old user
session[:switched_from_user_id] = current_user.id
# log new session # log new session
user.activity_stream_log( 'switch to', current_user.id, true ) user.activity_stream_log( 'switch to', current_user.id, true )
@ -208,6 +222,36 @@ class SessionsController < ApplicationController
redirect_to '/#' redirect_to '/#'
end end
# "switch" back to user
def switch_back_to_user
# check if it's a swich back
if !session[:switched_from_user_id]
response_access_deny
return false
end
user = User.lookup( :id => session[:switched_from_user_id] )
if !user
render(
:json => {},
:status => :not_found
)
return false
end
# log end session
current_user.activity_stream_log( 'ended switch to', user.id, true )
# remove switched_from_user_id
session[:switched_from_user_id] = nil
# set old session user again
current_user_set(user)
redirect_to '/#'
end
def list def list
return if deny_if_not_role('Admin') return if deny_if_not_role('Admin')
assets = {} assets = {}

View file

@ -2,7 +2,7 @@ Zammad::Application.routes.draw do
api_path = Rails.configuration.api_path api_path = Rails.configuration.api_path
# omniauth # omniauth
match '/auth/:provider/callback', :to => 'sessions#create_omniauth',:via => [:post, :get, :puts, :delete] match '/auth/:provider/callback', :to => 'sessions#create_omniauth', :via => [:post, :get, :puts, :delete]
# sso # sso
match '/auth/sso', :to => 'sessions#create_sso', :via => [:post, :get] match '/auth/sso', :to => 'sessions#create_sso', :via => [:post, :get]
@ -13,6 +13,7 @@ Zammad::Application.routes.draw do
match api_path + '/signout', :to => 'sessions#destroy', :via => [:get, :delete] match api_path + '/signout', :to => 'sessions#destroy', :via => [:get, :delete]
match api_path + '/sessions/switch/:id', :to => 'sessions#switch_to_user', :via => :get match api_path + '/sessions/switch/:id', :to => 'sessions#switch_to_user', :via => :get
match api_path + '/sessions/switch_back', :to => 'sessions#switch_back_to_user', :via => :get
match api_path + '/sessions', :to => 'sessions#list', :via => :get match api_path + '/sessions', :to => 'sessions#list', :via => :get
match api_path + '/sessions/:id', :to => 'sessions#delete', :via => :delete match api_path + '/sessions/:id', :to => 'sessions#delete', :via => :delete