Module: Redmine::SudoMode

Defined in:
lib/redmine/sudo_mode.rb

Defined Under Namespace

Modules: Controller, Helper Classes: Form, SudoRequired

Class Method Summary collapse

Class Method Details

.active!Object



192
193
194
# File 'lib/redmine/sudo_mode.rb', line 192

def self.active!
  RequestStore.store[:sudo_mode] = true
end

.active?Boolean

true if sudo mode is currently active.

Calling this method also turns was_used? to true, therefore it is important to only call this when sudo is actually needed, as the last condition to determine whether a change can be done or not.

If you do it wrong, timeout of the sudo mode will happen too late or not at all.

Returns:

  • (Boolean)


186
187
188
189
190
# File 'lib/redmine/sudo_mode.rb', line 186

def self.active?
  if !!RequestStore.store[:sudo_mode]
    RequestStore.store[:sudo_mode_was_used] = true
  end
end

.disable!Object

Turn off sudo mode (never require password entry).



201
202
203
# File 'lib/redmine/sudo_mode.rb', line 201

def self.disable!
  RequestStore.store[:sudo_mode_disabled] = true
end

.enable!Object

Turn sudo mode back on



206
207
208
# File 'lib/redmine/sudo_mode.rb', line 206

def self.enable!
  RequestStore.store[:sudo_mode_disabled] = nil
end

.enabled?Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/redmine/sudo_mode.rb', line 210

def self.enabled?
  Redmine::Configuration['sudo_mode'] && !RequestStore.store[:sudo_mode_disabled]
end

.possible?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/redmine/sudo_mode.rb', line 196

def self.possible?
  enabled? && User.current.logged?
end

.timeoutObject

Timespan after which sudo mode expires when unused.



215
216
217
218
# File 'lib/redmine/sudo_mode.rb', line 215

def self.timeout
  m = Redmine::Configuration['sudo_mode_timeout'].to_i
  (m > 0 ? m : 15).minutes
end

.was_used?Boolean

true if the sudo mode state was queried during this request

Returns:

  • (Boolean)


174
175
176
# File 'lib/redmine/sudo_mode.rb', line 174

def self.was_used?
  !!RequestStore.store[:sudo_mode_was_used]
end