zen 0.2.4.1 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +42 -33
- data/README.md +14 -27
- data/ROADMAP.md +20 -2
- data/{Thorfile → Rakefile} +2 -3
- data/bin/zen +27 -5
- data/lib/zen.rb +70 -52
- data/lib/zen/asset.rb +258 -0
- data/lib/zen/bin/app.rb +42 -0
- data/lib/zen/controller/admin_controller.rb +53 -36
- data/lib/zen/controller/base_controller.rb +13 -8
- data/lib/zen/controller/frontend_controller.rb +4 -3
- data/lib/zen/controller/main_controller.rb +17 -33
- data/lib/zen/error/validation_error.rb +10 -0
- data/lib/zen/ext/string.rb +185 -0
- data/lib/zen/helper/acl.rb +120 -92
- data/lib/zen/helper/common.rb +1 -3
- data/lib/zen/helper/theme.rb +73 -0
- data/lib/zen/language.rb +66 -57
- data/lib/zen/layout/admin.xhtml +5 -48
- data/lib/zen/layout/login.xhtml +4 -44
- data/lib/zen/model/methods.rb +1 -1
- data/lib/zen/model/settings.rb +0 -3
- data/lib/zen/package.rb +101 -83
- data/lib/zen/package/base.rb +62 -0
- data/lib/zen/package/categories/lib/categories.rb +29 -10
- data/lib/zen/package/categories/lib/categories/controller/categories.rb +4 -5
- data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +4 -5
- data/lib/zen/package/categories/lib/categories/language/en/category_groups.yml +4 -3
- data/lib/zen/package/categories/lib/categories/model/category.rb +2 -2
- data/lib/zen/package/categories/lib/categories/model/category_group.rb +3 -3
- data/lib/zen/package/categories/lib/categories/plugin/categories.rb +130 -0
- data/lib/zen/package/categories/lib/categories/view/admin/categories/form.xhtml +1 -1
- data/lib/zen/package/categories/lib/categories/view/admin/categories/index.xhtml +2 -2
- data/lib/zen/package/categories/lib/categories/view/admin/category-groups/index.xhtml +11 -6
- data/lib/zen/package/comments/lib/comments.rb +23 -13
- data/lib/zen/package/comments/lib/comments/controller/comments.rb +4 -5
- data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +7 -8
- data/lib/zen/package/comments/lib/comments/model/comment.rb +4 -4
- data/lib/zen/package/comments/lib/comments/plugin/comments.rb +111 -0
- data/lib/zen/package/comments/lib/comments/view/admin/comments/form.xhtml +2 -2
- data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields.rb +18 -11
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +4 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +4 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +2 -2
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-field-groups/index.xhtml +9 -5
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/form.xhtml +1 -1
- data/lib/zen/package/custom_fields/lib/custom_fields/view/admin/custom-fields/index.xhtml +3 -3
- data/lib/zen/package/menus/lib/menus.rb +25 -43
- data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +5 -6
- data/lib/zen/package/menus/lib/menus/controller/menus.rb +9 -5
- data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +4 -4
- data/lib/zen/package/menus/lib/menus/model/menu.rb +2 -2
- data/lib/zen/package/menus/lib/menus/model/menu_item.rb +4 -1
- data/lib/zen/package/menus/lib/menus/plugin/menus.rb +152 -0
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/form.xhtml +1 -1
- data/lib/zen/package/menus/lib/menus/view/admin/menu-items/index.xhtml +3 -3
- data/lib/zen/package/menus/lib/menus/view/admin/menus/index.xhtml +7 -7
- data/lib/zen/package/sections/lib/sections.rb +32 -16
- data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +9 -18
- data/lib/zen/package/sections/lib/sections/controller/sections.rb +8 -9
- data/lib/zen/package/sections/lib/sections/language/en/section_entries.yml +1 -1
- data/lib/zen/package/sections/lib/sections/model/section.rb +4 -4
- data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -10
- data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +224 -0
- data/lib/zen/package/sections/lib/sections/plugin/sections.rb +85 -0
- data/lib/zen/package/sections/lib/sections/view/admin/form.xhtml +1 -1
- data/lib/zen/package/sections/lib/sections/view/admin/index.xhtml +9 -5
- data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +2 -2
- data/lib/zen/package/settings/lib/settings.rb +145 -10
- data/lib/zen/package/settings/lib/settings/controller/settings.rb +28 -24
- data/lib/zen/package/settings/lib/settings/language/en/settings.yml +10 -0
- data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -64
- data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +40 -0
- data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +76 -0
- data/lib/zen/package/settings/lib/settings/plugin/settings.rb +236 -0
- data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +20 -49
- data/lib/zen/package/settings/migrations/1295597111_create_schema.rb +0 -12
- data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +31 -0
- data/lib/zen/package/users/lib/users.rb +18 -15
- data/lib/zen/package/users/lib/users/controller/access_rules.rb +44 -8
- data/lib/zen/package/users/lib/users/controller/user_groups.rb +4 -5
- data/lib/zen/package/users/lib/users/controller/users.rb +5 -6
- data/lib/zen/package/users/lib/users/language/en/access_rules.yml +11 -9
- data/lib/zen/package/users/lib/users/model/access_rule.rb +7 -6
- data/lib/zen/package/users/lib/users/model/user.rb +4 -4
- data/lib/zen/package/users/lib/users/model/user_group.rb +3 -3
- data/lib/zen/package/users/lib/users/public/admin/js/users/access_rules.js +50 -0
- data/lib/zen/package/users/lib/users/view/admin/access-rules/form.xhtml +32 -29
- data/lib/zen/package/users/lib/users/view/admin/access-rules/index.xhtml +8 -6
- data/lib/zen/package/users/lib/users/view/admin/user-groups/index.xhtml +3 -3
- data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +2 -2
- data/lib/zen/package/users/migrations/1303510943_class_rules.rb +13 -0
- data/lib/zen/plugin.rb +110 -104
- data/lib/zen/plugin/base.rb +46 -0
- data/lib/zen/{liquid/controller_behavior.rb → plugin/controller.rb} +9 -7
- data/lib/zen/plugin/helper.rb +47 -0
- data/lib/zen/plugin/markup/lib/markup.rb +14 -0
- data/lib/zen/plugin/markup/lib/markup/language/en/markup.yml +6 -0
- data/lib/zen/plugin/markup/lib/markup/markup.rb +154 -0
- data/lib/zen/public/admin/css/forms.css +4 -0
- data/lib/zen/public/admin/css/general.css +15 -15
- data/lib/zen/public/admin/css/layout.css +10 -10
- data/lib/zen/public/admin/css/reset.css +123 -0
- data/lib/zen/public/admin/images/icons/accept.png +0 -0
- data/lib/zen/public/admin/images/icons/add.png +0 -0
- data/lib/zen/public/admin/images/icons/back.png +0 -0
- data/lib/zen/public/admin/images/icons/bold.png +0 -0
- data/lib/zen/public/admin/images/icons/close.png +0 -0
- data/lib/zen/public/admin/images/icons/delete.png +0 -0
- data/lib/zen/public/admin/images/icons/edit.png +0 -0
- data/lib/zen/public/admin/images/icons/error.png +0 -0
- data/lib/zen/public/admin/images/icons/help.png +0 -0
- data/lib/zen/public/admin/images/icons/info.png +0 -0
- data/lib/zen/public/admin/images/icons/italic.png +0 -0
- data/lib/zen/public/admin/images/icons/large/error.png +0 -0
- data/lib/zen/public/admin/images/icons/large/notice.png +0 -0
- data/lib/zen/public/admin/images/icons/large/success.png +0 -0
- data/lib/zen/public/admin/images/icons/link.png +0 -0
- data/lib/zen/public/admin/images/icons/logout.png +0 -0
- data/lib/zen/public/admin/images/icons/ol.png +0 -0
- data/lib/zen/public/admin/images/icons/pdf.png +0 -0
- data/lib/zen/public/admin/images/icons/ul.png +0 -0
- data/lib/zen/public/admin/images/icons/user.png +0 -0
- data/lib/zen/public/admin/images/icons/view.png +0 -0
- data/lib/zen/public/admin/js/mootools/core.js +384 -333
- data/lib/zen/public/admin/js/mootools/more.js +256 -231
- data/lib/zen/public/admin/js/vendor/{datepicker/Picker.Date.js → datepicker.js} +447 -0
- data/lib/zen/public/admin/js/vendor/yepnope.js +1 -0
- data/lib/zen/public/admin/js/zen/editor/base.js +8 -1
- data/lib/zen/public/admin/js/zen/init.js +89 -26
- data/lib/zen/public/favicon.ico +0 -0
- data/lib/zen/task.rb +7 -0
- data/lib/zen/task/build.rake +60 -0
- data/lib/zen/task/clean.rake +27 -0
- data/lib/zen/task/db.rake +111 -0
- data/lib/zen/task/package.rake +67 -0
- data/lib/zen/task/plugin.rake +24 -0
- data/lib/zen/task/proto.rake +95 -0
- data/lib/zen/task/theme.rake +68 -0
- data/lib/zen/theme.rb +28 -55
- data/lib/zen/theme/base.rb +64 -0
- data/lib/zen/validation.rb +149 -0
- data/lib/zen/version.rb +1 -1
- data/lib/zen/view/bottom.xhtml +6 -0
- data/lib/zen/view/main.xhtml +32 -0
- data/proto/app/Rakefile +12 -0
- data/proto/app/app.rb +6 -6
- data/proto/app/config/config.rb +7 -14
- data/proto/app/config/database.rb +0 -20
- data/proto/app/start.rb +0 -1
- data/proto/app/{vendor/themes → task}/.gitkeep +0 -0
- data/proto/app/vendor/theme/.gitkeep +0 -0
- data/proto/package/lib/package.rb +8 -17
- data/proto/package/lib/package/controller/controllers.rb +4 -4
- data/proto/package/lib/package/language/en/languages.yml +3 -3
- data/proto/package/lib/package/model/model.rb +1 -1
- metadata +73 -73
- data/lib/zen/bin/base.rb +0 -109
- data/lib/zen/helper/asset.rb +0 -106
- data/lib/zen/liquid/general.rb +0 -94
- data/lib/zen/liquid/redirect.rb +0 -70
- data/lib/zen/liquid/strip.rb +0 -60
- data/lib/zen/package/categories/lib/categories/liquid/categories.rb +0 -16
- data/lib/zen/package/comments/lib/comments/liquid/comment_form.rb +0 -127
- data/lib/zen/package/comments/lib/comments/liquid/comments.rb +0 -115
- data/lib/zen/package/menus/lib/menus/liquid/menus.rb +0 -152
- data/lib/zen/package/sections/lib/sections/liquid/section_entries.rb +0 -228
- data/lib/zen/package/sections/lib/sections/liquid/sections.rb +0 -77
- data/lib/zen/package/settings/lib/settings/liquid/setting.rb +0 -58
- data/lib/zen/package/users/lib/users/liquid/user.rb +0 -77
- data/lib/zen/package/users/lib/users/liquid/users.rb +0 -82
- data/lib/zen/plugin/markup.rb +0 -30
- data/lib/zen/public/admin/css/boilerplate.css +0 -176
- data/lib/zen/public/admin/images/general/noise.jpg +0 -0
- data/lib/zen/public/admin/js/vendor/datepicker/Picker.Attach.js +0 -137
- data/lib/zen/public/admin/js/vendor/datepicker/Picker.js +0 -291
- data/lib/zen/public/admin/js/vendor/datepicker/README.md +0 -325
- data/lib/zen/public/admin/js/vendor/datepicker/locale.js +0 -16
- data/lib/zen/strict_struct.rb +0 -36
- data/lib/zen/task/build.rb +0 -123
- data/lib/zen/task/clean.rb +0 -46
- data/lib/zen/task/db.rb +0 -130
- data/lib/zen/task/package.rb +0 -87
- data/lib/zen/task/proto.rb +0 -116
- data/lib/zen/task/theme.rb +0 -88
- data/proto/app/Thorfile +0 -4
@@ -10,18 +10,6 @@ Sequel.migration do
|
|
10
10
|
String :type , :default => 'textbox'
|
11
11
|
String :value , :text => true
|
12
12
|
end
|
13
|
-
|
14
|
-
# Insert our default settings
|
15
|
-
Zen::Database.handle[:settings].insert_multiple([
|
16
|
-
{:key => 'website_name' , :group_key => 'general' , :default => 'Zen', :type => 'textbox'},
|
17
|
-
{:key => 'website_description', :group_key => 'general' , :type => 'textarea'},
|
18
|
-
{:key => 'website_enabled' , :group_key => 'general' , :default => '1', :type => 'radio'},
|
19
|
-
{:key => 'language' , :group_key => 'general' , :default => 'en', :type => 'select'},
|
20
|
-
{:key => 'default_section' , :group_key => 'general' , :type => 'select'},
|
21
|
-
{:key => 'theme' , :group_key => 'general' , :type => 'select'},
|
22
|
-
{:key => 'enable_antispam' , :group_key => 'security', :default => true, :type => 'radio'},
|
23
|
-
{:key => 'defensio_key' , :group_key => 'security', :type => 'textbox'}
|
24
|
-
])
|
25
13
|
end
|
26
14
|
|
27
15
|
down do
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
|
3
|
+
up do
|
4
|
+
rename_column(:settings, :key, :name, :unique => true)
|
5
|
+
rename_column(:settings, :group_key, :group)
|
6
|
+
|
7
|
+
drop_column(:settings, :language_key)
|
8
|
+
drop_column(:settings, :language_group_key)
|
9
|
+
|
10
|
+
# Ensure the identifiers are unique
|
11
|
+
#add_index(:settings, :key, :unique => true)
|
12
|
+
|
13
|
+
# Update the settings
|
14
|
+
Zen::Database.handle[:settings].all.each do |row|
|
15
|
+
name = row[:name].split('.').last
|
16
|
+
group = row[:group].split('.').last
|
17
|
+
|
18
|
+
Zen::Database.handle[:settings].filter(:id => row[:id])
|
19
|
+
.update(:name => name, :group => group)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
down do
|
24
|
+
rename_column(:settings, :name , :key)
|
25
|
+
rename_column(:settings, :group, :group_key)
|
26
|
+
|
27
|
+
add_column(:settings, :language_key , String)
|
28
|
+
add_column(:settings, :language_group_key, String)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -1,38 +1,41 @@
|
|
1
|
-
|
2
1
|
require __DIR__('users/model/user')
|
3
2
|
require __DIR__('users/model/user_group')
|
4
3
|
require __DIR__('users/model/access_rule')
|
5
|
-
|
6
4
|
require __DIR__('users/controller/users')
|
7
5
|
require __DIR__('users/controller/user_groups')
|
8
6
|
require __DIR__('users/controller/access_rules')
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
Liquid::Template.register_tag('user' , Users::Liquid::User)
|
8
|
+
Zen::Language.options.paths.push(__DIR__('users'))
|
9
|
+
Zen::Language.load('users')
|
10
|
+
Zen::Language.load('user_groups')
|
11
|
+
Zen::Language.load('access_rules')
|
15
12
|
|
16
13
|
# The trait for the User helper has to be specified in the constructor as
|
17
14
|
# our user model is loaded after this class is loaded (but before it's initialized)
|
18
|
-
Zen::
|
15
|
+
Zen::Controller::BaseController.trait(:user_model => Users::Model::User)
|
19
16
|
|
20
17
|
Zen::Package.add do |p|
|
21
|
-
p.name = '
|
18
|
+
p.name = 'users'
|
22
19
|
p.author = 'Yorick Peterse'
|
23
20
|
p.url = 'http://yorickpeterse.com/'
|
24
|
-
p.about = "Module for managing users along with handling authentication and
|
21
|
+
p.about = "Module for managing users along with handling authentication and
|
22
|
+
authorization."
|
25
23
|
|
26
|
-
p.identifier = 'com.zen.users'
|
27
24
|
p.directory = __DIR__('users')
|
28
25
|
p.migration_dir = __DIR__('../migrations')
|
29
26
|
|
30
27
|
p.menu = [{
|
31
|
-
:title =>
|
32
|
-
:url =>
|
28
|
+
:title => lang('users.titles.index'),
|
29
|
+
:url => 'admin/users',
|
33
30
|
:children => [
|
34
|
-
{:title =>
|
35
|
-
{:title =>
|
31
|
+
{:title => lang('user_groups.titles.index') , :url => 'admin/user-groups' },
|
32
|
+
{:title => lang('access_rules.titles.index'), :url => 'admin/access-rules'}
|
36
33
|
]
|
37
34
|
}]
|
35
|
+
|
36
|
+
p.controllers = {
|
37
|
+
lang('users.titles.index') => Users::Controller::Users,
|
38
|
+
lang('user_groups.titles.index') => Users::Controller::UserGroups,
|
39
|
+
lang('access_rules.titles.index') => Users::Controller::AccessRules
|
40
|
+
}
|
38
41
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Users
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
##
|
6
6
|
# Controller for managing access rules. Each access rule can be used
|
7
7
|
# to specify whether or not a user can edit or create something.
|
@@ -16,11 +16,12 @@ module Users
|
|
16
16
|
# @author Yorick Peterse
|
17
17
|
# @since 0.1
|
18
18
|
#
|
19
|
-
class AccessRules < Zen::
|
20
|
-
include ::Users::
|
19
|
+
class AccessRules < Zen::Controller::AdminController
|
20
|
+
include ::Users::Model
|
21
21
|
|
22
|
-
map
|
23
|
-
|
22
|
+
map('/admin/access-rules')
|
23
|
+
|
24
|
+
javascript(['users/access_rules'])
|
24
25
|
|
25
26
|
before_all do
|
26
27
|
csrf_protection(:save, :delete) do
|
@@ -51,8 +52,6 @@ module Users
|
|
51
52
|
@page_title = lang("access_rules.titles.#{method}") rescue nil
|
52
53
|
end
|
53
54
|
|
54
|
-
require_js 'users/access_rules'
|
55
|
-
|
56
55
|
@rule_applies_hash = {
|
57
56
|
lang('access_rules.labels.user') => 'div_user_id',
|
58
57
|
lang('access_rules.labels.user_group') => 'div_user_group_id'
|
@@ -80,6 +79,39 @@ module Users
|
|
80
79
|
@access_rules = AccessRule.all
|
81
80
|
end
|
82
81
|
|
82
|
+
##
|
83
|
+
# Hook that's executed before the edit and new method. This hook is used to
|
84
|
+
# pre-process some data used in the form.
|
85
|
+
#
|
86
|
+
# @author Yorick Peterse
|
87
|
+
# @since 0.2.5
|
88
|
+
#
|
89
|
+
before(:index, :edit, :new) do
|
90
|
+
@form_users = {}
|
91
|
+
@form_groups = {}
|
92
|
+
@form_packages = {}
|
93
|
+
@form_controllers = {}
|
94
|
+
|
95
|
+
::Users::Model::User.select(:id, :name).each do |user|
|
96
|
+
@form_users[user.id.to_s] = user.name
|
97
|
+
end
|
98
|
+
|
99
|
+
# Build the list of available packages and controllers
|
100
|
+
::Zen::Package::Registered.each do |name, pkg|
|
101
|
+
name = name.to_s
|
102
|
+
@form_packages[name] = name
|
103
|
+
@form_controllers[name] ||= {lang('access_rules.labels.all_controllers') => '*'}
|
104
|
+
|
105
|
+
pkg.controllers.each do |key, value|
|
106
|
+
@form_controllers[name][key] = value.to_s
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
::Users::Model::UserGroup.select(:id, :name).each do |group|
|
111
|
+
@form_groups[group.id.to_s] = group.name
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
83
115
|
##
|
84
116
|
# Edit an existing access rule.
|
85
117
|
#
|
@@ -151,7 +183,7 @@ module Users
|
|
151
183
|
|
152
184
|
post = request.params.dup
|
153
185
|
|
154
|
-
if post['rule_applies']
|
186
|
+
if post['rule_applies'] === 'div_user_id'
|
155
187
|
post['user_group_id'] = nil
|
156
188
|
else
|
157
189
|
post['user_id'] = nil
|
@@ -172,6 +204,9 @@ module Users
|
|
172
204
|
|
173
205
|
begin
|
174
206
|
@access_rule.update(post)
|
207
|
+
|
208
|
+
# Flush the existing rules from the session
|
209
|
+
session.delete(:access_rules)
|
175
210
|
notification(:success, lang('access_rules.titles.index'), flash_success)
|
176
211
|
rescue
|
177
212
|
notification(:error, lang('access_rules.titles.index'), flash_error)
|
@@ -217,6 +252,7 @@ module Users
|
|
217
252
|
|
218
253
|
begin
|
219
254
|
@access_rule.delete
|
255
|
+
session.delete(:access_rules)
|
220
256
|
notification(
|
221
257
|
:success,
|
222
258
|
lang('access_rules.titles.index'),
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Users
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
##
|
6
6
|
# Controller for managing all user groups. It's not
|
7
7
|
# required to add a user to a group but it can certainly
|
@@ -11,11 +11,10 @@ module Users
|
|
11
11
|
# @author Yorick Peterse
|
12
12
|
# @since 0.1
|
13
13
|
#
|
14
|
-
class UserGroups < Zen::
|
15
|
-
include ::Users::
|
14
|
+
class UserGroups < Zen::Controller::AdminController
|
15
|
+
include ::Users::Model
|
16
16
|
|
17
|
-
map
|
18
|
-
trait :extension_identifier => 'com.zen.users'
|
17
|
+
map('/admin/user-groups')
|
19
18
|
|
20
19
|
before_all do
|
21
20
|
csrf_protection(:save, :delete) do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Users
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
##
|
6
6
|
# Controller for managing users. Users in this case are people
|
7
7
|
# that have access to the backend. However, users might be able
|
@@ -14,11 +14,10 @@ module Users
|
|
14
14
|
# @author Yorick Peterse
|
15
15
|
# @since 0.1
|
16
16
|
#
|
17
|
-
class Users < Zen::
|
18
|
-
include ::Users::
|
17
|
+
class Users < Zen::Controller::AdminController
|
18
|
+
include ::Users::Model
|
19
19
|
|
20
|
-
map
|
21
|
-
trait :extension_identifier => 'com.zen.users'
|
20
|
+
map('/admin/users')
|
22
21
|
|
23
22
|
before_all do
|
24
23
|
csrf_protection(:save, :delete) do
|
@@ -158,7 +157,7 @@ module Users
|
|
158
157
|
User[:email => request.params['email']].update(:last_login => Time.new)
|
159
158
|
|
160
159
|
notification(:success, lang('users.titles.index'), lang('users.success.login'))
|
161
|
-
redirect(::Sections::
|
160
|
+
redirect(::Sections::Controller::Sections.r(:index))
|
162
161
|
else
|
163
162
|
notification(:error, lang('users.titles.index'), lang('users.errors.login'))
|
164
163
|
end
|
@@ -5,15 +5,17 @@ titles:
|
|
5
5
|
new : 'Add Access Rule'
|
6
6
|
|
7
7
|
labels:
|
8
|
-
id
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
id : '#'
|
9
|
+
package : 'Package'
|
10
|
+
controller : 'Controller'
|
11
|
+
rule_applies : 'Rule applies to'
|
12
|
+
create : 'Create'
|
13
|
+
read : 'Read'
|
14
|
+
update : 'Update'
|
15
|
+
delete : 'Delete'
|
16
|
+
user : 'User'
|
17
|
+
user_group : 'User group'
|
18
|
+
all_controllers: 'All controllers'
|
17
19
|
|
18
20
|
messages:
|
19
21
|
no_rules: 'No access rules have been added yet.'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Users
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Model
|
5
5
|
##
|
6
6
|
# Model that represents a single access rule. This model has the following
|
7
7
|
# relations:
|
@@ -13,8 +13,8 @@ module Users
|
|
13
13
|
# @since 0.1
|
14
14
|
#
|
15
15
|
class AccessRule < Sequel::Model
|
16
|
-
many_to_one :user , :class => "Users::
|
17
|
-
many_to_one :user_group, :class => "Users::
|
16
|
+
many_to_one :user , :class => "Users::Model::User"
|
17
|
+
many_to_one :user_group, :class => "Users::Model::UserGroup"
|
18
18
|
|
19
19
|
##
|
20
20
|
# Validation rules used when creating or updating an access rule.
|
@@ -23,9 +23,10 @@ module Users
|
|
23
23
|
# @since 0.1
|
24
24
|
#
|
25
25
|
def validate
|
26
|
-
validates_presence(
|
27
|
-
|
28
|
-
|
26
|
+
validates_presence([
|
27
|
+
:package, :controller, :create_access, :read_access, :update_access,
|
28
|
+
:delete_access
|
29
|
+
])
|
29
30
|
|
30
31
|
validates_type(
|
31
32
|
TrueClass,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Users
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Model
|
5
5
|
##
|
6
6
|
# Model that represents the very important user. This model
|
7
7
|
# can be used for both CRUD actions as well as authenticating a user.
|
@@ -22,8 +22,8 @@ module Users
|
|
22
22
|
class User < Sequel::Model
|
23
23
|
plugin :timestamps, :create => :created_at, :update => :updated_at
|
24
24
|
|
25
|
-
many_to_many :user_groups, :class => "Users::
|
26
|
-
one_to_many :access_rules, :class => "Users::
|
25
|
+
many_to_many :user_groups, :class => "Users::Model::UserGroup", :eager => [:access_rules]
|
26
|
+
one_to_many :access_rules, :class => "Users::Model::AccessRule"
|
27
27
|
|
28
28
|
##
|
29
29
|
# Try to authenticate the user based on the specified credentials.
|
@@ -49,7 +49,7 @@ module Users
|
|
49
49
|
user = self[:email => email]
|
50
50
|
|
51
51
|
if !user.nil? and user.password == password and user.status == 'open'
|
52
|
-
::Zen::
|
52
|
+
::Zen::Controller::BaseController.session[:user] = user
|
53
53
|
return user
|
54
54
|
else
|
55
55
|
return false
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#:nodoc:
|
2
2
|
module Users
|
3
3
|
#:nodoc:
|
4
|
-
module
|
4
|
+
module Model
|
5
5
|
##
|
6
6
|
# Model that represents a single user group. This model has the following
|
7
7
|
# relations:
|
@@ -17,8 +17,8 @@ module Users
|
|
17
17
|
# @since 0.1
|
18
18
|
#
|
19
19
|
class UserGroup < Sequel::Model
|
20
|
-
many_to_many(:users , :class => "Users::
|
21
|
-
one_to_many(:access_rules, :class => "Users::
|
20
|
+
many_to_many(:users , :class => "Users::Model::User")
|
21
|
+
one_to_many(:access_rules, :class => "Users::Model::AccessRule")
|
22
22
|
|
23
23
|
plugin :sluggable , :source => :name, :freeze => false
|
24
24
|
|
@@ -1,3 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* Function that toggles a given select element from the list of elements.
|
3
|
+
*
|
4
|
+
* @author Yorick Peterse
|
5
|
+
* @since 0.2.5
|
6
|
+
* @param {array} controllers A list of select boxes containing all controllers.
|
7
|
+
* @param {string} selected The ID of the select element that has to be displayed.
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
function toggleSelect(controllers, selected)
|
11
|
+
{
|
12
|
+
// Show the correct box and hide all others
|
13
|
+
controllers.each(function(element)
|
14
|
+
{
|
15
|
+
if ( element.id === selected )
|
16
|
+
{
|
17
|
+
element.removeClass('hidden').set('disabled', false);
|
18
|
+
}
|
19
|
+
else
|
20
|
+
{
|
21
|
+
if ( !element.hasClass('hidden') )
|
22
|
+
{
|
23
|
+
element.addClass('hidden');
|
24
|
+
}
|
25
|
+
|
26
|
+
element.set('disabled', true);
|
27
|
+
}
|
28
|
+
});
|
29
|
+
}
|
30
|
+
|
1
31
|
window.addEvent('domready', function()
|
2
32
|
{
|
3
33
|
// Hide the fields that allow a user to pick a user or group
|
@@ -39,4 +69,24 @@ window.addEvent('domready', function()
|
|
39
69
|
});
|
40
70
|
});
|
41
71
|
});
|
72
|
+
|
73
|
+
var package_select = $('form_package');
|
74
|
+
|
75
|
+
if ( package_select )
|
76
|
+
{
|
77
|
+
// Hide all the controller select boxes and only show the ones that belong to the
|
78
|
+
// currently selected package.
|
79
|
+
var controllers = $$('select.controllers');
|
80
|
+
|
81
|
+
// Show the first box by default
|
82
|
+
toggleSelect(controllers, package_select.get('value') + '_controllers');
|
83
|
+
|
84
|
+
// When the select element's value is changed the correct controller box should
|
85
|
+
// be displayed and the old one should be hidden
|
86
|
+
package_select.addEvent('change', function()
|
87
|
+
{
|
88
|
+
var selected = this.get('value') + '_controllers';
|
89
|
+
toggleSelect(controllers, selected);
|
90
|
+
});
|
91
|
+
}
|
42
92
|
});
|
@@ -3,31 +3,12 @@
|
|
3
3
|
@access_rule, :method => :post, :action => @form_save_url, :id => :access_rule_form
|
4
4
|
) do |f|
|
5
5
|
|
6
|
-
users = {}
|
7
|
-
groups = {}
|
8
|
-
extensions = {}
|
9
|
-
rule_applies = ''
|
10
|
-
|
11
6
|
if !@access_rule.user_id.nil?
|
12
7
|
rule_applies = 'div_user_id'
|
13
8
|
else
|
14
9
|
rule_applies = 'div_user_group_id'
|
15
10
|
end
|
16
11
|
|
17
|
-
Users::Models::User.select(:id, :name).each do |user|
|
18
|
-
users[user.id.to_s] = user.name
|
19
|
-
end
|
20
|
-
|
21
|
-
Zen::Package.packages.each do |ident, ext|
|
22
|
-
extensions[ident] = ext.name
|
23
|
-
end
|
24
|
-
|
25
|
-
Users::Models::UserGroup.select(:id, :name).each do |group|
|
26
|
-
groups[group.id.to_s] = group.name
|
27
|
-
end
|
28
|
-
|
29
|
-
# ---------------------
|
30
|
-
|
31
12
|
f.input_hidden(:id, @access_rule.id)
|
32
13
|
f.input_hidden(:csrf_token, get_csrf_token)
|
33
14
|
|
@@ -39,37 +20,59 @@
|
|
39
20
|
)
|
40
21
|
|
41
22
|
f.g.div(:id => 'div_user_id') do
|
42
|
-
|
43
23
|
f.select(
|
44
24
|
lang('access_rules.labels.user'),
|
45
25
|
:user_id,
|
46
|
-
:values =>
|
26
|
+
:values => @form_users,
|
47
27
|
:selected => @access_rule.user_id,
|
48
28
|
:size => 1
|
49
29
|
)
|
50
|
-
|
51
30
|
end
|
52
31
|
|
53
32
|
f.g.div(:id => 'div_user_group_id') do
|
54
|
-
|
55
33
|
f.select(
|
56
34
|
lang('access_rules.labels.user_group'),
|
57
35
|
:user_group_id,
|
58
|
-
:values =>
|
36
|
+
:values => @form_groups,
|
59
37
|
:selected => @access_rule.user_group_id,
|
60
38
|
:size => 1
|
61
39
|
)
|
62
|
-
|
63
40
|
end
|
64
41
|
|
65
42
|
f.select(
|
66
|
-
lang('access_rules.labels.
|
67
|
-
:
|
68
|
-
:values =>
|
69
|
-
:selected => @access_rule.
|
43
|
+
lang('access_rules.labels.package'),
|
44
|
+
:package,
|
45
|
+
:values => @form_packages,
|
46
|
+
:selected => @access_rule.package,
|
70
47
|
:size => 1
|
71
48
|
)
|
72
49
|
|
50
|
+
# Build the select boxes for all controllers
|
51
|
+
f.g.p do
|
52
|
+
f.g.label { lang('access_rules.labels.controller') }
|
53
|
+
@form_controllers.each do |pkg, controllers|
|
54
|
+
f.g.select(
|
55
|
+
:id => "#{pkg}_controllers", :class => 'controllers hidden', :name => 'controller'
|
56
|
+
) do
|
57
|
+
# Show all the options
|
58
|
+
controllers.each do |key, value|
|
59
|
+
args = {:value => value}
|
60
|
+
|
61
|
+
# Is it selected?
|
62
|
+
if value === @access_rule.controller
|
63
|
+
args[:selected] = 'selected'
|
64
|
+
else
|
65
|
+
args.delete(:selected)
|
66
|
+
end
|
67
|
+
|
68
|
+
f.g.option(args) do
|
69
|
+
key
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
73
76
|
f.input_radio(
|
74
77
|
lang('access_rules.labels.create'),
|
75
78
|
:create_access,
|