unotifier 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/provider/system/action_cable.rb +4 -0
- data/lib/provider/user/action_cable.rb +4 -0
- data/lib/provider/user/action_mailer.rb +4 -0
- data/lib/unotifier.rb +7 -2
- data/lib/unotifier/system_notifier.rb +1 -1
- data/lib/unotifier/user_notifier.rb +60 -34
- data/lib/unotifier/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f1f5e629d8d72498909aa0362e3731b5e1fa8ca2f80db9d0fae1625ff015239
|
4
|
+
data.tar.gz: c1965f64e2948c7a9e654d6dd5a7426ee4059bd0a87f98f18ccad02cc50f2011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfd76b2dd66a398b8dc75fe85971ee14f716c2df8e9abf0d05d2f1786a9bc583a8e615bea830a168103b8f88934a883ee725a3a283aab028b93efd0c585802f0
|
7
|
+
data.tar.gz: 61bbd5b17d968f46efd3685f7d12e6a21ed771c11b24f6ee1ab1c44aabbedfd01eeebf5b04ed9e85fc7c3d71bbe156fa24f97ae777041c715b53fcb10678328d
|
data/Gemfile.lock
CHANGED
data/lib/unotifier.rb
CHANGED
@@ -94,8 +94,8 @@ module UNotifier
|
|
94
94
|
|
95
95
|
notification.save!
|
96
96
|
|
97
|
-
UserNotifier.
|
98
|
-
SystemNotifier.
|
97
|
+
UserNotifier.call(notification, params)
|
98
|
+
SystemNotifier.call(notification, params[:system])
|
99
99
|
end
|
100
100
|
|
101
101
|
def self.notify_onsite(key, target, params)
|
@@ -120,6 +120,11 @@ module UNotifier
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
123
|
+
.merge("options" => user_settings["options"])
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.hide_sensitive_for?(target)
|
127
|
+
!!target.notification_settings.dig("options", "hide_sensitive")
|
123
128
|
end
|
124
129
|
|
125
130
|
def self.urgency_for(key, params = {})
|
@@ -1,52 +1,53 @@
|
|
1
1
|
module UNotifier
|
2
2
|
module UserNotifier
|
3
|
-
def self.
|
4
|
-
|
3
|
+
def self.call(notification, params = {})
|
4
|
+
config = UNotifier.load_notification!(notification.key)["user"]
|
5
|
+
user_settings = _load_user_settings(notification)
|
6
|
+
providers = _load_providers(notification, user_settings, params)
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
notification.target.notification_settings.dig("user", notification.key)
|
9
|
-
user_settings ||= Settings::DEFAULT_URGENCY
|
8
|
+
# By default we assume that notification is sensitive
|
9
|
+
is_sensitive = !config.has_key?("sensitive") || config["sensitive"]
|
10
10
|
|
11
|
-
|
11
|
+
providers.each do |provider|
|
12
|
+
is_private = is_sensitive &&
|
13
|
+
provider.sensitive? &&
|
14
|
+
UNotifier.hide_sensitive_for?(notification.target)
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
if is_private
|
17
|
+
notification.title = _translate(provider, notification, "title_private", params)
|
18
|
+
notification.body = ""
|
19
|
+
else
|
20
|
+
notification.title = _translate(provider, notification, "title", params)
|
21
|
+
notification.body = _translate(provider, notification, "body", params)
|
22
|
+
end
|
16
23
|
|
17
|
-
|
18
|
-
notify_with += UNotifier.configuration.external_providers
|
24
|
+
provider.notify(notification)
|
19
25
|
end
|
26
|
+
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
body_provider_key = "#{locale_key}.#{provider.class.to_s.split("::").last}.body"
|
28
|
+
def self._load_providers(notification, user_settings, params)
|
29
|
+
providers = []
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
title_provider_key, params.merge(locale: notification.target.locale)
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
if UNotifier.configuration.localization_provider.exists?(body_provider_key)
|
33
|
-
notification.body =
|
34
|
-
UNotifier.configuration.localization_provider.t(
|
35
|
-
body_provider_key, params.merge(locale: notification.target.locale, default: "")
|
36
|
-
)
|
37
|
-
end
|
31
|
+
if !params[:external_only] && _notify_onsite?(notification, user_settings)
|
32
|
+
providers += UNotifier.configuration.site_providers
|
33
|
+
end
|
38
34
|
|
39
|
-
|
35
|
+
if !params[:onsite_only] && _notify_external?(notification, user_settings)
|
36
|
+
providers += UNotifier.configuration.external_providers
|
40
37
|
end
|
41
|
-
end
|
42
38
|
|
43
|
-
|
44
|
-
|
39
|
+
providers
|
40
|
+
end
|
45
41
|
|
46
|
-
|
42
|
+
def self._load_user_settings(notification)
|
43
|
+
(
|
44
|
+
notification.target.notification_settings.is_a?(Hash) &&
|
45
|
+
notification.target.notification_settings.dig("user", notification.key)
|
46
|
+
) ||
|
47
|
+
Settings::DEFAULT_URGENCY
|
47
48
|
end
|
48
49
|
|
49
|
-
def self.
|
50
|
+
def self._notify_external?(notification, user_settings)
|
50
51
|
case notification.urgency
|
51
52
|
when "immediate"
|
52
53
|
true
|
@@ -58,5 +59,30 @@ module UNotifier
|
|
58
59
|
false
|
59
60
|
end
|
60
61
|
end
|
62
|
+
|
63
|
+
def self._notify_onsite?(notification, user_settings)
|
64
|
+
return false if notification.urgency == "optional" && user_settings == "off"
|
65
|
+
|
66
|
+
notification.target.online?
|
67
|
+
end
|
68
|
+
|
69
|
+
def self._translate(provider, notification, part, params)
|
70
|
+
locale_key = UNotifier.locale_key_for(notification.key, params)
|
71
|
+
locale_provider = UNotifier.configuration.localization_provider
|
72
|
+
|
73
|
+
plain_key = "#{locale_key}.#{part}"
|
74
|
+
provider_key = "#{locale_key}.#{provider.class.to_s.split("::").last}.#{part}"
|
75
|
+
|
76
|
+
key =
|
77
|
+
if locale_provider.exists?(provider_key)
|
78
|
+
provider_key
|
79
|
+
elsif locale_provider.exists?(plain_key)
|
80
|
+
plain_key
|
81
|
+
else
|
82
|
+
"notifications.default.#{part}"
|
83
|
+
end
|
84
|
+
|
85
|
+
locale_provider.t(key, params.merge(locale: notification.target.locale))
|
86
|
+
end
|
61
87
|
end
|
62
88
|
end
|
data/lib/unotifier/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unotifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mgpnd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|