snitch_reporting 1.1.4 → 1.2.0

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: 9c7c6a29f299f8c00142069303e84a5a52d627855bdafbbfeb28fdada01f5269
4
- data.tar.gz: a77a3f866addcb8c687562fab7e52efb8f062ffe444276211830dd11781939a5
3
+ metadata.gz: 64846e2c242ccd9b84512b6089c287128f336ce364a6b771fd4d08d0a03f4676
4
+ data.tar.gz: 7fbcec2fc85da6b4c8e8690c2794a2271a0f4ba2e192458f1778ae99af59c9a9
5
5
  SHA512:
6
- metadata.gz: 7c498d316d61f1d62781e733cd434286f94622f83f6e8341a011671eb4321302902576e6cefbffe5d8b11245750ba183da418f17bc61608d0d040253352ba09c
7
- data.tar.gz: 11c83a1f7db7b824fb4e8fe750d023fbb5eaa5a24156bcb7a48f98394e686cfd1585062eddd14c084daed7ad09de4660d130507652728995c4a0780e5f9f35b2
6
+ metadata.gz: fccfce35ca00431986d349ec8e5e2cc092d7c80534f9d687d41a5718ebee87bab1145fec6a425e9b8360501c39bfc4acddbed5fa4ca46e3afdf29cf4f441b5ee
7
+ data.tar.gz: ad39ef70738ab939e0bd49a62f46b30299287b82bb78ef4f07da3f672a78c9671e088a2986a75b6b46930f5f5fbc97b7908bce0e644fb90777fbef753ffe7f27
@@ -33,4 +33,54 @@
33
33
  }
34
34
  }
35
35
  }
36
+
37
+ .snitch-search-area {
38
+ display: flex;
39
+ position: relative;
40
+ flex-direction: row-reverse;
41
+
42
+ .filters {
43
+ display: none;
44
+ position: absolute;
45
+ top: 60px;
46
+ right: 0;
47
+ left: 0;
48
+ z-index: 100;
49
+ transition: all 0.3s;
50
+ box-shadow: 2px 2px 4px $border-grey;
51
+ border: 3px solid $border-grey;
52
+ border-radius: 4px;
53
+ background: white;
54
+ padding: 20px;
55
+ }
56
+
57
+ input[name=filter_string] {
58
+ box-shadow: 2px 2px 4px $border-grey;
59
+ border: 2px solid $border-grey;
60
+ border-radius: 4px;
61
+ padding: 10px;
62
+ width: 100%;
63
+ height: auto;
64
+ font-size: 32px;
65
+ }
66
+
67
+ button[type=submit] {
68
+ cursor: pointer;
69
+ box-shadow: 2px 2px 4px $border-grey;
70
+ border: 1px solid $border-grey;
71
+ border-radius: 6px;
72
+ background: linear-gradient($snitch-blue, darken($snitch-blue, 15%));
73
+ padding: 0 12px;
74
+ color: white;
75
+ font-size: 18px;
76
+
77
+ &:hover {
78
+ background: linear-gradient(darken($snitch-blue, 15%), $snitch-blue, $snitch-blue);
79
+ }
80
+ }
81
+
82
+ .filters.open {
83
+ display: block;
84
+ }
85
+ }
36
86
  }
@@ -33,54 +33,5 @@
33
33
  }
34
34
  }
35
35
 
36
- .snitch-search-area {
37
- display: flex;
38
- position: relative;
39
- flex-direction: row-reverse;
40
-
41
- .filters {
42
- display: none;
43
- position: absolute;
44
- top: 60px;
45
- right: 0;
46
- left: 0;
47
- z-index: 100;
48
- transition: all 0.3s;
49
- box-shadow: 2px 2px 4px $border-grey;
50
- border: 3px solid $border-grey;
51
- border-radius: 4px;
52
- background: white;
53
- padding: 20px;
54
- }
55
-
56
- input[name=filter_string] {
57
- box-shadow: 2px 2px 4px $border-grey;
58
- border: 2px solid $border-grey;
59
- border-radius: 4px;
60
- padding: 10px;
61
- width: 100%;
62
- font-size: 32px;
63
- }
64
-
65
- button[type=submit] {
66
- cursor: pointer;
67
- box-shadow: 2px 2px 4px $border-grey;
68
- border: 1px solid $border-grey;
69
- border-radius: 6px;
70
- background: linear-gradient($snitch-blue, darken($snitch-blue, 15%));
71
- padding: 0 12px;
72
- color: white;
73
- font-size: 18px;
74
-
75
- &:hover {
76
- background: linear-gradient(darken($snitch-blue, 15%), $snitch-blue, $snitch-blue);
77
- }
78
- }
79
-
80
- .filters.open {
81
- display: block;
82
- }
83
- }
84
-
85
36
  .snitch-breadcrumbs {}
86
37
  }
@@ -148,8 +148,9 @@ class ::SnitchReporting::SnitchReportsController < ApplicationController
148
148
  @reports = @reports.resolved if @filters[:status] == :resolved
149
149
  @reports = @reports.unresolved if @filters[:status] == :unresolved
150
150
  @reports = @reports.search(@filters[:search]) if @filters[:search].present?
151
- #
152
151
  @reports = @reports.by_level(@filters[:log_level]) if @filters[:log_level].present?
152
+
153
+ @reports = @reports.by_tag(*@filters[:tag]) if @filters[:tag].any?
153
154
  # @reports = @reports.by_severity(@filters[:severity_tags]) if @filters[:severity_tags].present?
154
155
  # @reports = @reports.by_source(@filters[:source_tags]) if @filters[:source_tags].present?
155
156
  #
@@ -200,6 +201,7 @@ class ::SnitchReporting::SnitchReportsController < ApplicationController
200
201
  end
201
202
 
202
203
  search_strings = []
204
+ tag_strings = []
203
205
  filter_strings = temp_filter_string.split(" ").select do |filter_string|
204
206
  search_strings << filter_string unless filter_string.include?(":")
205
207
  filter_string.include?(":")
@@ -215,15 +217,25 @@ class ::SnitchReporting::SnitchReportsController < ApplicationController
215
217
  @filters[filter.to_sym] = value.to_sym
216
218
  elsif filter == "search"
217
219
  search_strings << decode_string(secret_key, value)
220
+ elsif filter == "tag" || filter == "tags"
221
+ tag_strings << decode_string(secret_key, value)
218
222
  else
219
223
  @unknown_strings << filter_string
220
224
  end
221
225
  end
222
226
 
223
227
  @filters[:search] = "\"#{search_strings.join(' ')}\"" if search_strings.any?
228
+ @filters[:tag] = tag_strings
224
229
 
225
230
  new_filter_strings = @filters.each_with_object([]) do |(filter_string, filter_value), filter_array|
226
- filter_array << "#{filter_string}:#{filter_value}" if filter_value.present?
231
+ next unless filter_value.present?
232
+ if filter_value.is_a?(Array)
233
+ filter_value.each do |filter_value_i|
234
+ filter_array << "#{filter_string}:#{filter_value_i}"
235
+ end
236
+ else
237
+ filter_array << "#{filter_string}:#{filter_value}"
238
+ end
227
239
  end
228
240
 
229
241
  @filter_string = new_filter_strings.join(" ")
@@ -31,6 +31,18 @@ class SnitchReporting::SnitchReport < ApplicationRecord
31
31
  scope :unignored, -> { where(ignored_at: nil) }
32
32
  scope :by_level, ->(*level_tags) { where(log_level: level_tags) }
33
33
  scope :search, ->(text) { where("CONCAT(error, ' ', message) ILIKE :text", text: "%#{text}%") }
34
+ scope :by_tag, lambda { |*tags|
35
+ scopes = []
36
+ tags.each do |tag|
37
+ if tag[0] == "!"
38
+ tag[0] = ""
39
+ scopes << "tags !~* '(\\[|,).*\"#{tag}\".*(,|\\])'"
40
+ else
41
+ scopes << "tags ~* '(\\[|,).*\"#{tag}\".*(,|\\])'"
42
+ end
43
+ end
44
+ where(scopes.join(" AND "))
45
+ }
34
46
 
35
47
  enum log_level: {
36
48
  debug: 1,
@@ -54,7 +66,7 @@ class SnitchReporting::SnitchReport < ApplicationRecord
54
66
  env, klass, base_exception = extract_base_variables(exceptions, arg_hash, arg_values)
55
67
  always_notify = arg_hash.delete(:always_notify)
56
68
 
57
- report_title = retrieve_report_title(base_exception, arg_hash)
69
+ report_title = retrieve_report_title(base_exception, arg_hash, arg_values)
58
70
  report = retrieve_or_create_existing_report(log_level, santize_title(report_title), env, base_exception, arg_hash)
59
71
  return SnitchReporting::SnitchReport.error("Failed to save report.", report.errors.full_messages) unless report.persisted?
60
72
 
@@ -160,13 +172,14 @@ class SnitchReporting::SnitchReport < ApplicationRecord
160
172
  end
161
173
  end
162
174
 
163
- def retrieve_report_title(exception, arg_hash)
175
+ def retrieve_report_title(exception, arg_hash, arg_values)
164
176
  report_title = arg_hash[:title].presence
165
177
  report_title ||= exception.try(:message).presence
166
178
  report_title ||= exception.try(:body).presence
167
- report_title ||= exception.try(:class).presence
179
+ report_title ||= arg_values&.find { |arg_value| arg_value.is_a?(String) }
168
180
  report_title ||= (arg_hash[:klass] || arg_hash[:class]).presence
169
181
  report_title ||= trace_from_exception(exception).find { |row| row.include?("/app/") }
182
+ report_title ||= exception.try(:class).presence
170
183
  report_title
171
184
  end
172
185
 
@@ -267,7 +280,7 @@ class SnitchReporting::SnitchReport < ApplicationRecord
267
280
  end
268
281
 
269
282
  def tags
270
- super || []
283
+ (super || []).uniq
271
284
  end
272
285
 
273
286
  def tags=(new_tags)
@@ -277,7 +290,7 @@ class SnitchReporting::SnitchReport < ApplicationRecord
277
290
  def add_tags(new_tags)
278
291
  return if new_tags.blank?
279
292
 
280
- update(tags: tags + [new_tags])
293
+ update(tags: (tags + [new_tags]).compact.flatten.uniq)
281
294
  end
282
295
 
283
296
  def resolved?; resolved_at?; end
@@ -1,3 +1,3 @@
1
1
  module SnitchReporting
2
- VERSION = '1.1.4'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snitch_reporting
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rocco Nicholls