knitkit 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/README.md +22 -0
  2. data/app/controllers/knitkit/base_controller.rb +15 -2
  3. data/app/controllers/knitkit/blogs_controller.rb +4 -4
  4. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +16 -2
  5. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +198 -57
  6. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +25 -11
  7. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +123 -44
  8. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +83 -9
  9. data/app/controllers/knitkit/erp_app/desktop/online_document_sections_controller.rb +38 -0
  10. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +15 -6
  11. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +185 -98
  12. data/app/controllers/knitkit/erp_app/desktop/versions_controller.rb +38 -16
  13. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +126 -68
  14. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +154 -107
  15. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +113 -54
  16. data/app/controllers/knitkit/online_document_sections_controller.rb +45 -0
  17. data/app/controllers/knitkit/unauthorized_controller.rb +5 -0
  18. data/app/controllers/knitkit/website_sections_controller.rb +8 -9
  19. data/app/mailers/document_mailer.rb +10 -0
  20. data/app/models/article.rb +1 -1
  21. data/app/models/content.rb +35 -3
  22. data/app/models/document.rb +8 -0
  23. data/app/models/document_type.rb +3 -0
  24. data/app/models/documented_content.rb +29 -0
  25. data/app/models/documented_item.rb +31 -0
  26. data/app/models/extensions/configuration.rb +5 -0
  27. data/app/models/extensions/party.rb +13 -0
  28. data/app/models/online_document_section.rb +40 -0
  29. data/app/models/theme.rb +22 -26
  30. data/app/models/valid_document.rb +4 -0
  31. data/app/models/website.rb +158 -119
  32. data/app/models/website_inquiry.rb +7 -2
  33. data/app/models/website_inquiry_mailer.rb +4 -3
  34. data/app/models/website_party_role.rb +5 -0
  35. data/app/models/website_section.rb +76 -38
  36. data/app/views/document_mailer/email_document.html.erb +12 -0
  37. data/app/views/knitkit/blogs/_add_comment.html.erb +2 -2
  38. data/app/views/knitkit/online_document_sections/index.html.erb +149 -0
  39. data/app/views/knitkit/website_sections/index.html.erb +0 -1
  40. data/app/views/layouts/knitkit/base.html.erb +4 -2
  41. data/app/views/layouts/knitkit/online_document_sections.html.erb +59 -0
  42. data/app/views/menus/knitkit/_default_menu.html.erb +1 -1
  43. data/app/views/menus/knitkit/_default_section_menu.html.erb +1 -1
  44. data/app/views/menus/knitkit/_default_sub_menu.html.erb +2 -2
  45. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +1 -1
  46. data/app/widgets/contact_us/base.rb +5 -5
  47. data/app/widgets/contact_us/javascript/contact_us.js +2 -1
  48. data/app/widgets/google_map/base.rb +0 -4
  49. data/app/widgets/google_map/javascript/google_map.js +4 -3
  50. data/app/widgets/login/base.rb +0 -5
  51. data/app/widgets/login/javascript/login.js +155 -153
  52. data/app/widgets/login/views/index.html.erb +3 -3
  53. data/app/widgets/login/views/reset_password.html.erb +2 -2
  54. data/app/widgets/manage_profile/base.rb +46 -67
  55. data/app/widgets/manage_profile/javascript/manage_profile.js +2 -1
  56. data/app/widgets/manage_profile/views/_user_information_form.html.erb +5 -1
  57. data/app/widgets/reset_password/base.rb +4 -6
  58. data/app/widgets/reset_password/javascript/reset_password.js +2 -1
  59. data/app/widgets/reset_password/views/index.html.erb +4 -3
  60. data/app/widgets/search/base.rb +1 -5
  61. data/app/widgets/search/javascript/search.js +2 -1
  62. data/app/widgets/search/views/show.html.erb +2 -2
  63. data/app/widgets/signup/base.rb +7 -6
  64. data/app/widgets/signup/javascript/signup.js +2 -1
  65. data/app/widgets/signup/views/error.html.erb +1 -1
  66. data/config/routes.rb +6 -2
  67. data/db/data_migrations/20110509223702_add_publisher_role.rb +10 -0
  68. data/db/data_migrations/20111118182910_setup_knitkit_capabilities.rb +84 -0
  69. data/db/data_migrations/20120127144444_create_website_role_types.rb +13 -0
  70. data/db/data_migrations/20120127150505_create_website_default_configuration.rb +72 -0
  71. data/db/data_migrations/20120127150506_add_primary_host_to_website_configuration.rb +33 -0
  72. data/db/data_migrations/20120316150424_add_is_template_to_default_website_config.rb +16 -0
  73. data/db/data_migrations/upgrade/20120210195616_add_website_configs.rb +19 -0
  74. data/db/data_migrations/upgrade/20120213205519_populate_website_iids.rb +17 -0
  75. data/db/migrate/20110211002317_setup_knitkit.rb +22 -5
  76. data/db/migrate/20111207161928_create_documented_items_table.rb +13 -0
  77. data/db/migrate/20111208180539_add_document_id_to_documented_item.rb +9 -0
  78. data/db/migrate/20120315163736_add_document.rb +32 -0
  79. data/db/migrate/20120503183431_create_valid_documents.rb +16 -0
  80. data/db/migrate/upgrade/20120116201510_add_render_base_layout_flag.rb +13 -0
  81. data/db/migrate/upgrade/20120127143745_create_website_party_roles.rb +24 -0
  82. data/db/migrate/upgrade/20120213184509_add_iid_to_websites.rb +14 -0
  83. data/lib/knitkit.rb +2 -0
  84. data/lib/knitkit/config.rb +31 -0
  85. data/lib/knitkit/engine.rb +12 -3
  86. data/lib/knitkit/extensions.rb +1 -3
  87. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +2 -3
  88. data/lib/knitkit/extensions/active_record/acts_as_document.rb +63 -0
  89. data/lib/knitkit/extensions/active_record/acts_as_publishable.rb +5 -4
  90. data/lib/knitkit/extensions/compass_ae/widgets/base.rb +70 -0
  91. data/lib/knitkit/extensions/railties/action_view.rb +22 -10
  92. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +3 -3
  93. data/lib/knitkit/extensions/railties/theme_support/theme_file_resolver.rb +8 -3
  94. data/lib/knitkit/routing_filter/section_router.rb +16 -6
  95. data/lib/knitkit/version.rb +7 -1
  96. data/public/images/check.png +0 -0
  97. data/public/images/credit_card.png +0 -0
  98. data/public/images/knitkit/tooltip.gif +0 -0
  99. data/public/javascripts/ajax_pagination.js +33 -0
  100. data/public/javascripts/datepicker.js +6 -1
  101. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +731 -258
  102. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +289 -238
  103. data/public/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +2 -4
  104. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +29 -3
  105. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +193 -21
  106. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +27 -26
  107. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +167 -20
  108. data/public/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +1 -2
  109. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +5 -1
  110. data/public/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +2 -2
  111. data/public/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +20 -11
  112. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +279 -228
  113. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +40 -40
  114. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +83 -76
  115. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +1961 -1397
  116. data/public/javascripts/erp_app/desktop/applications/knitkit/widgets_panel.js +47 -43
  117. data/public/javascripts/knitkit/helpers.js +26 -0
  118. data/public/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +1 -2
  119. data/public/stylesheets/knitkit/documentation.css +50 -0
  120. data/public/stylesheets/knitkit/style.css +23 -1
  121. data/spec/controllers/knitkit/erp_app/desktop/articles_controller_spec.rb +8 -0
  122. data/spec/controllers/knitkit/erp_app/desktop/website_controller_spec.rb +396 -0
  123. data/spec/controllers/knitkit/erp_app/desktop/website_nav_controller_spec.rb +260 -0
  124. data/spec/controllers/knitkit/erp_app/desktop/website_section_controller_spec.rb +222 -0
  125. data/spec/dummy/Rakefile +7 -0
  126. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  127. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  128. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  129. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  130. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  131. data/spec/dummy/config.ru +4 -0
  132. data/spec/dummy/config/application.rb +43 -0
  133. data/spec/dummy/config/boot.rb +10 -0
  134. data/spec/dummy/config/database.yml +8 -0
  135. data/spec/dummy/config/environment.rb +5 -0
  136. data/spec/dummy/config/environments/spec.rb +27 -0
  137. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  138. data/spec/dummy/config/initializers/inflections.rb +10 -0
  139. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  140. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  141. data/spec/dummy/config/initializers/session_store.rb +8 -0
  142. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  143. data/spec/dummy/config/locales/en.yml +5 -0
  144. data/spec/dummy/config/routes.rb +4 -0
  145. data/spec/dummy/config/workflow.yml +1 -0
  146. data/spec/dummy/public/404.html +26 -0
  147. data/spec/dummy/public/422.html +26 -0
  148. data/spec/dummy/public/500.html +26 -0
  149. data/spec/dummy/public/favicon.ico +0 -0
  150. data/spec/dummy/script/rails +6 -0
  151. data/spec/factories/article.rb +4 -0
  152. data/spec/factories/basic.rb +3 -0
  153. data/spec/factories/blog.rb +5 -0
  154. data/spec/factories/documented_content.rb +4 -0
  155. data/spec/factories/documented_item.rb +4 -0
  156. data/spec/factories/online_document_section.rb +6 -0
  157. data/spec/factories/published_website.rb +4 -0
  158. data/spec/factories/theme.rb +6 -0
  159. data/spec/factories/website.rb +5 -0
  160. data/spec/factories/website_host.rb +4 -0
  161. data/spec/factories/website_nav.rb +5 -0
  162. data/spec/factories/website_nav_item.rb +4 -0
  163. data/spec/factories/website_section.rb +5 -0
  164. data/spec/models/article_spec.rb +35 -0
  165. data/spec/models/attribute_type_spec.rb +55 -0
  166. data/spec/models/attribute_value_spec.rb +114 -0
  167. data/spec/models/blog_spec.rb +16 -0
  168. data/spec/models/comment_spec.rb +11 -0
  169. data/spec/models/content_spec.rb +187 -0
  170. data/spec/models/documented_item_spec.rb +29 -0
  171. data/spec/models/online_document_section_spec.rb +34 -0
  172. data/spec/models/published_element_spec.rb +11 -0
  173. data/spec/models/published_website_spec.rb +11 -0
  174. data/spec/models/theme_spec.rb +12 -0
  175. data/spec/models/website_host_spec.rb +11 -0
  176. data/spec/models/website_inquiry_spec.rb +24 -0
  177. data/spec/models/website_nav_item_spec.rb +11 -0
  178. data/spec/models/website_nav_spec.rb +11 -0
  179. data/spec/models/website_section_content_spec.rb +11 -0
  180. data/spec/models/website_section_spec.rb +49 -0
  181. data/spec/models/website_spec.rb +146 -0
  182. data/spec/spec_helper.rb +61 -0
  183. metadata +391 -154
  184. data/app/controllers/knitkit/articles_controller.rb +0 -7
  185. data/lib/knitkit/extensions/compass/widgets/base.rb +0 -53
@@ -34,23 +34,44 @@ module Knitkit
34
34
  end
35
35
 
36
36
  def new
37
- unless params[:theme_data].blank?
38
- @website.themes.import(params[:theme_data], @website)
39
- else
40
- theme = Theme.create(:website => @website, :name => params[:name], :theme_id => params[:theme_id])
41
- theme.version = params[:version]
42
- theme.author = params[:author]
43
- theme.homepage = params[:homepage]
44
- theme.summary = params[:summary]
45
- theme.save
46
- theme.create_theme_files!
47
- end
37
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
38
+ begin
39
+ current_user.with_capability(model, 'view', 'Theme') do
40
+ unless params[:theme_data].blank?
41
+ @website.themes.import(params[:theme_data], @website)
42
+ else
43
+ theme = Theme.create(:website => @website, :name => params[:name], :theme_id => params[:theme_id])
44
+ theme.version = params[:version]
45
+ theme.author = params[:author]
46
+ theme.homepage = params[:homepage]
47
+ theme.summary = params[:summary]
48
+ theme.save
49
+ theme.create_theme_files!
50
+ end
48
51
 
49
- render :inline => {:success => true}.to_json
52
+ render :inline => {:success => true}.to_json
53
+ end
54
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
55
+ render :json => {:success => false, :message => ex.message}
56
+ end
50
57
  end
51
58
 
52
59
  def delete
53
- render :json => @theme.destroy ? {:success => true} : {:success => false}
60
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
61
+ begin
62
+ current_user.with_capability(model, 'view', 'Theme') do
63
+ if @theme.destroy
64
+ #clear resolver cache
65
+ path = File.join("#{@theme[:url]}","templates")
66
+ cached_resolver = ThemeSupport::Cache.theme_resolvers.find{|cached_resolver| cached_resolver.to_path == path}
67
+ render :json => {:success => true}
68
+ else
69
+ render :json => {:success => false}
70
+ end
71
+ end
72
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
73
+ render :json => {:success => false, :message => ex.message}
74
+ end
54
75
  end
55
76
 
56
77
  def export
@@ -62,11 +83,18 @@ module Knitkit
62
83
  end
63
84
 
64
85
  def change_status
65
- #clear active themes
66
- @website.deactivate_themes! if (params[:active] == 'true')
67
- (params[:active] == 'true') ? @theme.activate! : @theme.deactivate!
86
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
87
+ begin
88
+ current_user.with_capability(model, 'view', 'Theme') do
89
+ #clear active themes
90
+ @website.deactivate_themes! if (params[:active] == 'true')
91
+ (params[:active] == 'true') ? @theme.activate! : @theme.deactivate!
68
92
 
69
- render :json => {:success => true}
93
+ render :json => {:success => true}
94
+ end
95
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
96
+ render :json => {:success => false, :message => ex.message}
97
+ end
70
98
  end
71
99
 
72
100
  ##############################################################
@@ -76,60 +104,94 @@ module Knitkit
76
104
  ##############################################################
77
105
 
78
106
  def create_file
79
- path = File.join(@file_support.root,params[:path])
80
- name = params[:name]
107
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
108
+ begin
109
+ current_user.with_capability(model, 'view', 'Theme') do
110
+ path = File.join(@file_support.root,params[:path])
111
+ name = params[:name]
81
112
 
82
- theme = get_theme(path)
83
- theme.add_file('#Empty File', File.join(path, name))
113
+ theme = get_theme(path)
114
+ theme.add_file('#Empty File', File.join(path, name))
84
115
 
85
- render :json => {:success => true}
116
+ render :json => {:success => true}
117
+ end
118
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
119
+ render :json => {:success => false, :message => ex.message}
120
+ end
86
121
  end
87
122
 
88
123
  def create_folder
89
- path = File.join(@file_support.root,params[:path])
90
- name = params[:name]
124
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
125
+ begin
126
+ current_user.with_capability(model, 'view', 'Theme') do
127
+ path = File.join(@file_support.root,params[:path])
128
+ name = params[:name]
91
129
 
92
- @file_support.create_folder(path, name)
93
- render :json => {:success => true}
130
+ @file_support.create_folder(path, name)
131
+ render :json => {:success => true}
132
+ end
133
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
134
+ render :json => {:success => false, :message => ex.message}
135
+ end
94
136
  end
95
137
 
96
138
  def update_file
97
- path = File.join(@file_support.root,params[:node])
98
- content = params[:content]
139
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
140
+ begin
141
+ current_user.with_capability(model, 'view', 'Theme') do
142
+ path = File.join(@file_support.root,params[:node])
143
+ content = params[:content]
99
144
 
100
- type = File.extname(File.basename(path)).gsub(/^\.+/, '').to_sym
101
- result = Knitkit::SyntaxValidator.validate_content(type, content)
145
+ type = File.extname(File.basename(path)).gsub(/^\.+/, '').to_sym
146
+ result = Knitkit::SyntaxValidator.validate_content(type, content)
102
147
 
103
- unless result
104
- @file_support.update_file(path, content)
105
- render :json => {:success => true}
106
- else
107
- render :json => {:success => false, :message => result}
148
+ unless result
149
+ @file_support.update_file(path, content)
150
+ render :json => {:success => true}
151
+ else
152
+ render :json => {:success => false, :message => result}
153
+ end
154
+ end
155
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
156
+ render :json => {:success => false, :message => ex.message}
108
157
  end
109
158
  end
110
159
 
111
160
  def save_move
112
- result = {}
113
- path = params[:node]
114
- new_parent_path = params[:parent_node]
115
- new_parent_path = base_path if new_parent_path == ROOT_NODE
161
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
162
+ begin
163
+ current_user.with_capability(model, 'view', 'Theme') do
164
+ result = {}
165
+ path = File.join(@file_support.root, params[:node])
166
+ new_parent_path = File.join(@file_support.root, params[:parent_node])
116
167
 
117
- unless @file_support.exists? path
118
- result = {:success => false, :msg => 'File does not exists'}
119
- else
120
- theme_file = get_theme_file(path)
121
- theme_file.move(new_parent_path)
122
- result = {:success => true, :msg => "#{File.basename(path)} was moved to #{new_parent_path} successfully"}
123
- end
168
+ unless @file_support.exists? path
169
+ result = {:success => false, :msg => 'File does not exist.'}
170
+ else
171
+ theme_file = get_theme_file(path)
172
+ theme_file.move(params[:parent_node])
173
+ result = {:success => true, :msg => "#{File.basename(path)} was moved to #{new_parent_path} successfully"}
174
+ end
124
175
 
125
- render :json => result
176
+ render :json => result
177
+ end
178
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
179
+ render :json => {:success => false, :message => ex.message}
180
+ end
126
181
  end
127
182
 
128
183
  def download_file
129
- path = File.join(@file_support.root,params[:path])
130
- contents, message = @file_support.get_contents(path)
184
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
185
+ begin
186
+ current_user.with_capability(model, 'view', 'Theme') do
187
+ path = File.join(@file_support.root,params[:path])
188
+ contents, message = @file_support.get_contents(path)
131
189
 
132
- send_data contents, :filename => File.basename(path)
190
+ send_data contents, :filename => File.basename(path)
191
+ end
192
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
193
+ render :json => {:success => false, :message => ex.message}
194
+ end
133
195
  end
134
196
 
135
197
  def get_contents
@@ -144,58 +206,82 @@ module Knitkit
144
206
  end
145
207
 
146
208
  def upload_file
147
- result = {}
148
- upload_path = request.env['HTTP_EXTRAPOSTDATA_DIRECTORY'].blank? ? params[:directory] : request.env['HTTP_EXTRAPOSTDATA_DIRECTORY']
149
- name = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data].original_filename : request.env['HTTP_X_FILE_NAME']
150
- data = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data] : request.raw_post
151
-
152
- theme = get_theme(upload_path)
153
- name = File.join(@file_support.root, upload_path, name)
154
-
209
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
155
210
  begin
156
- theme.add_file(data, name)
157
- result = {:success => true}
158
- rescue Exception=>ex
159
- logger.error ex.message
160
- logger.error ex.backtrace.join("\n")
161
- result = {:success => false, :error => "Error uploading #{name}"}
162
- end
211
+ current_user.with_capability(model, 'view', 'Theme') do
212
+ result = {}
213
+ upload_path = request.env['HTTP_EXTRAPOSTDATA_DIRECTORY'].blank? ? params[:directory] : request.env['HTTP_EXTRAPOSTDATA_DIRECTORY']
214
+ name = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data].original_filename : request.env['HTTP_X_FILE_NAME']
215
+ data = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data] : request.raw_post
216
+
217
+ theme = get_theme(upload_path)
218
+ name = File.join(@file_support.root, upload_path, name)
219
+
220
+ begin
221
+ theme.add_file(data, name)
222
+ result = {:success => true}
223
+ rescue Exception=>ex
224
+ logger.error ex.message
225
+ logger.error ex.backtrace.join("\n")
226
+ result = {:success => false, :error => "Error uploading #{name}"}
227
+ end
163
228
 
164
- render :inline => result.to_json
229
+ render :inline => result.to_json
230
+ end
231
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
232
+ render :json => {:success => false, :message => ex.message}
233
+ end
165
234
  end
166
235
 
167
236
  def delete_file
168
- path = params[:node]
169
- result = {}
237
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
170
238
  begin
171
- name = File.basename(path)
172
- result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,path))
173
- if result && !is_folder
174
- theme_file = get_theme_file(path)
175
- theme_file.destroy
239
+ current_user.with_capability(model, 'view', 'Theme') do
240
+ path = params[:node]
241
+ result = {}
242
+ begin
243
+ name = File.basename(path)
244
+ result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,path))
245
+ if result && !is_folder
246
+ theme_file = get_theme_file(path)
247
+ theme_file.destroy
248
+ #clear resolver cache
249
+ path = File.join("#{@theme[:url]}","templates")
250
+ cached_resolver = ThemeSupport::Cache.theme_resolvers.find{|cached_resolver| cached_resolver.to_path == path}
251
+ end
252
+ result = {:success => result, :error => message}
253
+ rescue Exception=>ex
254
+ logger.error ex.message
255
+ logger.error ex.backtrace.join("\n")
256
+ result = {:success => false, :error => "Error deleting #{name}"}
257
+ end
258
+ render :json => result
176
259
  end
177
- result = {:success => result, :error => message}
178
- rescue Exception=>ex
179
- logger.error ex.message
180
- logger.error ex.backtrace.join("\n")
181
- result = {:success => false, :error => "Error deleting #{name}"}
260
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
261
+ render :json => {:success => false, :message => ex.message}
182
262
  end
183
- render :json => result
184
263
  end
185
264
 
186
265
  def rename_file
187
- result = {:success => true, :data => {:success => true}}
188
- path = params[:node]
189
- name = params[:file_name]
190
-
191
- result, message = @file_support.rename_file(path, name)
192
- if result
193
- theme_file = get_theme_file(path)
194
- theme_file.name = name
195
- theme_file.save
196
- end
266
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
267
+ begin
268
+ current_user.with_capability(model, 'view', 'Theme') do
269
+ result = {:success => true, :data => {:success => true}}
270
+ path = params[:node]
271
+ name = params[:file_name]
272
+
273
+ result, message = @file_support.rename_file(@file_support.root+path, name)
274
+ if result
275
+ theme_file = get_theme_file(path)
276
+ theme_file.name = name
277
+ theme_file.save
278
+ end
197
279
 
198
- render :json => {:success => true, :message => message}
280
+ render :json => {:success => true, :message => message}
281
+ end
282
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
283
+ render :json => {:success => false, :message => ex.message}
284
+ end
199
285
  end
200
286
 
201
287
  protected
@@ -204,19 +290,20 @@ module Knitkit
204
290
  sites_index = path.index('sites')
205
291
  sites_path = path[sites_index..path.length]
206
292
  site_name = sites_path.split('/')[1]
207
- site = Website.find(site_name.split('-')[1])
293
+ site = Website.find_by_internal_identifier(site_name)
208
294
 
209
295
  themes_index = path.index('themes')
210
296
  path = path[themes_index..path.length]
211
297
  theme_name = path.split('/')[1]
212
- theme = site.themes.find_by_theme_id(theme_name)
298
+ @theme = site.themes.find_by_theme_id(theme_name)
213
299
 
214
- theme
300
+ @theme
215
301
  end
216
302
 
217
303
  def get_theme_file(path)
218
304
  theme = get_theme(path)
219
- theme.files.where('name = ? and directory = ?', ::File.basename(path), ::File.dirname(path)).first
305
+ file_dir = ::File.dirname(path).gsub(Regexp.new(Rails.root.to_s), '')
306
+ theme.files.where('name = ? and directory = ?', ::File.basename(path), file_dir).first
220
307
  end
221
308
 
222
309
  def setup_tree
@@ -234,16 +321,16 @@ module Knitkit
234
321
  }
235
322
 
236
323
  #handle themes
237
- themes_hash = {:text => 'Themes', :contextMenuDisabled => true, :isThemeRoot => true, :siteId => site.id, :children => []}
324
+ themes_hash = {:text => 'Themes', :contextMenuDisabled => true, :iconCls => 'icon-content', :isThemeRoot => true, :siteId => site.id, :children => []}
238
325
  site.themes.each do |theme|
239
- theme_hash = {:text => "#{theme.name}[#{theme.theme_id}]", :handleContextMenu => true, :siteId => site.id, :isActive => (theme.active == 1), :isTheme => true, :id => theme.id, :children => []}
326
+ theme_hash = {:text => "#{theme.name}[#{theme.theme_id}]", :handleContextMenu => true, :siteId => site.id, :isActive => (theme.active == 1), :iconCls => 'icon-content', :isTheme => true, :id => theme.id, :children => []}
240
327
  if theme.active == 1
241
328
  theme_hash[:iconCls] = 'icon-add'
242
329
  else
243
330
  theme_hash[:iconCls] = 'icon-delete'
244
331
  end
245
332
  ['stylesheets', 'javascripts', 'images', 'templates', 'widgets'].each do |resource_folder|
246
- theme_hash[:children] << {:text => resource_folder, :leaf => false, :id => "/#{theme.url}/#{resource_folder}"}
333
+ theme_hash[:children] << {:text => resource_folder, :iconCls => 'icon-content', :id => "#{theme.url}/#{resource_folder}"}
247
334
  end
248
335
  themes_hash[:children] << theme_hash
249
336
  end
@@ -263,7 +350,7 @@ module Knitkit
263
350
  end
264
351
 
265
352
  def set_file_support
266
- @file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::FileSupport.options[:storage])
353
+ @file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::Config.file_storage)
267
354
  end
268
355
 
269
356
  end#ThemeController
@@ -34,11 +34,14 @@ module Knitkit
34
34
  def publisher
35
35
  published_element.published_by_username if published
36
36
  end
37
+
37
38
  end
38
39
 
39
- render :inline => "{\"totalCount\":#{content.versions.count},data:#{versions.to_json(
40
- :only => [:id, :version, :title, :body_html, :excerpt_html, :updated_at],
41
- :methods => [:active, :published, :publisher])}}"
40
+ render :json => {:totalCount => content.versions.count,
41
+ :data => versions.collect{|version|version.to_hash(
42
+ :only => [:id, :content_id, :version, :title, :body_html, :excerpt_html, :updated_at],
43
+ :methods => [:active, :published, :publisher])}
44
+ }
42
45
  end
43
46
 
44
47
  def non_published_content_versions
@@ -51,23 +54,40 @@ module Knitkit
51
54
 
52
55
  versions = content.versions.order("#{sort} #{dir}").offset(start).limit(limit)
53
56
 
54
- render :inline => "{\"totalCount\":#{content.versions.count},data:#{versions.to_json(:only => [:id, :version, :title, :body_html, :excerpt_html, :updated_at])}}"
57
+ render :json => {:totalCount => content.versions.count,
58
+ :data => versions.collect{|version|version.to_hash(
59
+ :only => [:id, :version, :title, :body_html, :excerpt_html, :updated_at])}
60
+ }
55
61
  end
56
62
 
57
63
  def publish_content
58
- content = Content.find(Content::Version.find(params[:id]).content_id)
59
- content.publish(Website.find(params[:site_id]), params[:comment], params[:version], current_user)
64
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
65
+ begin
66
+ current_user.with_capability(model, 'publish', 'Article') do
67
+ content = Content.find(Content::Version.find(params[:id]).content_id)
68
+ content.publish(Website.find(params[:site_id]), params[:comment], params[:version], current_user)
60
69
 
61
- render :json => {:success => true}
70
+ render :json => {:success => true}
71
+ end
72
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
73
+ render :json => {:success => false, :message => ex.message}
74
+ end
62
75
  end
63
76
 
64
77
  def revert_content
65
- content = Content.find(Content::Version.find(params[:id]).content_id)
66
- version = params[:version]
67
- content.revert_to(version)
68
- content.save!
69
-
70
- render :json => {:success => true}
78
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
79
+ begin
80
+ current_user.with_capability(model, 'revert_version', 'Article') do
81
+ content = Content.find(Content::Version.find(params[:id]).content_id)
82
+ version = params[:version]
83
+ content.revert_to(version)
84
+ content.save!
85
+
86
+ render :json => {:success => true}
87
+ end
88
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
89
+ render :json => {:success => false, :message => ex.message}
90
+ end
71
91
  end
72
92
 
73
93
  #website section layouts
@@ -104,9 +124,11 @@ module Knitkit
104
124
  end
105
125
  end
106
126
 
107
- render :inline => "{\"totalCount\":#{website_section.versions.count},data:#{versions.to_json(
108
- :only => [:id, :version, :title, :updated_at],
109
- :methods => [:active, :published, :publisher])}}"
127
+ render :json => {:totalCount => website_section.versions.count,
128
+ :data => versions.collect{|version|version.to_hash(
129
+ :only => [:id, :version, :title, :updated_at],
130
+ :methods => [:active, :published, :publisher])}
131
+ }
110
132
  end
111
133
 
112
134
  def get_website_section_version