kit_cms 2.3.20 → 2.3.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. data/app/assets/images/kit/toolbar/smile.png +0 -0
  2. data/app/assets/images/kit/toolbar/wink.gif +0 -0
  3. data/app/assets/images/kit/toolbar/wink.png +0 -0
  4. data/app/assets/javascripts/codemirror/editor.js +55 -17
  5. data/app/assets/javascripts/codemirror/jquery.js +0 -1
  6. data/app/assets/javascripts/codemirror/ruby.js +196 -0
  7. data/app/assets/javascripts/jquery.js +3036 -2838
  8. data/app/assets/javascripts/kit/utilities.js +655 -586
  9. data/app/assets/stylesheets/codemirror/style.css +1 -1
  10. data/app/assets/stylesheets/codemirror/theme.css +23 -3
  11. data/app/assets/stylesheets/kit/calendar.css +6 -1
  12. data/app/assets/stylesheets/kit/cms/cms.css +36 -0
  13. data/app/assets/stylesheets/kit/forums.css +5 -1
  14. data/app/assets/stylesheets/kit/kit.css +3 -1
  15. data/app/controllers/account_controller.rb +306 -0
  16. data/app/controllers/ad_controller.rb +2 -0
  17. data/app/controllers/admin/ad_units_controller.rb +1 -1
  18. data/app/controllers/admin/ad_zones_controller.rb +15 -0
  19. data/app/controllers/admin/ads_controller.rb +5 -0
  20. data/app/controllers/admin/block_controller.rb +1 -65
  21. data/app/controllers/admin/blocks_controller.rb +2 -0
  22. data/app/controllers/admin/content_controller.rb +3 -1
  23. data/app/controllers/admin/dashboard_controller.rb +28 -4
  24. data/app/controllers/admin/dj_controller.rb +45 -0
  25. data/app/controllers/admin/help_controller.rb +1 -1
  26. data/app/controllers/admin/html_asset_controller.rb +0 -12
  27. data/app/controllers/admin/q_controller.rb +120 -0
  28. data/app/controllers/admin/user_controller.rb +4 -4
  29. data/app/controllers/api_controller.rb +34 -0
  30. data/app/controllers/calendar_controller.rb +1 -1
  31. data/app/controllers/form_controller.rb +3 -3
  32. data/app/controllers/forum_controller.rb +39 -29
  33. data/app/controllers/kit_controller.rb +42 -15
  34. data/app/controllers/pages_controller.rb +25 -5
  35. data/app/controllers/q_controller.rb +235 -0
  36. data/app/controllers/repo_controller.rb +7 -0
  37. data/app/controllers/user_controller.rb +14 -10
  38. data/app/controllers/utility_controller.rb +1 -1
  39. data/app/helpers/account_helper.rb +47 -0
  40. data/app/helpers/admin/layouts_helper.rb +8 -0
  41. data/app/helpers/admin/page_templates_helper.rb +8 -0
  42. data/app/helpers/ads_helper.rb +11 -12
  43. data/app/helpers/calendar_helper.rb +6 -2
  44. data/app/helpers/form_data_helper.rb +1 -1
  45. data/app/helpers/form_helper.rb +8 -0
  46. data/app/helpers/forum_helper.rb +5 -1
  47. data/app/helpers/kit_helper.rb +65 -35
  48. data/app/helpers/kit_modules_helper.rb +4 -0
  49. data/app/helpers/user_helper.rb +0 -28
  50. data/app/jobs/page_link_job.rb +34 -0
  51. data/app/jobs/queue_job.rb +134 -0
  52. data/app/mailers/notification.rb +10 -0
  53. data/app/mailers/queue_mailer.rb +13 -0
  54. data/app/models/ad.rb +6 -6
  55. data/app/models/ad_unit.rb +1 -1
  56. data/app/models/ad_zone.rb +4 -0
  57. data/app/models/block.rb +1 -1
  58. data/app/models/delayed_job.rb +3 -0
  59. data/app/models/form.rb +16 -4
  60. data/app/models/html_asset.rb +19 -4
  61. data/app/models/html_asset_usage.rb +3 -0
  62. data/app/models/html_assetable.rb +4 -0
  63. data/app/models/layout.rb +36 -6
  64. data/app/models/newsletter.rb +1 -1
  65. data/app/models/page.rb +36 -2
  66. data/app/models/page_link.rb +5 -0
  67. data/app/models/page_template.rb +22 -2
  68. data/app/models/preference.rb +1 -1
  69. data/app/models/q_event.rb +12 -0
  70. data/app/models/q_klass.rb +5 -0
  71. data/app/models/q_message.rb +9 -0
  72. data/app/models/q_publisher.rb +35 -0
  73. data/app/models/q_subscription.rb +7 -0
  74. data/app/models/q_user.rb +29 -0
  75. data/app/models/q_users_method.rb +6 -0
  76. data/app/models/q_users_publisher.rb +6 -0
  77. data/app/models/user.rb +127 -19
  78. data/app/models/user_login.rb +4 -0
  79. data/app/validators/email_validator.rb +14 -0
  80. data/app/views/account/_edit.html.haml +40 -0
  81. data/app/views/account/_edit_intro.html.haml +3 -0
  82. data/app/views/account/_forgotten.html.haml +20 -0
  83. data/app/views/account/_forgotten_intro.html.haml +5 -0
  84. data/app/views/account/_sign_in.html.haml +31 -0
  85. data/app/views/account/_sign_in_intro.html.haml +4 -0
  86. data/app/views/account/_sign_up.html.haml +51 -0
  87. data/app/views/account/_sign_up_intro.html.haml +4 -0
  88. data/app/views/account/edit.html.haml +1 -0
  89. data/app/views/account/forgotten.html.haml +1 -0
  90. data/app/views/account/sign_in.html.haml +2 -0
  91. data/app/views/account/sign_up.html.haml +1 -0
  92. data/app/views/ad/_buy.html.haml +2 -1
  93. data/app/views/admin/ad_zones/_form.html.haml +1 -1
  94. data/app/views/admin/ad_zones/show.html.haml +2 -0
  95. data/app/views/admin/blocks/_form.html.haml +11 -1
  96. data/app/views/admin/dashboard/broken_links.html.haml +9 -0
  97. data/app/views/admin/dashboard/system.html.haml +11 -0
  98. data/app/views/admin/dj/index.html.haml +43 -0
  99. data/app/views/admin/form/_form.html.haml +15 -10
  100. data/app/views/admin/group/index.html.haml +1 -1
  101. data/app/views/admin/help/edit.html.haml +1 -1
  102. data/app/views/admin/html_asset/show.html.haml +9 -2
  103. data/app/views/admin/layouts/show.html.haml +10 -16
  104. data/app/views/admin/page_templates/_form.html.haml +9 -17
  105. data/app/views/admin/page_templates/show.html.haml +5 -4
  106. data/app/views/admin/q/events.html.haml +26 -0
  107. data/app/views/admin/q/index.html.haml +28 -0
  108. data/app/views/admin/q/klasses.html.haml +61 -0
  109. data/app/views/admin/q/messages.html.haml +37 -0
  110. data/app/views/admin/q/show.html.haml +98 -0
  111. data/app/views/admin/q/subscriptions.html.haml +26 -0
  112. data/app/views/admin/q/users.html.haml +27 -0
  113. data/app/views/admin/snippet/edit.html.erb +1 -1
  114. data/app/views/admin/snippet/new.html.erb +1 -1
  115. data/app/views/admin/stylesheet/show.html.haml +1 -1
  116. data/app/views/admin/user/index.html.erb +15 -6
  117. data/app/views/admin/user/view.html.erb +5 -4
  118. data/app/views/admin/views/_form.html.haml +3 -3
  119. data/app/views/calendar/_buy_tickets.html.haml +1 -1
  120. data/app/views/calendar/_calendar_entry.html.haml +1 -1
  121. data/app/views/calendar/_month.html.haml +7 -7
  122. data/app/views/form/_show.html.haml +1 -1
  123. data/app/views/forum/_add_post.html.haml +7 -8
  124. data/app/views/forum/_mod_thread.js.erb +46 -6
  125. data/app/views/forum/_post_moderation.html.haml +2 -1
  126. data/app/views/forum/_post_preview.html.haml +1 -9
  127. data/app/views/forum/_post_scripts.js.erb +29 -5
  128. data/app/views/forum/fetch_raw.html.haml +1 -0
  129. data/app/views/forum/moderate.html.haml +1 -0
  130. data/app/views/forum/topic_index.html.haml +4 -0
  131. data/app/views/notification/{event.txt.erb → event.text.erb} +0 -0
  132. data/app/views/notification/forgotten_password.text.erb +2 -0
  133. data/app/views/pages/content_edit.html.haml +1 -1
  134. data/app/views/pages/info.html.erb +13 -2
  135. data/app/views/pages/links.html.haml +63 -0
  136. data/app/views/user/edit_profile.html.haml +1 -1
  137. data/app/views/utility/_cm_editor.html.erb +13 -10
  138. data/app/views/utility/_cm_toolbar_markdown.html.haml +8 -1
  139. data/app/views/utility/_menu.html.haml +4 -0
  140. data/app/views/utility/mercury_html.html.haml +1 -0
  141. data/config/initializers/elastic_search.rb +6 -3
  142. data/config/initializers/extend_controller.rb +3 -0
  143. data/config/initializers/string.rb +9 -6
  144. data/config/initializers/warden.rb +49 -0
  145. data/config/locales/en.yml +29 -1
  146. data/config/routes.rb +35 -2
  147. data/lib/kit_cms.rb +7 -2
  148. data/lib/tasks/kit.rake +90 -2
  149. metadata +139 -27
  150. data/app/controllers/user/confirmations_controller.rb +0 -11
  151. data/app/controllers/user/passwords_controller.rb +0 -13
  152. data/app/controllers/user/registrations_controller.rb +0 -110
  153. data/app/controllers/user/sessions_controller.rb +0 -33
  154. data/app/controllers/user/unlocks_controller.rb +0 -13
  155. data/app/views/devise/_links.erb +0 -25
  156. data/app/views/devise/confirmations/new.html.erb +0 -12
  157. data/app/views/devise/mailer/confirmation_instructions.html.erb +0 -5
  158. data/app/views/devise/mailer/reset_password_instructions.html.erb +0 -8
  159. data/app/views/devise/mailer/unlock_instructions.html.erb +0 -7
  160. data/app/views/devise/passwords/edit.html.erb +0 -16
  161. data/app/views/devise/passwords/new.html.erb +0 -12
  162. data/app/views/devise/registrations/edit.html.erb +0 -28
  163. data/app/views/devise/registrations/new.html.erb +0 -18
  164. data/app/views/devise/sessions/new.html.erb +0 -18
  165. data/app/views/devise/shared/_links.erb +0 -25
  166. data/app/views/devise/unlocks/new.html.erb +0 -12
  167. data/app/views/pages/links.html.erb +0 -8
  168. data/app/views/user/shared/_links.erb +0 -25
  169. data/config/initializers/devise.rb +0 -196
  170. data/config/initializers/devise_extender.rb +0 -39
@@ -9,6 +9,8 @@ class AdController < KitController
9
9
  @ad.height = zone.height
10
10
  @ad.width = zone.width
11
11
  @ad.system_id = _sid
12
+ @ad.name = params[:ad][:name]
13
+ @ad.start_date = params[:ad][:start_date]
12
14
  @ad.user_id = current_user.id
13
15
  @ad.end_date = @ad.start_date + @ad.duration.send(zone.period.downcase) rescue nil
14
16
  @ad.activated = nil
@@ -10,7 +10,7 @@ class Admin::AdUnitsController < AdminController
10
10
  if block
11
11
  notice = 'Block already exists'
12
12
  else
13
- block = Block.create(:system_id=>_sid, :name=>@ad_unit.block_name, :description=>"System generated block to display an ad of size '#{@ad_unit.name}'", :show_editors=>true, :all_templates=>true, :user_id=>current_user.id, :body=>"<%= kit_ad_by_unit(#{@ad_unit.id}) %>")
13
+ block = Block.create(:system_id=>_sid, :name=>@ad_unit.block_name, :description=>"System generated block to display an ad of size '#{@ad_unit.name}'", :show_editors=>true, :all_templates=>true, :user_id=>current_user.id, :body=>"<% if params[:edit] %>[[ad will appear here]]<% else %><% ad = kit_ad_by_unit(#{@ad_unit.id}) %><%= kit_ad(ad.id) if ad %><% end %>")
14
14
  notice = 'Block created'
15
15
  end
16
16
 
@@ -2,6 +2,21 @@ class Admin::AdZonesController < AdminController
2
2
 
3
3
  before_filter :check_feature
4
4
 
5
+ def create_block
6
+ @ad_zone = AdZone.find_sys_id(_sid, params[:id])
7
+
8
+ block = Block.sys(_sid).where(:name=>@ad_zone.block_name).first
9
+
10
+ if block
11
+ notice = 'Block already exists'
12
+ else
13
+ block = Block.create(:system_id=>_sid, :name=>@ad_zone.block_name, :description=>"System generated block to display an ad from zone '#{@ad_zone.name}'", :show_editors=>true, :all_templates=>true, :user_id=>current_user.id, :body=>"<% if params[:edit] %>[[ad will appear here]]<% else %><% ad = kit_ad_by_zone(#{@ad_zone.id}) %><%= kit_ad(ad.id) if ad %><% end %>")
14
+ notice = 'Block created'
15
+ end
16
+
17
+ redirect_to [:admin, @ad_zone], :notice=>notice
18
+ end
19
+
5
20
  def index
6
21
  @ad_zones = AdZone.sys(_sid).includes(:ad_unit)
7
22
  @ad_zones = @ad_zones.where(:ad_unit_id=>params[:ad_unit]) if params[:ad_unit]
@@ -37,7 +37,12 @@ class Admin::AdsController < AdminController
37
37
  @ad = Ad.new(params[:ad])
38
38
  @ad.system_id = _sid
39
39
  @ad.activated = Time.now
40
+ # @ad.duration = params[:ad][:duration].to_i
40
41
  @ad.approved_by_id = current_user.id
42
+ @ad.user_id = current_user.id
43
+ @ad.name = params[:ad][:name]
44
+ @ad.start_date = params[:ad][:start_date]
45
+ @ad.end_date = params[:ad][:end_date] #@ad.start_date + @ad.duration.send(zone.period.downcase) rescue nil
41
46
 
42
47
  zones = check_zones
43
48
  if zones.instance_of?(String)
@@ -1,67 +1,3 @@
1
1
  class Admin::BlockController < AdminController
2
-
3
- layout "cms"
4
-
5
- def index
6
- @blocks = Block
7
- .includes(:user)
8
- .order("created_at desc")
9
- @blocks = @blocks.where('name like "%' + params[:for] + '%" or body like "%' + params[:for] + '%" or description like "%' + params[:for] + '%"') if params[:for].not_blank?
10
- @blocks = @blocks.page(params[:page]).per(3)
11
- end
12
-
13
- def new
14
- @block ||= Block.new
15
- end
16
-
17
- def show
18
- @block = Block.find_sys_id(_sid, params[:id])
19
- if params[:version]
20
- ver = params[:version].to_i
21
- for v in 0..ver
22
- @block.revert_to(v)
23
- end
24
- end
25
- end
26
-
27
- def destroy
28
- @block = Block.find_sys_id(_sid, params[:id])
29
- Activity.add(_sid, "Deleted block '#{@block.name}'", current_user.id, "Block")
30
- Block.delete_all("id = #{params[:id]} and system_id = #{_sid}")
31
- flash[:warn] = "Block deleted"
32
- redirect_to "/admin/block"
33
- end
34
-
35
- def update
36
- params[:block][:page_template_ids] ||= []
37
- @block = Block.find_sys_id(_sid, params[:id])
38
- @block.user_id = current_user.id
39
-
40
- @block.update_attributes(params[:block])
41
- if @block.save
42
- Activity.add(_sid, "Update block '#{@block.name}'", current_user.id, "Block")
43
-
44
- redirect_to "/admin/block/#{@block.id}"
45
- return
46
- else
47
- render "edit"
48
- end
49
- end
50
-
51
- def edit
52
- @block = Block.find(params[:id])
53
- end
54
-
55
- def create
56
- @block = Block.new(params[:block])
57
- @block.user_id = current_user.id
58
- if @block.save
59
- Activity.add(_sid, "Create block '#{@block.name}'", current_user.id, "Block")
60
- redirect_to "/admin/block/#{@block.id}"
61
- return
62
- else
63
- render "new"
64
- end
65
- end
66
-
2
+ # not used
67
3
  end
@@ -2,6 +2,7 @@ class Admin::BlocksController < AdminController
2
2
  layout "cms"
3
3
 
4
4
  def index
5
+ logger.debug "*****************************************" * 5
5
6
  @blocks = Block.sys(_sid).order(:name)
6
7
  @blocks = @blocks.where('name like "%' + params[:for] + '%" or body like "%' + params[:for] + '%" or description like "%' + params[:for] + '%"') if params[:for].not_blank?
7
8
  @blocks = @blocks.page(params[:page]).per(25)
@@ -11,6 +12,7 @@ class Admin::BlocksController < AdminController
11
12
  @block = Block.find_sys_id(_sid,params[:id])
12
13
  end
13
14
 
15
+
14
16
  def new
15
17
  @block = Block.new
16
18
  end
@@ -24,11 +24,13 @@ class Admin::ContentController < AdminController
24
24
  end
25
25
 
26
26
  indexes = [ "pages", "topic_posts", "topic_threads" ]
27
- search = Tire.search indexes.map { |name| "kit_#{app_name}_#{name}"}.join(',') do
27
+ system_id = _sid
28
+ search = Tire.search indexes.map { |name| "#{index_name}_#{name}"}.join(',') do
28
29
  query do
29
30
  string words.join(' ')
30
31
  end
31
32
  size 10
33
+ filter :term, :system_id=>system_id
32
34
  end
33
35
 
34
36
  @pages = search.results
@@ -105,8 +105,16 @@ class Admin::DashboardController < AdminController
105
105
  def system
106
106
  raise Exception("permissions") unless can?(:dashboard, :super)
107
107
 
108
+ if request.post? && params[:preference][:name]
109
+ name = params[:preference][:name]
110
+ value = params[:preference][:value]
111
+ Preference.set(_sid, name, value)
112
+ end
113
+
108
114
  @preferences = Preference.sys(_sid).where("user_id is null").order(:name)
109
115
  @preferences = @preferences.all
116
+
117
+ @preference = Preference.new
110
118
  end
111
119
 
112
120
  def build_system
@@ -164,7 +172,6 @@ class Admin::DashboardController < AdminController
164
172
  HtmlAsset.fetch(sid, ha.name, ha.file_type)
165
173
  end
166
174
 
167
-
168
175
  @system_id = sid
169
176
  prefs = {
170
177
  date_time_format: "%H:%M %d-%m-%y",
@@ -390,7 +397,7 @@ class Admin::DashboardController < AdminController
390
397
 
391
398
  @@to_search.each do |model|
392
399
  if params["include_#{model.pluralize.downcase}".to_sym]
393
- indexes << "kit_#{app_name.downcase}_" + model.tableize
400
+ indexes << "#{index_name}_" + model.tableize
394
401
  KitIndexed.indexed_columns(model).collect { |ic|
395
402
  next if ic[:include_in_all]==false
396
403
  next if ic[:index]==:not_analyzed
@@ -414,7 +421,7 @@ class Admin::DashboardController < AdminController
414
421
  filter :term, :system_id=>system_id
415
422
 
416
423
  end
417
- logger.debug "SEARCH: #{indexes.join(',')} #{search.to_json}"
424
+ logger.info "SEARCH: #{indexes.join(',')} #{search.to_json}"
418
425
 
419
426
  @results = search.results
420
427
  logger.debug "RESULTS: #{@results.size}"
@@ -442,13 +449,16 @@ class Admin::DashboardController < AdminController
442
449
  end
443
450
 
444
451
  def help
452
+ system_id = _sid
453
+
445
454
  if params[:search]
446
455
  search_for = params[:search]
447
456
 
448
- search = Tire.search "kit_#{app_name}_helps" do
457
+ search = Tire.search "#{index_name}_helps" do
449
458
  query do
450
459
  string search_for, :fields=>["name", "body", "path"]
451
460
  end
461
+ filter :term, :system_id=>system_id
452
462
  end
453
463
  @helps = search.results
454
464
  render "helps"
@@ -471,4 +481,18 @@ class Admin::DashboardController < AdminController
471
481
  "<span class='check_warning'>#{s}</span>".html_safe
472
482
  end
473
483
 
484
+ def broken_links
485
+ @broken = []
486
+ Anemone.crawl(Preference.get_cached(_sid, "host"), :skip_query_strings=>true) do |anemone|
487
+ anemone.skip_links_like [ /\/db/, /\/page\/\d+\/info/, /\?edit\=1/ ]
488
+ anemone.on_every_page do |page|
489
+ @broken << page
490
+ if page.code == 404
491
+ uri = URI.parse(page.url.to_s)
492
+ @broken << uri.path
493
+ end
494
+ end
495
+ end
496
+
497
+ end
474
498
  end
@@ -0,0 +1,45 @@
1
+ class Admin::DjController < AdminController
2
+
3
+ def index
4
+
5
+ if request.post? && params[:delete]
6
+ DelayedJob.delete_all("id = #{params[:delete]} and queue = '#{_sid}'")
7
+ redirect_to "/admin/dj", :notice=>"Job deleted"
8
+ end
9
+
10
+ if request.post? && params[:id]
11
+ dj = DelayedJob.where("queue = #{_sid} and id=#{params[:id]}").first
12
+ if dj
13
+ dj.run_at = Time.now
14
+ dj.save
15
+ end
16
+ redirect_to "/admin/dj"
17
+ end
18
+
19
+ if request.post? && params[:process]
20
+ do_process
21
+ redirect_to "/admin/dj"
22
+ end
23
+
24
+ @delayed_jobs = DelayedJob.where(:queue=>_sid).order("created_at desc").page(params[:page]).per(100).all
25
+
26
+ @running = false
27
+ if File.exist?("tmp/pids/delayed_job.pid")
28
+ begin
29
+ @pid = File.read("tmp/pids/delayed_job.pid").strip
30
+ Process.getpgid( @pid.to_i )
31
+ @running = true
32
+ rescue Errno::ESRCH
33
+ end
34
+ end
35
+ end
36
+
37
+ def do_process
38
+ if params[:process]
39
+ `bundle exec script/delayed_job #{params[:process]}`
40
+ flash[:notice] = "Process #{params[:process]}"
41
+ end
42
+ end
43
+
44
+ end
45
+
@@ -37,7 +37,7 @@ class Admin::HelpController < AdminController
37
37
  if params[:search]
38
38
  search_for = params[:search]
39
39
 
40
- search = Tire.search "kit_#{app_name.downcase}_helps" do
40
+ search = Tire.search "#{index_name}_helps" do
41
41
  query do
42
42
  string search_for, :fields=>["name", "body", "path"]
43
43
  end
@@ -6,18 +6,6 @@
6
6
  setup_index
7
7
  end
8
8
 
9
- # replace with model which writes itself to File system and is served up by webserver
10
- def serve
11
- name,stamp = params[:path].split('-')
12
- asset = HtmlAsset.fetch(_sid, name.downcase, params[:format])
13
- response.headers['Content-Type'] = "text/#{asset.file_type}"
14
- response.headers['Cache-Control'] = 'max-age=31536000, public'
15
- response.headers["Expires"] = CGI.rfc1123_date(Time.now + 360.days)
16
- mime_type = Mime::Type.lookup_by_extension(asset.file_type)
17
- content_type = mime_type.to_s unless mime_type.nil?
18
-
19
- render :inline=>asset.compiled, :type=>:erb, :layout=>false, :mime_type => content_type
20
- end
21
9
 
22
10
  def create
23
11
  add_sid(:html_asset)
@@ -0,0 +1,120 @@
1
+ class Admin::QController < KitController
2
+
3
+ before_filter :load_publisher, :except=>[:index, :create]
4
+ before_filter :check_user, :except=>[:index, :destroy, :create]
5
+ before_filter :check_admin, :only=>[ :destroy, :create]
6
+
7
+ def index
8
+ if current_user.admin?
9
+ @publishers = QPublisher.sys(_sid).order(:name).all
10
+ @q_publisher = QPublisher.new
11
+ render "index", :layout=>get_layout
12
+ else
13
+ @publisher = QPublisher.sys(_sid).where(:user_id=>current_user.id).first
14
+ redirect_to "/admin/q/#{@publisher.id}"
15
+ end
16
+ end
17
+
18
+ def destroy
19
+ @publisher.destroy
20
+ redirect_to "/admin/q", :notice=>"publisher deleted"
21
+ end
22
+
23
+ def create
24
+ @publisher = QPublisher.new(params[:q_publisher])
25
+ @publisher.system_id = _sid
26
+ @publisher.token = rand
27
+ @publisher.auth_id = QPublisher.generate_random
28
+ @publisher.auth_secret = QPublisher.generate_random
29
+ @publisher.auth_method = "digest"
30
+ @publisher.active = 1
31
+ @publisher.save
32
+
33
+ @q_user = QUser.create(:system_id=>_sid, :q_publisher_id=>@publisher.id, :q_external_id=>0, :notification_method=>"twitter", :source=>1)
34
+
35
+ QSubscription.create(:system_id=>_sid, :q_publisher_id=>@publisher.id, :topic=>"tweet", :q_user_id=>@q_user.id)
36
+ redirect_to "/admin/q/#{@publisher.id}?auth=1", :notice=>"Created new publisher - now set up authentication"
37
+ end
38
+
39
+ def show
40
+ if request.post?
41
+ @event = QEvent.new(params[:q_event])
42
+ @event.system_id = _sid
43
+ @event.q_publisher = @publisher
44
+ @event.save
45
+ flash[:notice] = "Event created"
46
+ redirect_to "/admin/q/#{@publisher.id}"
47
+ return
48
+ end
49
+ @event = QEvent.new
50
+
51
+ render "show", :layout=>get_layout
52
+ end
53
+
54
+ def klasses
55
+ if request.put? || request.post?
56
+ if params[:q_klass][:id]
57
+ @q_klass = QKlass.sys(_sid).where(:id=>params[:q_klass][:id]).first
58
+ else
59
+ @q_klass = QKlass.new
60
+ @q_klass.system_id = _sid
61
+ @q_klass.q_publisher_id = @publisher.id
62
+ end
63
+ @q_klass.update_attributes(params[:q_klass])
64
+ @q_klass.save
65
+ redirect_to "/admin/q/#{@publisher.id}/klasses", :notice=>"Saved"
66
+ return
67
+ else
68
+ @q_klass = params[:klass_id] ? QKlass.sys(_sid).where(:id=>params[:klass_id]).first : QKlass.new
69
+ end
70
+
71
+ render "klasses", :layout=>get_layout
72
+ end
73
+
74
+ def messages
75
+ render "messages", :layout=>get_layout
76
+ end
77
+
78
+ def users
79
+ render "users", :layout=>get_layout
80
+ end
81
+
82
+ def events
83
+ render "events", :layout=>get_layout
84
+ end
85
+
86
+ def subscriptions
87
+ render "subscriptions", :layout=>get_layout
88
+ end
89
+
90
+ def update
91
+ @publisher.update_attributes(params[:q_publisher])
92
+ respond_with_bip(@publisher)
93
+ end
94
+
95
+ private
96
+ def load_publisher
97
+ @publisher = QPublisher.sys(_sid).where(:id=>params[:id]).first
98
+ end
99
+
100
+ def get_layout
101
+ if user.admin?
102
+ "cms"
103
+ else
104
+ "#{_sid}/#{Preference.get_cached(_sid, "queue_manager_layout") || "application"}"
105
+ end
106
+ end
107
+
108
+ def check_user
109
+ return true if current_user.admin?
110
+ return true if current_user && @publisher.user_id == current_user.id
111
+
112
+ redirect_to "/"
113
+ end
114
+
115
+ def check_admin
116
+ current_user && current_user.admin?
117
+
118
+ redirect_to "/"
119
+ end
120
+ end
@@ -189,15 +189,15 @@ class Admin::UserController < AdminController
189
189
  musts << { :term => {:group_ids => group} } if group.not_blank?
190
190
  musts << { :query_string => {:fields => [ :email, :display_name ], :query => "*#{search_for.downcase}*" }} if search_for.not_blank?
191
191
  musts << { :term => {"attributes.#{parameter}" => value.downcase} } if parameter.not_blank? && value.not_blank?
192
+ musts << { :term => {:system_id=>system_id} }
192
193
 
193
194
  if musts.size > 0
194
- search = Tire.search "kit_#{app_name.downcase}_users", {:query => { :bool => { :must => musts } }, :size=>per_page, :from=>from}
195
+ search = Tire.search "#{index_name}_users", {:query => { :bool => { :must => musts } }, :size=>per_page, :from=>from}
195
196
  search.size(per_page)
196
197
  search.from(from)
197
- search.filter :terms, :system_id=>system_id
198
198
  @users = search.results
199
199
  else
200
- @users = User.sys(_sid).order(:email).page(params[:page]).per(per_page)
200
+ @users = User.sys(_sid).order('created_at desc').page(params[:page]).per(per_page)
201
201
  end
202
202
  end
203
203
 
@@ -274,7 +274,7 @@ class Admin::UserController < AdminController
274
274
  redirect_to "/db", :notice=>"You cannot become that user"
275
275
  return
276
276
  else
277
- sign_in(:user, target)
277
+ warden.set_user target
278
278
  redirect_to "/", :notice=>"You've successfully become that user"
279
279
  return
280
280
  end