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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ec81c1092462c6513cd56e7953a2101eae358249f501d32993f1666bfd8867a
4
- data.tar.gz: c92cde6155a2bc5fe17193155426ac2e593d6979092dae58e2ec64f0940bb9e9
3
+ metadata.gz: 48b04e1bddcad684cb26f044713db46a9b049c4f6a7ceaa0f0f5e60211dd085e
4
+ data.tar.gz: c01f94740262115c801c293abeeacec41a53c4e6fa17bcba1a8c8bd5899d3439
5
5
  SHA512:
6
- metadata.gz: fd6b3fb551373a67a76faeb79ffb8d49fa50740e2c9c3fb11838d9b99199e0bfa3f77f42e8dc847a86fb3b32f37371caef0dea2734b0d1c5ec75032abae574eb
7
- data.tar.gz: 854b1562ccdaf04ccaa17c7d96418100374b7cb7294f06e3120babb7098e94c7605a18a531e31166a310df47abbd1ed311202ec0d3b7213fcc8cd70522337ff6
6
+ metadata.gz: 4889b74712446a913cb1ec858ddb37a85cec01bd55769ba45d648250b01f0308e1f8a38e303d99a612f65d2cac105609fbc5db1d219686d80ba65376ec8f6eeb
7
+ data.tar.gz: a09513f54e837d8b7cf0f70a32ee9171b55c05bc2428ab5a71422bdbfe41428364f5bb384205e321c73bb20340b097f4e74fa74b05f36bb74c36ca61c47c1304
@@ -233,6 +233,9 @@
233
233
  .inset-0 {
234
234
  inset: calc(var(--spacing) * 0);
235
235
  }
236
+ .inset-x-2 {
237
+ inset-inline: calc(var(--spacing) * 2);
238
+ }
236
239
  .start {
237
240
  inset-inline-start: var(--spacing);
238
241
  }
@@ -245,6 +248,9 @@
245
248
  .right-4 {
246
249
  right: calc(var(--spacing) * 4);
247
250
  }
251
+ .z-10 {
252
+ z-index: 10;
253
+ }
248
254
  .z-50 {
249
255
  z-index: 50;
250
256
  }
@@ -254,6 +260,9 @@
254
260
  .-mx-4 {
255
261
  margin-inline: calc(var(--spacing) * -4);
256
262
  }
263
+ .mx-1 {
264
+ margin-inline: calc(var(--spacing) * 1);
265
+ }
257
266
  .mx-auto {
258
267
  margin-inline: auto;
259
268
  }
@@ -928,6 +937,10 @@
928
937
  .table {
929
938
  display: table;
930
939
  }
940
+ .size-4 {
941
+ width: calc(var(--spacing) * 4);
942
+ height: calc(var(--spacing) * 4);
943
+ }
931
944
  .size-5 {
932
945
  width: calc(var(--spacing) * 5);
933
946
  height: calc(var(--spacing) * 5);
@@ -945,6 +958,9 @@
945
958
  .h-16 {
946
959
  height: calc(var(--spacing) * 16);
947
960
  }
961
+ .max-h-72 {
962
+ max-height: calc(var(--spacing) * 72);
963
+ }
948
964
  .min-h-9 {
949
965
  min-height: calc(var(--spacing) * 9);
950
966
  }
@@ -960,6 +976,9 @@
960
976
  .w-full {
961
977
  width: 100%;
962
978
  }
979
+ .w-px {
980
+ width: 1px;
981
+ }
963
982
  .max-w-2xl {
964
983
  max-width: var(--container-2xl);
965
984
  }
@@ -987,6 +1006,9 @@
987
1006
  .shrink-0 {
988
1007
  flex-shrink: 0;
989
1008
  }
1009
+ .border-collapse {
1010
+ border-collapse: collapse;
1011
+ }
990
1012
  .translate-x-2 {
991
1013
  --tw-translate-x: calc(var(--spacing) * 2);
992
1014
  translate: var(--tw-translate-x) var(--tw-translate-y);
@@ -994,6 +1016,9 @@
994
1016
  .cursor-pointer {
995
1017
  cursor: pointer;
996
1018
  }
1019
+ .list-none {
1020
+ list-style-type: none;
1021
+ }
997
1022
  .flex-col {
998
1023
  flex-direction: column;
999
1024
  }
@@ -1030,6 +1055,13 @@
1030
1055
  .gap-4 {
1031
1056
  gap: calc(var(--spacing) * 4);
1032
1057
  }
1058
+ .space-y-2 {
1059
+ :where(& > :not(:last-child)) {
1060
+ --tw-space-y-reverse: 0;
1061
+ margin-block-start: calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));
1062
+ margin-block-end: calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)));
1063
+ }
1064
+ }
1033
1065
  .space-y-4 {
1034
1066
  :where(& > :not(:last-child)) {
1035
1067
  --tw-space-y-reverse: 0;
@@ -1070,6 +1102,9 @@
1070
1102
  border-color: var(--color-slate-100);
1071
1103
  }
1072
1104
  }
1105
+ .self-stretch {
1106
+ align-self: stretch;
1107
+ }
1073
1108
  .truncate {
1074
1109
  overflow: hidden;
1075
1110
  text-overflow: ellipsis;
@@ -1078,6 +1113,9 @@
1078
1113
  .overflow-x-auto {
1079
1114
  overflow-x: auto;
1080
1115
  }
1116
+ .overflow-y-auto {
1117
+ overflow-y: auto;
1118
+ }
1081
1119
  .rounded {
1082
1120
  border-radius: 0.25rem;
1083
1121
  }
@@ -1155,6 +1193,9 @@
1155
1193
  .bg-emerald-50 {
1156
1194
  background-color: var(--color-emerald-50);
1157
1195
  }
1196
+ .bg-gray-200 {
1197
+ background-color: var(--color-gray-200);
1198
+ }
1158
1199
  .bg-green-100 {
1159
1200
  background-color: var(--color-green-100);
1160
1201
  }
@@ -1191,6 +1232,9 @@
1191
1232
  .bg-yellow-100 {
1192
1233
  background-color: var(--color-yellow-100);
1193
1234
  }
1235
+ .p-1 {
1236
+ padding: calc(var(--spacing) * 1);
1237
+ }
1194
1238
  .p-2 {
1195
1239
  padding: calc(var(--spacing) * 2);
1196
1240
  }
@@ -1233,12 +1277,21 @@
1233
1277
  .pt-6 {
1234
1278
  padding-top: calc(var(--spacing) * 6);
1235
1279
  }
1280
+ .pr-10 {
1281
+ padding-right: calc(var(--spacing) * 10);
1282
+ }
1283
+ .pb-0 {
1284
+ padding-bottom: calc(var(--spacing) * 0);
1285
+ }
1236
1286
  .pb-4 {
1237
1287
  padding-bottom: calc(var(--spacing) * 4);
1238
1288
  }
1239
1289
  .pb-6 {
1240
1290
  padding-bottom: calc(var(--spacing) * 6);
1241
1291
  }
1292
+ .pl-3 {
1293
+ padding-left: calc(var(--spacing) * 3);
1294
+ }
1242
1295
  .text-center {
1243
1296
  text-align: center;
1244
1297
  }
@@ -1349,6 +1402,9 @@
1349
1402
  .italic {
1350
1403
  font-style: italic;
1351
1404
  }
1405
+ .underline {
1406
+ text-decoration-line: underline;
1407
+ }
1352
1408
  .accent-custom {
1353
1409
  accent-color: var(--color-custom);
1354
1410
  }
@@ -1407,6 +1463,11 @@
1407
1463
  transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
1408
1464
  transition-duration: var(--tw-duration, var(--default-transition-duration));
1409
1465
  }
1466
+ .transition-transform {
1467
+ transition-property: transform, translate, scale, rotate;
1468
+ transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
1469
+ transition-duration: var(--tw-duration, var(--default-transition-duration));
1470
+ }
1410
1471
  .duration-200 {
1411
1472
  --tw-duration: 200ms;
1412
1473
  transition-duration: 200ms;
@@ -1449,9 +1510,18 @@
1449
1510
  --tw-prose-invert-th-borders: oklch(44.6% 0.043 257.281);
1450
1511
  --tw-prose-invert-td-borders: oklch(37.2% 0.044 257.287);
1451
1512
  }
1513
+ .select-all {
1514
+ -webkit-user-select: all;
1515
+ user-select: all;
1516
+ }
1452
1517
  .ring-inset {
1453
1518
  --tw-ring-inset: inset;
1454
1519
  }
1520
+ .group-open\:rotate-180 {
1521
+ &:is(:where(.group):is([open], :popover-open, :open) *) {
1522
+ rotate: 180deg;
1523
+ }
1524
+ }
1455
1525
  .group-hover\:text-custom {
1456
1526
  &:is(:where(.group):hover *) {
1457
1527
  @media (hover: hover) {
@@ -1754,16 +1824,31 @@
1754
1824
  margin-inline: calc(var(--spacing) * 0);
1755
1825
  }
1756
1826
  }
1827
+ .md\:my-2 {
1828
+ @media (width >= 48rem) {
1829
+ margin-block: calc(var(--spacing) * 2);
1830
+ }
1831
+ }
1757
1832
  .md\:mt-8 {
1758
1833
  @media (width >= 48rem) {
1759
1834
  margin-top: calc(var(--spacing) * 8);
1760
1835
  }
1761
1836
  }
1837
+ .md\:h-px {
1838
+ @media (width >= 48rem) {
1839
+ height: 1px;
1840
+ }
1841
+ }
1762
1842
  .md\:w-1\/8 {
1763
1843
  @media (width >= 48rem) {
1764
1844
  width: calc(1 / 8 * 100%);
1765
1845
  }
1766
1846
  }
1847
+ .md\:w-auto {
1848
+ @media (width >= 48rem) {
1849
+ width: auto;
1850
+ }
1851
+ }
1767
1852
  .md\:shrink-0 {
1768
1853
  @media (width >= 48rem) {
1769
1854
  flex-shrink: 0;
@@ -1806,6 +1891,11 @@
1806
1891
  padding-right: calc(var(--spacing) * 6);
1807
1892
  }
1808
1893
  }
1894
+ .md\:pb-2 {
1895
+ @media (width >= 48rem) {
1896
+ padding-bottom: calc(var(--spacing) * 2);
1897
+ }
1898
+ }
1809
1899
  .md\:pl-0 {
1810
1900
  @media (width >= 48rem) {
1811
1901
  padding-left: calc(var(--spacing) * 0);
@@ -1846,6 +1936,11 @@
1846
1936
  max-width: var(--container-5xl);
1847
1937
  }
1848
1938
  }
1939
+ .\[\&\:\:-webkit-details-marker\]\:hidden {
1940
+ &::-webkit-details-marker {
1941
+ display: none;
1942
+ }
1943
+ }
1849
1944
  }
1850
1945
  .prose-100 {
1851
1946
  max-width: 100%;
@@ -0,0 +1,30 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Rows of attached and new files (Moduler::Form::AttachmentsComponent).
4
+ // Adding a row opens the file picker of its new file field; removing an
5
+ // attached file's row submits its id for removal when the form is saved.
6
+ export default class extends Controller {
7
+ static targets = ["list", "template"]
8
+ static values = { removeFieldName: String }
9
+
10
+ add() {
11
+ const row = this.templateTarget.content.firstElementChild.cloneNode(true)
12
+ this.listTarget.append(row)
13
+ row.querySelector("input[type=file]")?.click()
14
+ }
15
+
16
+ remove(event) {
17
+ const row = event.target.closest("li")
18
+ const attachmentId = row.dataset.attachmentId
19
+
20
+ if (attachmentId) {
21
+ const input = document.createElement("input")
22
+ input.type = "hidden"
23
+ input.name = this.removeFieldNameValue
24
+ input.value = attachmentId
25
+ this.element.append(input)
26
+ }
27
+
28
+ row.remove()
29
+ }
30
+ }
@@ -0,0 +1,19 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Repopulates the dependent select with the choices for the value chosen in
4
+ // the source select, e.g. the roles of the chosen organization.
5
+ //
6
+ // options value: { "<source value>": [[label, value], ...] }
7
+ export default class extends Controller {
8
+ static targets = ["source", "dependent"]
9
+ static values = { options: Object }
10
+
11
+ update() {
12
+ const choices = this.optionsValue[this.sourceTarget.value] || []
13
+ const blank = this.dependentTarget.querySelector("option[value='']")
14
+ const options = choices.map(([label, value]) => new Option(label, value))
15
+
16
+ this.dependentTarget.replaceChildren(...(blank ? [blank] : []), ...options)
17
+ this.dependentTarget.value = ""
18
+ }
19
+ }
@@ -0,0 +1,12 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Closes a <details> dropdown on a click outside it or on Escape.
4
+ export default class extends Controller {
5
+ closeOnOutsideClick(event) {
6
+ if (!this.element.contains(event.target)) this.close()
7
+ }
8
+
9
+ close() {
10
+ this.element.open = false
11
+ }
12
+ }
@@ -0,0 +1,15 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // A checkbox that checks or unchecks all child checkboxes, and is checked
4
+ // itself when all of them are.
5
+ export default class extends Controller {
6
+ static targets = ["parent", "child"]
7
+
8
+ toggleChildren() {
9
+ this.childTargets.forEach((child) => { child.checked = this.parentTarget.checked })
10
+ }
11
+
12
+ toggleParent() {
13
+ this.parentTarget.checked = this.childTargets.length > 0 && this.childTargets.every((child) => child.checked)
14
+ }
15
+ }
@@ -4,9 +4,17 @@
4
4
  class: "w-full rounded-md border border-slate-300 px-3 text-sm text-slate-900 placeholder:text-slate-400 focus:border-slate-900 focus:outline-none focus:ring-1 focus:ring-slate-900" %>
5
5
  </div>
6
6
 
7
+ <% selects.each do |select| %>
8
+ <div class="min-w-48">
9
+ <%= form.select select[:name], select[:choices], { include_blank: select.fetch(:prompt, true) },
10
+ "aria-label": select[:prompt],
11
+ class: "w-full rounded-md border border-slate-300 bg-white pl-3 pr-10 text-sm text-slate-900 focus:border-slate-900 focus:outline-none focus:ring-1 focus:ring-slate-900" %>
12
+ </div>
13
+ <% end %>
14
+
7
15
  <%= form.submit t("moduler.components.filter.action.filter"),
8
16
  class: "cursor-pointer whitespace-nowrap rounded-md bg-white px-3 py-2 text-sm/6 font-semibold text-custom ring-1 ring-inset ring-slate-300 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-custom" %>
9
- <% if @filter.query.present? %>
17
+ <% if filtered? %>
10
18
  <%= link_to t("moduler.components.filter.action.clear"), @url, class: "flex h-10 items-center text-sm text-slate-500 hover:text-slate-900" %>
11
19
  <% end %>
12
20
  <% end %>
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Moduler
4
4
  class FilterComponent < ViewComponent::Base
5
+ # options:
6
+ # placeholder: placeholder of the query field
7
+ # selects: additional select fields, each a hash with
8
+ # name (filter attribute), choices ([label, value] pairs) and prompt (label of the empty choice)
5
9
  def initialize(filter, url, options = {})
6
10
  @filter = filter
7
11
  @url = url
@@ -11,5 +15,13 @@ module Moduler
11
15
  def placeholder
12
16
  @options.fetch(:placeholder) { t("moduler.components.filter.placeholder.query") }
13
17
  end
18
+
19
+ def selects
20
+ @options.fetch(:selects, [])
21
+ end
22
+
23
+ def filtered?
24
+ @filter.query.present? || selects.any? { |select| @filter.public_send(select[:name]).present? }
25
+ end
14
26
  end
15
27
  end
@@ -0,0 +1,32 @@
1
+ <div class="mt-2" data-controller="attachments" data-attachments-remove-field-name-value="<%= remove_field_name %>">
2
+ <% if @options.key?(:label) %>
3
+ <p class="block text-sm text-slate-500"><%= @options[:label] %></p>
4
+ <% end %>
5
+
6
+ <ul class="mt-2 space-y-2" data-attachments-target="list">
7
+ <% attached.each do |attachment| %>
8
+ <li class="flex items-center justify-between gap-3 rounded-md border border-slate-200 px-3 py-2" data-attachment-id="<%= attachment.id %>">
9
+ <%= link_to attachment.filename, helpers.main_app.rails_blob_path(attachment, disposition: "attachment"), class: "truncate text-sm text-gray-900 hover:underline" %>
10
+ <button type="button" data-action="attachments#remove" class="shrink-0 cursor-pointer text-sm text-slate-500 hover:text-red-600"><%= t("moduler.components.form.attachments.action.remove") %></button>
11
+ </li>
12
+ <% end %>
13
+ </ul>
14
+
15
+ <template data-attachments-target="template">
16
+ <li class="flex items-center justify-between gap-3 rounded-md border border-slate-200 px-3 py-2">
17
+ <input type="file" name="<%= field_name %>" class="block w-full text-sm text-gray-900 file:mr-3 file:rounded-md file:border-0 file:bg-white file:px-3 file:py-1.5 file:text-sm file:font-semibold file:text-gray-900 file:shadow-xs file:ring-1 file:ring-inset file:ring-gray-300 hover:file:bg-gray-50">
18
+ <button type="button" data-action="attachments#remove" class="shrink-0 cursor-pointer text-sm text-slate-500 hover:text-red-600"><%= t("moduler.components.form.attachments.action.remove") %></button>
19
+ </li>
20
+ </template>
21
+
22
+ <button type="button" data-action="attachments#add" class="mt-2 cursor-pointer rounded-md bg-white px-2.5 py-1 text-sm font-medium text-slate-600 shadow-sm ring-1 ring-inset ring-slate-300 hover:bg-slate-50 hover:text-slate-900">
23
+ <%= t("moduler.components.form.attachments.action.add") %>
24
+ </button>
25
+
26
+ <% if @options.key?(:description) %>
27
+ <p class="mt-1 text-xs text-gray-400"><%= @options[:description] %></p>
28
+ <% end %>
29
+ <% if @form.error?(@name) %>
30
+ <%= @form.error(@name, class: "text-red-500 text-sm mt-1") %>
31
+ <% end %>
32
+ </div>
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Moduler
4
+ # Files of a has_many_attached association, one row per file. Rows of new
5
+ # files are added with a button, and each row (new or attached) can be
6
+ # removed. Attached files marked for removal are submitted as
7
+ # remove_<name singular>_ids[] (e.g. remove_attachment_ids[]) and removed
8
+ # by the controller when the form is saved.
9
+ class Form::AttachmentsComponent < ViewComponent::Base
10
+ def initialize(form, name, options = {})
11
+ @form = form
12
+ @name = name
13
+ @options = options
14
+ end
15
+
16
+ def attached
17
+ @form.object.public_send(@name).select(&:persisted?)
18
+ end
19
+
20
+ def field_name
21
+ "#{@form.object_name}[#{@name}][]"
22
+ end
23
+
24
+ def remove_field_name
25
+ "#{@form.object_name}[remove_#{@name.to_s.singularize}_ids][]"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ <fieldset class="mt-2">
2
+ <% if @options.key?(:label) %>
3
+ <legend class="block text-sm text-slate-500"><%= @options[:label] %></legend>
4
+ <% end %>
5
+ <div class="mt-2 space-y-2">
6
+ <%= @form.collection_check_boxes @name, @choices, :last, :first do |choice| %>
7
+ <div class="flex items-center gap-3">
8
+ <%= choice.check_box(class: "h-4 w-4 shrink-0 cursor-pointer rounded border-gray-300 accent-custom") %>
9
+ <%= choice.label(class: "cursor-pointer text-sm text-gray-900") %>
10
+ </div>
11
+ <% end %>
12
+ </div>
13
+ <% if @options.key?(:description) %>
14
+ <p class="mt-1 text-xs text-gray-400"><%= @options[:description] %></p>
15
+ <% end %>
16
+ <% if @form.error?(@name) %>
17
+ <%= @form.error(@name, class: "text-red-500 text-sm mt-1") %>
18
+ <% end %>
19
+ </fieldset>
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Moduler
4
+ class Form::CheckboxesComponent < ViewComponent::Base
5
+ # choices: array of [label, value] pairs
6
+ def initialize(form, name, choices, options = {})
7
+ @form = form
8
+ @name = name
9
+ @choices = choices
10
+ @options = options
11
+ end
12
+ end
13
+ end
@@ -3,7 +3,7 @@
3
3
  <%= @form.label @name, @options[:label], class: "block text-sm text-slate-500" %>
4
4
  <% end %>
5
5
  <div class="mt-2">
6
- <%= @form.select @name, @choices, { include_blank: @options[:include_blank] }, class: "block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-custom sm:text-sm/6" %>
6
+ <%= @form.select @name, @choices, { include_blank: @options[:include_blank] }, data: data, class: "block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-custom sm:text-sm/6" %>
7
7
  </div>
8
8
  <% if @options.key?(:description) %>
9
9
  <p class="mt-1 text-xs text-gray-400"><%= @options[:description] %></p>
@@ -8,5 +8,10 @@ module Moduler
8
8
  @choices = choices
9
9
  @options = options
10
10
  end
11
+
12
+ # Data attributes of the select, e.g. for Stimulus targets and actions.
13
+ def data
14
+ @options.fetch(:data, {})
15
+ end
11
16
  end
12
17
  end
@@ -54,7 +54,7 @@ module Moduler
54
54
 
55
55
  data.merge(
56
56
  wysiwyg_direct_upload_url_value: helpers.main_app.rails_direct_uploads_path,
57
- wysiwyg_blob_url_value: helpers.main_app.rails_service_blob_path(":signed_id", ":filename"),
57
+ wysiwyg_blob_url_value: helpers.main_app.rails_service_blob_url(":signed_id", ":filename"),
58
58
  wysiwyg_attachments_field_name_value: attachments_field_name
59
59
  )
60
60
  end
@@ -38,7 +38,7 @@ module Moduler
38
38
  end
39
39
 
40
40
  def after_authentication_url
41
- moduler.root_path
41
+ current_home_path
42
42
  end
43
43
 
44
44
  def start_new_session_for(user)
@@ -0,0 +1,29 @@
1
+ module Moduler
2
+ # Scopes a controller to the organization in the URL
3
+ # (+/organizations/:organization_id/...+), available as
4
+ # +Current.organization+ and the +current_organization+ helper. The
5
+ # organization is looked up among the signed-in user's organizations; for
6
+ # any other organization (for example after the user was removed from it)
7
+ # the user is redirected to the home page to choose another one. Keeping the
8
+ # organization in the URL lets every browser tab work in a different
9
+ # organization.
10
+ module OrganizationScoped
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ before_action :set_current_organization
15
+ end
16
+
17
+ private
18
+
19
+ def set_current_organization
20
+ Current.organization = Current.user.organizations.find_by(id: organization_id_param)
21
+
22
+ redirect_to moduler.root_path, alert: t("moduler.flash.organization_not_found") unless Current.organization
23
+ end
24
+
25
+ def organization_id_param
26
+ params[:organization_id]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ module Moduler
2
+ # Keeps administrators out of the application: they are redirected to the
3
+ # administration area. Controllers administrators may use (the
4
+ # administration area, the profile, signing in and out, public pages) opt
5
+ # out with +allow_administrator_access+.
6
+ module RestrictAdministratorAccess
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ before_action :restrict_administrator_access
11
+ helper_method :current_home_path
12
+ end
13
+
14
+ class_methods do
15
+ def allow_administrator_access(**options)
16
+ skip_before_action :restrict_administrator_access, **options
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ # The home page of the signed-in user: the administration area for
23
+ # administrators, the application for everyone else.
24
+ def current_home_path
25
+ Current.user&.administrator? ? moduler.administration_root_path : moduler.root_path
26
+ end
27
+
28
+ def restrict_administrator_access
29
+ redirect_to moduler.administration_root_path if Current.user&.administrator?
30
+ end
31
+ end
32
+ end
@@ -4,6 +4,7 @@ module Moduler
4
4
  after_action :verify_authorized
5
5
 
6
6
  skip_document_acceptance if: -> { current_user&.administrator? }
7
+ allow_administrator_access
7
8
  end
8
9
  end
9
10
  end
@@ -46,7 +46,7 @@ module Moduler
46
46
  end
47
47
 
48
48
  def permitted_parameters
49
- params.expect(article: [ :path, :title, :description, :keywords, :content, images: [] ])
49
+ params.expect(article: [ :status, :path, :title, :description, :keywords, :content, images: [] ])
50
50
  end
51
51
 
52
52
  def permitted_filter_parameters
@@ -0,0 +1,42 @@
1
+ module Moduler
2
+ module Administration
3
+ module Emails
4
+ # Sending an email to users chosen from a filterable list.
5
+ class DeliveriesController < ApplicationController
6
+ before_action :set_email
7
+
8
+ def new
9
+ @filter, @users = EmailDeliveryFilter.new(candidates, permitted_filter_parameters).call
10
+ end
11
+
12
+ def create
13
+ queued = @email.deliver_to(User.where(id: Array(params[:user_ids])))
14
+
15
+ redirect_to moduler.new_administration_email_delivery_path(@email), notice: t(".notice", count: queued)
16
+ end
17
+
18
+ private
19
+
20
+ def set_email
21
+ @email = Email.find(params[:email_id])
22
+ authorize(@email, :deliver?, policy_class: EmailPolicy)
23
+ end
24
+
25
+ # Users with the id and sent_at of their queued email, if any.
26
+ def candidates
27
+ User
28
+ .joins(User.sanitize_sql_array([
29
+ "LEFT JOIN moduler_user_emails ON moduler_user_emails.moduler_user_id = moduler_users.id AND moduler_user_emails.moduler_email_id = ?",
30
+ @email.id
31
+ ]))
32
+ .select("moduler_users.*", "moduler_user_emails.id AS user_email_id", "moduler_user_emails.sent_at AS user_email_sent_at")
33
+ .order(:email_address)
34
+ end
35
+
36
+ def permitted_filter_parameters
37
+ (params.permit(filter: %i[ query role sent per_page ])[:filter] || {}).merge(params.permit(:page))
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end