redmine_airbrake_backend 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b609db8df7b543900de190e58b947f287767f8add9e3b67b2010f358367b139
4
- data.tar.gz: 95e5a3453fd9736df2cc0ad566990fa04739eae0404a171825f2d661c7936af8
3
+ metadata.gz: bd9ed3cb0664c977824beee01de24dabd2883bba7bbaa0df8dbe1bfdbfd6ca47
4
+ data.tar.gz: 4d52088e65e445ab788d459ef88d88395716fd544e85ea97a15082198f586c11
5
5
  SHA512:
6
- metadata.gz: 9add4edc3af06753ea4f6de1876f65c5824b149e72e9cae14b73e714739e91216d667fd38515a24689b5677ad5fee521afa316f833e8e92d989390153b1306e8
7
- data.tar.gz: c3fe3ba17ab5863424b017a8f94e69f20dfe5e9b62992d498aa9438f199ddd112a5a2c8f069d3e1e675006bb42c58475b3761c34b13a96c5c29ad353e77933d5
6
+ metadata.gz: 2a17ebe81cdb4aac103031e7ee8920f33a0a23ed9075a1deb0f48b288ebb0c3fd24b91580b83c62c36d805c096a240d467ac6d488b6a75e38ebc4e9db7bdf398
7
+ data.tar.gz: dec97c57aab26ddd559c0680eae89ed05b810866755866b0ae8e326a6438a314423c5d31adb32e96f91d4ecd116b20473cfcd5450184819a3eac061c8b1604b0
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.1 (2018-01-29)
4
+ ### Features
5
+ - All responses are formatted as JSON
6
+
3
7
  ## 1.2.0 (2018-01-17)
4
8
  ### Features
5
9
  - Support airbrake token based authentication
@@ -3,9 +3,8 @@ require 'redmine_airbrake_backend/notice'
3
3
 
4
4
  # Controller with airbrake related stuff
5
5
  class AirbrakeController < ::ApplicationController
6
- class InvalidRequest < StandardError; end
7
-
8
6
  skip_before_action :verify_authenticity_token
7
+ skip_before_action :session_expiration, :user_setup, :check_if_login_required, :set_localization, :check_password_change
9
8
 
10
9
  prepend_before_action :find_project
11
10
  prepend_before_action :parse_key
@@ -19,8 +18,6 @@ class AirbrakeController < ::ApplicationController
19
18
 
20
19
  after_action :cleanup_tempfiles
21
20
 
22
- rescue_from InvalidRequest, with: :render_bad_request
23
-
24
21
  private
25
22
 
26
23
  def find_project
@@ -38,16 +35,30 @@ class AirbrakeController < ::ApplicationController
38
35
  @key = JSON.parse(params[:key]).with_indifferent_access rescue nil
39
36
  end
40
37
 
41
- invalid_request!('No or invalid API key') if @key.blank? || @key[:key].blank?
42
- params[:key] = @key[:key]
38
+ render_error('No or invalid API key format', :unauthorized) if @key.blank? || @key[:key].blank?
39
+ end
40
+
41
+ def authorize
42
+ User.current = User.find_by_api_key(@key[:key])
43
+
44
+ if User.current.blank? || User.current.anonymous?
45
+ render_error('Failed to authenticate', :unauthorized)
46
+
47
+ return
48
+ end
49
+
50
+ return if User.current.allowed_to?({ controller: params[:controller], action: params[:action] }, @project)
51
+
52
+ render_error('Access Denied', :forbidden)
43
53
  end
44
54
 
45
55
  def find_tracker
46
56
  @tracker = record_for(@project.trackers, :tracker)
47
- invalid_request!('No or invalid tracker') if @tracker.blank?
57
+
58
+ render_error('No or invalid tracker', :failed_dependency) if @tracker.blank?
48
59
 
49
60
  # Check notice ID field
50
- invalid_request!('Custom field for notice hash not available on selected tracker') if @tracker.custom_fields.find_by(id: notice_hash_field.id).blank?
61
+ render_error('Custom field for notice hash not available on selected tracker', :failed_dependency) if @tracker.custom_fields.find_by(id: notice_hash_field.id).blank?
51
62
  end
52
63
 
53
64
  def find_category
@@ -66,14 +77,10 @@ class AirbrakeController < ::ApplicationController
66
77
  @repository = @project.repositories.find_by(identifier: (@key[:repository] || ''))
67
78
  end
68
79
 
69
- def invalid_request!(message)
70
- raise InvalidRequest.new(message)
71
- end
72
-
73
- def render_bad_request(error)
74
- ::Rails.logger.warn(error.message)
80
+ def render_error(error, status = :internal_server_error)
81
+ ::Rails.logger.warn(error)
75
82
 
76
- render text: error.message, status: :bad_request
83
+ render json: { error: { message: error } }, status: status
77
84
  end
78
85
 
79
86
  def render_airbrake_response
@@ -1,4 +1,4 @@
1
1
  module RedmineAirbrakeBackend
2
2
  # Version of this gem
3
- VERSION = '1.2.0'
3
+ VERSION = '1.2.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_airbrake_backend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Schwab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-17 00:00:00.000000000 Z
11
+ date: 2018-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails