lowauth 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lowauth/guard.rb +6 -9
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7458d1a63ff0008c1504f57d718fa2720d51d33eee4b6131256851e4dac4b893
|
|
4
|
+
data.tar.gz: 7ff426e60d6e1c1a99fb222bd6c354b4e3d830182206f38b789b9db38234e174
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8133613d59de2894fd177b566b22d6c34c0e84a88cfdf20ab239536b4890d481ddb626fc7fdb5bc6c83529e9cd526581ad04c4dbae03f34a5a5799dbb9262c3
|
|
7
|
+
data.tar.gz: c1df53a2f375e6f4511f3851e1c8c0949bb3478eaa5b448520302d97b4e3205a47820ae448c868865ac023f5e33ba382f39bafa6769aafe00fadb47ee3af0c1c
|
data/lib/lowauth/guard.rb
CHANGED
|
@@ -4,23 +4,20 @@ require 'cgi'
|
|
|
4
4
|
|
|
5
5
|
module LowAuth
|
|
6
6
|
# "allows { |user| ... }" in a node lets only the users its block is true for call its actions, like
|
|
7
|
-
# "allows { |user| LowAuth.role?(user, :admin) }". "
|
|
8
|
-
# user. The
|
|
7
|
+
# "allows { |user| LowAuth.role?(user, :admin) }". "allows :admin" is short for that, and "allows" alone lets in any
|
|
8
|
+
# logged in user. The rule is also the node's "allowed?(user)", so a menu can ask whether to link to it.
|
|
9
9
|
# Anyone else gets nothing, so the router moves on and responds with a 404, which doesn't say there's a page. With
|
|
10
|
-
# config.login_path set, a logged out visitor reading a page is sent to log in instead,
|
|
10
|
+
# config.login_path set, a logged out visitor reading a page is sent to log in instead, with it as ?origin=, to come back to.
|
|
11
11
|
# Actions that change things, like "receive" and "post", also need the form to come from this site.
|
|
12
12
|
module Guard
|
|
13
13
|
READS = %i[render get query side_effect].freeze
|
|
14
14
|
|
|
15
|
-
def allows(&rule)
|
|
15
|
+
def allows(role = nil, &rule)
|
|
16
|
+
rule ||= ->(user) { LowAuth.role?(user, role) }
|
|
16
17
|
define_singleton_method(:allowed?) { |user| rule.call(user) ? true : false }
|
|
17
18
|
singleton_class.prepend(Guard.module_for_actions)
|
|
18
19
|
end
|
|
19
20
|
|
|
20
|
-
def requires(role = nil)
|
|
21
|
-
allows { |user| LowAuth.role?(user, role) }
|
|
22
|
-
end
|
|
23
|
-
|
|
24
21
|
# Whether an event's user may call an action, by the node's rule, with a form from this site for one that changes things.
|
|
25
22
|
def self.allowed?(node, event, action)
|
|
26
23
|
return false unless event && node.allowed?(LowAuth.current_user(event))
|
|
@@ -41,7 +38,7 @@ module LowAuth
|
|
|
41
38
|
path = event.respond_to?(:path) ? event.path : nil
|
|
42
39
|
return LowAuth.login_path unless path
|
|
43
40
|
|
|
44
|
-
"#{LowAuth.login_path}?
|
|
41
|
+
"#{LowAuth.login_path}?origin=#{CGI.escape(path)}"
|
|
45
42
|
end
|
|
46
43
|
|
|
47
44
|
def self.module_for_actions
|
data/lib/version.rb
CHANGED