agile_rails 0.0.0.1

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 (259) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +285 -0
  5. data/Rakefile +39 -0
  6. data/agile_rails.gemspec +36 -0
  7. data/app/assets/fonts/ibm-plex-sans-300.woff2 +0 -0
  8. data/app/assets/fonts/ibm-plex-sans-400.woff2 +0 -0
  9. data/app/assets/fonts/ibm-plex-sans-500.woff2 +0 -0
  10. data/app/assets/fonts/ibm-plex-sans-600.woff2 +0 -0
  11. data/app/assets/fonts/ibm-plex-sans-700.woff2 +0 -0
  12. data/app/assets/fonts/ibm-plex-sans-italic.woff2 +0 -0
  13. data/app/assets/images/32px.png +0 -0
  14. data/app/assets/images/throbber.gif +0 -0
  15. data/app/assets/javascripts/agile/agile.js +1489 -0
  16. data/app/assets/javascripts/agile/jquery-migrate.js +702 -0
  17. data/app/assets/javascripts/agile/jquery.bpopup.js +372 -0
  18. data/app/assets/javascripts/agile/jquery.datetimepicker.js +1353 -0
  19. data/app/assets/javascripts/agile/jstree.min.js +6 -0
  20. data/app/assets/javascripts/agile/select-multiple.js +459 -0
  21. data/app/assets/javascripts/agile/some_scripts.js +33 -0
  22. data/app/assets/javascripts/agile.js +22 -0
  23. data/app/assets/javascripts/agile_application.js +22 -0
  24. data/app/assets/javascripts/agile_editor.js +22 -0
  25. data/app/assets/stylesheets/agile/agile.css +1882 -0
  26. data/app/assets/stylesheets/agile/agile_apps.css +149 -0
  27. data/app/assets/stylesheets/agile/jquery.datetimepicker.css +304 -0
  28. data/app/assets/stylesheets/agile/jstree.css +1107 -0
  29. data/app/assets/stylesheets/agile/select-multiple.css +110 -0
  30. data/app/assets/stylesheets/agile/th-bg.png +0 -0
  31. data/app/assets/stylesheets/agile/theme.css +49 -0
  32. data/app/assets/stylesheets/agile.css +21 -0
  33. data/app/assets/stylesheets/agile_application.css +20 -0
  34. data/app/assets/stylesheets/agile_editor.css +19 -0
  35. data/app/controllers/agile_application_controller.rb +735 -0
  36. data/app/controllers/agile_common_controller.rb +345 -0
  37. data/app/controllers/agile_controller.rb +977 -0
  38. data/app/controllers/agile_main_controller.rb +36 -0
  39. data/app/controls/agile_control.rb +120 -0
  40. data/app/controls/agile_report.rb +364 -0
  41. data/app/controls/ar_category_control.rb +39 -0
  42. data/app/controls/ar_help_control.rb +139 -0
  43. data/app/controls/ar_image_control.rb +180 -0
  44. data/app/controls/ar_journal_control.rb +47 -0
  45. data/app/controls/ar_menu_item_control.rb +55 -0
  46. data/app/controls/ar_page_control.rb +64 -0
  47. data/app/controls/ar_poll_result_control.rb +84 -0
  48. data/app/controls/ar_setup_control.rb +62 -0
  49. data/app/controls/belongs_to_control.rb +61 -0
  50. data/app/controls/browse_models_control.rb +98 -0
  51. data/app/controls/settings_form_control.rb +137 -0
  52. data/app/forms/agile_help.yml +112 -0
  53. data/app/forms/agile_menu.yml +140 -0
  54. data/app/forms/agile_report_defaults.yml +39 -0
  55. data/app/forms/all_options.yml +810 -0
  56. data/app/forms/ar_ad.yml +121 -0
  57. data/app/forms/ar_big_table.yml +60 -0
  58. data/app/forms/ar_big_table_value.yml +52 -0
  59. data/app/forms/ar_browse_fields.yml +35 -0
  60. data/app/forms/ar_browse_models.yml +48 -0
  61. data/app/forms/ar_category.yml +73 -0
  62. data/app/forms/ar_category_as_tree.yml +31 -0
  63. data/app/forms/ar_design.yml +75 -0
  64. data/app/forms/ar_filter.yml +52 -0
  65. data/app/forms/ar_folder_permission.yml +56 -0
  66. data/app/forms/ar_folder_rule.yml +48 -0
  67. data/app/forms/ar_gallery.yml +55 -0
  68. data/app/forms/ar_image.yml +126 -0
  69. data/app/forms/ar_image_search.yml +83 -0
  70. data/app/forms/ar_journal.yml +76 -0
  71. data/app/forms/ar_json_ld.yml +56 -0
  72. data/app/forms/ar_key_value.yml +33 -0
  73. data/app/forms/ar_key_value_store.yml +33 -0
  74. data/app/forms/ar_link.yml +60 -0
  75. data/app/forms/ar_menu.yml +67 -0
  76. data/app/forms/ar_menu_item.yml +141 -0
  77. data/app/forms/ar_page.yml +187 -0
  78. data/app/forms/ar_part.yml +91 -0
  79. data/app/forms/ar_permission.yml +52 -0
  80. data/app/forms/ar_permission_rule.yml +40 -0
  81. data/app/forms/ar_piece.yml +106 -0
  82. data/app/forms/ar_policy.yml +64 -0
  83. data/app/forms/ar_policy_rule.yml +42 -0
  84. data/app/forms/ar_policy_rule_nocms.yml +40 -0
  85. data/app/forms/ar_poll.yml +118 -0
  86. data/app/forms/ar_poll_item.yml +78 -0
  87. data/app/forms/ar_poll_result.yml +88 -0
  88. data/app/forms/ar_poll_result_export.yml +35 -0
  89. data/app/forms/ar_removed_url.yml +41 -0
  90. data/app/forms/ar_role.yml +43 -0
  91. data/app/forms/ar_seo.yml +32 -0
  92. data/app/forms/ar_setup.yml +45 -0
  93. data/app/forms/ar_site.yml +149 -0
  94. data/app/forms/ar_steps_template.yml +51 -0
  95. data/app/forms/ar_user.yml +140 -0
  96. data/app/forms/ar_user_role.yml +57 -0
  97. data/app/forms/help/dc_category_as_tree.en +4 -0
  98. data/app/forms/help/dc_category_as_tree.sl +5 -0
  99. data/app/forms/json_ld_schema.yml +168 -0
  100. data/app/helpers/agile_application_helper.rb +1162 -0
  101. data/app/helpers/agile_category_helper.rb +128 -0
  102. data/app/helpers/agile_common_helper.rb +308 -0
  103. data/app/helpers/agile_edit_helper.rb +645 -0
  104. data/app/helpers/agile_helper.rb +509 -0
  105. data/app/helpers/agile_index_helper.rb +677 -0
  106. data/app/helpers/ar_image_helper.rb +128 -0
  107. data/app/models/agile_form_fields/action.rb +61 -0
  108. data/app/models/agile_form_fields/agile_form_field.rb +322 -0
  109. data/app/models/agile_form_fields/belongs_to.rb +112 -0
  110. data/app/models/agile_form_fields/check_box.rb +73 -0
  111. data/app/models/agile_form_fields/comment.rb +62 -0
  112. data/app/models/agile_form_fields/date_picker.rb +104 -0
  113. data/app/models/agile_form_fields/date_select.rb +68 -0
  114. data/app/models/agile_form_fields/datetime_picker.rb +88 -0
  115. data/app/models/agile_form_fields/datetime_select.rb +73 -0
  116. data/app/models/agile_form_fields/file_field.rb +52 -0
  117. data/app/models/agile_form_fields/file_select.rb +69 -0
  118. data/app/models/agile_form_fields/hidden_field.rb +51 -0
  119. data/app/models/agile_form_fields/html_field.rb +69 -0
  120. data/app/models/agile_form_fields/journal_diff.rb +62 -0
  121. data/app/models/agile_form_fields/link_to.rb +69 -0
  122. data/app/models/agile_form_fields/method.rb +66 -0
  123. data/app/models/agile_form_fields/multitext_autocomplete.rb +215 -0
  124. data/app/models/agile_form_fields/number_field.rb +92 -0
  125. data/app/models/agile_form_fields/password_field.rb +63 -0
  126. data/app/models/agile_form_fields/radio_button.rb +95 -0
  127. data/app/models/agile_form_fields/readonly.rb +77 -0
  128. data/app/models/agile_form_fields/select.rb +281 -0
  129. data/app/models/agile_form_fields/submit_tag.rb +58 -0
  130. data/app/models/agile_form_fields/text_area.rb +61 -0
  131. data/app/models/agile_form_fields/text_autocomplete.rb +171 -0
  132. data/app/models/agile_form_fields/text_field.rb +55 -0
  133. data/app/models/agile_form_fields/text_with_select.rb +94 -0
  134. data/app/models/agile_form_fields/tree_select.rb +170 -0
  135. data/app/models/ar_big_table.rb +82 -0
  136. data/app/models/ar_big_table_value.rb +53 -0
  137. data/app/models/ar_category.rb +109 -0
  138. data/app/models/ar_design.rb +116 -0
  139. data/app/models/ar_filter.rb +200 -0
  140. data/app/models/ar_folder_permission.rb +50 -0
  141. data/app/models/ar_folder_rule.rb +47 -0
  142. data/app/models/ar_gallery.rb +53 -0
  143. data/app/models/ar_image.rb +198 -0
  144. data/app/models/ar_internals.rb +60 -0
  145. data/app/models/ar_journal.rb +46 -0
  146. data/app/models/ar_json_ld.rb +131 -0
  147. data/app/models/ar_key_value_store.rb +128 -0
  148. data/app/models/ar_link.rb +48 -0
  149. data/app/models/ar_memory.rb +172 -0
  150. data/app/models/ar_menu.rb +144 -0
  151. data/app/models/ar_menu_item.rb +106 -0
  152. data/app/models/ar_page.rb +74 -0
  153. data/app/models/ar_part.rb +66 -0
  154. data/app/models/ar_permission.rb +180 -0
  155. data/app/models/ar_permission_rule.rb +65 -0
  156. data/app/models/ar_policy.rb +78 -0
  157. data/app/models/ar_policy_rule.rb +65 -0
  158. data/app/models/ar_poll.rb +74 -0
  159. data/app/models/ar_poll_item.rb +47 -0
  160. data/app/models/ar_poll_result.rb +38 -0
  161. data/app/models/ar_removed_url.rb +42 -0
  162. data/app/models/ar_role.rb +84 -0
  163. data/app/models/ar_setup.rb +115 -0
  164. data/app/models/ar_site.rb +68 -0
  165. data/app/models/ar_temp.rb +150 -0
  166. data/app/models/ar_user.rb +72 -0
  167. data/app/models/ar_user_group.rb +38 -0
  168. data/app/models/ar_user_role.rb +54 -0
  169. data/app/models/ar_visit.rb +41 -0
  170. data/app/models/concerns/ar_page_concern.rb +128 -0
  171. data/app/models/concerns/ar_part_concern.rb +48 -0
  172. data/app/models/concerns/ar_piece_concern.rb +48 -0
  173. data/app/models/concerns/ar_policy_rule_concern.rb +87 -0
  174. data/app/models/concerns/ar_seo_concern.rb +66 -0
  175. data/app/models/concerns/ar_site_concern.rb +103 -0
  176. data/app/models/concerns/ar_user_concern.rb +195 -0
  177. data/app/renderers/agile_common_renderer.rb +93 -0
  178. data/app/renderers/agile_renderer.rb +59 -0
  179. data/app/renderers/ar_ad_renderer.rb +219 -0
  180. data/app/renderers/ar_captcha_renderer.rb +113 -0
  181. data/app/renderers/ar_common_renderer.rb +90 -0
  182. data/app/renderers/ar_gallery_renderer.rb +107 -0
  183. data/app/renderers/ar_menu_renderer.rb +195 -0
  184. data/app/renderers/ar_page_renderer.rb +147 -0
  185. data/app/renderers/ar_part_renderer.rb +235 -0
  186. data/app/renderers/ar_piece_renderer.rb +119 -0
  187. data/app/renderers/ar_poll_renderer.rb +272 -0
  188. data/app/views/agile/_edit_stuff.html.erb +57 -0
  189. data/app/views/agile/_form.html.erb +24 -0
  190. data/app/views/agile/_result.html.erb +28 -0
  191. data/app/views/agile/edit.html.erb +13 -0
  192. data/app/views/agile/error.html.erb +2 -0
  193. data/app/views/agile/index.html.erb +14 -0
  194. data/app/views/agile/login.html.erb +19 -0
  195. data/app/views/agile/new.html.erb +12 -0
  196. data/app/views/agile_common/_help.html.erb +18 -0
  197. data/app/views/agile_common/_iframe_edit.html.erb +2 -0
  198. data/app/views/agile_common/paste_clipboard.html.erb +17 -0
  199. data/app/views/layouts/agile.html.erb +17 -0
  200. data/app/views/layouts/content.html.erb +20 -0
  201. data/app/views/models/dump_models.html.erb +47 -0
  202. data/config/initializers/kaminari_patch.rb +56 -0
  203. data/config/locales/agile_de.yml +138 -0
  204. data/config/locales/agile_en.yml +162 -0
  205. data/config/locales/agile_sl.yml +163 -0
  206. data/config/locales/datetimepicker.yml +19 -0
  207. data/config/locales/de.yml +231 -0
  208. data/config/locales/en.yml +13 -0
  209. data/config/locales/kaminari.yml +26 -0
  210. data/config/locales/models_en.yml +1032 -0
  211. data/config/locales/models_sl.yml +1065 -0
  212. data/config/locales/sl.yml +211 -0
  213. data/db/migrate/20240120160001_add_sessions_table.rb +12 -0
  214. data/db/migrate/20240120160002_ar_big_table.rb +17 -0
  215. data/db/migrate/20240120160003_ar_big_table_value.rb +18 -0
  216. data/db/migrate/20240120160004_ar_category.rb +22 -0
  217. data/db/migrate/20240120160005_ar_design.rb +20 -0
  218. data/db/migrate/20240120160006_ar_filter.rb +17 -0
  219. data/db/migrate/20240120160007_ar_gallery.rb +21 -0
  220. data/db/migrate/20240120160008_ar_journal.rb +19 -0
  221. data/db/migrate/20240120160009_ar_key_value_store.rb +11 -0
  222. data/db/migrate/20240120160010_ar_link.rb +19 -0
  223. data/db/migrate/20240120160011_ar_memory.rb +8 -0
  224. data/db/migrate/20240120160012_ar_menu.rb +21 -0
  225. data/db/migrate/20240120160013_ar_menu_item.rb +28 -0
  226. data/db/migrate/20240120160014_ar_page.rb +50 -0
  227. data/db/migrate/20240120160015_ar_part.rb +33 -0
  228. data/db/migrate/20240120160016_ar_permission.rb +16 -0
  229. data/db/migrate/20240120160017_ar_permission_rule.rb +17 -0
  230. data/db/migrate/20240120160018_ar_piece.rb +28 -0
  231. data/db/migrate/20240120160019_ar_policy.rb +21 -0
  232. data/db/migrate/20240120160020_ar_policy_rule.rb +18 -0
  233. data/db/migrate/20240120160021_ar_poll.rb +27 -0
  234. data/db/migrate/20240120160022_ar_poll_item.rb +23 -0
  235. data/db/migrate/20240120160023_ar_poll_result.rb +14 -0
  236. data/db/migrate/20240120160024_ar_removed_url.rb +16 -0
  237. data/db/migrate/20240120160025_ar_role.rb +17 -0
  238. data/db/migrate/20240120160026_ar_site.rb +37 -0
  239. data/db/migrate/20240120160027_ar_temp.rb +11 -0
  240. data/db/migrate/20240120160028_ar_user.rb +42 -0
  241. data/db/migrate/20240120160029_ar_user_group.rb +12 -0
  242. data/db/migrate/20240120160030_ar_user_role.rb +18 -0
  243. data/db/migrate/20240120160031_ar_visit.rb +15 -0
  244. data/db/migrate/20240703016001_ar_setup.rb +16 -0
  245. data/db/migrate/20240703016002_ar_folder_permission.rb +15 -0
  246. data/db/migrate/20240703016003_ar_folder_rule.rb +14 -0
  247. data/db/migrate/20250115000001_ar_image.rb +25 -0
  248. data/lib/agile/configuration.rb +43 -0
  249. data/lib/agile/engine.rb +29 -0
  250. data/lib/agile/version.rb +27 -0
  251. data/lib/agile.rb +282 -0
  252. data/lib/agile_rails.rb +1 -0
  253. data/lib/generators/agile/USAGE +11 -0
  254. data/lib/generators/agile/new_form_generator.rb +369 -0
  255. data/lib/generators/convert_to_ar/convert_to_ar_generator.rb +158 -0
  256. data/lib/tasks/agile_db_clone.rake +132 -0
  257. data/lib/tasks/agile_db_export_to_yaml.rake +37 -0
  258. data/lib/tasks/agile_db_migrate.rake +35 -0
  259. metadata +414 -0
@@ -0,0 +1,180 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_permission : Table permissions
28
+ #
29
+ # id Integer id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # table_name String Permission is valid for table
33
+ # is_default Boolean This is default permission for all tables in database
34
+ # active Boolean Permission is active
35
+ # ar_policy_rules Embedded: ArPolicyRule Defined policy rules
36
+ #
37
+ # ar_permissions table define permissions for accessing single table when in edit mode.
38
+ # They define table and user role that can view, edit or delete documents in a table.
39
+ # Document marked as default is the top level document and defines general permissions valid for
40
+ # all tables. It usually states that admiin can delete all documents and guest has no access.
41
+ #
42
+ # Rules can also be namespaced. If you have an isolated application which is using its own set
43
+ # of tables, you can start table names with same (3 letter) prefix and add a permission rule like ar_*.
44
+ #########################################################################
45
+ class ArPermission < ApplicationRecord
46
+ #- Available permissions settings
47
+
48
+ # User has no access
49
+ NO_ACCESS = 0
50
+ # User can view documents
51
+ CAN_VIEW = 1
52
+ # User can create new documents
53
+ CAN_CREATE = 2
54
+ # User can edit his own documents
55
+ CAN_EDIT = 4
56
+ # User can edit all documents in table
57
+ CAN_EDIT_ALL = 8
58
+ # User can delete his own documents
59
+ CAN_DELETE = 16
60
+ # User can delete all documents in table
61
+ CAN_DELETE_ALL = 32
62
+ # User can admin table (same as can_delete_all, but can see documents which do not belong to current site)
63
+ CAN_ADMIN = 64
64
+ # User is superadmin. Basicly same as admin.
65
+ SUPERADMIN = 128
66
+
67
+ has_many :ar_permission_rules
68
+
69
+ validates :table_name, presence: true
70
+ validates :table_name, uniqueness: true
71
+
72
+ after_save :cache_clear
73
+ after_destroy :cache_clear
74
+
75
+ ####################################################################
76
+ # Clear cache if cache is configured
77
+ ####################################################################
78
+ def cache_clear
79
+ Agile.cache_clear(:ar_permission)
80
+ end
81
+
82
+ ########################################################################
83
+ # Will return choices for permissions prepared for usega in select input field.
84
+ # This will return english only comments so it is not used.
85
+ ########################################################################
86
+ def self.table_permissions #:nodoc:
87
+ [['NO_ACCESS', 0], ['CAN_VIEW', 1], ['CAN_CREATE', 2], ['CAN_EDIT', 4], ['CAN_EDIT_ALL', 8],
88
+ ['CAN_DELETE', 16], ['CAN_DELETE_ALL', 32], ['CAN_ADMIN', 64], ['SUPERADMIN', 128]]
89
+ end
90
+
91
+ ########################################################################
92
+ # Will return choices for permissions prepared for usega in select input field.
93
+ # This will return english only comments so it is not used.
94
+ ########################################################################
95
+ def self.site_permissions #:nodoc:
96
+ [['NO_ACCESS', 0], ['CAN_VIEW', 1], ['CAN_EDIT', 2]]
97
+ end
98
+
99
+ #############################################################################
100
+ # Will return permissions for table
101
+ ############################################################################
102
+ def self.permissions_for_table(table_name)
103
+ result = permissions_for('*')
104
+ result = permissions_for("#{table_name[0,3]}*", result)
105
+ permissions_for(table_name, result)
106
+ end
107
+
108
+ #############################################################################
109
+ #
110
+ ############################################################################
111
+ def self.permissions_for(table_name, result = {}) #:nodoc:
112
+ permissions = if table_name == '*'
113
+ find_by(is_default: true)
114
+ else
115
+ find_by(table_name: table_name, active: true)
116
+ end
117
+ if permissions
118
+ permissions.ar_permission_rules.each { |rule| result[rule.ar_role_id] = rule.permission }
119
+ end
120
+ result
121
+ end
122
+
123
+ #########################################################################
124
+ # Returns values for permissions ready to be used in select field.
125
+ #
126
+ # Example (as used in AgileRails form):
127
+ # 20:
128
+ # name: permission
129
+ # type: select
130
+ # eval: ArPermission.values_for_permissions
131
+ #########################################################################
132
+ def self.choices_for_permissions
133
+ values_for_permissions_for_key 'helpers.label.ar_policy_rule.choices_for_permission'
134
+ end
135
+
136
+ #########################################################################
137
+ # Returns values for site_permissions ready to be used in select field.
138
+ #
139
+ # Example (as used in AgileRails form):
140
+ # 20:
141
+ # name: permission
142
+ # type: select
143
+ # eval: ArPermission.values_for_site_permissions
144
+ #########################################################################
145
+ def self.choices_for_site_permissions
146
+ values_for_permissions_for_key 'helpers.label.ar_policy_rule.choices_for_sites_permission'
147
+ end
148
+
149
+ #########################################################################
150
+ def self.values_for_permissions_for_key(key)
151
+ c = I18n.t(key)
152
+ c = I18n.t(key, locale: 'en') if c.class == Hash || c.match(/translation missing/i)
153
+ c.split(',').map { |e| (ar = e.split(':'); [ar.first, ar.last.to_i]) }
154
+ end
155
+
156
+ #########################################################################
157
+ # Will return translated permission name for value.
158
+ #
159
+ # Parameters:
160
+ # [value] Integer. Permission value
161
+ #
162
+ # Example (as used in AgileRails form):
163
+ # data_set:
164
+ # columns:
165
+ # 2:
166
+ # name: permission
167
+ # eval: ArPermission.permission_name_for_value
168
+ #
169
+ # Returns:
170
+ # String. Name (description) for value
171
+ #########################################################################
172
+ def self.permission_name_for_value(value)
173
+ choices_for_permissions.reduce('error') { |r, v| break v.first if v.last.to_i == value.to_i }
174
+ end
175
+
176
+ def self.site_permission_name_for_value(value)
177
+ choices_for_site_permissions.reduce('error') { |r, v| break v.first if v.last.to_i == value.to_i }
178
+ end
179
+
180
+ end
@@ -0,0 +1,65 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ #########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_permission_rule : Table access permisssion rules
28
+ #
29
+ # id Integer id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # ar_role_id Object User role access defined by this rule
33
+ # permission Integer Access permission
34
+ #
35
+ # ar_permission_rules records define rules for accessing single database table.
36
+ # They define user roles and their permissions to view, create, edit or delete data.
37
+ #
38
+ #########################################################################
39
+ class ArPermissionRule < ApplicationRecord
40
+
41
+ belongs_to :ar_permission
42
+ has_many :ar_roles
43
+
44
+ after_save :cache_clear
45
+ after_destroy :cache_clear
46
+
47
+ validate :validations
48
+
49
+ ####################################################################
50
+ # Clear cache if cache is configured
51
+ ####################################################################
52
+ def cache_clear
53
+ Agile.cache_clear(:ar_permission)
54
+ end
55
+
56
+ ####################################################################
57
+ # Additional validations.
58
+ ####################################################################
59
+ def validations
60
+ if new_record? && ArPermissionRule.find_by(ar_permission_id: ar_permission_id, ar_role_id: ar_role_id).present?
61
+ errors.add('ar_role_id', I18n.t('agile.already_defined'))
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,78 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_policy : Access policy declarations
28
+ #
29
+ # id Integer id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # name String Unique policy name
33
+ # description String Description for this policy
34
+ # is_default Boolean This is default policy for the site
35
+ # active Boolean Policy is active
36
+ # updated_by Integer updated_by
37
+ # message String Error message when blocked by this policy
38
+ # rules String Policy rules
39
+ #
40
+ # ArPolicy documents define policies for accessing data on web site. Policies define which
41
+ # user roles (defined in ar_policy_roles table) has no access, can view or edit data (sees CMS menu) on
42
+ # current active web page. Policies can then be applied to individual documents or parts of the site.
43
+ #
44
+ # Document defined as default, holds top level policy which is inherited by all
45
+ # other policies. Default policy is also used when document has no access policy assigned.
46
+ #########################################################################
47
+ class ArPolicy < ApplicationRecord
48
+ belongs_to :ar_site
49
+ has_many :ar_policy_rules
50
+
51
+ validates :name, length: { minimum: 4 }
52
+ validates :message, length: { minimum: 5 }
53
+
54
+ after_save :cache_clear
55
+ after_destroy :cache_clear
56
+
57
+ validate :is_the_only_default_policy
58
+
59
+ ####################################################################
60
+ # Clear cache if cache is configured
61
+ ####################################################################
62
+ def cache_clear
63
+ Agile.cache_clear(:ar_permission)
64
+ Agile.cache_clear(:ar_site)
65
+ end
66
+
67
+ ####################################################################
68
+ # There should be only one default policy.
69
+ ####################################################################
70
+ def is_the_only_default_policy
71
+ existing_policy_id = ArPolicy.find_by(ar_site_id: ar_site_id, is_default: true)&.id
72
+
73
+ if is_default && existing_policy_id && existing_policy_id != id
74
+ errors.add('is_default', I18n.t('agile.already_defined'))
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,65 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ #########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_policy_rule : Access policy rules
28
+ #
29
+ # id Integer id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # ar_role_id Object User role access defined by this rule
33
+ # permission Integer Access permission
34
+ #
35
+ # ArPolicyRule records define rules for the policy. They define user roles and their
36
+ # permission to view or edit data on site.
37
+ #
38
+ #########################################################################
39
+ class ArPolicyRule < ApplicationRecord
40
+
41
+ belongs_to :ar_policy
42
+ has_many :ar_roles
43
+
44
+ after_save :cache_clear
45
+ after_destroy :cache_clear
46
+
47
+ validate :validations
48
+
49
+ ####################################################################
50
+ # Clear cache if cache is configured
51
+ ####################################################################
52
+ def cache_clear
53
+ Agile.cache_clear(:ar_site)
54
+ end
55
+
56
+ ####################################################################
57
+ # Additional validations.
58
+ ####################################################################
59
+ def validations
60
+ if new_record? && ArPolicyRule.find_by(ar_policy_id: ar_policy_id, ar_role_id: ar_role_id).present?
61
+ errors.add('ar_role_id', I18n.t('agile.already_defined'))
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,74 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_poll : Polls
28
+ #
29
+ # id Integer id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # name String Unique poll name
33
+ # title String Title for the poll
34
+ # sub_text String Short description of the poll
35
+ # pre_display String pre_display
36
+ # operation String Operation performed on submit
37
+ # parameters String Aditional parameters for operation
38
+ # display String Select how fields are positioned on form
39
+ # css String CSS specific to this poll
40
+ # form String You can specified input items by providing form acording to rules of AgileRails form.
41
+ # valid_from DateTime Pole is valid from
42
+ # valid_to DateTime Pole is valid to
43
+ # captcha_type String Catpcha type name if captcha is used
44
+ # active Boolean active
45
+ # created_by Integer created_by
46
+ # updated_by Integer updated_by
47
+ #
48
+ # ArPoll documents are used for different questionaries and formulars which can
49
+ # be accessed independent or connected with ArPage documents. Entry fields can be defined
50
+ # in related ar_poll_items table or as AgileRails form YAML style entered into form field.
51
+ ########################################################################
52
+ class ArPoll < ApplicationRecord
53
+
54
+ has_many :ar_poll_items
55
+
56
+ ########################################################################
57
+ # Save poll results to ArPollResults table
58
+ #
59
+ # Params:
60
+ # data : Hash : Records hash (params[:record])
61
+ ########################################################################
62
+ def save_results(data)
63
+ h = {}
64
+ items = form.blank? ? ArPollItem.where(ar_poll_id: id) : YAML.load(self.form.gsub('&nbsp;', ' '))
65
+ items.each do |item|
66
+ next if %w(hidden_field submit_tag link_to comment).include?(item.field_type) # ignore
67
+ next if item.try(:options).match('hidden') # also ignore
68
+
69
+ h[ item['name'] ] = data[ item['name'] ]
70
+ end
71
+ ArPollResult.create(ar_poll_id: id, data: h.to_yaml)
72
+ end
73
+
74
+ end
@@ -0,0 +1,47 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_poll_item : Poll items define entry fields on poll questionary and formulars.
28
+ #
29
+ # id Integer id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # name String Name (alias) of returned field name
33
+ # text String Caption of item
34
+ # field_type String Input field type
35
+ # size String size
36
+ # mandatory Boolean Item entry is mandatory
37
+ # separator String Separator between items
38
+ # options String Options for the item. Depends on item type.
39
+ # order Integer Order of item on poll
40
+ # active Boolean Item is active
41
+ #
42
+ ########################################################################
43
+ class ArPollItem < ApplicationRecord
44
+ validates_length_of :name, minimum: 3
45
+
46
+ belongs_to :ar_poll
47
+ end
@@ -0,0 +1,38 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_poll_results : Pools results saved
28
+ #
29
+ # id Integer id
30
+ # ar_poll_id Integer poll id
31
+ # data String Data saved as YAML
32
+ # confirmed Boolean Poll entry was confirmed
33
+ #
34
+ # Results of polls saved as YAML structure.
35
+ ########################################################################
36
+ class ArPollResult < ApplicationRecord
37
+ belongs_to :ar_poll
38
+ end
@@ -0,0 +1,42 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ##########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_removed_url : List of URL-s removed from site
28
+ #
29
+ # id Integer id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # url String URL that is no longer active
33
+ # ar_site_id Integer URL is valid only for the site
34
+ #
35
+ # List of URLs removed from site so web crawlers will also remove them from their
36
+ # indexes. Use when creating sitemaps.
37
+ ##########################################################################
38
+ class ArRemovedUrl < ApplicationRecord
39
+ belongs_to :ar_site, optional: true
40
+
41
+ validates :url, presence: true
42
+ end
@@ -0,0 +1,84 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ########################################################################
25
+ # == Schema information
26
+ #
27
+ # Table name: ar_role : User roles
28
+ #
29
+ # id Integer id
30
+ # created_at Time created_at
31
+ # updated_at Time updated_at
32
+ # name String Role name
33
+ # system_name String System role name if required by application
34
+ # active Boolean Role is active
35
+ #
36
+ # Documents in this model define all available user roles in the application. Roles
37
+ # are defined by unique name which is valid for current application or as alternative name (system_name)
38
+ # which can be persistent, when application is used as Rails plugin.
39
+ #########################################################################
40
+ class ArRole < ApplicationRecord
41
+
42
+ validates :name, :length => { :minimum => 4 }
43
+ validates :name, uniqueness: true
44
+
45
+ after_save :cache_clear
46
+ after_destroy :cache_clear
47
+
48
+ ####################################################################
49
+ # Clear cache if cache is configured
50
+ ####################################################################
51
+ def cache_clear
52
+ Agile.cache_clear(:ar_permission)
53
+ Agile.cache_clear(:ar_site)
54
+ Agile.cache_clear(:ar_role)
55
+ end
56
+
57
+ ########################################################################
58
+ # Return all defined roles as choices for use in select field.
59
+ ########################################################################
60
+ def self.choices_for_roles
61
+ where(active: true).order(name: :asc).map { |role| [ role.name, role.id] }
62
+ end
63
+
64
+ ########################################################################
65
+ # Search for role when role parameter is String.
66
+ ########################################################################
67
+ def self.get_role(name)
68
+ record = Agile.cache_read(['ar_role', name])
69
+ return record if record
70
+
71
+ record = find_by(name: name) || find_by(system_name: name)
72
+ Agile.cache_write(['ar_policy_role', name], record)
73
+ end
74
+
75
+ ########################################################################
76
+ # Search for role when role parameter is String.
77
+ ########################################################################
78
+ def self.get_role(name)
79
+ Agile.cache_read(['ar_role', name]) do
80
+ record = find_by(name: name) || find_by(system_name: name)
81
+ end
82
+ end
83
+
84
+ end