Module: Redmine::SudoMode
- Defined in:
- lib/redmine/sudo_mode.rb
Defined Under Namespace
Modules: Controller, Helper Classes: Form, SudoRequired
Class Method Summary collapse
- .active! ⇒ Object
-
.active? ⇒ Boolean
true if sudo mode is currently active.
-
.disable! ⇒ Object
Turn off sudo mode (never require password entry).
-
.enable! ⇒ Object
Turn sudo mode back on.
- .enabled? ⇒ Boolean
- .possible? ⇒ Boolean
-
.timeout ⇒ Object
Timespan after which sudo mode expires when unused.
-
.was_used? ⇒ Boolean
true if the sudo mode state was queried during this request.
Class Method Details
.active! ⇒ Object
196 197 198 |
# File 'lib/redmine/sudo_mode.rb', line 196 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 wether 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.
190 191 192 193 194 |
# File 'lib/redmine/sudo_mode.rb', line 190 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).
205 206 207 |
# File 'lib/redmine/sudo_mode.rb', line 205 def self.disable! RequestStore.store[:sudo_mode_disabled] = true end |
.enable! ⇒ Object
Turn sudo mode back on
210 211 212 |
# File 'lib/redmine/sudo_mode.rb', line 210 def self.enable! RequestStore.store[:sudo_mode_disabled] = nil end |
.enabled? ⇒ Boolean
214 215 216 |
# File 'lib/redmine/sudo_mode.rb', line 214 def self.enabled? Redmine::Configuration['sudo_mode'] && !RequestStore.store[:sudo_mode_disabled] end |
.possible? ⇒ Boolean
200 201 202 |
# File 'lib/redmine/sudo_mode.rb', line 200 def self.possible? enabled? && User.current.logged? end |
.timeout ⇒ Object
Timespan after which sudo mode expires when unused.
219 220 221 222 |
# File 'lib/redmine/sudo_mode.rb', line 219 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
178 179 180 |
# File 'lib/redmine/sudo_mode.rb', line 178 def self.was_used? !!RequestStore.store[:sudo_mode_was_used] end |