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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7335d982bbd3cf526c810489e7950980fbd5a5b61cebb1c2e224bedc301e3c38
4
- data.tar.gz: 00abe5cfe6d403719e654fc70d8e3604e8086fd6af41030167c4c982b6e60c10
3
+ metadata.gz: 7458d1a63ff0008c1504f57d718fa2720d51d33eee4b6131256851e4dac4b893
4
+ data.tar.gz: 7ff426e60d6e1c1a99fb222bd6c354b4e3d830182206f38b789b9db38234e174
5
5
  SHA512:
6
- metadata.gz: 856f2707ec748555f66fbf5089769dc58f3669b1b4390893ea76558780ed78f8df6f8bca5803fd5b21cfc934545cc869920c09f4e6142f79eb2e510c8bf0cac6
7
- data.tar.gz: 26dccd6e6fe26905c4ca6ab89c2e6df9302c59bd750b440999a9e527cc0ab7087aeee5362b3a758564db5709b4ee8f9061f2400bb16974c2032789d9ff17f047
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) }". "requires :admin" is short for that, and "requires" for any logged in
8
- # user. The block is also the node's "allowed?(user)", so a menu can ask whether to link to it.
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, and back to it after.
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}?redirect=#{CGI.escape(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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LowAuth
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lowauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi