moduler 0.5.0 → 0.7.0

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.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/builds/moduler/tailwind.css +95 -0
  3. data/app/assets/javascripts/moduler/controllers/attachments_controller.js +30 -0
  4. data/app/assets/javascripts/moduler/controllers/dependent_select_controller.js +19 -0
  5. data/app/assets/javascripts/moduler/controllers/dropdown_controller.js +12 -0
  6. data/app/assets/javascripts/moduler/controllers/select_all_controller.js +15 -0
  7. data/app/components/moduler/filter_component.html.erb +9 -1
  8. data/app/components/moduler/filter_component.rb +12 -0
  9. data/app/components/moduler/form/attachments_component.html.erb +32 -0
  10. data/app/components/moduler/form/attachments_component.rb +28 -0
  11. data/app/components/moduler/form/checkboxes_component.html.erb +19 -0
  12. data/app/components/moduler/form/checkboxes_component.rb +13 -0
  13. data/app/components/moduler/form/select_component.html.erb +1 -1
  14. data/app/components/moduler/form/select_component.rb +5 -0
  15. data/app/components/moduler/form/wysiwyg_component.rb +1 -1
  16. data/app/controllers/concerns/moduler/authentication.rb +1 -1
  17. data/app/controllers/concerns/moduler/organization_scoped.rb +29 -0
  18. data/app/controllers/concerns/moduler/restrict_administrator_access.rb +32 -0
  19. data/app/controllers/moduler/administration/application_controller.rb +1 -0
  20. data/app/controllers/moduler/administration/articles_controller.rb +1 -1
  21. data/app/controllers/moduler/administration/emails/deliveries_controller.rb +42 -0
  22. data/app/controllers/moduler/administration/emails_controller.rb +68 -0
  23. data/app/controllers/moduler/administration/memberships_controller.rb +62 -0
  24. data/app/controllers/moduler/administration/organizations_controller.rb +51 -0
  25. data/app/controllers/moduler/administration/preferences_controller.rb +57 -0
  26. data/app/controllers/moduler/administration/roles_controller.rb +56 -0
  27. data/app/controllers/moduler/administration/users_controller.rb +2 -2
  28. data/app/controllers/moduler/application_controller.rb +7 -2
  29. data/app/controllers/moduler/articles_controller.rb +3 -2
  30. data/app/controllers/moduler/home_controller.rb +3 -1
  31. data/app/controllers/moduler/organizations_controller.rb +13 -0
  32. data/app/controllers/moduler/profile/sent_emails_controller.rb +18 -0
  33. data/app/controllers/moduler/profile/sessions/revocation_controller.rb +1 -0
  34. data/app/controllers/moduler/profile/sessions_controller.rb +1 -0
  35. data/app/controllers/moduler/profile_controller.rb +4 -1
  36. data/app/controllers/moduler/sessions_controller.rb +1 -0
  37. data/app/controllers/moduler/users_controller.rb +2 -0
  38. data/app/filters/email_delivery_filter.rb +35 -0
  39. data/app/filters/organization_query_filter.rb +23 -0
  40. data/app/jobs/moduler/email_delivery_job.rb +14 -0
  41. data/app/lib/moduler/form_builder.rb +17 -3
  42. data/app/mailers/moduler/application_mailer.rb +27 -1
  43. data/app/mailers/moduler/email_mailer.rb +14 -0
  44. data/app/models/moduler/article.rb +2 -0
  45. data/app/models/moduler/current.rb +1 -1
  46. data/app/models/moduler/email.rb +59 -0
  47. data/app/models/moduler/membership.rb +25 -0
  48. data/app/models/moduler/organization.rb +13 -0
  49. data/app/models/moduler/preference.rb +44 -0
  50. data/app/models/moduler/role.rb +26 -0
  51. data/app/models/moduler/sent_email.rb +13 -0
  52. data/app/models/moduler/user.rb +13 -1
  53. data/app/models/moduler/user_email.rb +15 -0
  54. data/app/policies/moduler/administration/email_policy.rb +26 -0
  55. data/app/policies/moduler/administration/membership_policy.rb +29 -0
  56. data/app/policies/moduler/administration/organization_policy.rb +25 -0
  57. data/app/policies/moduler/administration/preference_policy.rb +29 -0
  58. data/app/policies/moduler/administration/role_policy.rb +25 -0
  59. data/app/views/layouts/moduler/mailer.html.erb +30 -0
  60. data/app/views/layouts/moduler/mailer.text.erb +1 -0
  61. data/app/views/moduler/administration/articles/_article.html.erb +2 -0
  62. data/app/views/moduler/administration/articles/_form.html.erb +1 -0
  63. data/app/views/moduler/administration/emails/_email.html.erb +33 -0
  64. data/app/views/moduler/administration/emails/_form.html.erb +23 -0
  65. data/app/views/moduler/administration/emails/deliveries/new.html.erb +58 -0
  66. data/app/views/moduler/administration/emails/edit.html.erb +1 -0
  67. data/app/views/moduler/administration/emails/index.html.erb +13 -0
  68. data/app/views/moduler/administration/emails/new.html.erb +1 -0
  69. data/app/views/moduler/administration/memberships/_form.html.erb +38 -0
  70. data/app/views/moduler/administration/memberships/_membership.html.erb +23 -0
  71. data/app/views/moduler/administration/memberships/edit.html.erb +1 -0
  72. data/app/views/moduler/administration/memberships/index.html.erb +14 -0
  73. data/app/views/moduler/administration/memberships/new.html.erb +1 -0
  74. data/app/views/moduler/administration/organizations/_form.html.erb +13 -0
  75. data/app/views/moduler/administration/organizations/_organization.html.erb +23 -0
  76. data/app/views/moduler/administration/organizations/edit.html.erb +1 -0
  77. data/app/views/moduler/administration/organizations/index.html.erb +13 -0
  78. data/app/views/moduler/administration/organizations/new.html.erb +1 -0
  79. data/app/views/moduler/administration/preferences/_form.html.erb +16 -0
  80. data/app/views/moduler/administration/preferences/_preference.html.erb +24 -0
  81. data/app/views/moduler/administration/preferences/edit.html.erb +1 -0
  82. data/app/views/moduler/administration/preferences/index.html.erb +13 -0
  83. data/app/views/moduler/administration/preferences/new.html.erb +1 -0
  84. data/app/views/moduler/administration/roles/_form.html.erb +24 -0
  85. data/app/views/moduler/administration/roles/_role.html.erb +15 -0
  86. data/app/views/moduler/administration/roles/edit.html.erb +1 -0
  87. data/app/views/moduler/administration/roles/index.html.erb +14 -0
  88. data/app/views/moduler/administration/roles/new.html.erb +1 -0
  89. data/app/views/moduler/administration/users/_user.html.erb +4 -0
  90. data/app/views/moduler/administration/users/edit.html.erb +1 -0
  91. data/app/views/moduler/administration/users/new.html.erb +1 -0
  92. data/app/views/moduler/common/_header.html.erb +2 -7
  93. data/app/views/moduler/common/_organization_switcher.html.erb +29 -0
  94. data/app/views/moduler/common/_sidebar.html.erb +4 -1
  95. data/app/views/moduler/common/administration/_sidebar.html.erb +9 -0
  96. data/app/views/moduler/common/profile/_sidebar.html.erb +1 -0
  97. data/app/views/moduler/email_mailer/custom.html.erb +3 -0
  98. data/app/views/moduler/email_mailer/custom.text.erb +1 -0
  99. data/app/views/moduler/home/index.html.erb +22 -4
  100. data/app/views/moduler/organizations/show.html.erb +7 -0
  101. data/app/views/moduler/profile/edit.html.erb +1 -0
  102. data/app/views/moduler/profile/sent_emails/index.html.erb +26 -0
  103. data/config/locales/moduler/administration/articles/en.yml +5 -0
  104. data/config/locales/moduler/administration/emails/en.yml +75 -0
  105. data/config/locales/moduler/administration/memberships/en.yml +35 -0
  106. data/config/locales/moduler/administration/organizations/en.yml +26 -0
  107. data/config/locales/moduler/administration/preferences/en.yml +44 -0
  108. data/config/locales/moduler/administration/roles/en.yml +32 -0
  109. data/config/locales/moduler/administration/users/en.yml +6 -1
  110. data/config/locales/moduler/common/en.yml +12 -1
  111. data/config/locales/moduler/components/en.yml +5 -0
  112. data/config/locales/moduler/en.yml +1 -0
  113. data/config/locales/moduler/home/en.yml +7 -0
  114. data/config/locales/moduler/models/en.yml +8 -0
  115. data/config/locales/moduler/profile/en.yml +2 -0
  116. data/config/locales/moduler/profile/sent_emails/en.yml +11 -0
  117. data/config/routes.rb +12 -0
  118. data/db/migrate/20261111113522_create_moduler_organizations.rb +11 -0
  119. data/db/migrate/20261111150000_create_moduler_roles.rb +13 -0
  120. data/db/migrate/20261111160000_create_moduler_memberships.rb +13 -0
  121. data/db/migrate/20261111180000_add_name_to_moduler_users.rb +5 -0
  122. data/db/migrate/20261111190000_add_status_to_moduler_articles.rb +8 -0
  123. data/db/migrate/20261111200000_create_moduler_preferences.rb +13 -0
  124. data/db/migrate/20261111210000_create_moduler_emails.rb +15 -0
  125. data/db/migrate/20261111210001_create_moduler_user_emails.rb +13 -0
  126. data/db/migrate/20261111210002_create_moduler_sent_emails.rb +12 -0
  127. data/lib/moduler/configuration.rb +6 -0
  128. data/lib/moduler/version.rb +1 -1
  129. metadata +86 -2
@@ -0,0 +1,59 @@
1
+ module Moduler
2
+ # An email composed in the administration area and sent to chosen users,
3
+ # or from code by its event name:
4
+ #
5
+ # Moduler::Email.deliver_event("order.paid", to: user)
6
+ #
7
+ # The engine itself sends "user.signup" after a user signs up.
8
+ class Email < ApplicationRecord
9
+ include PgSearch::Model
10
+
11
+ KINDS = %w[ custom system newsletter ].freeze
12
+ EVENT_FORMAT = /\A[a-z0-9_]+(\.[a-z0-9_]+)*\z/
13
+
14
+ has_many :user_emails, class_name: "Moduler::UserEmail", foreign_key: "moduler_email_id", dependent: :destroy
15
+
16
+ has_many_attached :attachments
17
+ has_many_attached :images
18
+
19
+ normalizes :event, with: ->(event) { event.strip.presence }
20
+ normalizes :sender, with: ->(sender) { sender.strip.presence }
21
+
22
+ validates :subject, presence: true
23
+ validates :kind, presence: true, inclusion: { in: KINDS }
24
+ validates :event, uniqueness: true, format: { with: EVENT_FORMAT }, allow_nil: true
25
+ validates :body, presence: true
26
+ validates :images, content_type: %w[ image/png image/jpeg image/gif image/webp ], size: { less_than: 10.megabytes }
27
+
28
+ pg_search_scope :search_by_query, against: %i[ subject kind ], using: { trigram: { word_similarity: true } }
29
+
30
+ # Sends the email of the given event to the user, once. Does nothing
31
+ # when no email has the event.
32
+ def self.deliver_event(event, to:)
33
+ find_by(event: event.to_s)&.deliver_to([ to ])
34
+ end
35
+
36
+ # Queues the email for the users it has not been queued for yet and
37
+ # returns how many were queued.
38
+ def deliver_to(users)
39
+ users.count do |user|
40
+ user_email = user_emails.find_or_create_by!(user: user)
41
+ next false unless user_email.previously_new_record?
42
+
43
+ EmailDeliveryJob.perform_later(user_email)
44
+ true
45
+ end
46
+ end
47
+
48
+ # The number of users the email has been delivered to.
49
+ def sent_count
50
+ user_emails.sent.count
51
+ end
52
+
53
+ def to_html
54
+ html = Redcarpet::Markdown.new(Redcarpet::Render::HTML, tables: true, fenced_code_blocks: true).render(body.to_s)
55
+
56
+ ActionController::Base.helpers.sanitize(html, tags: Moduler::Article::ALLOWED_TAGS)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ module Moduler
2
+ class Membership < ApplicationRecord
3
+ include PgSearch::Model
4
+
5
+ belongs_to :user, class_name: "Moduler::User", foreign_key: "moduler_user_id"
6
+ belongs_to :organization, class_name: "Moduler::Organization", foreign_key: "moduler_organization_id"
7
+ belongs_to :role, class_name: "Moduler::Role", foreign_key: "moduler_role_id"
8
+
9
+ validates :user, uniqueness: { scope: :moduler_organization_id }
10
+ validate :user_must_be_member
11
+ validate :role_must_belong_to_organization
12
+
13
+ pg_search_scope :search_by_query, associated_against: { user: :email_address }, using: { trigram: { word_similarity: true } }
14
+
15
+ private
16
+
17
+ def user_must_be_member
18
+ errors.add(:user, :not_member) if user && !user.member?
19
+ end
20
+
21
+ def role_must_belong_to_organization
22
+ errors.add(:role, :inclusion) if role && role.moduler_organization_id != moduler_organization_id
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module Moduler
2
+ class Organization < ApplicationRecord
3
+ include PgSearch::Model
4
+
5
+ has_many :memberships, class_name: "Moduler::Membership", foreign_key: "moduler_organization_id", dependent: :delete_all
6
+ has_many :users, class_name: "Moduler::User", through: :memberships
7
+ has_many :roles, class_name: "Moduler::Role", foreign_key: "moduler_organization_id", dependent: :delete_all
8
+
9
+ validates :name, presence: true, uniqueness: true
10
+
11
+ pg_search_scope :search_by_query, against: %i[ name ], using: { trigram: { word_similarity: true } }
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ module Moduler
2
+ # Runtime settings and feature toggles managed in the administration area
3
+ # and read in code as Moduler::Preference::NAME, cast to the preference's
4
+ # kind. A preference that does not exist reads as nil.
5
+ class Preference < ApplicationRecord
6
+ include PgSearch::Model
7
+
8
+ KINDS = %w[ string boolean integer ].freeze
9
+ NAME_FORMAT = /\A[A-Z][A-Z0-9_]*\z/
10
+
11
+ before_validation :normalize_boolean_value
12
+
13
+ validates :kind, presence: true, inclusion: { in: KINDS }
14
+ validates :name, presence: true, uniqueness: true, format: { with: NAME_FORMAT }
15
+ validates :value, presence: true
16
+ validates :value, inclusion: { in: %w[ true false ] }, if: -> { kind == "boolean" }
17
+ validates :value, format: { with: /\A-?\d+\z/ }, if: -> { kind == "integer" }
18
+
19
+ pg_search_scope :search_by_query, against: %i[ kind name ], using: { trigram: { word_similarity: true } }
20
+
21
+ class << self
22
+ def const_missing(name)
23
+ return super unless name.to_s.match?(NAME_FORMAT)
24
+
25
+ find_by(name: name.to_s)&.cast_value
26
+ end
27
+ end
28
+
29
+ # The value cast to the preference's kind.
30
+ def cast_value
31
+ case kind
32
+ when "string" then value
33
+ when "integer" then Integer(value)
34
+ when "boolean" then value.to_s.strip.downcase == "true"
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def normalize_boolean_value
41
+ self.value = value.strip.downcase if kind == "boolean" && value.present?
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ module Moduler
2
+ class Role < ApplicationRecord
3
+ include PgSearch::Model
4
+
5
+ belongs_to :organization, class_name: "Moduler::Organization", foreign_key: "moduler_organization_id"
6
+ has_many :memberships, class_name: "Moduler::Membership", foreign_key: "moduler_role_id", dependent: :restrict_with_error
7
+
8
+ normalizes :permissions, with: ->(permissions) { Array(permissions).map(&:to_s).compact_blank.uniq }
9
+
10
+ validates :name, presence: true, uniqueness: { scope: :moduler_organization_id }
11
+ validate :permissions_must_be_configured
12
+
13
+ pg_search_scope :search_by_query, against: %i[ name ], using: { trigram: { word_similarity: true } }
14
+
15
+ def permission?(permission)
16
+ permissions.include?(permission.to_s)
17
+ end
18
+
19
+ private
20
+
21
+ def permissions_must_be_configured
22
+ unknown = permissions - Moduler.configuration.permissions
23
+ errors.add(:permissions, :inclusion, value: unknown.join(", ")) if unknown.any?
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module Moduler
2
+ # A copy of every email delivered by the engine's mailers, recorded by
3
+ # Moduler::ApplicationMailer and shown in the recipient's profile.
4
+ class SentEmail < ApplicationRecord
5
+ belongs_to :user, class_name: "Moduler::User", foreign_key: "moduler_user_id", optional: true
6
+
7
+ has_many_attached :attachments
8
+
9
+ validates :to_address, presence: true
10
+ validates :subject, presence: true
11
+ validates :body, presence: true
12
+ end
13
+ end
@@ -5,18 +5,30 @@ module Moduler
5
5
  has_many :sessions, class_name: "Moduler::Session", foreign_key: "moduler_user_id", dependent: :destroy
6
6
  has_many :user_documents, class_name: "Moduler::UserDocument", foreign_key: "moduler_user_id", dependent: :destroy
7
7
  has_many :documents, class_name: "Moduler::Document", through: :user_documents
8
+ has_many :memberships, class_name: "Moduler::Membership", foreign_key: "moduler_user_id", dependent: :destroy
9
+ has_many :organizations, class_name: "Moduler::Organization", through: :memberships
10
+ has_many :user_emails, class_name: "Moduler::UserEmail", foreign_key: "moduler_user_id", dependent: :destroy
11
+ has_many :emails, class_name: "Moduler::Email", through: :user_emails
12
+ has_many :sent_emails, class_name: "Moduler::SentEmail", foreign_key: "moduler_user_id", dependent: :nullify
8
13
 
9
14
  has_secure_password
10
15
 
11
16
  normalizes :email_address, with: ->(email_address) { email_address.strip.downcase }
17
+ normalizes :name, with: ->(name) { name.strip.presence }
12
18
 
13
19
  validates :email_address, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
14
20
  validates :password, length: { minimum: 8 }, allow_nil: true
21
+ validates :name, length: { maximum: 100 }
15
22
 
16
23
  enum :role, { member: 0, administrator: 1 }
17
24
  enum :status, { waitlisted: 0, active: 1, inactive: 2 }, default: :active
18
25
 
19
- pg_search_scope :search_by_query, against: %i[ email_address ], using: { trigram: { word_similarity: true } }
26
+ pg_search_scope :search_by_query, against: %i[ email_address name ], using: { trigram: { word_similarity: true } }
27
+
28
+ # The name, or the email address when the user has no name.
29
+ def display_name
30
+ name.presence || email_address
31
+ end
20
32
 
21
33
  # Documents the user has not accepted yet.
22
34
  def pending_documents
@@ -0,0 +1,15 @@
1
+ module Moduler
2
+ # An email queued for a user; sent_at is set once it has been delivered.
3
+ class UserEmail < ApplicationRecord
4
+ belongs_to :user, class_name: "Moduler::User", foreign_key: "moduler_user_id"
5
+ belongs_to :email, class_name: "Moduler::Email", foreign_key: "moduler_email_id"
6
+
7
+ validates :user, uniqueness: { scope: :moduler_email_id }
8
+
9
+ scope :sent, -> { where.not(sent_at: nil) }
10
+
11
+ def sent?
12
+ sent_at.present?
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module Moduler
2
+ module Administration
3
+ class EmailPolicy < BasePolicy
4
+ def index?
5
+ administrator?
6
+ end
7
+
8
+ def create?
9
+ administrator?
10
+ end
11
+
12
+ def update?
13
+ administrator?
14
+ end
15
+
16
+ def destroy?
17
+ administrator?
18
+ end
19
+
20
+ # Sending the email to chosen users.
21
+ def deliver?
22
+ administrator?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ module Moduler
2
+ module Administration
3
+ class MembershipPolicy < BasePolicy
4
+ def index?
5
+ administrator?
6
+ end
7
+
8
+ def create?
9
+ administrator?
10
+ end
11
+
12
+ def update?
13
+ administrator?
14
+ end
15
+
16
+ def destroy?
17
+ administrator?
18
+ end
19
+
20
+ def new?
21
+ create?
22
+ end
23
+
24
+ def edit?
25
+ update?
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module Moduler
2
+ module Administration
3
+ class OrganizationPolicy < BasePolicy
4
+ def index?
5
+ administrator?
6
+ end
7
+
8
+ def create?
9
+ administrator?
10
+ end
11
+
12
+ def update?
13
+ administrator?
14
+ end
15
+
16
+ def new?
17
+ create?
18
+ end
19
+
20
+ def edit?
21
+ update?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ module Moduler
2
+ module Administration
3
+ class PreferencePolicy < BasePolicy
4
+ def index?
5
+ administrator?
6
+ end
7
+
8
+ def create?
9
+ administrator?
10
+ end
11
+
12
+ def update?
13
+ administrator?
14
+ end
15
+
16
+ def new?
17
+ create?
18
+ end
19
+
20
+ def edit?
21
+ update?
22
+ end
23
+
24
+ def destroy?
25
+ administrator?
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module Moduler
2
+ module Administration
3
+ class RolePolicy < BasePolicy
4
+ def index?
5
+ administrator?
6
+ end
7
+
8
+ def create?
9
+ administrator?
10
+ end
11
+
12
+ def update?
13
+ administrator?
14
+ end
15
+
16
+ def new?
17
+ create?
18
+ end
19
+
20
+ def edit?
21
+ update?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <style>
6
+ /* Email clients do not load external stylesheets, so the Markdown styles are inlined here. */
7
+ .markdown-content { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; color: #334155; }
8
+ .markdown-content > * + * { margin-top: 1em; }
9
+ .markdown-content h1, .markdown-content h2, .markdown-content h3 { font-weight: 600; color: #0f172a; margin-top: 1.5em; }
10
+ .markdown-content h1 { font-size: 1.5em; }
11
+ .markdown-content h2 { font-size: 1.25em; }
12
+ .markdown-content h3 { font-size: 1.125em; }
13
+ .markdown-content ul, .markdown-content ol { padding-left: 1.5em; }
14
+ .markdown-content ul { list-style-type: disc; }
15
+ .markdown-content ol { list-style-type: decimal; }
16
+ .markdown-content blockquote { border-left: 3px solid #cbd5e1; padding-left: 1em; color: #64748b; }
17
+ .markdown-content code { background: #f1f5f9; padding: 0.125em 0.375em; border-radius: 0.25em; font-size: 0.875em; }
18
+ .markdown-content pre { background: #0f172a; color: #f1f5f9; padding: 1em; border-radius: 0.5em; overflow-x: auto; }
19
+ .markdown-content pre code { background: none; padding: 0; }
20
+ .markdown-content a { color: #4f46e5; text-decoration: underline; }
21
+ .markdown-content table { border-collapse: collapse; width: 100%; }
22
+ .markdown-content th, .markdown-content td { border: 1px solid #cbd5e1; padding: 0.5em 0.75em; text-align: left; }
23
+ .markdown-content img { width: 100%; max-width: 1024px; height: auto; }
24
+ </style>
25
+ </head>
26
+
27
+ <body>
28
+ <%= yield %>
29
+ </body>
30
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -1,4 +1,6 @@
1
1
  <%= render(Moduler::ListItemComponent.new(article.title, id: dom_id(article))) do |item| %>
2
+ <% item.with_badge(t("moduler.administration.articles.statuses.#{article.status}"), variant: article.published? ? :success : :muted) %>
3
+
2
4
  <% item.with_meta do %>
3
5
  <%= time_tag article.created_at, t(".created", time: time_ago_in_words(article.created_at)), title: l(article.created_at, format: :long) %>
4
6
  <% end %>
@@ -6,6 +6,7 @@
6
6
 
7
7
  <div class="max-w-lg space-y-6">
8
8
  <%= render(::Moduler::Form::TextComponent.new(form, :title, label: t(".label.title"))) %>
9
+ <%= render(::Moduler::Form::SelectComponent.new(form, :status, Moduler::Article.statuses.keys.map { |status| [ t("moduler.administration.articles.statuses.#{status}"), status ] }, label: t(".label.status"), description: t(".description.status"))) %>
9
10
  <%= render(::Moduler::Form::TextComponent.new(form, :path, label: t(".label.path"), description: t(".description.path"))) %>
10
11
  <%= render(::Moduler::Form::TextareaComponent.new(form, :description, label: t(".label.description"), description: t(".description.description"))) %>
11
12
  <%= render(::Moduler::Form::TextComponent.new(form, :keywords, label: t(".label.keywords"), description: t(".description.keywords"))) %>
@@ -0,0 +1,33 @@
1
+ <%= render(Moduler::ListItemComponent.new(email.subject, id: dom_id(email))) do |item| %>
2
+ <% item.with_badge(t("moduler.administration.emails.kinds.#{email.kind}")) %>
3
+ <% if email.event %>
4
+ <% item.with_badge(email.event, variant: :muted) %>
5
+ <% end %>
6
+
7
+ <% item.with_meta do %>
8
+ <%= t(".sent", count: email.sent_count) %>
9
+ <span aria-hidden="true">&middot;</span>
10
+ <%= time_tag email.updated_at, t(".updated", time: time_ago_in_words(email.updated_at)), title: l(email.updated_at, format: :long) %>
11
+ <% end %>
12
+
13
+ <% policy = Moduler::Administration::EmailPolicy.new(current_user, email) %>
14
+
15
+ <% if policy.deliver? %>
16
+ <% item.with_action do %>
17
+ <%= render(Moduler::ButtonLinkComponent.new(t(".action.deliver"), moduler.new_administration_email_delivery_path(email), size: :sm)) %>
18
+ <% end %>
19
+ <% end %>
20
+
21
+ <% if policy.edit? %>
22
+ <% item.with_action do %>
23
+ <%= render(Moduler::ButtonLinkComponent.new(t(".action.edit"), moduler.edit_administration_email_path(email), size: :sm)) %>
24
+ <% end %>
25
+ <% end %>
26
+
27
+ <% if policy.destroy? %>
28
+ <% item.with_action do %>
29
+ <%= render(Moduler::ButtonComponent.new(t(".action.destroy"), moduler.administration_email_path(email), method: :delete, size: :sm,
30
+ confirm: t(".confirmation.destroy", subject: email.subject))) %>
31
+ <% end %>
32
+ <% end %>
33
+ <% end %>
@@ -0,0 +1,23 @@
1
+ <%= render(Moduler::Administration::PageComponent.new) do %>
2
+ <%= render(Moduler::PageHeaderComponent.new(t(".title"))) %>
3
+
4
+ <%= form_with model: @email, url: @email.persisted? ? moduler.administration_email_path(@email) : moduler.administration_emails_path, multipart: true, data: { turbo: false }, class: "w-full space-y-6" do |form| %>
5
+ <%= render(::Moduler::Form::BaseErrorComponent.new(form)) %>
6
+
7
+ <div class="max-w-lg space-y-6">
8
+ <%= render(::Moduler::Form::TextComponent.new(form, :subject, label: t(".label.subject"))) %>
9
+ <%= render(::Moduler::Form::TextComponent.new(form, :sender, label: t(".label.sender"), placeholder: t(".placeholder.sender"), description: t(".description.sender"))) %>
10
+ <%= render(::Moduler::Form::SelectComponent.new(form, :kind, Moduler::Email::KINDS.map { |kind| [ t("moduler.administration.emails.kinds.#{kind}"), kind ] },
11
+ label: t(".label.kind"), include_blank: true)) %>
12
+ <%= render(::Moduler::Form::TextComponent.new(form, :event, label: t(".label.event"), placeholder: t(".placeholder.event"), description: t(".description.event"))) %>
13
+ </div>
14
+
15
+ <%= render(::Moduler::Form::WysiwygComponent.new(form, :body, label: t(".label.body"), description: t(".description.body"))) %>
16
+
17
+ <div class="max-w-lg space-y-6">
18
+ <%= render(::Moduler::Form::AttachmentsComponent.new(form, :attachments, label: t(".label.attachments"))) %>
19
+ </div>
20
+
21
+ <%= render(::Moduler::Form::SubmitComponent.new(form, text: t(".action.save"))) %>
22
+ <% end %>
23
+ <% end %>
@@ -0,0 +1,58 @@
1
+ <%= render(Moduler::Administration::PageComponent.new) do %>
2
+ <%= render(Moduler::PageHeaderComponent.new(t(".title", subject: @email.subject), description: t(".description"))) %>
3
+
4
+ <%= render(Moduler::FilterComponent.new(@filter, moduler.new_administration_email_delivery_path(@email), selects: [
5
+ { name: :role, choices: Moduler::User.roles.keys.map { |role| [ t("moduler.administration.users.roles.#{role}"), role ] }, prompt: t(".placeholder.role") },
6
+ { name: :sent, choices: [ [ t(".sent.true"), "true" ], [ t(".sent.false"), "false" ] ], prompt: t(".placeholder.sent") },
7
+ { name: :per_page, choices: EmailDeliveryFilter::PER_PAGE.map { |per_page| [ t(".per_page", count: per_page), per_page ] }, prompt: false }
8
+ ])) %>
9
+
10
+ <%= form_with url: moduler.administration_email_deliveries_path(@email), data: { turbo: false, controller: "select-all" } do |form| %>
11
+ <% if @users.any? %>
12
+ <div class="mt-6">
13
+ <label class="flex items-center gap-3 px-4 text-sm text-slate-500 sm:px-5">
14
+ <input type="checkbox" data-select-all-target="parent" data-action="change->select-all#toggleChildren" class="h-4 w-4 cursor-pointer rounded border-gray-300 accent-custom">
15
+ <%= t(".action.select_all") %>
16
+ </label>
17
+ </div>
18
+ <% end %>
19
+
20
+ <%= render(Moduler::ListComponent.new(@users, id: "users", empty: t(".empty"))) do %>
21
+ <% @users.each do |user| %>
22
+ <li id="<%= dom_id(user) %>" class="flex items-center gap-3 px-4 py-4 sm:px-5">
23
+ <% if user.user_email_id %>
24
+ <input type="checkbox" checked disabled aria-label="<%= user.email_address %>" class="h-4 w-4 shrink-0 rounded border-gray-300 accent-custom">
25
+ <% else %>
26
+ <input type="checkbox" name="user_ids[]" value="<%= user.id %>" id="user_ids_<%= user.id %>"
27
+ data-select-all-target="child" data-action="change->select-all#toggleParent"
28
+ class="h-4 w-4 shrink-0 cursor-pointer rounded border-gray-300 accent-custom">
29
+ <% end %>
30
+
31
+ <div class="min-w-0 flex-1">
32
+ <label for="user_ids_<%= user.id %>" class="flex flex-wrap items-center gap-2">
33
+ <span class="truncate text-sm font-semibold text-gray-900"><%= user.display_name %></span>
34
+ <%= render(Moduler::BadgeComponent.new(t("moduler.administration.users.roles.#{user.role}"))) %>
35
+ </label>
36
+ <p class="mt-1 text-xs text-slate-400">
37
+ <% if user.name.present? %>
38
+ <%= user.email_address %>
39
+ <span aria-hidden="true">&middot;</span>
40
+ <% end %>
41
+ <% if user.user_email_sent_at %>
42
+ <%= t(".status.sent", time: l(user.user_email_sent_at, format: :long)) %>
43
+ <% elsif user.user_email_id %>
44
+ <%= t(".status.queued") %>
45
+ <% else %>
46
+ <%= t(".status.not_sent") %>
47
+ <% end %>
48
+ </p>
49
+ </div>
50
+ </li>
51
+ <% end %>
52
+ <% end %>
53
+
54
+ <% if @users.any? %>
55
+ <%= render(::Moduler::Form::SubmitComponent.new(form, text: t(".action.submit"))) %>
56
+ <% end %>
57
+ <% end %>
58
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render "form" %>
@@ -0,0 +1,13 @@
1
+ <%= render(Moduler::Administration::PageComponent.new) do %>
2
+ <%= render(Moduler::PageHeaderComponent.new(t(".title"), description: t(".description"))) do |header| %>
3
+ <% header.with_action do %>
4
+ <%= render(Moduler::ButtonLinkComponent.new(t(".action.new"), moduler.new_administration_email_path)) %>
5
+ <% end %>
6
+ <% end %>
7
+
8
+ <%= render(Moduler::FilterComponent.new(@filter, moduler.administration_emails_path)) %>
9
+
10
+ <%= render(Moduler::ListComponent.new(@emails, id: "emails", empty: t(".empty"))) do %>
11
+ <%= render partial: "moduler/administration/emails/email", collection: @emails %>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render "form" %>
@@ -0,0 +1,38 @@
1
+ <%= render(Moduler::Administration::PageComponent.new) do %>
2
+ <%= render(Moduler::PageHeaderComponent.new(t(".title"))) %>
3
+
4
+ <%= form_with model: @membership, url: @membership.persisted? ? moduler.administration_membership_path(@membership) : moduler.administration_memberships_path, data: { turbo: false }, class: "w-full space-y-6" do |form| %>
5
+ <%= render(::Moduler::Form::BaseErrorComponent.new(form)) %>
6
+
7
+ <div class="max-w-lg space-y-6">
8
+ <% if @membership.persisted? %>
9
+ <div class="mt-2">
10
+ <p class="block text-sm text-slate-500"><%= t(".label.organization") %></p>
11
+ <p id="membership_organization" class="mt-2 text-sm text-gray-900"><%= @membership.organization.name %></p>
12
+ </div>
13
+ <div class="mt-2">
14
+ <p class="block text-sm text-slate-500"><%= t(".label.user") %></p>
15
+ <p id="membership_user" class="mt-2 text-sm text-gray-900"><%= @membership.user.email_address %></p>
16
+ <p class="mt-1 text-xs text-gray-400"><%= t(".description.locked") %></p>
17
+ </div>
18
+ <%= render(::Moduler::Form::SelectComponent.new(form, :moduler_role_id, @membership.organization.roles.order(:name).pluck(:name, :id),
19
+ label: t(".label.role"))) %>
20
+ <% else %>
21
+ <% organizations = Moduler::Organization.includes(:roles).order(:name) %>
22
+ <% roles = organizations.to_h { |organization| [ organization.id, organization.roles.sort_by(&:name).map { |role| [ role.name, role.id ] } ] } %>
23
+ <div class="space-y-6" data-controller="dependent-select" data-dependent-select-options-value="<%= roles.to_json %>">
24
+ <%= render(::Moduler::Form::SelectComponent.new(form, :moduler_organization_id, organizations.map { |organization| [ organization.name, organization.id ] },
25
+ label: t(".label.organization"), include_blank: true,
26
+ data: { dependent_select_target: "source", action: "dependent-select#update" })) %>
27
+ <%= render(::Moduler::Form::SelectComponent.new(form, :moduler_role_id, roles.fetch(@membership.moduler_organization_id, []),
28
+ label: t(".label.role"), include_blank: true, description: t(".description.role"),
29
+ data: { dependent_select_target: "dependent" })) %>
30
+ </div>
31
+ <%= render(::Moduler::Form::SelectComponent.new(form, :moduler_user_id, Moduler::User.member.order(:email_address).pluck(:email_address, :id),
32
+ label: t(".label.user"), include_blank: true, description: t(".description.user"))) %>
33
+ <% end %>
34
+ </div>
35
+
36
+ <%= render(::Moduler::Form::SubmitComponent.new(form, text: t(".action.save"))) %>
37
+ <% end %>
38
+ <% end %>
@@ -0,0 +1,23 @@
1
+ <%= render(Moduler::ListItemComponent.new(membership.user.email_address, id: dom_id(membership))) do |item| %>
2
+ <% item.with_badge(membership.organization.name) %>
3
+ <% item.with_badge(membership.role.name, variant: :muted) %>
4
+
5
+ <% item.with_meta do %>
6
+ <%= time_tag membership.created_at, t(".created", time: time_ago_in_words(membership.created_at)), title: l(membership.created_at, format: :long) %>
7
+ <% end %>
8
+
9
+ <% policy = Moduler::Administration::MembershipPolicy.new(current_user, membership) %>
10
+
11
+ <% if policy.edit? %>
12
+ <% item.with_action do %>
13
+ <%= render(Moduler::ButtonLinkComponent.new(t(".action.edit"), moduler.edit_administration_membership_path(membership), size: :sm)) %>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <% if policy.destroy? %>
18
+ <% item.with_action do %>
19
+ <%= render(Moduler::ButtonComponent.new(t(".action.destroy"), moduler.administration_membership_path(membership), method: :delete, size: :sm,
20
+ confirm: t(".confirmation.destroy", email_address: membership.user.email_address, organization: membership.organization.name))) %>
21
+ <% end %>
22
+ <% end %>
23
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render "form" %>
@@ -0,0 +1,14 @@
1
+ <%= render(Moduler::Administration::PageComponent.new) do %>
2
+ <%= render(Moduler::PageHeaderComponent.new(t(".title"), description: t(".description"))) do |header| %>
3
+ <% header.with_action do %>
4
+ <%= render(Moduler::ButtonLinkComponent.new(t(".action.new"), moduler.new_administration_membership_path(organization_id: @filter.organization_id.presence))) %>
5
+ <% end %>
6
+ <% end %>
7
+
8
+ <%= render(Moduler::FilterComponent.new(@filter, moduler.administration_memberships_path,
9
+ selects: [ { name: :organization_id, choices: Moduler::Organization.order(:name).pluck(:name, :id), prompt: t("moduler.components.filter.placeholder.organization") } ])) %>
10
+
11
+ <%= render(Moduler::ListComponent.new(@memberships, id: "memberships", empty: t(".empty"))) do %>
12
+ <%= render partial: "moduler/administration/memberships/membership", collection: @memberships %>
13
+ <% end %>
14
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render "form" %>