moduler 0.4.0 → 0.6.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 (139) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/builds/moduler/tailwind.css +155 -1
  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/select_all_controller.js +15 -0
  6. data/app/components/moduler/filter_component.html.erb +9 -1
  7. data/app/components/moduler/filter_component.rb +12 -0
  8. data/app/components/moduler/form/attachments_component.html.erb +32 -0
  9. data/app/components/moduler/form/attachments_component.rb +28 -0
  10. data/app/components/moduler/form/checkboxes_component.html.erb +19 -0
  11. data/app/components/moduler/form/checkboxes_component.rb +13 -0
  12. data/app/components/moduler/form/file_component.html.erb +14 -0
  13. data/app/components/moduler/form/file_component.rb +11 -0
  14. data/app/components/moduler/form/select_component.html.erb +1 -1
  15. data/app/components/moduler/form/select_component.rb +5 -0
  16. data/app/components/moduler/form/wysiwyg_component.rb +1 -1
  17. data/app/controllers/concerns/moduler/authentication.rb +2 -2
  18. data/app/controllers/concerns/moduler/require_document_acceptance.rb +31 -0
  19. data/app/controllers/concerns/moduler/restrict_administrator_access.rb +32 -0
  20. data/app/controllers/moduler/administration/application_controller.rb +3 -0
  21. data/app/controllers/moduler/administration/articles_controller.rb +1 -1
  22. data/app/controllers/moduler/administration/documents_controller.rb +56 -0
  23. data/app/controllers/moduler/administration/emails/deliveries_controller.rb +42 -0
  24. data/app/controllers/moduler/administration/emails_controller.rb +68 -0
  25. data/app/controllers/moduler/administration/memberships_controller.rb +62 -0
  26. data/app/controllers/moduler/administration/organizations_controller.rb +51 -0
  27. data/app/controllers/moduler/administration/preferences_controller.rb +57 -0
  28. data/app/controllers/moduler/administration/roles_controller.rb +56 -0
  29. data/app/controllers/moduler/administration/users_controller.rb +2 -2
  30. data/app/controllers/moduler/application_controller.rb +3 -1
  31. data/app/controllers/moduler/articles_controller.rb +4 -2
  32. data/app/controllers/moduler/document_acceptances_controller.rb +25 -0
  33. data/app/controllers/moduler/profile/sent_emails_controller.rb +18 -0
  34. data/app/controllers/moduler/profile/sessions/revocation_controller.rb +3 -0
  35. data/app/controllers/moduler/profile/sessions_controller.rb +3 -0
  36. data/app/controllers/moduler/profile_controller.rb +6 -1
  37. data/app/controllers/moduler/sessions_controller.rb +16 -6
  38. data/app/controllers/moduler/users_controller.rb +3 -0
  39. data/app/filters/email_delivery_filter.rb +35 -0
  40. data/app/filters/organization_query_filter.rb +23 -0
  41. data/app/jobs/moduler/email_delivery_job.rb +14 -0
  42. data/app/lib/moduler/form_builder.rb +17 -3
  43. data/app/mailers/moduler/application_mailer.rb +27 -1
  44. data/app/mailers/moduler/email_mailer.rb +14 -0
  45. data/app/models/moduler/article.rb +2 -0
  46. data/app/models/moduler/document.rb +17 -0
  47. data/app/models/moduler/email.rb +59 -0
  48. data/app/models/moduler/membership.rb +25 -0
  49. data/app/models/moduler/organization.rb +13 -0
  50. data/app/models/moduler/preference.rb +44 -0
  51. data/app/models/moduler/role.rb +26 -0
  52. data/app/models/moduler/sent_email.rb +13 -0
  53. data/app/models/moduler/user.rb +21 -1
  54. data/app/models/moduler/user_document.rb +8 -0
  55. data/app/models/moduler/user_email.rb +15 -0
  56. data/app/policies/moduler/administration/document_policy.rb +25 -0
  57. data/app/policies/moduler/administration/email_policy.rb +26 -0
  58. data/app/policies/moduler/administration/membership_policy.rb +29 -0
  59. data/app/policies/moduler/administration/organization_policy.rb +25 -0
  60. data/app/policies/moduler/administration/preference_policy.rb +29 -0
  61. data/app/policies/moduler/administration/role_policy.rb +25 -0
  62. data/app/services/moduler/document_acceptance.rb +43 -0
  63. data/app/views/layouts/moduler/mailer.html.erb +30 -0
  64. data/app/views/layouts/moduler/mailer.text.erb +1 -0
  65. data/app/views/moduler/administration/articles/_article.html.erb +2 -0
  66. data/app/views/moduler/administration/articles/_form.html.erb +1 -0
  67. data/app/views/moduler/administration/documents/_document.html.erb +19 -0
  68. data/app/views/moduler/administration/documents/_form.html.erb +23 -0
  69. data/app/views/moduler/administration/documents/edit.html.erb +1 -0
  70. data/app/views/moduler/administration/documents/index.html.erb +13 -0
  71. data/app/views/moduler/administration/documents/new.html.erb +1 -0
  72. data/app/views/moduler/administration/emails/_email.html.erb +33 -0
  73. data/app/views/moduler/administration/emails/_form.html.erb +23 -0
  74. data/app/views/moduler/administration/emails/deliveries/new.html.erb +58 -0
  75. data/app/views/moduler/administration/emails/edit.html.erb +1 -0
  76. data/app/views/moduler/administration/emails/index.html.erb +13 -0
  77. data/app/views/moduler/administration/emails/new.html.erb +1 -0
  78. data/app/views/moduler/administration/memberships/_form.html.erb +38 -0
  79. data/app/views/moduler/administration/memberships/_membership.html.erb +23 -0
  80. data/app/views/moduler/administration/memberships/edit.html.erb +1 -0
  81. data/app/views/moduler/administration/memberships/index.html.erb +14 -0
  82. data/app/views/moduler/administration/memberships/new.html.erb +1 -0
  83. data/app/views/moduler/administration/organizations/_form.html.erb +13 -0
  84. data/app/views/moduler/administration/organizations/_organization.html.erb +23 -0
  85. data/app/views/moduler/administration/organizations/edit.html.erb +1 -0
  86. data/app/views/moduler/administration/organizations/index.html.erb +13 -0
  87. data/app/views/moduler/administration/organizations/new.html.erb +1 -0
  88. data/app/views/moduler/administration/preferences/_form.html.erb +16 -0
  89. data/app/views/moduler/administration/preferences/_preference.html.erb +24 -0
  90. data/app/views/moduler/administration/preferences/edit.html.erb +1 -0
  91. data/app/views/moduler/administration/preferences/index.html.erb +13 -0
  92. data/app/views/moduler/administration/preferences/new.html.erb +1 -0
  93. data/app/views/moduler/administration/roles/_form.html.erb +24 -0
  94. data/app/views/moduler/administration/roles/_role.html.erb +15 -0
  95. data/app/views/moduler/administration/roles/edit.html.erb +1 -0
  96. data/app/views/moduler/administration/roles/index.html.erb +14 -0
  97. data/app/views/moduler/administration/roles/new.html.erb +1 -0
  98. data/app/views/moduler/administration/users/_user.html.erb +4 -0
  99. data/app/views/moduler/administration/users/edit.html.erb +2 -0
  100. data/app/views/moduler/administration/users/new.html.erb +2 -0
  101. data/app/views/moduler/common/_header.html.erb +2 -7
  102. data/app/views/moduler/common/administration/_sidebar.html.erb +10 -0
  103. data/app/views/moduler/common/profile/_sidebar.html.erb +1 -0
  104. data/app/views/moduler/document_acceptances/new.html.erb +36 -0
  105. data/app/views/moduler/email_mailer/custom.html.erb +3 -0
  106. data/app/views/moduler/email_mailer/custom.text.erb +1 -0
  107. data/app/views/moduler/profile/edit.html.erb +1 -0
  108. data/app/views/moduler/profile/sent_emails/index.html.erb +26 -0
  109. data/config/locales/moduler/administration/articles/en.yml +5 -0
  110. data/config/locales/moduler/administration/documents/en.yml +35 -0
  111. data/config/locales/moduler/administration/emails/en.yml +75 -0
  112. data/config/locales/moduler/administration/memberships/en.yml +35 -0
  113. data/config/locales/moduler/administration/organizations/en.yml +26 -0
  114. data/config/locales/moduler/administration/preferences/en.yml +44 -0
  115. data/config/locales/moduler/administration/roles/en.yml +32 -0
  116. data/config/locales/moduler/administration/users/en.yml +12 -1
  117. data/config/locales/moduler/common/en.yml +7 -1
  118. data/config/locales/moduler/components/en.yml +5 -0
  119. data/config/locales/moduler/document_acceptances/en.yml +17 -0
  120. data/config/locales/moduler/models/en.yml +8 -0
  121. data/config/locales/moduler/profile/en.yml +2 -0
  122. data/config/locales/moduler/profile/sent_emails/en.yml +11 -0
  123. data/config/locales/moduler/sessions/en.yml +1 -0
  124. data/config/routes.rb +13 -0
  125. data/db/migrate/20261104120000_add_status_to_moduler_users.rb +6 -0
  126. data/db/migrate/20261104205837_create_moduler_documents.rb +10 -0
  127. data/db/migrate/20261104205950_create_moduler_user_documents.rb +12 -0
  128. data/db/migrate/20261111113522_create_moduler_organizations.rb +11 -0
  129. data/db/migrate/20261111150000_create_moduler_roles.rb +13 -0
  130. data/db/migrate/20261111160000_create_moduler_memberships.rb +13 -0
  131. data/db/migrate/20261111180000_add_name_to_moduler_users.rb +5 -0
  132. data/db/migrate/20261111190000_add_status_to_moduler_articles.rb +8 -0
  133. data/db/migrate/20261111200000_create_moduler_preferences.rb +13 -0
  134. data/db/migrate/20261111210000_create_moduler_emails.rb +15 -0
  135. data/db/migrate/20261111210001_create_moduler_user_emails.rb +13 -0
  136. data/db/migrate/20261111210002_create_moduler_sent_emails.rb +12 -0
  137. data/lib/moduler/configuration.rb +6 -0
  138. data/lib/moduler/version.rb +1 -1
  139. metadata +100 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bef4750b890390a7ed190a171abecbad432378673ed5aee71487cdf669369b11
4
- data.tar.gz: 46782a61ddd7ac48ddd10da394315110d1673d4c0b12fdae6be3136013bbfca8
3
+ metadata.gz: 81844153b9bf050ad6dcd61506cb7f4c899fc319a2e24e9f7d419de203522c0e
4
+ data.tar.gz: 89ec8cc74bfaed32d389e447773ed65249d442097d045984d7f142ba6c5ed4a4
5
5
  SHA512:
6
- metadata.gz: 71aaf10f6880c35954bd3c8d60ba22a2bd0b251565a3ffdada709e566ab164fc771d3ec7ac4fe5af57976ee34748c8b413c25b814ac5c96ba5a697f1f135dc03
7
- data.tar.gz: f4b4b157a4bbb5490c64ec907d6e5a4f68ff7900421238761d0e80b1744c0d855eba512c301c314f6218f373be82ab2dae0286c9d2680600d64bd42e06accb60
6
+ metadata.gz: cab1f5b5af985d380606853e560f2f25b22697cca35220e61d689880db48760f679d373257a34eb1169b4df03b16cd682016ed86a8be60fe7f448bf39658013d
7
+ data.tar.gz: 0256ba167de24fc8f243003cbee2ad8862c9f154fd5a7bd769792c3a29a3ee33447e4482980d7be92c9ae1e4b36db7ad6c650f4362971d207096627aa216b63b
@@ -32,6 +32,7 @@
32
32
  --color-slate-600: oklch(44.6% 0.043 257.281);
33
33
  --color-slate-700: oklch(37.2% 0.044 257.287);
34
34
  --color-slate-900: oklch(20.8% 0.042 265.755);
35
+ --color-gray-50: oklch(98.5% 0.002 247.839);
35
36
  --color-gray-200: oklch(92.8% 0.006 264.531);
36
37
  --color-gray-300: oklch(87.2% 0.01 258.338);
37
38
  --color-gray-400: oklch(70.7% 0.022 261.325);
@@ -41,6 +42,7 @@
41
42
  --spacing: 0.25rem;
42
43
  --container-sm: 24rem;
43
44
  --container-lg: 32rem;
45
+ --container-2xl: 42rem;
44
46
  --container-3xl: 48rem;
45
47
  --container-5xl: 64rem;
46
48
  --text-xs: 0.75rem;
@@ -52,7 +54,6 @@
52
54
  --text-xl: 1.25rem;
53
55
  --text-xl--line-height: calc(1.75 / 1.25);
54
56
  --text-2xl: 1.5rem;
55
- --text-2xl--line-height: calc(2 / 1.5);
56
57
  --font-weight-medium: 500;
57
58
  --font-weight-semibold: 600;
58
59
  --font-weight-bold: 700;
@@ -252,6 +253,9 @@
252
253
  .-mx-4 {
253
254
  margin-inline: calc(var(--spacing) * -4);
254
255
  }
256
+ .mx-1 {
257
+ margin-inline: calc(var(--spacing) * 1);
258
+ }
255
259
  .mx-auto {
256
260
  margin-inline: auto;
257
261
  }
@@ -872,6 +876,9 @@
872
876
  margin-bottom: 0;
873
877
  }
874
878
  }
879
+ .mt-0\.5 {
880
+ margin-top: calc(var(--spacing) * 0.5);
881
+ }
875
882
  .mt-1 {
876
883
  margin-top: calc(var(--spacing) * 1);
877
884
  }
@@ -955,6 +962,12 @@
955
962
  .w-full {
956
963
  width: 100%;
957
964
  }
965
+ .w-px {
966
+ width: 1px;
967
+ }
968
+ .max-w-2xl {
969
+ max-width: var(--container-2xl);
970
+ }
958
971
  .max-w-3xl {
959
972
  max-width: var(--container-3xl);
960
973
  }
@@ -979,6 +992,9 @@
979
992
  .shrink-0 {
980
993
  flex-shrink: 0;
981
994
  }
995
+ .border-collapse {
996
+ border-collapse: collapse;
997
+ }
982
998
  .translate-x-2 {
983
999
  --tw-translate-x: calc(var(--spacing) * 2);
984
1000
  translate: var(--tw-translate-x) var(--tw-translate-y);
@@ -1022,6 +1038,13 @@
1022
1038
  .gap-4 {
1023
1039
  gap: calc(var(--spacing) * 4);
1024
1040
  }
1041
+ .space-y-2 {
1042
+ :where(& > :not(:last-child)) {
1043
+ --tw-space-y-reverse: 0;
1044
+ margin-block-start: calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));
1045
+ margin-block-end: calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)));
1046
+ }
1047
+ }
1025
1048
  .space-y-4 {
1026
1049
  :where(& > :not(:last-child)) {
1027
1050
  --tw-space-y-reverse: 0;
@@ -1052,11 +1075,19 @@
1052
1075
  border-bottom-width: calc(1px * calc(1 - var(--tw-divide-y-reverse)));
1053
1076
  }
1054
1077
  }
1078
+ .divide-gray-200 {
1079
+ :where(& > :not(:last-child)) {
1080
+ border-color: var(--color-gray-200);
1081
+ }
1082
+ }
1055
1083
  .divide-slate-100 {
1056
1084
  :where(& > :not(:last-child)) {
1057
1085
  border-color: var(--color-slate-100);
1058
1086
  }
1059
1087
  }
1088
+ .self-stretch {
1089
+ align-self: stretch;
1090
+ }
1060
1091
  .truncate {
1061
1092
  overflow: hidden;
1062
1093
  text-overflow: ellipsis;
@@ -1118,6 +1149,9 @@
1118
1149
  .border-gray-200 {
1119
1150
  border-color: var(--color-gray-200);
1120
1151
  }
1152
+ .border-gray-300 {
1153
+ border-color: var(--color-gray-300);
1154
+ }
1121
1155
  .border-red-200 {
1122
1156
  border-color: var(--color-red-200);
1123
1157
  }
@@ -1139,6 +1173,9 @@
1139
1173
  .bg-emerald-50 {
1140
1174
  background-color: var(--color-emerald-50);
1141
1175
  }
1176
+ .bg-gray-200 {
1177
+ background-color: var(--color-gray-200);
1178
+ }
1142
1179
  .bg-green-100 {
1143
1180
  background-color: var(--color-green-100);
1144
1181
  }
@@ -1217,12 +1254,18 @@
1217
1254
  .pt-6 {
1218
1255
  padding-top: calc(var(--spacing) * 6);
1219
1256
  }
1257
+ .pr-10 {
1258
+ padding-right: calc(var(--spacing) * 10);
1259
+ }
1220
1260
  .pb-4 {
1221
1261
  padding-bottom: calc(var(--spacing) * 4);
1222
1262
  }
1223
1263
  .pb-6 {
1224
1264
  padding-bottom: calc(var(--spacing) * 6);
1225
1265
  }
1266
+ .pl-3 {
1267
+ padding-left: calc(var(--spacing) * 3);
1268
+ }
1226
1269
  .text-center {
1227
1270
  text-align: center;
1228
1271
  }
@@ -1333,6 +1376,12 @@
1333
1376
  .italic {
1334
1377
  font-style: italic;
1335
1378
  }
1379
+ .underline {
1380
+ text-decoration-line: underline;
1381
+ }
1382
+ .accent-custom {
1383
+ accent-color: var(--color-custom);
1384
+ }
1336
1385
  .opacity-0 {
1337
1386
  opacity: 0%;
1338
1387
  }
@@ -1430,6 +1479,10 @@
1430
1479
  --tw-prose-invert-th-borders: oklch(44.6% 0.043 257.281);
1431
1480
  --tw-prose-invert-td-borders: oklch(37.2% 0.044 257.287);
1432
1481
  }
1482
+ .select-all {
1483
+ -webkit-user-select: all;
1484
+ user-select: all;
1485
+ }
1433
1486
  .ring-inset {
1434
1487
  --tw-ring-inset: inset;
1435
1488
  }
@@ -1440,6 +1493,76 @@
1440
1493
  }
1441
1494
  }
1442
1495
  }
1496
+ .file\:mr-3 {
1497
+ &::file-selector-button {
1498
+ margin-right: calc(var(--spacing) * 3);
1499
+ }
1500
+ }
1501
+ .file\:rounded-md {
1502
+ &::file-selector-button {
1503
+ border-radius: var(--radius-md);
1504
+ }
1505
+ }
1506
+ .file\:border-0 {
1507
+ &::file-selector-button {
1508
+ border-style: var(--tw-border-style);
1509
+ border-width: 0px;
1510
+ }
1511
+ }
1512
+ .file\:bg-white {
1513
+ &::file-selector-button {
1514
+ background-color: var(--color-white);
1515
+ }
1516
+ }
1517
+ .file\:px-3 {
1518
+ &::file-selector-button {
1519
+ padding-inline: calc(var(--spacing) * 3);
1520
+ }
1521
+ }
1522
+ .file\:py-1\.5 {
1523
+ &::file-selector-button {
1524
+ padding-block: calc(var(--spacing) * 1.5);
1525
+ }
1526
+ }
1527
+ .file\:text-sm {
1528
+ &::file-selector-button {
1529
+ font-size: var(--text-sm);
1530
+ line-height: var(--tw-leading, var(--text-sm--line-height));
1531
+ }
1532
+ }
1533
+ .file\:font-semibold {
1534
+ &::file-selector-button {
1535
+ --tw-font-weight: var(--font-weight-semibold);
1536
+ font-weight: var(--font-weight-semibold);
1537
+ }
1538
+ }
1539
+ .file\:text-gray-900 {
1540
+ &::file-selector-button {
1541
+ color: var(--color-gray-900);
1542
+ }
1543
+ }
1544
+ .file\:shadow-xs {
1545
+ &::file-selector-button {
1546
+ --tw-shadow: 0 1px 2px 0 var(--tw-shadow-color, rgb(0 0 0 / 0.05));
1547
+ box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
1548
+ }
1549
+ }
1550
+ .file\:ring-1 {
1551
+ &::file-selector-button {
1552
+ --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);
1553
+ box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
1554
+ }
1555
+ }
1556
+ .file\:ring-gray-300 {
1557
+ &::file-selector-button {
1558
+ --tw-ring-color: var(--color-gray-300);
1559
+ }
1560
+ }
1561
+ .file\:ring-inset {
1562
+ &::file-selector-button {
1563
+ --tw-ring-inset: inset;
1564
+ }
1565
+ }
1443
1566
  .placeholder\:text-gray-400 {
1444
1567
  &::placeholder {
1445
1568
  color: var(--color-gray-400);
@@ -1520,6 +1643,13 @@
1520
1643
  }
1521
1644
  }
1522
1645
  }
1646
+ .hover\:underline {
1647
+ &:hover {
1648
+ @media (hover: hover) {
1649
+ text-decoration-line: underline;
1650
+ }
1651
+ }
1652
+ }
1523
1653
  .hover\:ring-red-200 {
1524
1654
  &:hover {
1525
1655
  @media (hover: hover) {
@@ -1527,6 +1657,15 @@
1527
1657
  }
1528
1658
  }
1529
1659
  }
1660
+ .hover\:file\:bg-gray-50 {
1661
+ &:hover {
1662
+ @media (hover: hover) {
1663
+ &::file-selector-button {
1664
+ background-color: var(--color-gray-50);
1665
+ }
1666
+ }
1667
+ }
1668
+ }
1530
1669
  .focus\:border-slate-900 {
1531
1670
  &:focus {
1532
1671
  border-color: var(--color-slate-900);
@@ -1649,16 +1788,31 @@
1649
1788
  margin-inline: calc(var(--spacing) * 0);
1650
1789
  }
1651
1790
  }
1791
+ .md\:my-2 {
1792
+ @media (width >= 48rem) {
1793
+ margin-block: calc(var(--spacing) * 2);
1794
+ }
1795
+ }
1652
1796
  .md\:mt-8 {
1653
1797
  @media (width >= 48rem) {
1654
1798
  margin-top: calc(var(--spacing) * 8);
1655
1799
  }
1656
1800
  }
1801
+ .md\:h-px {
1802
+ @media (width >= 48rem) {
1803
+ height: 1px;
1804
+ }
1805
+ }
1657
1806
  .md\:w-1\/8 {
1658
1807
  @media (width >= 48rem) {
1659
1808
  width: calc(1 / 8 * 100%);
1660
1809
  }
1661
1810
  }
1811
+ .md\:w-auto {
1812
+ @media (width >= 48rem) {
1813
+ width: auto;
1814
+ }
1815
+ }
1662
1816
  .md\:shrink-0 {
1663
1817
  @media (width >= 48rem) {
1664
1818
  flex-shrink: 0;
@@ -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,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
@@ -0,0 +1,14 @@
1
+ <div class="mt-2">
2
+ <% if @options.key?(:label) %>
3
+ <%= @form.label @name, @options[:label], class: "block text-sm text-slate-500" %>
4
+ <% end %>
5
+ <div class="mt-2">
6
+ <%= @form.file_field @name, accept: @options[:accept], 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" %>
7
+ </div>
8
+ <% if @options.key?(:description) %>
9
+ <p class="mt-1 text-xs text-gray-400"><%= @options[:description] %></p>
10
+ <% end %>
11
+ <% if @form.error?(@name) %>
12
+ <%= @form.error(@name, class: "text-red-500 text-sm mt-1") %>
13
+ <% end %>
14
+ </div>
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Moduler
4
+ class Form::FileComponent < ViewComponent::Base
5
+ def initialize(form, name, options = {})
6
+ @form = form
7
+ @name = name
8
+ @options = options
9
+ end
10
+ end
11
+ 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
@@ -29,7 +29,7 @@ module Moduler
29
29
 
30
30
  def find_session_by_cookie
31
31
  if cookies.signed[:session_id]
32
- Session.active.find_by(id: cookies.signed[:session_id], signed_in_at: Session::LIFETIME.ago..)
32
+ Session.active.joins(:user).where(user: { status: :active }).find_by(id: cookies.signed[:session_id], signed_in_at: Session::LIFETIME.ago..)
33
33
  end
34
34
  end
35
35
 
@@ -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,31 @@
1
+ module Moduler
2
+ # Blocks the panel for signed-in users until they accept every document.
3
+ # Controllers that must stay available meanwhile (the profile, signing out,
4
+ # public pages) opt out with +skip_document_acceptance+.
5
+ module RequireDocumentAcceptance
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before_action :require_document_acceptance
10
+ helper_method :document_acceptance_required?
11
+ end
12
+
13
+ class_methods do
14
+ def skip_document_acceptance(**options)
15
+ skip_before_action :require_document_acceptance, **options
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def document_acceptance_required?
22
+ return @document_acceptance_required if defined?(@document_acceptance_required)
23
+
24
+ @document_acceptance_required = Current.user.present? && Current.user.pending_documents.exists?
25
+ end
26
+
27
+ def require_document_acceptance
28
+ redirect_to moduler.new_document_acceptance_path if document_acceptance_required?
29
+ end
30
+ end
31
+ 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
@@ -2,6 +2,9 @@ module Moduler
2
2
  module Administration
3
3
  class ApplicationController < ::Moduler::ApplicationController
4
4
  after_action :verify_authorized
5
+
6
+ skip_document_acceptance if: -> { current_user&.administrator? }
7
+ allow_administrator_access
5
8
  end
6
9
  end
7
10
  end