|
@@ -10,16 +10,16 @@ class ApiController < ActionController::Base
|
10
|
10
|
|
11
|
11
|
protected
|
12
|
12
|
def api_require_authentication!
|
13
|
|
- if !is_logged_in?
|
14
|
|
- head :unauthorized
|
15
|
|
- end
|
|
13
|
+ return if is_logged_in?
|
|
14
|
+
|
|
15
|
+ head :unauthorized
|
16
|
16
|
end
|
17
|
17
|
|
18
|
18
|
def api_require_admin!
|
19
|
|
- if !current_person.is_admin?
|
20
|
|
- @message = I18n.t('authentication.admin_required')
|
21
|
|
- render 'api/error', status: :forbidden
|
22
|
|
- end
|
|
19
|
+ return if current_person&.is_admin?
|
|
20
|
+
|
|
21
|
+ @message = I18n.t('authentication.admin_required')
|
|
22
|
+ render 'api/error', status: :forbidden
|
23
|
23
|
end
|
24
|
24
|
|
25
|
25
|
# Authenticate a request by a 'Authorization: Group xxx'-header.
|
|
@@ -35,9 +35,9 @@ class ApiController < ActionController::Base
|
35
|
35
|
|
36
|
36
|
# Require user to be a member of group OR admin, requires @group set
|
37
|
37
|
def require_membership!
|
38
|
|
- if !current_person.groups.include?(@group) && !current_person.is_admin?
|
39
|
|
- @message = I18n.t('authentication.membership_required')
|
40
|
|
- render 'api/error', status: :forbidden
|
41
|
|
- end
|
|
38
|
+ return if current_person&.groups.include?(@group) || current_person&.is_admin?
|
|
39
|
+
|
|
40
|
+ @message = I18n.t('authentication.membership_required')
|
|
41
|
+ render 'api/error', status: :forbidden
|
42
|
42
|
end
|
43
|
43
|
end
|