浏览代码

:except has precedence over :if

Maarten van den Berg 6 年之前
父节点
当前提交
a784502b38
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5 4
      app/controllers/api/groups_controller.rb

+ 5 - 4
app/controllers/api/groups_controller.rb

8
   has_no_group = [:index]
8
   has_no_group = [:index]
9
 
9
 
10
   # Session-based authentication / authorization filters
10
   # Session-based authentication / authorization filters
11
-  before_action :set_group,           except: has_no_group, unless: 'request.authorization'
12
-  before_action :require_membership!, except: has_no_group, unless: 'request.authorization'
13
-  before_action :api_require_admin!,  only: has_no_group,   unless: 'request.authorization'
11
+  before_action :set_group,           except: has_no_group
12
+  before_action :require_membership!, except: has_no_group
13
+  before_action :api_require_admin!,  only:   has_no_group
14
+  skip_before_action :set_group, :require_membership!, :api_require_authentication!, if: 'request.authorization'
14
 
15
 
15
   # API key based filter (both authenticates and authorizes)
16
   # API key based filter (both authenticates and authorizes)
16
   before_action :api_auth_token, if: 'request.authorization'
17
   before_action :api_auth_token, if: 'request.authorization'
53
   # @group variable from the key's associated group.
54
   # @group variable from the key's associated group.
54
   def api_auth_token
55
   def api_auth_token
55
     words = request.authorization.split(' ')
56
     words = request.authorization.split(' ')
56
-    head :unauthorized unless words[0].casecmp('Group').zero?
57
+    head :unauthorized unless words[0].casecmp('group').zero?
57
 
58
 
58
     @group = Group.find_by api_token: words[1]
59
     @group = Group.find_by api_token: words[1]
59
     head :unauthorized unless @group
60
     head :unauthorized unless @group