-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.rb
28 lines (25 loc) · 980 Bytes
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'redmine'
require_dependency 'application_controller'
class ApplicationController < ActionController::Base
unloadable
before_filter :_enable_session_from_redmine_plugin
alias_method :logout_user_without_spectator, :logout_user
def logout_user
session[:spectator] = nil
logout_user_without_spectator
end
protected
def _enable_session_from_redmine_plugin
request = instance_variable_get(:@_request)
Redmine::Plugin.send(:define_method, "spectator_id", proc {request.session[:spectator_id]})
end
end
Redmine::Plugin.register :spectator do
name 'Spectator plugin'
author 'Alexey Pisarenko'
description 'Plugin for logging as another user'
version '0.0.2'
url 'https://github.com/alpcrimea/redmine-spectator-plugin'
author_url 'https://github.com/alpcrimea'
menu :account_menu, :spectator, { :controller => 'spectator', :action => 'index' }, :caption => :change_user, :if => Proc.new { User.current.admin? || spectator_id }
end