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
@@ -42,9 +42,16 @@ module Knitkit
42
42
  end
43
43
 
44
44
  def activate_publication
45
- @website.set_publication_version(params[:version].to_f, current_user)
45
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
46
+ begin
47
+ current_user.with_capability(model, 'activate', 'Website') do
48
+ @website.set_publication_version(params[:version].to_f, current_user)
46
49
 
47
- render :json => {:success => true}
50
+ render :json => {:success => true}
51
+ end
52
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
53
+ render :json => {:success => false, :message => ex.message}
54
+ end
48
55
  end
49
56
 
50
57
  def set_viewing_version
@@ -60,62 +67,91 @@ module Knitkit
60
67
  end
61
68
 
62
69
  def publish
63
- @website.publish(params[:comment], current_user)
70
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
71
+ begin
72
+ current_user.with_capability(model, 'publish', 'Website') do
73
+ @website.publish(params[:comment], current_user)
64
74
 
65
- render :json => {:success => true}
75
+ render :json => {:success => true}
76
+ end
77
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
78
+ render :json => {:success => false, :message => ex.message}
79
+ end
66
80
  end
67
81
 
68
82
  def new
69
- result = {}
70
- website = Website.new
71
- website.subtitle = params[:subtitle]
72
- website.title = params[:title]
73
- website.name = params[:name]
74
- website.email = params[:email]
75
- website.auto_activate_publication = params[:auto_activate_publication] == 'yes'
76
- website.email_inquiries = params[:email_inquiries] == 'yes'
77
-
78
- # create homepage
79
- website_section = WebsiteSection.new
80
- website_section.title = "Home"
81
- website_section.in_menu = true
82
- website.website_sections << website_section
83
- if website.save
84
- website.setup_default_pages
85
-
86
- #set default publication published by user
87
- first_publication = website.published_websites.first
88
- first_publication.published_by = current_user
89
- first_publication.save
90
-
91
- website.hosts << WebsiteHost.create(:host => params[:host])
92
- website.save
93
-
94
- website.publish("Publish Default Sections", current_user)
95
- PublishedWebsite.activate(website, 1, current_user)
83
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
84
+ begin
85
+ current_user.with_capability(model, 'create', 'Website') do
86
+ result = {}
87
+ website = Website.new
88
+ website.subtitle = params[:subtitle]
89
+ website.title = params[:title]
90
+ website.name = params[:name]
91
+ website.email = params[:email]
92
+ website.auto_activate_publication = params[:auto_activate_publication] == 'yes'
93
+ website.email_inquiries = params[:email_inquiries] == 'yes'
94
+
95
+ # create homepage
96
+ website_section = WebsiteSection.new
97
+ website_section.title = "Home"
98
+ website_section.in_menu = true
99
+ website.website_sections << website_section
100
+ if website.save
101
+ website.setup_default_pages
102
+
103
+ #set default publication published by user
104
+ first_publication = website.published_websites.first
105
+ first_publication.published_by = current_user
106
+ first_publication.save
107
+
108
+ website.hosts << WebsiteHost.create(:host => params[:host])
109
+ website.configurations.first.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('primary_host'), params[:host])
110
+ website.save
111
+
112
+ website.publish("Publish Default Sections", current_user)
113
+ PublishedWebsite.activate(website, 1, current_user)
96
114
 
97
- result[:success] = true
98
- else
99
- result[:success] = false
100
- end
115
+ result[:success] = true
116
+ else
117
+ result[:success] = false
118
+ end
101
119
 
102
- render :json => result
120
+ render :json => result
121
+ end
122
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
123
+ render :json => {:success => false, :message => ex.message}
124
+ end
103
125
  end
104
126
 
105
127
  def update
106
- @website.email = params[:email]
107
- @website.name = params[:name]
108
- @website.title = params[:title]
109
- @website.subtitle = params[:subtitle]
110
- @website.auto_activate_publication = params[:auto_activate_publication] == 'yes'
111
- @website.email_inquiries = params[:email_inquiries] == 'yes'
112
-
113
- render :json => @website.save ? {:success => true} : {:success => false}
128
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
129
+ begin
130
+ current_user.with_capability(model, 'edit', 'Website') do
131
+ @website.email = params[:email]
132
+ @website.name = params[:name]
133
+ @website.title = params[:title]
134
+ @website.subtitle = params[:subtitle]
135
+ @website.auto_activate_publication = params[:auto_activate_publication] == 'yes'
136
+ @website.email_inquiries = params[:email_inquiries] == 'yes'
137
+
138
+ render :json => @website.save ? {:success => true} : {:success => false}
139
+ end
140
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
141
+ render :json => {:success => false, :message => ex.message}
142
+ end
114
143
  end
115
144
 
116
145
 
117
146
  def delete
118
- render :json => @website.destroy ? {:success => true} : {:success => false}
147
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
148
+ begin
149
+ current_user.with_capability(model, 'delete', 'Website') do
150
+ render :json => @website.destroy ? {:success => true} : {:success => false}
151
+ end
152
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
153
+ render :json => {:success => false, :message => ex.message}
154
+ end
119
155
  end
120
156
 
121
157
  def export
@@ -125,6 +161,7 @@ module Knitkit
125
161
  FileUtils.rm_r File.dirname(zip_path) rescue nil
126
162
  end
127
163
 
164
+ # TODO add role restriction to this
128
165
  def import
129
166
  result, message = Website.import(params[:website_data], current_user)
130
167
 
@@ -134,35 +171,56 @@ module Knitkit
134
171
  end
135
172
 
136
173
  def add_host
137
- website = Website.find(params[:id])
138
- website_host = WebsiteHost.create(:host => params[:host])
139
- website.hosts << website_host
140
- website.save
141
-
142
- render :json => {
143
- :success => true,
144
- :node => {
145
- :text => website_host.attributes['host'],
146
- :websiteHostId => website_host.id,
147
- :host => website_host.attributes['host'],
148
- :iconCls => 'icon-globe',
149
- :url => "http://#{website_host.attributes['host']}",
150
- :isHost => true,
151
- :leaf => true,
152
- :children => []}
153
- }
174
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
175
+ begin
176
+ current_user.with_capability(model, 'create', 'Host') do
177
+ website = Website.find(params[:id])
178
+ website_host = WebsiteHost.create(:host => params[:host])
179
+ website.hosts << website_host
180
+ website.save
181
+
182
+ render :json => {
183
+ :success => true,
184
+ :node => {
185
+ :text => website_host.attributes['host'],
186
+ :websiteHostId => website_host.id,
187
+ :host => website_host.attributes['host'],
188
+ :iconCls => 'icon-globe',
189
+ :url => "http://#{website_host.attributes['host']}",
190
+ :isHost => true,
191
+ :leaf => true,
192
+ :children => []}
193
+ }
194
+ end
195
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
196
+ render :json => {:success => false, :message => ex.message}
197
+ end
154
198
  end
155
199
 
156
200
  def update_host
157
- website_host = WebsiteHost.find(params[:id])
158
- website_host.host = params[:host]
159
- website_host.save
160
-
161
- render :json => {:success => true}
201
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
202
+ begin
203
+ current_user.with_capability(model, 'edit', 'Host') do
204
+ website_host = WebsiteHost.find(params[:id])
205
+ website_host.host = params[:host]
206
+ website_host.save
207
+
208
+ render :json => {:success => true}
209
+ end
210
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
211
+ render :json => {:success => false, :message => ex.message}
212
+ end
162
213
  end
163
214
 
164
215
  def delete_host
165
- render :json => WebsiteHost.destroy(params[:id]) ? {:success => true} : {:success => false}
216
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
217
+ begin
218
+ current_user.with_capability(model, 'delete', 'Host') do
219
+ render :json => WebsiteHost.destroy(params[:id]) ? {:success => true} : {:success => false}
220
+ end
221
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
222
+ render :json => {:success => false, :message => ex.message}
223
+ end
166
224
  end
167
225
 
168
226
  protected
@@ -3,138 +3,185 @@ module Knitkit
3
3
  module Desktop
4
4
  class WebsiteNavController < Knitkit::ErpApp::Desktop::AppController
5
5
  def new
6
- result = {}
7
- website = Website.find(params[:website_id])
8
- website_nav = WebsiteNav.new(:name => params[:name])
9
- website.website_navs << website_nav
10
-
11
- if website_nav.save
12
- result[:success] = true
13
- result[:node] = {:text => params[:name],
14
- :websiteNavId => website_nav.id,
15
- :websiteId => website.id,
16
- :iconCls => 'icon-index',
17
- :canAddMenuItems => true,
18
- :isWebsiteNav => true,
19
- :leaf => false,
20
- :children => []}
21
- else
22
- result[:success] = false
6
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
7
+ begin
8
+ current_user.with_capability(model, 'create', 'Menu') do
9
+ result = {}
10
+ website = Website.find(params[:website_id])
11
+ website_nav = WebsiteNav.new(:name => params[:name])
12
+ website.website_navs << website_nav
13
+
14
+ if website_nav.save
15
+ result[:success] = true
16
+ result[:node] = {:text => params[:name],
17
+ :websiteNavId => website_nav.id,
18
+ :websiteId => website.id,
19
+ :iconCls => 'icon-index',
20
+ :canAddMenuItems => true,
21
+ :isWebsiteNav => true,
22
+ :leaf => false,
23
+ :children => []}
24
+ else
25
+ result[:success] = false
26
+ end
27
+
28
+ render :json => result
29
+ end
30
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
31
+ render :json => {:success => false, :message => ex.message}
23
32
  end
24
-
25
- render :json => result
26
33
  end
27
34
 
28
35
  def update
29
- website_nav = WebsiteNav.find(params[:website_nav_id])
30
- website_nav.name = params[:name]
36
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
37
+ begin
38
+ current_user.with_capability(model, 'edit', 'Menu') do
39
+ website_nav = WebsiteNav.find(params[:website_nav_id])
40
+ website_nav.name = params[:name]
31
41
 
32
- render :json => (website_nav.save ? {:success => true} : {:success => false})
42
+ render :json => (website_nav.save ? {:success => true} : {:success => false})
43
+ end
44
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
45
+ render :json => {:success => false, :message => ex.message}
46
+ end
33
47
  end
34
48
 
35
49
  def delete
36
- render :json => (WebsiteNav.destroy(params[:id]) ? {:success => true} : {:success => false})
50
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
51
+ begin
52
+ current_user.with_capability(model, 'delete', 'Menu') do
53
+ render :json => (WebsiteNav.destroy(params[:id]) ? {:success => true} : {:success => false})
54
+ end
55
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
56
+ render :json => {:success => false, :message => ex.message}
57
+ end
37
58
  end
38
59
 
39
60
  def add_menu_item
40
- result = {}
41
- klass = params[:klass].constantize
42
- parent = klass.find(params[:id])
43
- website_nav = parent.is_a?(WebsiteNav) ? parent : parent.website_nav
44
- website_nav_item = WebsiteNavItem.new(:title => params[:title])
45
-
46
- url = params[:url]
47
- if(params[:link_to] != 'url')
48
- #user wants to see Section so this is needed
49
- params[:link_to] = 'WebsiteSection' if params[:link_to] == 'website_section'
50
-
51
- #get link to item can be Article or Section
52
- linked_to_id = params["#{params[:link_to].underscore}_id".to_sym]
53
- link_to_item = params[:link_to].constantize.find(linked_to_id)
54
- #setup link
55
- website_nav_item.url = '/' + link_to_item.permalink
56
- website_nav_item.linked_to_item = link_to_item
57
- url = "http://#{website_nav.website.hosts.first.host}/" + link_to_item.permalink
58
- else
59
- website_nav_item.url = url
60
- end
61
-
62
- if website_nav_item.save
63
- if parent.is_a?(WebsiteNav)
64
- parent.website_nav_items << website_nav_item
65
- else
66
- website_nav_item.move_to_child_of(parent)
61
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
62
+ begin
63
+ current_user.with_capability(model, 'create', 'MenuItem') do
64
+ result = {}
65
+ klass = params[:klass].constantize
66
+ parent = klass.find(params[:id])
67
+ website_nav = parent.is_a?(WebsiteNav) ? parent : parent.website_nav
68
+ website_nav_item = WebsiteNavItem.new(:title => params[:title])
69
+
70
+ url = params[:url]
71
+ if(params[:link_to] != 'url')
72
+ #user wants to see Section so this is needed
73
+ params[:link_to] = 'WebsiteSection' if params[:link_to] == 'website_section'
74
+
75
+ #get link to item can be Article or Section
76
+ linked_to_id = params["#{params[:link_to].underscore}_id".to_sym]
77
+ link_to_item = params[:link_to].constantize.find(linked_to_id)
78
+ #setup link
79
+ website_nav_item.url = '/' + link_to_item.permalink
80
+ website_nav_item.linked_to_item = link_to_item
81
+ url = "http://#{website_nav.website.hosts.first.host}/" + link_to_item.permalink
82
+ else
83
+ website_nav_item.url = url
84
+ end
85
+
86
+ if website_nav_item.save
87
+ if parent.is_a?(WebsiteNav)
88
+ parent.website_nav_items << website_nav_item
89
+ else
90
+ website_nav_item.move_to_child_of(parent)
91
+ end
92
+
93
+ result[:success] = true
94
+ result[:node] = {:text => params[:title],
95
+ :linkToType => params[:link_to].underscore,
96
+ :linkedToId => linked_to_id,
97
+ :websiteId => website_nav.website.id,
98
+ :url => url,
99
+ :isSecure => false,
100
+ :canAddMenuItems => true,
101
+ :websiteNavItemId => website_nav_item.id,
102
+ :iconCls => 'icon-document',
103
+ :isWebsiteNavItem => true,
104
+ :leaf => false,
105
+ :children => []}
106
+ else
107
+ result[:success] = false
108
+ end
109
+
110
+ render :json => result
67
111
  end
68
-
69
- result[:success] = true
70
- result[:node] = {:text => params[:title],
71
- :linkToType => params[:link_to].underscore,
72
- :linkedToId => linked_to_id,
73
- :websiteId => website_nav.website.id,
74
- :url => url,
75
- :isSecure => false,
76
- :canAddMenuItems => true,
77
- :websiteNavItemId => website_nav_item.id,
78
- :iconCls => 'icon-document',
79
- :isWebsiteNavItem => true,
80
- :leaf => false,
81
- :children => []}
82
- else
83
- result[:success] = false
112
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
113
+ render :json => {:success => false, :message => ex.message}
84
114
  end
85
-
86
- render :json => result
87
115
  end
88
116
 
89
117
  def update_menu_item
90
- result = {}
91
- website_nav_item = WebsiteNavItem.find(params[:website_nav_item_id])
92
- website_nav_item.title = params[:title]
93
-
94
- url = params[:url]
95
- linked_to_id = nil
96
- if(params[:link_to] != 'url')
97
- #user wants to see Section so this is needed
98
- params[:link_to] = 'WebsiteSection' if params[:link_to] == 'website_section'
99
-
100
- #get link to item can be Article or Section
101
- linked_to_id = params["#{params[:link_to].underscore}_id".to_sym]
102
- link_to_item = params[:link_to].constantize.find(linked_to_id)
103
- #setup link
104
- website_nav_item.url = '/' + link_to_item.permalink
105
- website_nav_item.linked_to_item = link_to_item
106
- url = "http://#{website_nav_item.website_nav.website.hosts.first.host}/" + link_to_item.permalink
107
- else
108
- website_nav_item.url = url
109
- end
110
-
111
- if website_nav_item.save
112
- result[:success] = true
113
- result[:title] = params[:title]
114
- result[:linkedToId] = linked_to_id
115
- result[:linkToType] = params[:link_to].underscore
116
- result[:url] = url
117
- else
118
- result[:success] = false
118
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
119
+ begin
120
+ current_user.with_capability(model, 'edit', 'MenuItem') do
121
+ result = {}
122
+ website_nav_item = WebsiteNavItem.find(params[:website_nav_item_id])
123
+ website_nav_item.title = params[:title]
124
+
125
+ url = params[:url]
126
+ linked_to_id = nil
127
+ if(params[:link_to] != 'url')
128
+ #user wants to see Section so this is needed
129
+ params[:link_to] = 'WebsiteSection' if params[:link_to] == 'website_section'
130
+
131
+ #get link to item can be Article or Section
132
+ linked_to_id = params["#{params[:link_to].underscore}_id".to_sym]
133
+ link_to_item = params[:link_to].constantize.find(linked_to_id)
134
+ #setup link
135
+ website_nav_item.url = '/' + link_to_item.permalink
136
+ website_nav_item.linked_to_item = link_to_item
137
+ url = "http://#{website_nav_item.website_nav.website.hosts.first.host}/" + link_to_item.permalink
138
+ else
139
+ website_nav_item.url = url
140
+ end
141
+
142
+ if website_nav_item.save
143
+ result[:success] = true
144
+ result[:title] = params[:title]
145
+ result[:linkedToId] = linked_to_id
146
+ result[:linkToType] = params[:link_to].underscore
147
+ result[:url] = url
148
+ else
149
+ result[:success] = false
150
+ end
151
+
152
+ render :json => result
153
+ end
154
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
155
+ render :json => {:success => false, :message => ex.message}
119
156
  end
120
-
121
- render :json => result
122
157
  end
123
158
 
124
159
  def update_security
125
- website_nav_item = WebsiteNavItem.find(params[:id])
126
- website = Website.find(params[:site_id])
127
- if(params[:secure] == "true")
128
- website_nav_item.add_role(website.role)
160
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
161
+ if current_user.has_capability?(model, 'secure', 'MenuItem') or current_user.has_capability?(model, 'unsecure', 'MenuItem')
162
+ website_nav_item = WebsiteNavItem.find(params[:id])
163
+ website = Website.find(params[:site_id])
164
+ if(params[:secure] == "true")
165
+ website_nav_item.add_role(website.role)
166
+ else
167
+ website_nav_item.remove_role(website.role)
168
+ end
169
+
170
+ render :json => {:success => true}
129
171
  else
130
- website_nav_item.remove_role(website.role)
172
+ render :json => {:success => false, :message => "User does not have capability."}
131
173
  end
132
-
133
- render :json => {:success => true}
134
174
  end
135
175
 
136
176
  def delete_menu_item
137
- render :json => (WebsiteNavItem.destroy(params[:id]) ? {:success => true} : {:success => false})
177
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
178
+ begin
179
+ current_user.with_capability(model, 'delete', 'MenuItem') do
180
+ render :json => (WebsiteNavItem.destroy(params[:id]) ? {:success => true} : {:success => false})
181
+ end
182
+ rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
183
+ render :json => {:success => false, :message => ex.message}
184
+ end
138
185
  end
139
186
 
140
187
  end#WebsiteNavController