zen 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/.gems +34 -0
  2. data/.travis.yml +7 -0
  3. data/AUTHORS +5 -0
  4. data/CHANGELOG +14 -0
  5. data/{license.txt → LICENSE} +0 -0
  6. data/MANIFEST +67 -51
  7. data/README.md +18 -25
  8. data/Rakefile +2 -3
  9. data/bin/zen +2 -2
  10. data/lib/zen.rb +93 -57
  11. data/lib/zen/asset.rb +7 -8
  12. data/lib/zen/bin/app.rb +0 -2
  13. data/lib/zen/controller/admin_controller.rb +4 -9
  14. data/lib/zen/controller/base_controller.rb +0 -25
  15. data/lib/zen/controller/main_controller.rb +5 -5
  16. data/lib/zen/controller/preview.rb +50 -0
  17. data/lib/zen/helper/common.rb +4 -68
  18. data/lib/zen/helper/message.rb +82 -0
  19. data/lib/zen/helper/theme.rb +2 -2
  20. data/lib/zen/language.rb +68 -38
  21. data/lib/zen/language/en/zen_general.yml +1 -4
  22. data/lib/zen/language/nl/zen_general.yml +28 -0
  23. data/lib/zen/language/nl/zen_models.yml +13 -0
  24. data/lib/zen/layout/admin.xhtml +1 -1
  25. data/lib/zen/layout/login.xhtml +1 -1
  26. data/lib/zen/model/settings.rb +2 -0
  27. data/lib/zen/package.rb +29 -25
  28. data/lib/zen/package/all.rb +1 -1
  29. data/lib/zen/package/categories/lib/categories/controller/categories.rb +51 -63
  30. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +45 -52
  31. data/lib/zen/package/categories/lib/categories/language/en/categories.yml +2 -2
  32. data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +39 -0
  33. data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +33 -0
  34. data/lib/zen/package/categories/lib/categories/plugin/categories.rb +2 -2
  35. data/lib/zen/package/comments/lib/comments.rb +31 -2
  36. data/lib/zen/package/comments/lib/comments/controller/comments.rb +42 -57
  37. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +36 -51
  38. data/lib/zen/package/comments/lib/comments/language/en/comments.yml +7 -3
  39. data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +48 -0
  40. data/lib/zen/package/comments/lib/comments/model/comment.rb +45 -4
  41. data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +152 -0
  42. data/lib/zen/package/comments/lib/comments/plugin/comments.rb +5 -6
  43. data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +2 -2
  44. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +43 -52
  45. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +68 -67
  46. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +1 -1
  47. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +32 -0
  48. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +52 -0
  49. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +3 -3
  50. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +4 -7
  51. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
  52. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +37 -44
  53. data/lib/zen/package/menus/lib/menus/controller/menus.rb +33 -43
  54. data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +5 -10
  55. data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +41 -0
  56. data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +39 -0
  57. data/lib/zen/package/menus/lib/menus/model/menu.rb +3 -3
  58. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +3 -3
  59. data/lib/zen/package/menus/lib/menus/plugin/menus.rb +5 -6
  60. data/lib/zen/package/menus/migrations/1297184342_create_schema.rb +1 -1
  61. data/lib/zen/package/sections/lib/sections.rb +20 -0
  62. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +85 -79
  63. data/lib/zen/package/sections/lib/sections/controller/sections.rb +58 -66
  64. data/lib/zen/package/sections/lib/sections/language/en/sections.yml +0 -1
  65. data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +43 -0
  66. data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +47 -0
  67. data/lib/zen/package/sections/lib/sections/model/section.rb +11 -15
  68. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -5
  69. data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +7 -8
  70. data/lib/zen/package/sections/lib/sections/plugin/sections.rb +3 -4
  71. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +0 -4
  72. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +8 -2
  73. data/lib/zen/package/sections/migrations/1306772479_remove_unique_slug.rb +28 -0
  74. data/lib/zen/package/settings/lib/settings.rb +21 -34
  75. data/lib/zen/package/settings/lib/settings/controller/settings.rb +29 -22
  76. data/lib/zen/package/settings/lib/settings/language/en/settings.yml +7 -5
  77. data/lib/zen/package/settings/lib/settings/language/nl/settings.yml +39 -0
  78. data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -5
  79. data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +3 -4
  80. data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +3 -5
  81. data/lib/zen/package/settings/lib/settings/plugin/settings.rb +11 -4
  82. data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +5 -5
  83. data/lib/zen/package/settings/migrations/1299538742_add_language_key.rb +8 -8
  84. data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +2 -5
  85. data/lib/zen/package/users/lib/users/controller/access_rules.rb +54 -61
  86. data/lib/zen/package/users/lib/users/controller/user_groups.rb +49 -57
  87. data/lib/zen/package/users/lib/users/controller/users.rb +58 -73
  88. data/lib/zen/package/users/lib/users/language/en/users.yml +6 -0
  89. data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +37 -0
  90. data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +31 -0
  91. data/lib/zen/package/users/lib/users/language/nl/users.yml +56 -0
  92. data/lib/zen/package/users/lib/users/model/user.rb +16 -1
  93. data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +27 -2
  94. data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +15 -3
  95. data/lib/zen/package/users/migrations/1304939855_user_settings.rb +15 -0
  96. data/lib/zen/plugin.rb +7 -9
  97. data/lib/zen/public/admin/css/{buttons.css → zen/buttons.css} +11 -7
  98. data/lib/zen/public/admin/css/{datepicker.css → zen/datepicker.css} +0 -0
  99. data/lib/zen/public/admin/css/{editor.css → zen/editor.css} +10 -5
  100. data/lib/zen/public/admin/css/{forms.css → zen/forms.css} +1 -1
  101. data/lib/zen/public/admin/css/{general.css → zen/general.css} +7 -7
  102. data/lib/zen/public/admin/css/{grid.css → zen/grid.css} +0 -0
  103. data/lib/zen/public/admin/css/{layout.css → zen/layout.css} +4 -5
  104. data/lib/zen/public/admin/css/zen/messages.css +61 -0
  105. data/lib/zen/public/admin/css/{notifications.css → zen/notifications.css} +4 -4
  106. data/lib/zen/public/admin/css/{reset.css → zen/reset.css} +0 -0
  107. data/lib/zen/public/admin/css/{tables.css → zen/tables.css} +3 -3
  108. data/lib/zen/public/admin/css/{tabs.css → zen/tabs.css} +5 -5
  109. data/lib/zen/public/admin/css/zen/window.css +79 -0
  110. data/lib/zen/public/admin/images/{icons → zen/icons}/accept.png +0 -0
  111. data/lib/zen/public/admin/images/{icons → zen/icons}/add.png +0 -0
  112. data/lib/zen/public/admin/images/{icons → zen/icons}/back.png +0 -0
  113. data/lib/zen/public/admin/images/{icons → zen/icons}/bold.png +0 -0
  114. data/lib/zen/public/admin/images/zen/icons/close.png +0 -0
  115. data/lib/zen/public/admin/images/{icons → zen/icons}/delete.png +0 -0
  116. data/lib/zen/public/admin/images/{icons → zen/icons}/edit.png +0 -0
  117. data/lib/zen/public/admin/images/{icons → zen/icons}/error.png +0 -0
  118. data/lib/zen/public/admin/images/{icons → zen/icons}/help.png +0 -0
  119. data/lib/zen/public/admin/images/{icons → zen/icons}/info.png +0 -0
  120. data/lib/zen/public/admin/images/{icons → zen/icons}/italic.png +0 -0
  121. data/lib/zen/public/admin/images/{icons → zen/icons}/large/error.png +0 -0
  122. data/lib/zen/public/admin/images/{icons → zen/icons}/large/notice.png +0 -0
  123. data/lib/zen/public/admin/images/{icons → zen/icons}/large/success.png +0 -0
  124. data/lib/zen/public/admin/images/{icons → zen/icons}/link.png +0 -0
  125. data/lib/zen/public/admin/images/{icons → zen/icons}/logout.png +0 -0
  126. data/lib/zen/public/admin/images/{icons → zen/icons}/ol.png +0 -0
  127. data/lib/zen/public/admin/images/{icons → zen/icons}/pdf.png +0 -0
  128. data/lib/zen/public/admin/images/zen/icons/preview.png +0 -0
  129. data/lib/zen/public/admin/images/{icons → zen/icons}/ul.png +0 -0
  130. data/lib/zen/public/admin/images/{icons → zen/icons}/user.png +0 -0
  131. data/lib/zen/public/admin/images/{icons → zen/icons}/view.png +0 -0
  132. data/lib/zen/public/admin/js/zen/core.js +73 -0
  133. data/lib/zen/public/admin/js/zen/editor.js +527 -0
  134. data/lib/zen/public/admin/js/zen/editor/markdown.js +84 -0
  135. data/lib/zen/public/admin/js/zen/editor/textile.js +84 -0
  136. data/lib/zen/public/admin/js/zen/init.js +12 -66
  137. data/lib/zen/public/admin/js/zen/tabs.js +5 -0
  138. data/lib/zen/public/admin/js/zen/window.js +206 -0
  139. data/lib/zen/task/build.rake +23 -6
  140. data/lib/zen/task/clean.rake +6 -7
  141. data/lib/zen/task/db.rake +7 -9
  142. data/lib/zen/task/package.rake +6 -6
  143. data/lib/zen/task/test.rake +6 -0
  144. data/lib/zen/task/theme.rake +3 -3
  145. data/lib/zen/theme.rb +3 -4
  146. data/lib/zen/validation.rb +7 -9
  147. data/lib/zen/version.rb +3 -4
  148. data/lib/zen/view/bottom.xhtml +0 -5
  149. data/lib/zen/view/main.xhtml +2 -0
  150. data/proto/app/app.rb +6 -4
  151. data/proto/app/config/config.rb +1 -7
  152. data/proto/app/config/database.rb +47 -43
  153. data/proto/app/config/middlewares.rb +0 -40
  154. data/proto/app/start.rb +1 -6
  155. data/proto/app/{vendor → theme}/.gitkeep +0 -0
  156. data/proto/migration.rb +3 -3
  157. data/proto/package/lib/package.rb +0 -1
  158. data/proto/package/lib/package/controller/controllers.rb +7 -40
  159. data/proto/package/lib/package/model/model.rb +3 -3
  160. metadata +106 -79
  161. data/CHANGELOG.md +0 -27
  162. data/ROADMAP.md +0 -53
  163. data/lib/zen/database.rb +0 -112
  164. data/lib/zen/logger.rb +0 -56
  165. data/lib/zen/public/admin/css/modals.css +0 -63
  166. data/lib/zen/public/admin/images/icons/close.png +0 -0
  167. data/lib/zen/public/admin/js/vendor/yepnope.js +0 -1
  168. data/lib/zen/public/admin/js/zen/editor/base.js +0 -262
  169. data/lib/zen/public/admin/js/zen/editor/drivers/html.js +0 -89
  170. data/lib/zen/public/admin/js/zen/editor/drivers/markdown.js +0 -87
  171. data/lib/zen/public/admin/js/zen/editor/drivers/textile.js +0 -87
  172. data/lib/zen/public/admin/js/zen/modal.js +0 -146
  173. data/lib/zen/public/admin/js/zen/notification.js +0 -211
  174. data/proto/app/config/requires.rb +0 -10
  175. data/proto/app/vendor/theme/.gitkeep +0 -0
  176. data/proto/package/lib/package/view/admin/package/edit.xhtml +0 -0
  177. data/proto/package/lib/package/view/admin/package/form.xhtml +0 -0
  178. data/proto/package/lib/package/view/admin/package/new.xhtml +0 -0
@@ -5,49 +5,49 @@ Sequel.migration do
5
5
  add_column(:settings, :language_group_key, String)
6
6
 
7
7
  # Set the correct values for all rows
8
- Zen::Database.handle[:settings].filter(:key => 'website_name')
8
+ Zen.database[:settings].filter(:key => 'website_name') \
9
9
  .update(
10
10
  :language_key => 'settings.labels.website_name',
11
11
  :language_group_key => 'settings.tabs.general'
12
12
  )
13
13
 
14
- Zen::Database.handle[:settings].filter(:key => 'website_description')
14
+ Zen.database[:settings].filter(:key => 'website_description') \
15
15
  .update(
16
16
  :language_key => 'settings.labels.website_description',
17
17
  :language_group_key => 'settings.tabs.general'
18
18
  )
19
19
 
20
- Zen::Database.handle[:settings].filter(:key => 'website_enabled')
20
+ Zen.database[:settings].filter(:key => 'website_enabled') \
21
21
  .update(
22
22
  :language_key => 'settings.labels.website_enabled',
23
23
  :language_group_key => 'settings.tabs.general'
24
24
  )
25
25
 
26
- Zen::Database.handle[:settings].filter(:key => 'language')
26
+ Zen.database[:settings].filter(:key => 'language') \
27
27
  .update(
28
28
  :language_key => 'settings.labels.language',
29
29
  :language_group_key => 'settings.tabs.general'
30
30
  )
31
31
 
32
- Zen::Database.handle[:settings].filter(:key => 'default_section')
32
+ Zen.database[:settings].filter(:key => 'default_section') \
33
33
  .update(
34
34
  :language_key => 'settings.labels.default_section',
35
35
  :language_group_key => 'settings.tabs.general'
36
36
  )
37
37
 
38
- Zen::Database.handle[:settings].filter(:key => 'theme')
38
+ Zen.database[:settings].filter(:key => 'theme') \
39
39
  .update(
40
40
  :language_key => 'settings.labels.theme',
41
41
  :language_group_key => 'settings.tabs.general'
42
42
  )
43
43
 
44
- Zen::Database.handle[:settings].filter(:key => 'enable_antispam')
44
+ Zen.database[:settings].filter(:key => 'enable_antispam') \
45
45
  .update(
46
46
  :language_key => 'settings.labels.enable_antispam',
47
47
  :language_group_key => 'settings.tabs.security'
48
48
  )
49
49
 
50
- Zen::Database.handle[:settings].filter(:key => 'defensio_key')
50
+ Zen.database[:settings].filter(:key => 'defensio_key') \
51
51
  .update(
52
52
  :language_key => 'settings.labels.defensio_key',
53
53
  :language_group_key => 'settings.tabs.security'
@@ -7,15 +7,12 @@ Sequel.migration do
7
7
  drop_column(:settings, :language_key)
8
8
  drop_column(:settings, :language_group_key)
9
9
 
10
- # Ensure the identifiers are unique
11
- #add_index(:settings, :key, :unique => true)
12
-
13
10
  # Update the settings
14
- Zen::Database.handle[:settings].all.each do |row|
11
+ Zen.database[:settings].all.each do |row|
15
12
  name = row[:name].split('.').last
16
13
  group = row[:group].split('.').last
17
14
 
18
- Zen::Database.handle[:settings].filter(:id => row[:id])
15
+ Zen.database[:settings].filter(:id => row[:id]) \
19
16
  .update(:name => name, :group => group)
20
17
  end
21
18
  end
@@ -3,9 +3,9 @@ module Users
3
3
  #:nodoc:
4
4
  module Controller
5
5
  ##
6
- # Controller for managing access rules. Each access rule can be used
7
- # to specify whether or not a user can edit or create something.
8
- #
6
+ # Controller for managing access rules. Each access rule can be used to specify
7
+ # whether or not a user can edit or create something.
8
+ #
9
9
  # The following permissions are available:
10
10
  #
11
11
  # * create
@@ -21,14 +21,14 @@ module Users
21
21
 
22
22
  map('/admin/access-rules')
23
23
 
24
- javascript(['users/access_rules'])
25
-
24
+ javascript ['users/access_rules']
25
+
26
26
  before_all do
27
27
  csrf_protection(:save, :delete) do
28
28
  respond(lang('zen_general.errors.csrf'), 403)
29
29
  end
30
30
  end
31
-
31
+
32
32
  ##
33
33
  # Load our language packs, set the form URLs and define our page title.
34
34
  #
@@ -41,23 +41,23 @@ module Users
41
41
  #
42
42
  def initialize
43
43
  super
44
-
44
+
45
45
  @form_save_url = AccessRules.r(:save)
46
46
  @form_delete_url = AccessRules.r(:delete)
47
47
  @rules_lang = Zen::Language.load('access_rules')
48
-
48
+
49
49
  # Set the page title
50
50
  if !action.method.nil?
51
51
  method = action.method.to_sym
52
52
  @page_title = lang("access_rules.titles.#{method}") rescue nil
53
53
  end
54
-
54
+
55
55
  @rule_applies_hash = {
56
- lang('access_rules.labels.user') => 'div_user_id',
56
+ lang('access_rules.labels.user') => 'div_user_id',
57
57
  lang('access_rules.labels.user_group') => 'div_user_group_id'
58
58
  }
59
59
  end
60
-
60
+
61
61
  ##
62
62
  # Show an overview of all access rules and allow the current user
63
63
  # to manage these groups.
@@ -73,14 +73,14 @@ module Users
73
73
  if !user_authorized?([:read])
74
74
  respond(lang('zen_general.errors.not_authorized'), 403)
75
75
  end
76
-
76
+
77
77
  set_breadcrumbs(lang('access_rules.titles.index'))
78
-
78
+
79
79
  @access_rules = AccessRule.all
80
80
  end
81
-
81
+
82
82
  ##
83
- # Hook that's executed before the edit and new method. This hook is used to
83
+ # Hook that's executed before the edit and new method. This hook is used to
84
84
  # pre-process some data used in the form.
85
85
  #
86
86
  # @author Yorick Peterse
@@ -95,7 +95,7 @@ module Users
95
95
  ::Users::Model::User.select(:id, :name).each do |user|
96
96
  @form_users[user.id.to_s] = user.name
97
97
  end
98
-
98
+
99
99
  # Build the list of available packages and controllers
100
100
  ::Zen::Package::Registered.each do |name, pkg|
101
101
  name = name.to_s
@@ -109,7 +109,7 @@ module Users
109
109
 
110
110
  ::Users::Model::UserGroup.select(:id, :name).each do |group|
111
111
  @form_groups[group.id.to_s] = group.name
112
- end
112
+ end
113
113
  end
114
114
 
115
115
  ##
@@ -128,19 +128,19 @@ module Users
128
128
  if !user_authorized?([:read, :update])
129
129
  respond(lang('zen_general.errors.not_authorized'), 403)
130
130
  end
131
-
131
+
132
132
  set_breadcrumbs(
133
- anchor_to(lang('access_rules.titles.index'), AccessRules.r(:index)),
133
+ anchor_to(lang('access_rules.titles.index'), AccessRules.r(:index)),
134
134
  lang('access_rules.titles.edit')
135
135
  )
136
-
136
+
137
137
  if flash[:form_data]
138
138
  @access_rule = flash[:form_data]
139
139
  else
140
140
  @access_rule = AccessRule[id]
141
141
  end
142
142
  end
143
-
143
+
144
144
  ##
145
145
  # Create a new access rule.
146
146
  #
@@ -156,15 +156,15 @@ module Users
156
156
  if !user_authorized?([:read, :create])
157
157
  respond(lang('zen_general.errors.not_authorized'), 403)
158
158
  end
159
-
159
+
160
160
  set_breadcrumbs(
161
- anchor_to(lang('access_rules.titles.index'), AccessRules.r(:index)),
161
+ anchor_to(lang('access_rules.titles.index'), AccessRules.r(:index)),
162
162
  lang('access_rules.titles.new')
163
163
  )
164
-
164
+
165
165
  @access_rule = AccessRule.new
166
166
  end
167
-
167
+
168
168
  ##
169
169
  # Saves or creates a new access rule based on the POST data and a field named 'id'.
170
170
  #
@@ -180,16 +180,17 @@ module Users
180
180
  if !user_authorized?([:create, :update])
181
181
  respond(lang('zen_general.errors.not_authorized'), 403)
182
182
  end
183
-
184
- post = request.params.dup
183
+
184
+ post = request.subset(
185
+ :id, :package, :read_access, :create_access, :update_access, :delete_access,
186
+ :user_id, :user_group_id, :controller, :rule_applies
187
+ )
185
188
 
186
189
  if post['rule_applies'] === 'div_user_id'
187
190
  post['user_group_id'] = nil
188
191
  else
189
192
  post['user_id'] = nil
190
193
  end
191
-
192
- post.delete('rule_applies')
193
194
 
194
195
  if post['id'] and !post['id'].empty?
195
196
  @access_rule = AccessRule[post['id']]
@@ -198,30 +199,34 @@ module Users
198
199
  @access_rule = AccessRule.new
199
200
  save_action = :new
200
201
  end
201
-
202
+
203
+ post.delete('rule_applies')
204
+ post.delete('id')
205
+
202
206
  flash_success = lang("access_rules.success.#{save_action}")
203
207
  flash_error = lang("access_rules.errors.#{save_action}")
204
-
208
+
205
209
  begin
206
210
  @access_rule.update(post)
207
211
 
208
212
  # Flush the existing rules from the session
209
213
  session.delete(:access_rules)
210
- notification(:success, lang('access_rules.titles.index'), flash_success)
211
- rescue
212
- notification(:error, lang('access_rules.titles.index'), flash_error)
213
-
214
+ message(:success, flash_success)
215
+ rescue => e
216
+ Ramaze::Log.error(e.inspect)
217
+ message(:error, flash_error)
218
+
214
219
  flash[:form_data] = @access_rule
215
220
  flash[:form_errors] = @access_rule.errors
216
221
  end
217
-
222
+
218
223
  if @access_rule.id
219
224
  redirect(AccessRules.r(:edit, @access_rule.id))
220
225
  else
221
226
  redirect_referrer
222
227
  end
223
228
  end
224
-
229
+
225
230
  ##
226
231
  # Delete all specified access rules.
227
232
  #
@@ -236,39 +241,27 @@ module Users
236
241
  if !user_authorized?([:delete])
237
242
  respond(lang('zen_general.errors.not_authorized'), 403)
238
243
  end
239
-
240
- if !request.params['access_rule_ids'] or request.params['access_rule_ids'].empty?
241
- notification(
242
- :error,
243
- lang('access_rules.titles.index'),
244
- lang('access_rules.errors.no_delete')
245
- )
246
244
 
245
+ if !request.params['access_rule_ids'] or request.params['access_rule_ids'].empty?
246
+ message(:error, lang('access_rules.errors.no_delete'))
247
247
  redirect_referrer
248
248
  end
249
-
249
+
250
250
  request.params['access_rule_ids'].each do |id|
251
251
  @access_rule = AccessRule[id]
252
-
252
+
253
253
  begin
254
254
  @access_rule.delete
255
255
  session.delete(:access_rules)
256
- notification(
257
- :success,
258
- lang('access_rules.titles.index'),
259
- lang('access_rules.success.delete')
260
- )
261
- rescue
262
- notification(
263
- :error,
264
- lang('access_rules.titles.index'),
265
- lang('access_rules.errors.delete') % id
266
- )
256
+ message(:success, lang('access_rules.success.delete'))
257
+ rescue => e
258
+ Ramaze::Log.error(e.inspect)
259
+ message(:error, lang('access_rules.errors.delete') % id)
267
260
  end
268
261
  end
269
-
262
+
270
263
  redirect_referrer
271
264
  end
272
- end
273
- end
274
- end
265
+ end # AccessRules
266
+ end # Controller
267
+ end # Users
@@ -3,11 +3,10 @@ module Users
3
3
  #:nodoc:
4
4
  module Controller
5
5
  ##
6
- # Controller for managing all user groups. It's not
7
- # required to add a user to a group but it can certainly
8
- # make it easier when adding custom permissions or
9
- # granting a user full access to the backend.
10
- #
6
+ # Controller for managing all user groups. It's not required to add a user to a group
7
+ # but it can certainly make it easier when adding custom permissions or granting a
8
+ # user full access to the backend.
9
+ #
11
10
  # @author Yorick Peterse
12
11
  # @since 0.1
13
12
  #
@@ -15,13 +14,13 @@ module Users
15
14
  include ::Users::Model
16
15
 
17
16
  map('/admin/user-groups')
18
-
17
+
19
18
  before_all do
20
19
  csrf_protection(:save, :delete) do
21
20
  respond(lang('zen_general.errors.csrf'), 403)
22
21
  end
23
22
  end
24
-
23
+
25
24
  ##
26
25
  # Load our language packs, set the form URLs and define our page title.
27
26
  #
@@ -34,19 +33,19 @@ module Users
34
33
  #
35
34
  def initialize
36
35
  super
37
-
36
+
38
37
  @form_save_url = UserGroups.r(:save)
39
38
  @form_delete_url = UserGroups.r(:delete)
40
39
 
41
40
  Zen::Language.load('user_groups')
42
-
41
+
43
42
  # Set the page title
44
43
  if !action.method.nil?
45
44
  method = action.method.to_sym
46
45
  @page_title = lang("user_groups.titles.#{method}") rescue nil
47
46
  end
48
47
  end
49
-
48
+
50
49
  ##
51
50
  # Show an overview of all user groups and allow the current user
52
51
  # to manage these groups
@@ -62,12 +61,12 @@ module Users
62
61
  if !user_authorized?([:read])
63
62
  respond(lang('zen_general.errors.not_authorized'), 403)
64
63
  end
65
-
64
+
66
65
  set_breadcrumbs(lang('user_groups.titles.index'))
67
-
66
+
68
67
  @user_groups = UserGroup.all
69
68
  end
70
-
69
+
71
70
  ##
72
71
  # Edit an existing user group.
73
72
  #
@@ -84,19 +83,19 @@ module Users
84
83
  if !user_authorized?([:read, :update])
85
84
  respond(lang('zen_general.errors.not_authorized'), 403)
86
85
  end
87
-
86
+
88
87
  set_breadcrumbs(
89
- anchor_to(lang('user_groups.titles.index'), UserGroups.r(:index)),
88
+ anchor_to(lang('user_groups.titles.index'), UserGroups.r(:index)),
90
89
  lang('user_groups.titles.edit')
91
90
  )
92
-
91
+
93
92
  if flash[:form_data]
94
93
  @user_group = flash[:form_data]
95
94
  else
96
95
  @user_group = UserGroup[id.to_i]
97
96
  end
98
97
  end
99
-
98
+
100
99
  ##
101
100
  # Create a new user group.
102
101
  #
@@ -112,18 +111,18 @@ module Users
112
111
  if !user_authorized?([:read, :create])
113
112
  respond(lang('zen_general.errors.not_authorized'), 403)
114
113
  end
115
-
114
+
116
115
  set_breadcrumbs(
117
- anchor_to(lang('user_groups.titles.index'), UserGroups.r(:index)),
116
+ anchor_to(lang('user_groups.titles.index'), UserGroups.r(:index)),
118
117
  lang('user_groups.titles.new')
119
118
  )
120
-
119
+
121
120
  @user_group = UserGroup.new
122
121
  end
123
-
122
+
124
123
  ##
125
124
  # Saves or creates a new user group based on the POST data and a field named 'id'.
126
- #
125
+ #
127
126
  # This method requires the following permissions:
128
127
  #
129
128
  # * create
@@ -136,37 +135,42 @@ module Users
136
135
  if !user_authorized?([:create, :update])
137
136
  respond(lang('zen_general.errors.not_authorized'), 403)
138
137
  end
139
-
140
- post = request.params.dup
141
-
138
+
139
+ post = request.subset(:id, :name, :slug, :description, :super_group)
140
+
142
141
  if post['id'] and !post['id'].empty?
143
142
  @user_group = UserGroup[post['id']]
144
143
  save_action = :save
145
144
  else
146
145
  @user_group = UserGroup.new
147
146
  save_action = :new
147
+
148
+ post.delete('slug') if post['slug'].empty?
148
149
  end
149
-
150
+
151
+ post.delete('id')
152
+
150
153
  flash_success = lang("user_groups.success.#{save_action}")
151
154
  flash_error = lang("user_groups.errors.#{save_action}")
152
-
155
+
153
156
  begin
154
157
  @user_group.update(post)
155
- notification(:success, lang('user_groups.titles.index'), flash_success)
156
- rescue
157
- notification(:error, lang('user_groups.titles.index'), flash_error)
158
-
158
+ message(:success, flash_success)
159
+ rescue => e
160
+ Ramaze::Log.error(e.inspect)
161
+ message(:error, flash_error)
162
+
159
163
  flash[:form_data] = @user_group
160
164
  flash[:form_errors] = @user_group.errors
161
165
  end
162
-
166
+
163
167
  if @user_group.id
164
168
  redirect(UserGroups.r(:edit, @user_group.id))
165
169
  else
166
170
  redirect_referrer
167
171
  end
168
172
  end
169
-
173
+
170
174
  ##
171
175
  # Delete all specified user groups.
172
176
  #
@@ -181,36 +185,24 @@ module Users
181
185
  if !user_authorized?([:delete])
182
186
  respond(lang('zen_general.errors.not_authorized'), 403)
183
187
  end
184
-
185
- if !request.params['user_group_ids'] or request.params['user_group_ids'].empty?
186
- notification(
187
- :error,
188
- lang('user_groups.titles.index'),
189
- lang('user_groups.errors.no_delete')
190
- )
191
188
 
189
+ if !request.params['user_group_ids'] or request.params['user_group_ids'].empty?
190
+ message(:error, lang('user_groups.errors.no_delete'))
192
191
  redirect_referrer
193
192
  end
194
-
193
+
195
194
  request.params['user_group_ids'].each do |id|
196
195
  begin
197
- UserGroup[id.to_i].destroy
198
- notification(
199
- :success,
200
- lang('user_groups.titles.index'),
201
- lang('user_groups.success.delete')
202
- )
203
- rescue
204
- notification(
205
- :error,
206
- lang('user_groups.titles.index'),
207
- lang('user_groups.errors.delete') % id
208
- )
196
+ UserGroup[id].destroy
197
+ message(:success, lang('user_groups.success.delete'))
198
+ rescue => e
199
+ Ramaze::Log.error(e.inspect)
200
+ message(:error, lang('user_groups.errors.delete') % id)
209
201
  end
210
202
  end
211
-
203
+
212
204
  redirect_referrer
213
205
  end
214
- end
215
- end
216
- end
206
+ end # UserGroups
207
+ end # Controller
208
+ end # Users