Module: Redmine::SudoMode

Defined in:
lib/redmine/sudo_mode.rb

Defined Under Namespace

Modules: Controller, Helper Classes: CurrentSudoMode, Form, SudoRequired

Class Method Summary collapse

Class Method Details

.active!Object



213
214
215
# File 'lib/redmine/sudo_mode.rb', line 213

def self.active!
  CurrentSudoMode.active = 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)


207
208
209
210
211
# File 'lib/redmine/sudo_mode.rb', line 207

def self.active?
  if !!CurrentSudoMode.active
    CurrentSudoMode.was_used = true
  end
end

.disable!Object

Turn off sudo mode (never require password entry).



222
223
224
# File 'lib/redmine/sudo_mode.rb', line 222

def self.disable!
  CurrentSudoMode.disabled = true
end

.enable!Object

Turn sudo mode back on



227
228
229
# File 'lib/redmine/sudo_mode.rb', line 227

def self.enable!
  CurrentSudoMode.disabled = nil
end

.enabled?Boolean

Returns:

  • (Boolean)


231
232
233
# File 'lib/redmine/sudo_mode.rb', line 231

def self.enabled?
  Redmine::Configuration['sudo_mode'] && !CurrentSudoMode.disabled
end

.possible?Boolean

Returns:

  • (Boolean)


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

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

.timeoutObject

Timespan after which sudo mode expires when unused.



236
237
238
239
# File 'lib/redmine/sudo_mode.rb', line 236

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)


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

def self.was_used?
  !!CurrentSudoMode.was_used
end