lesli_bell 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/lesli_bell/application.css +21 -0
- data/app/controllers/lesli_bell/announcements_controller.rb +107 -61
- data/app/helpers/lesli_bell/announcements_helper.rb +20 -2
- data/app/models/lesli_bell/announcement/role_recipient.rb +20 -0
- data/app/models/lesli_bell/announcement/user.rb +5 -2
- data/app/models/lesli_bell/announcement/user_recipient.rb +20 -0
- data/app/models/lesli_bell/announcement.rb +97 -2
- data/app/services/lesli_bell/announcement_service.rb +111 -64
- data/app/views/lesli_bell/announcements/_form.html.erb +34 -0
- data/app/views/lesli_bell/announcements/edit.html.erb +6 -10
- data/app/views/lesli_bell/announcements/index.html.erb +25 -33
- data/app/views/lesli_bell/announcements/new.html.erb +6 -9
- data/app/views/lesli_bell/announcements/show.html.erb +27 -10
- data/config/locales/translations.en.yml +72 -1
- data/config/locales/translations.es.yml +72 -1
- data/config/locales/translations.fr.yml +2 -1
- data/config/locales/translations.it.yml +2 -1
- data/config/locales/translations.pt.yml +2 -1
- data/config/routes.rb +3 -1
- data/db/migrate/v1.0/0308110110_create_lesli_bell_announcements.rb +7 -7
- data/db/migrate/v1.0/0308110310_create_lesli_bell_announcement_users.rb +3 -3
- data/db/migrate/v1.0/0308110410_create_lesli_bell_announcement_recipients.rb +17 -0
- data/db/seed/announcements.rb +10 -14
- data/db/seed/seeds.json +2 -1
- data/lib/lesli_bell/version.rb +2 -2
- data/readme.md +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1f9b9cb352ab9a1e0f6ec1cf3be97b85a0ea236e8c5ff408f23b98119233f9d7
|
|
4
|
+
data.tar.gz: c1a09650a703ba04dd09644fca6560b07f423b5739847e70d519860ec0eba76f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 353a35be16ec75b1873fad071a822550b2de57663f601c171e78c3d910e0b7d27a76d6907ba8cb7dca0fb9535e3fff5a8d1ac0cca30199d6cdd689a5867616e3
|
|
7
|
+
data.tar.gz: e505f7fa1314d354346333873e17a027668c447d057e4575c5c42b5e911449b86e0b37d4a565fc420bd50270af4c2c9cd605560f7fcb93bdb7ca24ea5c7ecf86
|
|
@@ -62,6 +62,12 @@
|
|
|
62
62
|
.mt-1\.5 {
|
|
63
63
|
margin-top: calc(var(--spacing) * 1.5);
|
|
64
64
|
}
|
|
65
|
+
.mt-6 {
|
|
66
|
+
margin-top: calc(var(--spacing) * 6);
|
|
67
|
+
}
|
|
68
|
+
.mb-6 {
|
|
69
|
+
margin-bottom: calc(var(--spacing) * 6);
|
|
70
|
+
}
|
|
65
71
|
.line-clamp-2 {
|
|
66
72
|
overflow: hidden;
|
|
67
73
|
display: -webkit-box;
|
|
@@ -74,6 +80,9 @@
|
|
|
74
80
|
.flex {
|
|
75
81
|
display: flex;
|
|
76
82
|
}
|
|
83
|
+
.grid {
|
|
84
|
+
display: grid;
|
|
85
|
+
}
|
|
77
86
|
.inline-flex {
|
|
78
87
|
display: inline-flex;
|
|
79
88
|
}
|
|
@@ -121,6 +130,9 @@
|
|
|
121
130
|
.gap-3 {
|
|
122
131
|
gap: calc(var(--spacing) * 3);
|
|
123
132
|
}
|
|
133
|
+
.gap-4 {
|
|
134
|
+
gap: calc(var(--spacing) * 4);
|
|
135
|
+
}
|
|
124
136
|
.gap-x-2 {
|
|
125
137
|
column-gap: calc(var(--spacing) * 2);
|
|
126
138
|
}
|
|
@@ -258,6 +270,12 @@
|
|
|
258
270
|
--tw-font-weight: var(--font-weight-semibold);
|
|
259
271
|
font-weight: var(--font-weight-semibold);
|
|
260
272
|
}
|
|
273
|
+
.break-words {
|
|
274
|
+
overflow-wrap: break-word;
|
|
275
|
+
}
|
|
276
|
+
.whitespace-pre-wrap {
|
|
277
|
+
white-space: pre-wrap;
|
|
278
|
+
}
|
|
261
279
|
.text-danger-700 {
|
|
262
280
|
color: var(--lesli-color-danger-700);
|
|
263
281
|
}
|
|
@@ -352,6 +370,9 @@
|
|
|
352
370
|
.sm\:right-5 {
|
|
353
371
|
right: calc(var(--spacing) * 5);
|
|
354
372
|
}
|
|
373
|
+
.sm\:grid-cols-2 {
|
|
374
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
375
|
+
}
|
|
355
376
|
.sm\:px-5 {
|
|
356
377
|
padding-inline: calc(var(--spacing) * 5);
|
|
357
378
|
}
|
|
@@ -1,75 +1,121 @@
|
|
|
1
1
|
module LesliBell
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
class AnnouncementsController < ApplicationController
|
|
3
|
+
prepend_before_action :use_html_for_page_navigation, only: [:index, :show, :new, :edit]
|
|
4
|
+
before_action :load_service
|
|
5
|
+
before_action :load_announcement, only: [:show, :edit, :update, :destroy]
|
|
6
|
+
before_action :load_audience_options, only: [:new, :edit, :create, :update]
|
|
7
|
+
rescue_from ActiveRecord::RecordNotFound do
|
|
8
|
+
if action_name == "dismiss" && request.format.turbo_stream?
|
|
9
|
+
dismissal_error(:not_found)
|
|
10
|
+
else
|
|
11
|
+
respond_with_not_found
|
|
12
|
+
end
|
|
13
|
+
end
|
|
4
14
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
format.html { }
|
|
9
|
-
format.json {
|
|
10
|
-
respond_with_pagination(AnnouncementService.new(current_user, query).list)
|
|
11
|
-
}
|
|
15
|
+
def index
|
|
16
|
+
@announcements = @service.index.result
|
|
17
|
+
respond_with_lesli(json: respond_with_pagination(@announcements))
|
|
12
18
|
end
|
|
13
|
-
end
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
respond_to do |format|
|
|
18
|
-
format.html { }
|
|
19
|
-
format.json {
|
|
20
|
-
respond_with_pagination(AnnouncementService.new(current_user, query).index)
|
|
21
|
-
}
|
|
20
|
+
def show
|
|
21
|
+
respond_with_lesli(json: announcement_json)
|
|
22
22
|
end
|
|
23
|
-
end
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
def new
|
|
25
|
+
@announcement = Announcement.new
|
|
26
|
+
end
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@announcement = Announcement.new
|
|
32
|
-
end
|
|
28
|
+
def edit
|
|
29
|
+
end
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
def create
|
|
32
|
+
@service.create(announcement_params)
|
|
33
|
+
save_response(:new, :created, :created)
|
|
34
|
+
end
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
def update
|
|
37
|
+
@service.update(announcement_params)
|
|
38
|
+
save_response(:edit, :updated, :ok)
|
|
39
|
+
end
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end
|
|
41
|
+
def destroy
|
|
42
|
+
@service.destroy
|
|
43
|
+
success(t("lesli_bell.announcements.deleted"))
|
|
44
|
+
respond_with_lesli(json: { id: @announcement.id }, redirect: announcements_path)
|
|
45
|
+
end
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
def dismiss
|
|
48
|
+
dismissal = @service.dismiss(params[:id]).result
|
|
49
|
+
respond_with_lesli(
|
|
50
|
+
turbo: turbo_stream.remove("announcement-#{dismissal.announcement_id}"),
|
|
51
|
+
json: { id: dismissal.announcement_id, dismissed_at: dismissal.created_at },
|
|
52
|
+
redirect: announcements_path
|
|
53
|
+
)
|
|
54
|
+
rescue ActiveRecord::RecordInvalid => exception
|
|
55
|
+
@announcement = exception.record
|
|
56
|
+
respond_with_lesli(
|
|
57
|
+
html: :show, json: { errors: @announcement.errors.to_hash },
|
|
58
|
+
turbo: stream_notification_danger(@announcement.errors.full_messages.to_sentence),
|
|
59
|
+
status: :unprocessable_content
|
|
60
|
+
)
|
|
61
|
+
end
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
# Turbo preserves its Accept header when following a form's redirect.
|
|
66
|
+
# These actions render complete pages, including Core's HTML banner loader.
|
|
67
|
+
def use_html_for_page_navigation
|
|
68
|
+
request.format = :html if request.get? && request.format.turbo_stream?
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# A failed close must not replace the current page or remove its banner.
|
|
72
|
+
# Authorization still runs through Core's existing callback.
|
|
73
|
+
def respond_with_forbidden(details = {})
|
|
74
|
+
return super unless action_name == "dismiss" && request.format.turbo_stream?
|
|
63
75
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
dismissal_error(:forbidden)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def dismissal_error(status)
|
|
80
|
+
respond_with_lesli(
|
|
81
|
+
turbo: stream_notification_danger(t("lesli_bell.announcements.dismiss_failed")),
|
|
82
|
+
status: status
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def load_service
|
|
87
|
+
@service = AnnouncementService.new(current_user, query)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def load_announcement
|
|
91
|
+
@announcement = @service.show(params[:id]).result
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def load_audience_options
|
|
95
|
+
@audience_users = current_user.account.users.order(:email).pluck(:email, :id)
|
|
96
|
+
@audience_roles = current_user.account.roles.order(:name).pluck(:name, :id) if defined?(LesliShield)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def announcement_json
|
|
100
|
+
@announcement.as_json.merge(user_ids: @announcement.user_ids, role_ids: @announcement.role_ids)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def announcement_params
|
|
104
|
+
params.require(:announcement).permit(*AnnouncementService::EDITABLE_ATTRIBUTES, user_ids: [], role_ids: []).to_h
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def save_response(template, message, status)
|
|
108
|
+
@announcement = @service.result
|
|
109
|
+
unless @service.successful?
|
|
110
|
+
return respond_with_lesli(
|
|
111
|
+
html: template, json: { errors: @announcement.errors.to_hash },
|
|
112
|
+
turbo: turbo_stream.replace("announcement-form", partial: "lesli_bell/announcements/form"),
|
|
113
|
+
status: :unprocessable_content
|
|
114
|
+
)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
success(t("lesli_bell.announcements.#{message}"))
|
|
118
|
+
respond_with_lesli(json: announcement_json, status: status, redirect: announcement_path(@announcement))
|
|
119
|
+
end
|
|
120
|
+
end
|
|
75
121
|
end
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
module LesliBell
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module AnnouncementsHelper
|
|
3
|
+
def announcement_categories
|
|
4
|
+
Announcement.categories.keys.map { |category| [t("lesli_bell.announcements.categories.#{category}"), category] }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def announcement_audiences
|
|
8
|
+
Announcement.audiences.keys.map { |audience| [t("lesli_bell.announcements.audiences.#{audience}"), audience] }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def announcement_audience_summary(announcement)
|
|
12
|
+
return t("lesli_bell.announcements.audiences.account") if announcement.audience_account?
|
|
13
|
+
|
|
14
|
+
labels = announcement.recipient_users.pluck(:email) + announcement.recipient_roles.pluck(:name)
|
|
15
|
+
labels.presence&.join(", ") || t("lesli_bell.announcements.audience_empty")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def announcement_datetime(value)
|
|
19
|
+
value ? l(value, format: :long) : t("lesli_bell.announcements.no_limit")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
4
22
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module LesliBell
|
|
2
|
+
class Announcement::RoleRecipient < ActiveRecord::Base
|
|
3
|
+
self.table_name = "lesli_bell_announcement_role_recipients"
|
|
4
|
+
|
|
5
|
+
belongs_to :announcement, class_name: "LesliBell::Announcement", inverse_of: :role_recipients
|
|
6
|
+
belongs_to :role, class_name: "Lesli::Role"
|
|
7
|
+
validate :recipient_belongs_to_account
|
|
8
|
+
before_destroy -> { announcement.lock! }
|
|
9
|
+
after_destroy -> { announcement.deactivate_without_recipients! }
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def recipient_belongs_to_account
|
|
14
|
+
return unless announcement && role
|
|
15
|
+
return if role.account_id == announcement.account.account_id
|
|
16
|
+
|
|
17
|
+
errors.add(:role, :invalid)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module LesliBell
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
# Dismissals are permanent records; do not inherit the soft-delete behavior.
|
|
3
|
+
class Announcement::User < ActiveRecord::Base
|
|
4
|
+
self.table_name = "lesli_bell_announcement_users"
|
|
5
|
+
|
|
6
|
+
belongs_to :announcement, class_name: "LesliBell::Announcement", inverse_of: :dismissals
|
|
4
7
|
belongs_to :user, class_name: "::Lesli::User"
|
|
5
8
|
end
|
|
6
9
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module LesliBell
|
|
2
|
+
class Announcement::UserRecipient < ActiveRecord::Base
|
|
3
|
+
self.table_name = "lesli_bell_announcement_user_recipients"
|
|
4
|
+
|
|
5
|
+
belongs_to :announcement, class_name: "LesliBell::Announcement", inverse_of: :user_recipients
|
|
6
|
+
belongs_to :user, class_name: "Lesli::User"
|
|
7
|
+
validate :recipient_belongs_to_account
|
|
8
|
+
before_destroy -> { announcement.lock! }
|
|
9
|
+
after_destroy -> { announcement.deactivate_without_recipients! }
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def recipient_belongs_to_account
|
|
14
|
+
return unless announcement && user
|
|
15
|
+
return if user.account_id == announcement.account.account_id
|
|
16
|
+
|
|
17
|
+
errors.add(:user, :invalid)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -1,14 +1,109 @@
|
|
|
1
|
+
require "uri"
|
|
2
|
+
|
|
1
3
|
module LesliBell
|
|
2
4
|
class Announcement < ApplicationRecord
|
|
3
5
|
belongs_to :account, class_name: "LesliBell::Account"
|
|
6
|
+
# The user is the author, not a recipient of the announcement.
|
|
4
7
|
belongs_to :user, class_name: "::Lesli::User"
|
|
5
|
-
has_many :
|
|
8
|
+
has_many :dismissals, class_name: "LesliBell::Announcement::User", inverse_of: :announcement
|
|
9
|
+
|
|
10
|
+
has_many :user_recipients, class_name: "LesliBell::Announcement::UserRecipient", inverse_of: :announcement
|
|
11
|
+
has_many :role_recipients, class_name: "LesliBell::Announcement::RoleRecipient", inverse_of: :announcement
|
|
12
|
+
has_many :recipient_users, through: :user_recipients, source: :user
|
|
13
|
+
has_many :recipient_roles, through: :role_recipients, source: :role
|
|
14
|
+
|
|
15
|
+
enum :audience, { account: "account", specific: "specific" }, prefix: true, default: :account, validate: true
|
|
16
|
+
|
|
17
|
+
# Submitted IDs remain available to the form when validation fails.
|
|
18
|
+
attr_writer :user_ids, :role_ids
|
|
19
|
+
attr_accessor :allow_empty_audience
|
|
6
20
|
|
|
7
21
|
enum :category, {
|
|
8
22
|
:info => 'info',
|
|
9
23
|
:danger => 'danger',
|
|
10
24
|
:warning => 'warning',
|
|
11
25
|
:success => 'success'
|
|
12
|
-
}
|
|
26
|
+
}, default: :info, validate: true
|
|
27
|
+
|
|
28
|
+
attribute :active, :boolean, default: true
|
|
29
|
+
attribute :can_be_closed, :boolean, default: true
|
|
30
|
+
|
|
31
|
+
normalizes :name, :message, with: ->(value) { value.strip }
|
|
32
|
+
normalizes :path, :url, with: ->(value) { value.strip.presence }
|
|
33
|
+
|
|
34
|
+
validates :name, :message, presence: true
|
|
35
|
+
validates :active, :can_be_closed, inclusion: { in: [true, false] }
|
|
36
|
+
validates :end_at, comparison: { greater_than: :start_at },
|
|
37
|
+
if: -> { start_at.present? && end_at.present? }
|
|
38
|
+
|
|
39
|
+
# Match request.path exactly: no host, query string, fragment, or wildcard.
|
|
40
|
+
validates :path, format: { with: %r{\A/(?!/)[^?#\\\s*]*\z} }, allow_nil: true
|
|
41
|
+
validate :url_is_a_supported_destination
|
|
42
|
+
validate :audience_is_valid
|
|
43
|
+
validate :publication_dates_are_valid
|
|
44
|
+
|
|
45
|
+
def user_ids
|
|
46
|
+
@user_ids || user_recipients.pluck(:user_id)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def role_ids
|
|
50
|
+
@role_ids || role_recipients.pluck(:role_id)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def clear_audience_selection
|
|
54
|
+
@user_ids = @role_ids = nil
|
|
55
|
+
self.allow_empty_audience = false
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Keep a specific audience specific even after its final recipient is removed.
|
|
59
|
+
def deactivate_without_recipients!
|
|
60
|
+
return unless audience_specific?
|
|
61
|
+
return if user_recipients.exists? || role_recipients.exists?
|
|
62
|
+
|
|
63
|
+
# An empty specific audience is intentionally retained but cannot be published.
|
|
64
|
+
# Skip the recipient-presence validation when disabling it.
|
|
65
|
+
update_columns(active: false, updated_at: Time.current)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
# Rails casts malformed datetime input to nil; distinguish it from an empty field.
|
|
71
|
+
def publication_dates_are_valid
|
|
72
|
+
[:start_at, :end_at].each do |attribute|
|
|
73
|
+
if public_send("#{attribute}_before_type_cast").present? && public_send(attribute).nil?
|
|
74
|
+
errors.add(attribute, :invalid)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def audience_is_valid
|
|
80
|
+
if audience_specific? && user_ids.empty? && role_ids.empty? && !allow_empty_audience
|
|
81
|
+
errors.add(:base, I18n.t("lesli_bell.announcements.audience_required"))
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
core_account = account&.account
|
|
85
|
+
return unless core_account
|
|
86
|
+
|
|
87
|
+
valid_users = core_account.users.where(id: user_ids).pluck(:id).map(&:to_s)
|
|
88
|
+
unless (user_ids.map(&:to_s) - valid_users).empty?
|
|
89
|
+
errors.add(:base, I18n.t("lesli_bell.announcements.invalid_users"))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
valid_roles = defined?(LesliShield) ? core_account.roles.where(id: role_ids).pluck(:id).map(&:to_s) : []
|
|
93
|
+
unless (role_ids.map(&:to_s) - valid_roles).empty?
|
|
94
|
+
errors.add(:base, I18n.t("lesli_bell.announcements.invalid_roles"))
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def url_is_a_supported_destination
|
|
99
|
+
return if url.nil?
|
|
100
|
+
|
|
101
|
+
destination = URI.parse(url)
|
|
102
|
+
internal_path = destination.relative? && url.start_with?("/") && !url.start_with?("//")
|
|
103
|
+
web_url = destination.is_a?(URI::HTTP) && destination.host.present?
|
|
104
|
+
errors.add(:url, :invalid) unless internal_path || web_url
|
|
105
|
+
rescue URI::InvalidURIError
|
|
106
|
+
errors.add(:url, :invalid)
|
|
107
|
+
end
|
|
13
108
|
end
|
|
14
109
|
end
|
|
@@ -1,84 +1,131 @@
|
|
|
1
1
|
module LesliBell
|
|
2
2
|
class AnnouncementService < Lesli::ApplicationLesliService
|
|
3
|
+
EDITABLE_ATTRIBUTES = %i[name message category active start_at end_at path url can_be_closed audience].freeze
|
|
4
|
+
|
|
5
|
+
# Banner selection is independent of administrative pagination.
|
|
6
|
+
# Compare both date boundaries against the same instant.
|
|
7
|
+
def list(path: nil)
|
|
8
|
+
now = Time.current
|
|
9
|
+
dismissed_ids = Announcement::User.where(user: current_user).select(:announcement_id)
|
|
10
|
+
|
|
11
|
+
visible = announcements.where(audience: :account)
|
|
12
|
+
user_matches = Announcement::UserRecipient.where(user_id: current_user.id).select(:announcement_id)
|
|
13
|
+
visible = visible.or(announcements.where(audience: :specific, id: user_matches))
|
|
14
|
+
if defined?(LesliShield)
|
|
15
|
+
memberships = LesliShield::User::Role.where(user: current_user).select(:role_id)
|
|
16
|
+
role_ids = current_user.account.roles.where(id: memberships).select(:id)
|
|
17
|
+
role_matches = Announcement::RoleRecipient.where(role_id: role_ids).select(:announcement_id)
|
|
18
|
+
visible = visible.or(announcements.where(audience: :specific, id: role_matches))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
visible
|
|
22
|
+
.where(active: true, path: [nil, path.presence])
|
|
23
|
+
.where("start_at IS NULL OR start_at <= ?", now)
|
|
24
|
+
.where("end_at IS NULL OR end_at > ?", now)
|
|
25
|
+
.where.not(id: dismissed_ids)
|
|
26
|
+
.order(:created_at, :id)
|
|
27
|
+
end
|
|
3
28
|
|
|
4
|
-
def
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# Get all the announcements for the current user
|
|
10
|
-
announcements = current_user.account.bell.announcements
|
|
11
|
-
|
|
12
|
-
# joining to the announcement_users table, to see if the users already mark the announcement as read
|
|
13
|
-
announcements = announcements.left_joins(:users)
|
|
14
|
-
|
|
15
|
-
# get the announcements without a specific path (global announcements)
|
|
16
|
-
announcements = announcements.where(path: nil)
|
|
17
|
-
|
|
18
|
-
# get the announcements with a specific path (to show only in a specific page)
|
|
19
|
-
#announcements = announcements.or(Announcement.where("path = ?", filters[:base_path])) if params.dig(:f, :base_path)
|
|
20
|
-
|
|
21
|
-
# get the announcements with a start date greater than or equal to current date and with expiration date less or equal than current date
|
|
22
|
-
# announcements = announcements.where("start_at <= '#{Date.now.end_of_day}' or start_at is NULL")
|
|
23
|
-
# .where("cloud_bell_announcements.end_at >= '#{LC::Date.now.beginning_of_day}' or end_at is NULL")
|
|
24
|
-
|
|
25
|
-
# get the announcements that are not marked as read by the user
|
|
26
|
-
announcements = announcements.where(users: { id: nil })
|
|
27
|
-
|
|
28
|
-
announcements.select(
|
|
29
|
-
:id,
|
|
30
|
-
:name,
|
|
31
|
-
:category,
|
|
32
|
-
:message,
|
|
33
|
-
:can_be_closed,
|
|
34
|
-
:start_at,
|
|
35
|
-
:end_at,
|
|
36
|
-
:path
|
|
37
|
-
).page(query[:pagination][:page])
|
|
38
|
-
.per(query[:pagination][:perPage])
|
|
39
|
-
.order(:start_at)
|
|
29
|
+
def index
|
|
30
|
+
pagination = query.fetch(:pagination, {})
|
|
31
|
+
response(announcements.order(:created_at, :id)
|
|
32
|
+
.page(pagination[:page]).per(pagination[:perPage]))
|
|
40
33
|
end
|
|
41
34
|
|
|
42
|
-
def
|
|
35
|
+
def show(id)
|
|
36
|
+
response(announcements.find(id))
|
|
37
|
+
end
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
announcements = current_user.account.bell
|
|
46
|
-
.announcements
|
|
47
|
-
.order(:start_at)
|
|
39
|
+
alias_method :find, :show
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
announcements
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
.order(:updated_at)
|
|
41
|
+
def create(attributes)
|
|
42
|
+
announcement = announcements.build(editable_attributes(attributes))
|
|
43
|
+
announcement.user = current_user
|
|
44
|
+
persist(announcement, attributes)
|
|
54
45
|
end
|
|
55
46
|
|
|
56
|
-
def
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
send_to_user_ids:nil,
|
|
60
|
-
send_to_user_emails:nil
|
|
61
|
-
)
|
|
47
|
+
def update(attributes)
|
|
48
|
+
persist(resource, attributes)
|
|
49
|
+
end
|
|
62
50
|
|
|
63
|
-
|
|
51
|
+
def destroy
|
|
52
|
+
resource.destroy!
|
|
53
|
+
response(resource)
|
|
54
|
+
end
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
def dismiss(id)
|
|
57
|
+
announcement = announcements.find(id)
|
|
58
|
+
unless announcement.can_be_closed?
|
|
59
|
+
announcement.errors.add(:base, I18n.t("lesli_bell.announcements.cannot_dismiss"))
|
|
60
|
+
raise ActiveRecord::RecordInvalid.new(announcement)
|
|
67
61
|
end
|
|
68
62
|
|
|
69
|
-
|
|
63
|
+
# The unique index makes repeated requests return the same dismissal,
|
|
64
|
+
# preserving the original created_at even when requests overlap.
|
|
65
|
+
self.resource = announcement.dismissals.create_or_find_by!(user: current_user)
|
|
66
|
+
self
|
|
67
|
+
end
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
private
|
|
72
70
|
|
|
73
|
-
|
|
71
|
+
def announcements
|
|
72
|
+
current_user.account.bell.announcements
|
|
73
|
+
end
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
# Ownership comes from the authenticated context, including direct service calls.
|
|
76
|
+
def editable_attributes(attributes)
|
|
77
|
+
attributes.to_h.symbolize_keys.slice(*EDITABLE_ATTRIBUTES)
|
|
78
|
+
end
|
|
77
79
|
|
|
78
|
-
def
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
def persist(announcement, attributes)
|
|
81
|
+
attributes = attributes.to_h.symbolize_keys
|
|
82
|
+
Announcement.transaction do
|
|
83
|
+
# Serialize recipient replacement with other edits and dismissals of recipients.
|
|
84
|
+
announcement.lock! if announcement.persisted?
|
|
85
|
+
announcement.assign_attributes(editable_attributes(attributes))
|
|
86
|
+
assign_audience(announcement, attributes)
|
|
87
|
+
announcement.save!
|
|
88
|
+
# Add both kinds before removing either, including user-to-role replacements.
|
|
89
|
+
add_recipients(announcement.user_recipients, :user_id, announcement.user_ids)
|
|
90
|
+
add_recipients(announcement.role_recipients, :role_id, announcement.role_ids)
|
|
91
|
+
announcement.user_recipients.where.not(user_id: announcement.user_ids).each(&:destroy!)
|
|
92
|
+
announcement.role_recipients.where.not(role_id: announcement.role_ids).each(&:destroy!)
|
|
93
|
+
announcement.clear_audience_selection
|
|
94
|
+
end
|
|
95
|
+
response(announcement)
|
|
96
|
+
rescue ActiveRecord::RecordInvalid => exception
|
|
97
|
+
if exception.record != announcement
|
|
98
|
+
announcement.errors.add(:base, exception.record.errors.full_messages.to_sentence)
|
|
99
|
+
end
|
|
100
|
+
error(announcement.errors.full_messages.to_sentence)
|
|
101
|
+
response(announcement)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def assign_audience(announcement, attributes)
|
|
105
|
+
[:user_ids, :role_ids].each do |key|
|
|
106
|
+
next unless attributes.key?(key)
|
|
107
|
+
|
|
108
|
+
announcement.public_send("#{key}=", Array(attributes[key]).reject(&:blank?).map(&:to_s).uniq)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
has_recipients = announcement.user_ids.any? || announcement.role_ids.any?
|
|
112
|
+
if attributes[:audience].to_s == "account"
|
|
113
|
+
announcement.user_ids = []
|
|
114
|
+
announcement.role_ids = []
|
|
115
|
+
elsif has_recipients && !attributes.key?(:audience)
|
|
116
|
+
announcement.audience = :specific
|
|
117
|
+
elsif announcement.audience_specific? && !has_recipients && !attributes.key?(:audience)
|
|
118
|
+
# An API caller can explicitly empty the audience, but never publish it to everyone.
|
|
119
|
+
announcement.active = false
|
|
120
|
+
announcement.allow_empty_audience = true
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def add_recipients(association, foreign_key, ids)
|
|
125
|
+
existing_ids = association.pluck(foreign_key).map(&:to_s)
|
|
126
|
+
(ids.map(&:to_s) - existing_ids).each do |id|
|
|
127
|
+
association.create!(foreign_key => id)
|
|
128
|
+
end
|
|
82
129
|
end
|
|
83
130
|
end
|
|
84
131
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<div id="announcement-form">
|
|
2
|
+
<%= form_with model: @announcement, scope: :announcement, builder: LesliView::Forms::Builder,
|
|
3
|
+
url: @announcement.persisted? ? announcement_path(@announcement) : announcements_path,
|
|
4
|
+
data: { turbo_frame: "_top" } do |form| %>
|
|
5
|
+
<%= form.fieldset do %>
|
|
6
|
+
<% if @announcement.errors.any? %>
|
|
7
|
+
<div role="alert"><%= form.field_control_builder(message_text: @announcement.errors.full_messages.to_sentence, category: :danger) %></div>
|
|
8
|
+
<% end %>
|
|
9
|
+
<%= form.field_control(:name, label: t("lesli_bell.announcements.name"), required: true) %>
|
|
10
|
+
<%= form.field_control_textarea(:message, label: t("lesli_bell.announcements.message"), required: true, rows: 4) %>
|
|
11
|
+
<%= form.field_control_select(:category, announcement_categories, label: t("lesli_bell.announcements.category"), humanize: false) %>
|
|
12
|
+
<%= form.field_control_select(:audience, announcement_audiences,
|
|
13
|
+
label: t("lesli_bell.announcements.audience"), humanize: false,
|
|
14
|
+
message: t("lesli_bell.announcements.audience_hint")) %>
|
|
15
|
+
<%= form.field_control_select(:user_ids, @audience_users,
|
|
16
|
+
label: t("lesli_bell.announcements.recipient_users"), humanize: false,
|
|
17
|
+
html_options: { multiple: true, size: 5 }) %>
|
|
18
|
+
<% if @audience_roles %>
|
|
19
|
+
<%= form.field_control_select(:role_ids, @audience_roles,
|
|
20
|
+
label: t("lesli_bell.announcements.recipient_roles"), humanize: false,
|
|
21
|
+
html_options: { multiple: true, size: 5 }) %>
|
|
22
|
+
<% end %>
|
|
23
|
+
<%= form.field_control_checkbox(:active, label: t("lesli_bell.announcements.active")) %>
|
|
24
|
+
<% [:start_at, :end_at].each do |field| %>
|
|
25
|
+
<%= form.field_control(field, label: t("lesli_bell.announcements.#{field}"), type: "datetime-local",
|
|
26
|
+
value: @announcement.public_send(field)&.strftime("%Y-%m-%dT%H:%M:%S"), step: 1) %>
|
|
27
|
+
<% end %>
|
|
28
|
+
<%= form.field_control(:path, label: t("lesli_bell.announcements.path"), message: t("lesli_bell.announcements.path_hint")) %>
|
|
29
|
+
<%= form.field_control(:url, label: t("lesli_bell.announcements.url"), message: t("lesli_bell.announcements.url_hint")) %>
|
|
30
|
+
<%= form.field_control_checkbox(:can_be_closed, label: t("lesli_bell.announcements.can_be_closed")) %>
|
|
31
|
+
<%= form.field_control_submit(t("lesli_bell.announcements.save")) %>
|
|
32
|
+
<% end %>
|
|
33
|
+
<% end %>
|
|
34
|
+
</div>
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<%= render "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<div>
|
|
8
|
-
<%= link_to "Show this announcement", @announcement %> |
|
|
9
|
-
<%= link_to "Back to announcements", announcements_path %>
|
|
10
|
-
</div>
|
|
1
|
+
<%= render LesliView::Layout::Container.new("announcements-edit") do %>
|
|
2
|
+
<%= render LesliView::Components::Header.new(t("lesli_bell.announcements.edit")) do %>
|
|
3
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.back"), url: announcements_path, icon: "arrow_back", solid: false) %>
|
|
4
|
+
<% end %>
|
|
5
|
+
<%= render "form" %>
|
|
6
|
+
<% end %>
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@website https://www.lesli.tech
|
|
27
|
-
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
|
28
|
-
|
|
29
|
-
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
|
30
|
-
// ·
|
|
31
|
-
%>
|
|
32
|
-
|
|
33
|
-
<router-view></router-view>
|
|
1
|
+
<%= render LesliView::Layout::Container.new("announcements-index") do %>
|
|
2
|
+
<%= render LesliView::Components::Header.new(t("lesli_bell.announcements.title")) do %>
|
|
3
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.new"), url: new_announcement_path, icon: "add") %>
|
|
4
|
+
<% end %>
|
|
5
|
+
<%= render LesliView::Elements::Table.new(
|
|
6
|
+
columns: %w[name category publication start_at end_at].map { |field| { field: field, label: t("lesli_bell.announcements.#{field}") } },
|
|
7
|
+
records: @announcements.map { |announcement| {
|
|
8
|
+
id: announcement.id, name: announcement.name,
|
|
9
|
+
category: t("lesli_bell.announcements.categories.#{announcement.category}"),
|
|
10
|
+
publication: t("lesli_bell.announcements.#{announcement.active? ? 'active' : 'inactive'}"),
|
|
11
|
+
start_at: announcement_datetime(announcement.start_at),
|
|
12
|
+
end_at: announcement_datetime(announcement.end_at)
|
|
13
|
+
} },
|
|
14
|
+
link: ->(announcement) { announcement_path(announcement.fetch(:id)) },
|
|
15
|
+
empty: t("lesli_bell.announcements.empty")
|
|
16
|
+
) %>
|
|
17
|
+
<nav class="mt-6 flex gap-3" aria-label="<%= t('lesli_bell.announcements.pagination') %>">
|
|
18
|
+
<% if @announcements.prev_page %>
|
|
19
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.previous"), url: announcements_path(page: @announcements.prev_page, perPage: @announcements.limit_value), solid: false) %>
|
|
20
|
+
<% end %>
|
|
21
|
+
<% if @announcements.next_page %>
|
|
22
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.next"), url: announcements_path(page: @announcements.next_page, perPage: @announcements.limit_value), solid: false) %>
|
|
23
|
+
<% end %>
|
|
24
|
+
</nav>
|
|
25
|
+
<% end %>
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<%= render "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<div>
|
|
8
|
-
<%= link_to "Back to announcements", announcements_path %>
|
|
9
|
-
</div>
|
|
1
|
+
<%= render LesliView::Layout::Container.new("announcements-new") do %>
|
|
2
|
+
<%= render LesliView::Components::Header.new(t("lesli_bell.announcements.new")) do %>
|
|
3
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.back"), url: announcements_path, icon: "arrow_back", solid: false) %>
|
|
4
|
+
<% end %>
|
|
5
|
+
<%= render "form" %>
|
|
6
|
+
<% end %>
|
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<%= render
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<%= render LesliView::Layout::Container.new("announcements-show") do %>
|
|
2
|
+
<%= render LesliView::Components::Header.new(@announcement.name) do %>
|
|
3
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.back"), url: announcements_path, icon: "arrow_back", solid: false) %>
|
|
4
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.edit"), url: edit_announcement_path(@announcement), icon: "edit") %>
|
|
5
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.delete"), url: announcement_path(@announcement), method: :delete,
|
|
6
|
+
data: { turbo_confirm: t("lesli_bell.announcements.confirm_delete") }, icon: "delete", danger: true, solid: false) %>
|
|
7
|
+
<% end %>
|
|
8
|
+
<% if @announcement.errors.any? %>
|
|
9
|
+
<p role="alert"><%= @announcement.errors.full_messages.to_sentence %></p>
|
|
10
|
+
<% end %>
|
|
11
|
+
<p class="mb-6 whitespace-pre-wrap break-words"><%= @announcement.message %></p>
|
|
12
|
+
<dl class="grid gap-4 sm:grid-cols-2">
|
|
13
|
+
<% {
|
|
14
|
+
audience: announcement_audience_summary(@announcement),
|
|
15
|
+
category: t("lesli_bell.announcements.categories.#{@announcement.category}"),
|
|
16
|
+
publication: t("lesli_bell.announcements.#{@announcement.active? ? 'active' : 'inactive'}"),
|
|
17
|
+
start_at: announcement_datetime(@announcement.start_at), end_at: announcement_datetime(@announcement.end_at),
|
|
18
|
+
path: @announcement.path || t("lesli_bell.announcements.all_pages"),
|
|
19
|
+
can_be_closed: t("lesli_bell.announcements.#{@announcement.can_be_closed? ? 'yes' : 'no'}")
|
|
20
|
+
}.each do |field, value| %>
|
|
21
|
+
<div><dt class="font-medium"><%= t("lesli_bell.announcements.#{field}") %></dt><dd><%= value %></dd></div>
|
|
22
|
+
<% end %>
|
|
23
|
+
</dl>
|
|
24
|
+
<% if @announcement.url.present? %>
|
|
25
|
+
<%= render LesliView::Elements::Button.new(t("lesli_bell.announcements.open_link"), url: @announcement.url, solid: false) %>
|
|
26
|
+
<% end %>
|
|
27
|
+
<% end %>
|
|
@@ -1,2 +1,73 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
2
|
+
en:
|
|
3
|
+
lesli_bell:
|
|
4
|
+
announcements:
|
|
5
|
+
audience: "Audience"
|
|
6
|
+
audience_hint: "Choose specific users or roles below. Matching either is sufficient. Entire account clears the selection. Use Ctrl or Command to select multiple entries."
|
|
7
|
+
recipient_users: "Users"
|
|
8
|
+
recipient_roles: "Roles"
|
|
9
|
+
audience_required: "Select at least one user or role for a specific audience."
|
|
10
|
+
invalid_users: "Selected users must belong to this account."
|
|
11
|
+
invalid_roles: "Selected roles must belong to this account and require LesliShield."
|
|
12
|
+
audience_empty: "No recipients (inactive)"
|
|
13
|
+
audiences:
|
|
14
|
+
account: "Entire account"
|
|
15
|
+
specific: "Specific users or roles"
|
|
16
|
+
dismiss_failed: "The announcement could not be dismissed."
|
|
17
|
+
"title": "Announcements"
|
|
18
|
+
"new": "Create announcement"
|
|
19
|
+
"edit": "Edit announcement"
|
|
20
|
+
"back": "All announcements"
|
|
21
|
+
"name": "Name"
|
|
22
|
+
"message": "Message"
|
|
23
|
+
"category": "Category"
|
|
24
|
+
"publication": "Publication"
|
|
25
|
+
"active": "Active"
|
|
26
|
+
"inactive": "Inactive"
|
|
27
|
+
"start_at": "Starts at"
|
|
28
|
+
"end_at": "Ends at"
|
|
29
|
+
"path": "Page"
|
|
30
|
+
"path_hint": "Leave blank for all pages, or enter an exact path such as /support."
|
|
31
|
+
"url": "Link"
|
|
32
|
+
"url_hint": "Optional internal path or HTTP/HTTPS URL."
|
|
33
|
+
"can_be_closed": "Allow users to dismiss"
|
|
34
|
+
"save": "Save"
|
|
35
|
+
"delete": "Delete"
|
|
36
|
+
"confirm_delete": "Delete this announcement?"
|
|
37
|
+
"created": "Announcement created."
|
|
38
|
+
"updated": "Announcement updated."
|
|
39
|
+
"deleted": "Announcement deleted."
|
|
40
|
+
"empty": "No announcements found"
|
|
41
|
+
"pagination": "Announcement pages"
|
|
42
|
+
"previous": "Previous"
|
|
43
|
+
"next": "Next"
|
|
44
|
+
"no_limit": "No limit"
|
|
45
|
+
"all_pages": "All pages"
|
|
46
|
+
"yes": "Yes"
|
|
47
|
+
"no": "No"
|
|
48
|
+
"open_link": "Open link"
|
|
49
|
+
categories:
|
|
50
|
+
info: "Information"
|
|
51
|
+
success: "Success"
|
|
52
|
+
warning: "Warning"
|
|
53
|
+
danger: "Danger"
|
|
54
|
+
cannot_dismiss: "This announcement cannot be dismissed."
|
|
55
|
+
dashboards: {}
|
|
56
|
+
items/attachments: {}
|
|
57
|
+
items/discussions: {}
|
|
58
|
+
items/tasks: {}
|
|
59
|
+
notifications: {}
|
|
60
|
+
shared: {}
|
|
61
|
+
activerecord:
|
|
62
|
+
attributes:
|
|
63
|
+
lesli_bell/announcement:
|
|
64
|
+
audience: "Audience"
|
|
65
|
+
name: "Name"
|
|
66
|
+
message: "Message"
|
|
67
|
+
category: "Category"
|
|
68
|
+
active: "Active"
|
|
69
|
+
start_at: "Starts at"
|
|
70
|
+
end_at: "Ends at"
|
|
71
|
+
path: "Page"
|
|
72
|
+
url: "Link"
|
|
73
|
+
can_be_closed: "Allow users to dismiss"
|
|
@@ -1,2 +1,73 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
2
|
+
es:
|
|
3
|
+
lesli_bell:
|
|
4
|
+
announcements:
|
|
5
|
+
audience: "Audiencia"
|
|
6
|
+
audience_hint: "Selecciona usuarios o roles abajo. Basta con coincidir con cualquiera. Toda la cuenta elimina la selección. Usa Ctrl o Command para seleccionar varias opciones."
|
|
7
|
+
recipient_users: "Usuarios"
|
|
8
|
+
recipient_roles: "Roles"
|
|
9
|
+
audience_required: "Selecciona al menos un usuario o rol para una audiencia específica."
|
|
10
|
+
invalid_users: "Los usuarios seleccionados deben pertenecer a esta cuenta."
|
|
11
|
+
invalid_roles: "Los roles seleccionados deben pertenecer a esta cuenta y requieren LesliShield."
|
|
12
|
+
audience_empty: "Sin destinatarios (inactivo)"
|
|
13
|
+
audiences:
|
|
14
|
+
account: "Toda la cuenta"
|
|
15
|
+
specific: "Usuarios o roles específicos"
|
|
16
|
+
dismiss_failed: "No se pudo cerrar el anuncio."
|
|
17
|
+
"title": "Anuncios"
|
|
18
|
+
"new": "Crear anuncio"
|
|
19
|
+
"edit": "Editar anuncio"
|
|
20
|
+
"back": "Todos los anuncios"
|
|
21
|
+
"name": "Nombre"
|
|
22
|
+
"message": "Mensaje"
|
|
23
|
+
"category": "Categoría"
|
|
24
|
+
"publication": "Publicación"
|
|
25
|
+
"active": "Activo"
|
|
26
|
+
"inactive": "Inactivo"
|
|
27
|
+
"start_at": "Inicio"
|
|
28
|
+
"end_at": "Fin"
|
|
29
|
+
"path": "Página"
|
|
30
|
+
"path_hint": "Dejar vacío para todas las páginas o indicar una ruta exacta como /support."
|
|
31
|
+
"url": "Enlace"
|
|
32
|
+
"url_hint": "Ruta interna o URL HTTP/HTTPS opcional."
|
|
33
|
+
"can_be_closed": "Permitir cerrar el anuncio"
|
|
34
|
+
"save": "Guardar"
|
|
35
|
+
"delete": "Eliminar"
|
|
36
|
+
"confirm_delete": "¿Eliminar este anuncio?"
|
|
37
|
+
"created": "Anuncio creado."
|
|
38
|
+
"updated": "Anuncio actualizado."
|
|
39
|
+
"deleted": "Anuncio eliminado."
|
|
40
|
+
"empty": "No se encontraron anuncios"
|
|
41
|
+
"pagination": "Páginas de anuncios"
|
|
42
|
+
"previous": "Anterior"
|
|
43
|
+
"next": "Siguiente"
|
|
44
|
+
"no_limit": "Sin límite"
|
|
45
|
+
"all_pages": "Todas las páginas"
|
|
46
|
+
"yes": "Sí"
|
|
47
|
+
"no": "No"
|
|
48
|
+
"open_link": "Abrir enlace"
|
|
49
|
+
categories:
|
|
50
|
+
info: "Información"
|
|
51
|
+
success: "Éxito"
|
|
52
|
+
warning: "Advertencia"
|
|
53
|
+
danger: "Peligro"
|
|
54
|
+
cannot_dismiss: "Este anuncio no se puede cerrar."
|
|
55
|
+
dashboards: {}
|
|
56
|
+
items/attachments: {}
|
|
57
|
+
items/discussions: {}
|
|
58
|
+
items/tasks: {}
|
|
59
|
+
notifications: {}
|
|
60
|
+
shared: {}
|
|
61
|
+
activerecord:
|
|
62
|
+
attributes:
|
|
63
|
+
lesli_bell/announcement:
|
|
64
|
+
audience: "Audiencia"
|
|
65
|
+
name: "Nombre"
|
|
66
|
+
message: "Mensaje"
|
|
67
|
+
category: "Categoría"
|
|
68
|
+
active: "Activo"
|
|
69
|
+
start_at: "Inicio"
|
|
70
|
+
end_at: "Fin"
|
|
71
|
+
path: "Página"
|
|
72
|
+
url: "Enlace"
|
|
73
|
+
can_be_closed: "Permitir cerrar el anuncio"
|
data/config/routes.rb
CHANGED
|
@@ -35,5 +35,7 @@ LesliBell::Engine.routes.draw do
|
|
|
35
35
|
resources :notifications, only: [:index, :new, :update] do
|
|
36
36
|
put :mark_all_as_read, on: :collection
|
|
37
37
|
end
|
|
38
|
-
resources :announcements
|
|
38
|
+
resources :announcements do
|
|
39
|
+
post :dismiss, on: :member
|
|
40
|
+
end
|
|
39
41
|
end
|
|
@@ -33,22 +33,22 @@ Building a better future, one line of code at a time.
|
|
|
33
33
|
class CreateLesliBellAnnouncements < ActiveRecord::Migration[6.0]
|
|
34
34
|
def change
|
|
35
35
|
create_table :lesli_bell_announcements do |t|
|
|
36
|
-
t.string :name
|
|
36
|
+
t.string :name, null: false
|
|
37
37
|
t.string :url
|
|
38
38
|
t.string :path
|
|
39
|
-
t.string :category
|
|
40
|
-
t.
|
|
41
|
-
t.
|
|
39
|
+
t.string :category, null: false
|
|
40
|
+
t.string :audience, null: false
|
|
41
|
+
t.text :message, null: false
|
|
42
|
+
t.boolean :active, null: false
|
|
42
43
|
t.datetime :start_at
|
|
43
44
|
t.datetime :end_at
|
|
44
|
-
t.boolean :can_be_closed, :
|
|
45
|
+
t.boolean :can_be_closed, null: false
|
|
45
46
|
|
|
46
47
|
t.datetime :deleted_at, index: true
|
|
47
48
|
t.timestamps
|
|
48
49
|
end
|
|
49
50
|
|
|
50
|
-
add_reference(:lesli_bell_announcements, :user, foreign_key: { to_table: :lesli_users })
|
|
51
|
-
add_reference(:lesli_bell_announcements, :role, foreign_key: { to_table: :lesli_roles })
|
|
51
|
+
add_reference(:lesli_bell_announcements, :user, null: false, foreign_key: { to_table: :lesli_users })
|
|
52
52
|
add_reference(:lesli_bell_announcements, :account, null: false, foreign_key: { to_table: :lesli_bell_accounts })
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -2,10 +2,10 @@ class CreateLesliBellAnnouncementUsers < ActiveRecord::Migration[7.0]
|
|
|
2
2
|
def change
|
|
3
3
|
create_table :lesli_bell_announcement_users do |t|
|
|
4
4
|
t.timestamps
|
|
5
|
-
t.datetime :deleted_at, index: true
|
|
6
5
|
end
|
|
7
6
|
|
|
8
|
-
add_reference(:lesli_bell_announcement_users, :user, foreign_key: { to_table: :lesli_users })
|
|
9
|
-
add_reference
|
|
7
|
+
add_reference(:lesli_bell_announcement_users, :user, null: false, foreign_key: { to_table: :lesli_users })
|
|
8
|
+
add_reference(:lesli_bell_announcement_users, :announcement, null: false, foreign_key: { to_table: :lesli_bell_announcements }, index: false)
|
|
9
|
+
add_index(:lesli_bell_announcement_users, [:announcement_id, :user_id], unique: true, name: "index_bell_dismissals_on_announcement_and_user")
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class CreateLesliBellAnnouncementRecipients < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
create_table :lesli_bell_announcement_user_recipients do |t|
|
|
4
|
+
t.references :announcement, null: false, foreign_key: { to_table: :lesli_bell_announcements }, index: false
|
|
5
|
+
t.references :user, null: false, foreign_key: { to_table: :lesli_users }
|
|
6
|
+
t.timestamps
|
|
7
|
+
t.index [:announcement_id, :user_id], unique: true, name: "index_bell_audience_users"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
create_table :lesli_bell_announcement_role_recipients do |t|
|
|
11
|
+
t.references :announcement, null: false, foreign_key: { to_table: :lesli_bell_announcements }, index: false
|
|
12
|
+
t.references :role, null: false, foreign_key: { to_table: :lesli_roles }
|
|
13
|
+
t.timestamps
|
|
14
|
+
t.index [:announcement_id, :role_id], unique: true, name: "index_bell_audience_roles"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/db/seed/announcements.rb
CHANGED
|
@@ -31,17 +31,13 @@ Building a better future, one line of code at a time.
|
|
|
31
31
|
=end
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
LesliBell::AnnouncementService.new(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
message: notification["message"],
|
|
45
|
-
url: notification["url"]
|
|
46
|
-
}, send_to_user_ids: ::Lesli::User.all.pluck(:id))
|
|
47
|
-
end
|
|
34
|
+
seeds = JSON.parse(File.read(LesliBell::Engine.root.join("db", "seed", "seeds.json")))
|
|
35
|
+
author = Lesli::User.first!
|
|
36
|
+
|
|
37
|
+
seeds.fetch("announcements").each do |attributes|
|
|
38
|
+
# Repeated seeds preserve edits, dismissals, and publication choices.
|
|
39
|
+
next if author.account.bell.announcements.with_deleted.exists?(name: attributes.fetch("name"))
|
|
40
|
+
|
|
41
|
+
service = LesliBell::AnnouncementService.new(author).create(attributes.merge("audience" => "account"))
|
|
42
|
+
raise ActiveRecord::RecordInvalid.new(service.result) unless service.successful?
|
|
43
|
+
end
|
data/db/seed/seeds.json
CHANGED
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
{ "message": "Unusual login attempt detected", "category": "danger", "body": "We noticed a login attempt from an unfamiliar location. Please review your account security.", "url": "https://example.com/security-alert" }
|
|
28
28
|
],
|
|
29
29
|
"announcements": [
|
|
30
|
-
{ "name": "
|
|
30
|
+
{ "name": "instance-created", "message": "Your new Lesli instance is ready. Welcome!", "category": "success" },
|
|
31
|
+
{ "name": "standard", "message": "Exciting News: Welcome to our platform!", "category": "info" },
|
|
31
32
|
{ "name": "information", "message": "Upcoming Event: System Maintenance Scheduled", "category": "info", "url": "https://example.com/maintenance-info" },
|
|
32
33
|
{ "name": "success", "message": "Success Update: Your Profile Has Been Updated!", "category": "success" },
|
|
33
34
|
{ "name": "warning", "message": "Friendly Reminder: Password Expiring Soon", "category": "warning", "url": "https://example.com/update-password" },
|
data/lib/lesli_bell/version.rb
CHANGED
data/readme.md
CHANGED
|
@@ -194,6 +194,7 @@ COVERAGE=true bin/rails test
|
|
|
194
194
|
- [Installation](https://www.lesli.dev/engines/bell/about/installation/)
|
|
195
195
|
- [Notifications](https://www.lesli.dev/engines/bell/notifications/overview/)
|
|
196
196
|
- [Announcements](https://www.lesli.dev/engines/bell/announcements/overview/)
|
|
197
|
+
- [Announcement testing](https://www.lesli.dev/engines/bell/announcements/testing/)
|
|
197
198
|
- [Database](https://www.lesli.dev/engines/bell/about/database/)
|
|
198
199
|
- [Translations](https://www.lesli.dev/engines/bell/about/translations/)
|
|
199
200
|
- [Frontend](https://www.lesli.dev/engines/bell/about/frontend/)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lesli_bell
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- The Lesli Development Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lesli
|
|
@@ -50,7 +50,9 @@ files:
|
|
|
50
50
|
- app/mailers/lesli_bell/application_mailer.rb
|
|
51
51
|
- app/models/lesli_bell/account.rb
|
|
52
52
|
- app/models/lesli_bell/announcement.rb
|
|
53
|
+
- app/models/lesli_bell/announcement/role_recipient.rb
|
|
53
54
|
- app/models/lesli_bell/announcement/user.rb
|
|
55
|
+
- app/models/lesli_bell/announcement/user_recipient.rb
|
|
54
56
|
- app/models/lesli_bell/application_record.rb
|
|
55
57
|
- app/models/lesli_bell/dashboard.rb
|
|
56
58
|
- app/models/lesli_bell/notification.rb
|
|
@@ -62,6 +64,7 @@ files:
|
|
|
62
64
|
- app/views/lesli_bell/accounts/index.html.erb
|
|
63
65
|
- app/views/lesli_bell/accounts/new.html.erb
|
|
64
66
|
- app/views/lesli_bell/accounts/show.html.erb
|
|
67
|
+
- app/views/lesli_bell/announcements/_form.html.erb
|
|
65
68
|
- app/views/lesli_bell/announcements/edit.html.erb
|
|
66
69
|
- app/views/lesli_bell/announcements/index.html.erb
|
|
67
70
|
- app/views/lesli_bell/announcements/new.html.erb
|
|
@@ -84,6 +87,7 @@ files:
|
|
|
84
87
|
- db/migrate/v1.0/0308110110_create_lesli_bell_announcements.rb
|
|
85
88
|
- db/migrate/v1.0/0308110210_create_lesli_bell_announcement_activities.rb
|
|
86
89
|
- db/migrate/v1.0/0308110310_create_lesli_bell_announcement_users.rb
|
|
90
|
+
- db/migrate/v1.0/0308110410_create_lesli_bell_announcement_recipients.rb
|
|
87
91
|
- db/seed/announcements.rb
|
|
88
92
|
- db/seed/notifications.rb
|
|
89
93
|
- db/seed/seeds.json
|