Class: ROM::Auth::Plugins::LockdownPlugin
- Inherits:
-
Plugin
- Object
- Plugin
- ROM::Auth::Plugins::LockdownPlugin
show all
- Defined in:
- lib/rom/auth/plugins/lockdown_plugin.rb
Defined Under Namespace
Modules: CallbackOverrides
Classes: Configuration, Lockdown, LockdownMigration
Instance Attribute Summary
Attributes inherited from Plugin
#configuration, #system
Instance Method Summary
collapse
Constructor Details
Returns a new instance of LockdownPlugin.
13
14
15
16
17
18
|
# File 'lib/rom/auth/plugins/lockdown_plugin.rb', line 13
def initialize(*args)
super
configuration.table_name ||= system.configuration.users_table_name
end
|
Instance Method Details
#install ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rom/auth/plugins/lockdown_plugin.rb', line 20
def install
system.extend(CallbackOverrides)
config = configuration
@relation = Class.new(ROM::Relation[:sql]) do
register_as :rom_auth_lockdowns
dataset(config.table_name)
def by_user_id(user_id)
where(id: user_id)
end
end
@mapper = Class.new(ROM::Mapper) do
relation(:rom_auth_lockdowns)
model(Lockdown)
register_as :rom_auth_lockdown
end
@command = Class.new(ROM::Commands::Update[:sql]) do
register_as :update
relation(:rom_auth_lockdowns)
result :one
end
end
|
#is_locked?(user_id) ⇒ Boolean
59
60
61
62
|
# File 'lib/rom/auth/plugins/lockdown_plugin.rb', line 59
def is_locked?(user_id)
ROM.env.relation(:rom_auth_lockdowns).by_user_id(user_id).as(:rom_auth_lockdown).first.try(:locked_at).present?
end
|
#lock(user_id, reason) ⇒ Object
64
65
66
67
|
# File 'lib/rom/auth/plugins/lockdown_plugin.rb', line 64
def lock(user_id, reason)
raise ArgumentError unless user_id.is_a?(Integer)
ROM.env.command(:rom_auth_lockdowns).update.where(id: user_id).call(locked_at: Time.now, lock_reason: reason)
end
|
#lock_strategy ⇒ Object
51
52
53
|
# File 'lib/rom/auth/plugins/lockdown_plugin.rb', line 51
def lock_strategy
configuration.lock_strategy
end
|
#migrate(setup) ⇒ Object
47
48
49
|
# File 'lib/rom/auth/plugins/lockdown_plugin.rb', line 47
def migrate(setup)
LockdownMigration.new(system, setup, configuration).run
end
|
#unlock(user_id) ⇒ Object
69
70
71
|
# File 'lib/rom/auth/plugins/lockdown_plugin.rb', line 69
def unlock(user_id)
ROM.env.command(:rom_auth_lockdowns).update.where(id: user_id).call(locked_at: nil, lock_reason: nil)
end
|
#unlock_strategy ⇒ Object
55
56
57
|
# File 'lib/rom/auth/plugins/lockdown_plugin.rb', line 55
def unlock_strategy
configuration.unlock_strategy
end
|