netzke-basepack 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/CHANGELOG.rdoc +10 -0
- data/README.md +36 -2
- data/Rakefile +1 -3
- data/config/ci/before-travis.sh +28 -0
- data/lib/netzke/active_record.rb +10 -8
- data/lib/netzke/active_record/attributes.rb +28 -17
- data/lib/netzke/active_record/relation_extensions.rb +3 -1
- data/lib/netzke/basepack.rb +10 -2
- data/lib/netzke/basepack/action_column.rb +6 -8
- data/lib/netzke/basepack/data_accessor.rb +11 -174
- data/lib/netzke/basepack/data_adapters/abstract_adapter.rb +164 -0
- data/lib/netzke/basepack/data_adapters/active_record_adapter.rb +279 -0
- data/lib/netzke/basepack/data_adapters/data_mapper_adapter.rb +264 -0
- data/lib/netzke/basepack/data_adapters/sequel_adapter.rb +260 -0
- data/lib/netzke/basepack/form_panel.rb +3 -3
- data/lib/netzke/basepack/form_panel/fields.rb +6 -10
- data/lib/netzke/basepack/form_panel/javascripts/form_panel.js +1 -0
- data/lib/netzke/basepack/form_panel/services.rb +15 -16
- data/lib/netzke/basepack/grid_panel.rb +16 -10
- data/lib/netzke/basepack/grid_panel/columns.rb +6 -7
- data/lib/netzke/basepack/grid_panel/javascripts/event_handling.js +29 -27
- data/lib/netzke/basepack/grid_panel/services.rb +13 -90
- data/lib/netzke/basepack/paging_form_panel.rb +3 -3
- data/lib/netzke/basepack/query_builder.rb +2 -0
- data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +29 -19
- data/lib/netzke/basepack/search_panel.rb +6 -3
- data/lib/netzke/basepack/search_panel/javascripts/search_panel.js +2 -1
- data/lib/netzke/basepack/search_window.rb +2 -1
- data/lib/netzke/basepack/version.rb +1 -1
- data/lib/netzke/data_mapper.rb +18 -0
- data/lib/netzke/data_mapper/attributes.rb +273 -0
- data/lib/netzke/data_mapper/combobox_options.rb +11 -0
- data/lib/netzke/data_mapper/relation_extensions.rb +38 -0
- data/lib/netzke/sequel.rb +18 -0
- data/lib/netzke/sequel/attributes.rb +274 -0
- data/lib/netzke/sequel/combobox_options.rb +10 -0
- data/lib/netzke/sequel/relation_extensions.rb +40 -0
- data/netzke-basepack.gemspec +24 -13
- data/test/basepack_test_app/Gemfile +33 -8
- data/test/basepack_test_app/Gemfile.lock +98 -79
- data/test/basepack_test_app/Guardfile +46 -0
- data/test/basepack_test_app/app/components/book_grid_with_persistence.rb +3 -0
- data/test/basepack_test_app/app/components/extras/book_presentation.rb +10 -3
- data/test/basepack_test_app/app/models/address.rb +27 -1
- data/test/basepack_test_app/app/models/author.rb +28 -0
- data/test/basepack_test_app/app/models/book.rb +43 -0
- data/test/basepack_test_app/app/models/book_with_custom_primary_key.rb +22 -0
- data/test/basepack_test_app/app/models/role.rb +21 -0
- data/test/basepack_test_app/app/models/user.rb +24 -0
- data/test/basepack_test_app/config/database.yml.sample +11 -10
- data/test/basepack_test_app/config/database.yml.travis +15 -0
- data/test/basepack_test_app/config/initializers/data_mapper_logging.rb +3 -0
- data/test/basepack_test_app/config/initializers/sequel.rb +26 -0
- data/test/basepack_test_app/db/schema.rb +0 -3
- data/test/basepack_test_app/features/grid_panel.feature +28 -8
- data/test/basepack_test_app/features/grid_sorting.feature +6 -6
- data/test/basepack_test_app/features/paging_form_panel.feature +13 -13
- data/test/basepack_test_app/features/search_in_grid.feature +31 -31
- data/test/basepack_test_app/features/step_definitions/generic_steps.rb +3 -1
- data/test/basepack_test_app/features/support/env.rb +17 -4
- data/test/basepack_test_app/lib/tasks/travis.rake +7 -0
- data/test/basepack_test_app/spec/components/form_panel_spec.rb +2 -2
- data/test/basepack_test_app/spec/data_adapter/adapter_spec.rb +68 -0
- data/test/basepack_test_app/spec/{active_record → data_adapter}/attributes_spec.rb +12 -4
- data/test/basepack_test_app/spec/data_adapter/relation_extensions_spec.rb +125 -0
- data/test/basepack_test_app/spec/spec_helper.rb +9 -0
- data/test/unit/active_record_basepack_test.rb +1 -1
- data/test/unit/grid_panel_test.rb +1 -1
- metadata +26 -31
- data/app/models/netzke_field_list.rb +0 -261
- data/app/models/netzke_model_attr_list.rb +0 -21
- data/app/models/netzke_persistent_array_auto_model.rb +0 -57
- data/test/basepack_test_app/spec/active_record/relation_extensions_spec.rb +0 -44
@@ -10,6 +10,13 @@ Factory.find_definitions
|
|
10
10
|
# in spec/support/ and its subdirectories.
|
11
11
|
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
12
12
|
|
13
|
+
if defined?(DataMapper::Resource) || defined?(Sequel::Model)
|
14
|
+
|
15
|
+
# DatabaseCleaner not working in transaction mode for DM
|
16
|
+
DatabaseCleaner.strategy=:truncation
|
17
|
+
DatabaseCleaner.clean!
|
18
|
+
end
|
19
|
+
|
13
20
|
RSpec.configure do |config|
|
14
21
|
# == Mock Framework
|
15
22
|
#
|
@@ -27,4 +34,6 @@ RSpec.configure do |config|
|
|
27
34
|
# examples within a transaction, remove the following line or assign false
|
28
35
|
# instead of true.
|
29
36
|
config.use_transactional_fixtures = true
|
37
|
+
config.before(:all) { DatabaseCleaner.clean! }
|
38
|
+
config.after(:suite) { DatabaseCleaner.clean! }
|
30
39
|
end
|
@@ -47,7 +47,7 @@ class ActiveRecordBasepackTest < ActiveSupport::TestCase
|
|
47
47
|
Book.send(:include, ::Netzke::ActiveRecord::DataAccessor )
|
48
48
|
b = Book.create({:title => 'Rayuela', :genre_id => 200, :amount => 1000})
|
49
49
|
columns = [{:name => "recent"}, {:name => "title"}, {:name => "amount"}, {:name => "genre_id"}]
|
50
|
-
assert_equal(['Yes', 'Rayuela', 1000, 200], b.
|
50
|
+
assert_equal(['Yes', 'Rayuela', 1000, 200], b.netzke_array(columns))
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
@@ -24,7 +24,7 @@ class GridPanelTest < ActiveSupport::TestCase
|
|
24
24
|
assert_equal('Yes', data[2][2]) # "recent" virtual column in the last book
|
25
25
|
|
26
26
|
# delete all books
|
27
|
-
res = grid.delete_data(:records => Book.all.map(&:id).
|
27
|
+
res = grid.delete_data(:records => Book.all.map(&:id).netzke_json)
|
28
28
|
assert_equal(nil, Book.first)
|
29
29
|
|
30
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netzke-basepack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: netzke-core
|
16
|
-
requirement: &
|
16
|
+
requirement: &70312998876040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,29 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.7.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: will_paginate
|
27
|
-
requirement: &70335624108080 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 3.0.0
|
33
|
-
type: :runtime
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *70335624108080
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: acts_as_list
|
38
|
-
requirement: &70335624107600 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 0.1.4
|
44
|
-
type: :runtime
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *70335624107600
|
24
|
+
version_requirements: *70312998876040
|
47
25
|
description: A set of full-featured extendible Netzke components (such as FormPanel,
|
48
26
|
GridPanel, Window, BorderLayoutPanel, etc) which can be used as building block for
|
49
27
|
your RIA
|
@@ -55,14 +33,13 @@ extra_rdoc_files:
|
|
55
33
|
- README.md
|
56
34
|
files:
|
57
35
|
- .autotest
|
36
|
+
- .travis.yml
|
58
37
|
- CHANGELOG.rdoc
|
59
38
|
- LICENSE
|
60
39
|
- README.md
|
61
40
|
- Rakefile
|
62
41
|
- TODO.rdoc
|
63
|
-
-
|
64
|
-
- app/models/netzke_model_attr_list.rb
|
65
|
-
- app/models/netzke_persistent_array_auto_model.rb
|
42
|
+
- config/ci/before-travis.sh
|
66
43
|
- init.rb
|
67
44
|
- install.rb
|
68
45
|
- javascripts/basepack.js
|
@@ -84,6 +61,10 @@ files:
|
|
84
61
|
- lib/netzke/basepack/border_layout_panel.rb
|
85
62
|
- lib/netzke/basepack/border_layout_panel/javascripts/border_layout_panel.js
|
86
63
|
- lib/netzke/basepack/data_accessor.rb
|
64
|
+
- lib/netzke/basepack/data_adapters/abstract_adapter.rb
|
65
|
+
- lib/netzke/basepack/data_adapters/active_record_adapter.rb
|
66
|
+
- lib/netzke/basepack/data_adapters/data_mapper_adapter.rb
|
67
|
+
- lib/netzke/basepack/data_adapters/sequel_adapter.rb
|
87
68
|
- lib/netzke/basepack/form_panel.rb
|
88
69
|
- lib/netzke/basepack/form_panel/fields.rb
|
89
70
|
- lib/netzke/basepack/form_panel/javascripts/comma_list_cbg.js
|
@@ -123,6 +104,14 @@ files:
|
|
123
104
|
- lib/netzke/basepack/window/javascripts/window.js
|
124
105
|
- lib/netzke/basepack/wrap_lazy_loaded.rb
|
125
106
|
- lib/netzke/basepack/wrapper.rb
|
107
|
+
- lib/netzke/data_mapper.rb
|
108
|
+
- lib/netzke/data_mapper/attributes.rb
|
109
|
+
- lib/netzke/data_mapper/combobox_options.rb
|
110
|
+
- lib/netzke/data_mapper/relation_extensions.rb
|
111
|
+
- lib/netzke/sequel.rb
|
112
|
+
- lib/netzke/sequel/attributes.rb
|
113
|
+
- lib/netzke/sequel/combobox_options.rb
|
114
|
+
- lib/netzke/sequel/relation_extensions.rb
|
126
115
|
- lib/tasks/netzke_basepack_tasks.rake
|
127
116
|
- locales/de.yml
|
128
117
|
- locales/en.yml
|
@@ -133,6 +122,7 @@ files:
|
|
133
122
|
- test/basepack_test_app/.rvmrc
|
134
123
|
- test/basepack_test_app/Gemfile
|
135
124
|
- test/basepack_test_app/Gemfile.lock
|
125
|
+
- test/basepack_test_app/Guardfile
|
136
126
|
- test/basepack_test_app/README
|
137
127
|
- test/basepack_test_app/Rakefile
|
138
128
|
- test/basepack_test_app/app/components/author_form.rb
|
@@ -206,15 +196,18 @@ files:
|
|
206
196
|
- test/basepack_test_app/config/boot.rb
|
207
197
|
- test/basepack_test_app/config/cucumber.yml
|
208
198
|
- test/basepack_test_app/config/database.yml.sample
|
199
|
+
- test/basepack_test_app/config/database.yml.travis
|
209
200
|
- test/basepack_test_app/config/environment.rb
|
210
201
|
- test/basepack_test_app/config/environments/development.rb
|
211
202
|
- test/basepack_test_app/config/environments/production.rb
|
212
203
|
- test/basepack_test_app/config/environments/test.rb
|
213
204
|
- test/basepack_test_app/config/initializers/backtrace_silencers.rb
|
205
|
+
- test/basepack_test_app/config/initializers/data_mapper_logging.rb
|
214
206
|
- test/basepack_test_app/config/initializers/inflections.rb
|
215
207
|
- test/basepack_test_app/config/initializers/mime_types.rb
|
216
208
|
- test/basepack_test_app/config/initializers/netzke.rb
|
217
209
|
- test/basepack_test_app/config/initializers/secret_token.rb
|
210
|
+
- test/basepack_test_app/config/initializers/sequel.rb
|
218
211
|
- test/basepack_test_app/config/initializers/session_store.rb
|
219
212
|
- test/basepack_test_app/config/locales/de.yml
|
220
213
|
- test/basepack_test_app/config/locales/es.yml
|
@@ -261,6 +254,7 @@ files:
|
|
261
254
|
- test/basepack_test_app/features/window.feature
|
262
255
|
- test/basepack_test_app/lib/tasks/.gitkeep
|
263
256
|
- test/basepack_test_app/lib/tasks/cucumber.rake
|
257
|
+
- test/basepack_test_app/lib/tasks/travis.rake
|
264
258
|
- test/basepack_test_app/public/404.html
|
265
259
|
- test/basepack_test_app/public/422.html
|
266
260
|
- test/basepack_test_app/public/500.html
|
@@ -277,10 +271,11 @@ files:
|
|
277
271
|
- test/basepack_test_app/public/stylesheets/.gitkeep
|
278
272
|
- test/basepack_test_app/script/cucumber
|
279
273
|
- test/basepack_test_app/script/rails
|
280
|
-
- test/basepack_test_app/spec/active_record/attributes_spec.rb
|
281
|
-
- test/basepack_test_app/spec/active_record/relation_extensions_spec.rb
|
282
274
|
- test/basepack_test_app/spec/components/form_panel_spec.rb
|
283
275
|
- test/basepack_test_app/spec/components/grid_panel_spec.rb
|
276
|
+
- test/basepack_test_app/spec/data_adapter/adapter_spec.rb
|
277
|
+
- test/basepack_test_app/spec/data_adapter/attributes_spec.rb
|
278
|
+
- test/basepack_test_app/spec/data_adapter/relation_extensions_spec.rb
|
284
279
|
- test/basepack_test_app/spec/factories.rb
|
285
280
|
- test/basepack_test_app/spec/spec_helper.rb
|
286
281
|
- test/basepack_test_app/test/performance/browsing_test.rb
|
@@ -1,261 +0,0 @@
|
|
1
|
-
# TODO: clean up, document and test
|
2
|
-
class NetzkeFieldList < ActiveRecord::Base
|
3
|
-
belongs_to :user
|
4
|
-
belongs_to :role
|
5
|
-
belongs_to :parent, :class_name => "NetzkeFieldList"
|
6
|
-
has_many :children, :class_name => "NetzkeFieldList", :foreign_key => "parent_id"
|
7
|
-
|
8
|
-
|
9
|
-
def self.update_fields(owner_id, attrs_hash)
|
10
|
-
self.find_all_below_current_authority_level(owner_id).each do |list|
|
11
|
-
list.update_attrs(attrs_hash)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Updates attributes in the list
|
16
|
-
def update_attrs(attrs_hash)
|
17
|
-
list = ActiveSupport::JSON.decode(self.value)
|
18
|
-
list.each do |field|
|
19
|
-
field.merge!(attrs_hash[field["name"]]) if attrs_hash[field["name"]]
|
20
|
-
end
|
21
|
-
update_attribute(:value, list.to_json)
|
22
|
-
end
|
23
|
-
|
24
|
-
def append_attr(attr_hash)
|
25
|
-
list = ActiveSupport::JSON.decode(self.value)
|
26
|
-
list << attr_hash
|
27
|
-
update_attribute(:value, list.to_json)
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.find_all_below_current_authority_level(pref_name)
|
31
|
-
authority_level, authority_id = Netzke::Base.authority_level
|
32
|
-
case authority_level
|
33
|
-
when :world
|
34
|
-
self.all(:conditions => {:name => pref_name})
|
35
|
-
when :role
|
36
|
-
role = Role.find(authority_id)
|
37
|
-
role.users.inject([]) do |r, user|
|
38
|
-
r += self.all(:conditions => {:user_id => user.id, :name => pref_name})
|
39
|
-
end
|
40
|
-
else
|
41
|
-
[]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.find_all_lists_under_current_authority(model_name)
|
46
|
-
authority_level, authority_id = Netzke::Base.authority_level
|
47
|
-
case authority_level
|
48
|
-
when :world
|
49
|
-
self.all(:conditions => {:model_name => model_name})
|
50
|
-
when :role
|
51
|
-
role = Role.find(authority_id)
|
52
|
-
role.users.inject([]) do |r, user|
|
53
|
-
r += self.all(:conditions => {:user_id => user.id, :model_name => model_name})
|
54
|
-
end
|
55
|
-
when :user
|
56
|
-
self.all(:conditions => {:user_id => authority_id, :model_name => model_name})
|
57
|
-
when :self
|
58
|
-
self.all(:conditions => {:user_id => authority_id, :model_name => model_name})
|
59
|
-
else
|
60
|
-
[]
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
# Replaces the list with the data - only for the list found for the current authority.
|
67
|
-
# If the list is not found, it's created.
|
68
|
-
def self.update_list_for_current_authority(pref_name, data, model_name = nil)
|
69
|
-
pref = find_or_create_pref_to_read(pref_name)
|
70
|
-
pref.value = data.to_json
|
71
|
-
pref.model_name = model_name
|
72
|
-
pref.save!
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
# If the <tt>model</tt> param is provided, then this preference will be assigned a parent preference
|
77
|
-
# that configures the attributes for that model. This way we can track all preferences related to a model.
|
78
|
-
def self.write_list(name, list, model = nil)
|
79
|
-
pref_to_store_the_list = self.pref_to_write(name)
|
80
|
-
pref_to_store_the_list.try(:update_attribute, :value, list.to_json)
|
81
|
-
|
82
|
-
# link this preference to the parent that contains default attributes for the same model
|
83
|
-
if model
|
84
|
-
model_level_attrs_pref = self.pref_to_read("#{model.tableize}_model_attrs")
|
85
|
-
model_level_attrs_pref.children << pref_to_store_the_list if model_level_attrs_pref && pref_to_store_the_list
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.read_list(name)
|
90
|
-
json_encoded_value = self.pref_to_read(name).try(:value)
|
91
|
-
ActiveSupport::JSON.decode(json_encoded_value).map(&:symbolize_keys) if json_encoded_value
|
92
|
-
end
|
93
|
-
|
94
|
-
# Read model-level attrs
|
95
|
-
# def self.read_attrs_for_model(model_name)
|
96
|
-
# read_list(model_name)
|
97
|
-
# # read_list("#{model.tableize}_model_attrs")
|
98
|
-
# end
|
99
|
-
|
100
|
-
# Write model-level attrs
|
101
|
-
# def self.write_attrs_for_model(model_name, data)
|
102
|
-
# # write_list("#{model_name.tableize}_model_attrs", data)
|
103
|
-
# write_list(model_name, data)
|
104
|
-
# end
|
105
|
-
|
106
|
-
# Options:
|
107
|
-
# :attr - attribute to propagate. If not specified, all attrs found in configuration for the model
|
108
|
-
# will be propagated.
|
109
|
-
def self.update_children_on_attr(model, options = {})
|
110
|
-
attr_name = options[:attr].try(:to_s)
|
111
|
-
|
112
|
-
parent_pref = pref_to_read("#{model.tableize}_model_attrs")
|
113
|
-
|
114
|
-
if parent_pref
|
115
|
-
parent_list = ActiveSupport::JSON.decode(parent_pref.value)
|
116
|
-
parent_pref.children.each do |ch|
|
117
|
-
child_list = ActiveSupport::JSON.decode(ch.value)
|
118
|
-
|
119
|
-
if attr_name
|
120
|
-
# propagate a certain attribute
|
121
|
-
propagate_attr(attr_name, parent_list, child_list)
|
122
|
-
else
|
123
|
-
# propagate all attributes found in parent
|
124
|
-
all_attrs = parent_list.first.try(:keys)
|
125
|
-
all_attrs && all_attrs.each{ |attr_name| propagate_attr(attr_name, parent_list, child_list) }
|
126
|
-
end
|
127
|
-
|
128
|
-
ch.update_attribute(:value, child_list.to_json)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# meta_attrs:
|
134
|
-
# {"city"=>{"included"=>true}, "building_number"=>{"default_value"=>100}}
|
135
|
-
def self.update_children(model, meta_attrs)
|
136
|
-
parent_pref = pref_to_read("#{model.tableize}_model_attrs")
|
137
|
-
|
138
|
-
|
139
|
-
if parent_pref
|
140
|
-
parent_pref.children.each do |ch|
|
141
|
-
child_list = ActiveSupport::JSON.decode(ch.value)
|
142
|
-
|
143
|
-
meta_attrs.each_pair do |k,v|
|
144
|
-
child_list.detect{ |child_attr| child_attr["name"] == k }.try(:merge!, v)
|
145
|
-
end
|
146
|
-
|
147
|
-
ch.update_attribute(:value, child_list.to_json)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
private
|
153
|
-
|
154
|
-
def self.propagate_attr(attr_name, src_list, dest_list)
|
155
|
-
for src_field in src_list
|
156
|
-
dest_field = dest_list.detect{ |df| df["name"] == src_field["name"] }
|
157
|
-
dest_field[attr_name] = src_field[attr_name] if dest_field && src_field[attr_name]
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
# Overwrite pref_to_read, pref_to_write methods, and find_all_for_component if you want a different way of
|
162
|
-
# identifying the proper preference based on your own authorization strategy.
|
163
|
-
#
|
164
|
-
# The default strategy is:
|
165
|
-
# 1) if no masq_user or masq_role defined
|
166
|
-
# pref_to_read will search for the preference for user first, then for user's role
|
167
|
-
# pref_to_write will always find or create a preference for the current user (never for its role)
|
168
|
-
# 2) if masq_user or masq_role is defined
|
169
|
-
# pref_to_read and pref_to_write will always take the masquerade into account, e.g. reads/writes will go to
|
170
|
-
# the user/role specified
|
171
|
-
#
|
172
|
-
def self.pref_to_read(name)
|
173
|
-
name = name.to_s
|
174
|
-
session = Netzke::Base.session
|
175
|
-
cond = {:name => name}
|
176
|
-
|
177
|
-
if session[:masq_user]
|
178
|
-
# first, get the prefs for this user it they exist
|
179
|
-
res = self.find(:first, :conditions => cond.merge({:user_id => session[:masq_user]}))
|
180
|
-
# if it doesn't exist, get them for the user's role
|
181
|
-
user = User.find(session[:masq_user])
|
182
|
-
res ||= self.find(:first, :conditions => cond.merge({:role_id => user.role.id}))
|
183
|
-
# if it doesn't exist either, get them for the World (role_id = 0)
|
184
|
-
res ||= self.find(:first, :conditions => cond.merge({:role_id => 0}))
|
185
|
-
elsif session[:masq_role]
|
186
|
-
# first, get the prefs for this role
|
187
|
-
res = self.find(:first, :conditions => cond.merge({:role_id => session[:masq_role]}))
|
188
|
-
# if it doesn't exist, get them for the World (role_id = 0)
|
189
|
-
res ||= self.find(:first, :conditions => cond.merge({:role_id => 0}))
|
190
|
-
elsif session[:masq_world]
|
191
|
-
res = self.find(:first, :conditions => cond.merge({:role_id => 0}))
|
192
|
-
elsif session[:netzke_user_id]
|
193
|
-
user = User.find(session[:netzke_user_id])
|
194
|
-
# first, get the prefs for this user
|
195
|
-
res = self.find(:first, :conditions => cond.merge({:user_id => user.id}))
|
196
|
-
# if it doesn't exist, get them for the user's role
|
197
|
-
res ||= self.find(:first, :conditions => cond.merge({:role_id => user.role.id}))
|
198
|
-
# if it doesn't exist either, get them for the World (role_id = 0)
|
199
|
-
res ||= self.find(:first, :conditions => cond.merge({:role_id => 0}))
|
200
|
-
else
|
201
|
-
res = self.find(:first, :conditions => cond)
|
202
|
-
end
|
203
|
-
|
204
|
-
res
|
205
|
-
end
|
206
|
-
|
207
|
-
def self.find_or_create_pref_to_read(name)
|
208
|
-
name = name.to_s
|
209
|
-
attrs = {:name => name}
|
210
|
-
extend_attrs_for_current_authority(attrs)
|
211
|
-
self.first(:conditions => attrs) || self.new(attrs)
|
212
|
-
end
|
213
|
-
|
214
|
-
def self.extend_attrs_for_current_authority(hsh)
|
215
|
-
authority_level, authority_id = Netzke::Base.authority_level
|
216
|
-
case authority_level
|
217
|
-
when :world
|
218
|
-
hsh.merge!(:role_id => 0)
|
219
|
-
when :role
|
220
|
-
hsh.merge!(:role_id => authority_id)
|
221
|
-
when :user
|
222
|
-
hsh.merge!(:user_id => authority_id)
|
223
|
-
when :self
|
224
|
-
hsh.merge!(:user_id => authority_id)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
def self.pref_to_write(name)
|
229
|
-
name = name.to_s
|
230
|
-
session = Netzke::Base.session
|
231
|
-
cond = {:name => name}
|
232
|
-
|
233
|
-
if session[:masq_user]
|
234
|
-
cond.merge!({:user_id => session[:masq_user]})
|
235
|
-
# first, try to find the preference for masq_user
|
236
|
-
res = self.find(:first, :conditions => cond)
|
237
|
-
# if it doesn't exist, create it
|
238
|
-
res ||= self.new(cond)
|
239
|
-
elsif session[:masq_role]
|
240
|
-
# first, delete all the corresponding preferences for the users that have this role
|
241
|
-
Role.find(session[:masq_role]).users.each do |u|
|
242
|
-
self.delete_all(cond.merge({:user_id => u.id}))
|
243
|
-
end
|
244
|
-
cond.merge!({:role_id => session[:masq_role]})
|
245
|
-
res = self.find(:first, :conditions => cond)
|
246
|
-
res ||= self.new(cond)
|
247
|
-
elsif session[:masq_world]
|
248
|
-
# first, delete all the corresponding preferences for all users and roles
|
249
|
-
self.delete_all(cond)
|
250
|
-
# then, create the new preference for the World (role_id = 0)
|
251
|
-
res = self.new(cond.merge(:role_id => 0))
|
252
|
-
elsif session[:netzke_user_id]
|
253
|
-
res = self.find(:first, :conditions => cond.merge({:user_id => session[:netzke_user_id]}))
|
254
|
-
res ||= self.new(cond.merge({:user_id => session[:netzke_user_id]}))
|
255
|
-
else
|
256
|
-
res = self.find(:first, :conditions => cond)
|
257
|
-
res ||= self.new(cond)
|
258
|
-
end
|
259
|
-
res
|
260
|
-
end
|
261
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# Holds attribute lists for application models.
|
2
|
-
# Is used to configure attributes in the layer between a model and its representation in the Netzke application, thus providing default attributes
|
3
|
-
# for grids and panels.
|
4
|
-
class NetzkeModelAttrList < NetzkeFieldList
|
5
|
-
|
6
|
-
# Updates attributes for all lists owned by owner_id and below the current authority level
|
7
|
-
def self.update_fields(owner_id, attrs_hash)
|
8
|
-
super
|
9
|
-
|
10
|
-
NetzkeFieldList.find_all_lists_under_current_authority(owner_id).each do |list|
|
11
|
-
list.update_attrs(attrs_hash)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.add_attrs(attrs)
|
16
|
-
NetzkeFieldList.find_all_lists_under_current_authority(owner_id).each do |list|
|
17
|
-
attrs.each{ |attr_hash| list.append_attr(attr_hash) }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|