fat_free_crm 0.11.1 → 0.11.2

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.

Potentially problematic release.


This version of fat_free_crm might be problematic. Click here for more details.

Files changed (179) hide show
  1. data/Gemfile +30 -12
  2. data/Gemfile.lock +131 -119
  3. data/Procfile +1 -1
  4. data/README.md +1 -1
  5. data/app/assets/images/notifications.png +0 -0
  6. data/app/assets/javascripts/application.js.erb +3 -0
  7. data/app/assets/javascripts/crm_textarea_autocomplete.js +44 -0
  8. data/app/assets/stylesheets/application.css.erb +2 -0
  9. data/app/assets/stylesheets/common.scss +7 -11
  10. data/app/assets/stylesheets/textarea_autocomplete.scss +42 -0
  11. data/app/controllers/admin/application_controller.rb +5 -5
  12. data/app/controllers/admin/field_groups_controller.rb +11 -51
  13. data/app/controllers/admin/fields_controller.rb +13 -59
  14. data/app/controllers/admin/plugins_controller.rb +1 -4
  15. data/app/controllers/admin/settings_controller.rb +0 -4
  16. data/app/controllers/admin/tags_controller.rb +11 -66
  17. data/app/controllers/admin/users_controller.rb +20 -83
  18. data/app/controllers/application_controller.rb +83 -69
  19. data/app/controllers/comments_controller.rb +12 -29
  20. data/app/controllers/emails_controller.rb +1 -5
  21. data/app/controllers/entities/accounts_controller.rb +13 -32
  22. data/app/controllers/entities/campaigns_controller.rb +17 -32
  23. data/app/controllers/entities/contacts_controller.rb +20 -38
  24. data/app/controllers/entities/leads_controller.rb +33 -55
  25. data/app/controllers/entities/opportunities_controller.rb +26 -42
  26. data/app/controllers/entities_controller.rb +92 -83
  27. data/app/controllers/home_controller.rb +1 -10
  28. data/app/controllers/lists_controller.rb +1 -4
  29. data/app/controllers/{entities/tasks_controller.rb → tasks_controller.rb} +21 -32
  30. data/app/controllers/users_controller.rb +6 -5
  31. data/app/helpers/accounts_helper.rb +32 -9
  32. data/app/helpers/application_helper.rb +15 -1
  33. data/app/helpers/campaigns_helper.rb +1 -1
  34. data/app/helpers/comments_helper.rb +11 -1
  35. data/app/helpers/leads_helper.rb +1 -1
  36. data/app/helpers/opportunities_helper.rb +1 -1
  37. data/app/{models/mailers/notifier.rb → mailers/dropbox_mailer.rb} +5 -16
  38. data/app/mailers/subscription_mailer.rb +37 -0
  39. data/{lib/tasks/dropbox.rake → app/mailers/user_mailer.rb} +11 -13
  40. data/app/models/entities/account.rb +3 -1
  41. data/app/models/entities/campaign.rb +3 -1
  42. data/app/models/entities/contact.rb +3 -1
  43. data/app/models/entities/lead.rb +6 -5
  44. data/app/models/entities/opportunity.rb +3 -1
  45. data/app/models/fields/field.rb +1 -1
  46. data/app/models/polymorphic/comment.rb +34 -0
  47. data/app/models/{entities → polymorphic}/task.rb +16 -3
  48. data/app/models/setting.rb +15 -15
  49. data/app/models/users/ability.rb +12 -5
  50. data/app/models/users/user.rb +7 -2
  51. data/app/views/accounts/index.html.haml +1 -1
  52. data/app/views/accounts/index.js.rjs +1 -1
  53. data/app/views/admin/plugins/index.html.haml +1 -7
  54. data/app/views/{shared/auto_complete.html.haml → application/_auto_complete.html.haml} +0 -0
  55. data/app/views/{shared → application}/index.atom.builder +1 -1
  56. data/app/views/{shared → application}/index.rss.builder +1 -1
  57. data/app/views/campaigns/index.html.haml +1 -1
  58. data/app/views/campaigns/index.js.rjs +1 -1
  59. data/app/views/comments/_new.html.haml +6 -0
  60. data/app/views/comments/_subscription_links.html.haml +13 -0
  61. data/app/views/comments/new.js.rjs +2 -0
  62. data/app/views/contacts/_top_section.html.haml +3 -13
  63. data/app/views/contacts/index.html.haml +1 -1
  64. data/app/views/contacts/index.js.rjs +1 -1
  65. data/app/views/{notifier/dropbox_ack_notification.html.haml → dropbox_mailer/dropbox_notification.html.haml} +2 -2
  66. data/app/views/{shared → entities}/attach.js.rjs +1 -1
  67. data/app/views/entities/contacts.js.rjs +1 -1
  68. data/app/views/{shared/discard.rjs → entities/discard.js.rjs} +0 -0
  69. data/app/views/entities/leads.js.rjs +1 -1
  70. data/app/views/entities/opportunities.js.rjs +1 -1
  71. data/app/views/entities/subscription_update.js.rjs +4 -0
  72. data/app/views/entities/versions.js.rjs +1 -1
  73. data/app/views/layouts/_footer.html.haml +1 -1
  74. data/app/views/layouts/application.html.haml +3 -0
  75. data/app/views/leads/_contact.html.haml +1 -0
  76. data/app/views/leads/index.html.haml +1 -1
  77. data/app/views/leads/index.js.rjs +1 -1
  78. data/app/views/opportunities/_top_section.html.haml +4 -14
  79. data/app/views/opportunities/index.html.haml +1 -1
  80. data/app/views/opportunities/index.js.rjs +1 -1
  81. data/app/views/subscription_mailer/comment_notification.text.erb +7 -0
  82. data/app/views/{notifier → user_mailer}/password_reset_instructions.html.haml +0 -0
  83. data/config/application.rb +3 -1
  84. data/config/environments/development.rb +1 -1
  85. data/config/environments/test.rb +3 -0
  86. data/config/initializers/action_mailer.rb +8 -5
  87. data/config/initializers/cancan.rb +151 -0
  88. data/config/initializers/constants.rb +1 -0
  89. data/config/initializers/locale.rb +20 -0
  90. data/config/initializers/paper_trail.rb +4 -5
  91. data/config/initializers/relative_url_root.rb +0 -1
  92. data/config/initializers/squeel.rb +5 -0
  93. data/config/locales/cz_fat_free_crm.yml +3 -3
  94. data/config/locales/de.yml +2 -2
  95. data/config/locales/de_fat_free_crm.yml +651 -596
  96. data/config/locales/en-GB_fat_free_crm.yml +3 -3
  97. data/config/locales/en-US_fat_free_crm.yml +13 -3
  98. data/config/locales/es_fat_free_crm.yml +3 -3
  99. data/config/locales/fr-CA_fat_free_crm.yml +3 -3
  100. data/config/locales/fr_fat_free_crm.yml +3 -3
  101. data/config/locales/it_fat_free_crm.yml +3 -3
  102. data/config/locales/pl_fat_free_crm.yml +3 -3
  103. data/config/locales/pt-BR_fat_free_crm.yml +3 -3
  104. data/config/locales/ru_fat_free_crm.yml +3 -3
  105. data/config/locales/sv-SE_fat_free_crm.yml +3 -3
  106. data/config/locales/th_fat_free_crm.yml +3 -3
  107. data/config/routes.rb +10 -0
  108. data/config/settings.default.yml +29 -10
  109. data/config/unicorn.rb +4 -0
  110. data/db/migrate/20111201030535_add_field_groups_klass_name.rb +3 -1
  111. data/db/migrate/20120314080441_add_subscribed_users_to_entities.rb +23 -0
  112. data/db/migrate/20120405080727_change_subscribed_users_to_set.rb +24 -0
  113. data/db/migrate/20120405080742_change_further_subscribed_users_to_set.rb +27 -0
  114. data/db/migrate/20120413034923_add_index_on_versions_item_type.rb +5 -0
  115. data/db/schema.rb +109 -126
  116. data/fat_free_crm.gemspec +12 -18
  117. data/lib/fat_free_crm.rb +0 -1
  118. data/lib/fat_free_crm/core_ext/array.rb +1 -0
  119. data/lib/fat_free_crm/gem_dependencies.rb +1 -0
  120. data/lib/fat_free_crm/mail_processor/base.rb +226 -0
  121. data/lib/fat_free_crm/mail_processor/comment_replies.rb +86 -0
  122. data/lib/fat_free_crm/mail_processor/dropbox.rb +288 -0
  123. data/lib/fat_free_crm/permissions.rb +6 -19
  124. data/lib/fat_free_crm/renderers.rb +0 -8
  125. data/lib/fat_free_crm/tabs.rb +1 -1
  126. data/lib/fat_free_crm/version.rb +1 -1
  127. data/lib/plugins/country_select/lib/country_select.rb +2 -2
  128. data/lib/tasks/mail_processing.rake +60 -0
  129. data/spec/controllers/admin/users_controller_spec.rb +0 -2
  130. data/spec/controllers/{accounts_controller_spec.rb → entities/accounts_controller_spec.rb} +7 -9
  131. data/spec/controllers/{campaigns_controller_spec.rb → entities/campaigns_controller_spec.rb} +7 -7
  132. data/spec/controllers/{contacts_controller_spec.rb → entities/contacts_controller_spec.rb} +5 -9
  133. data/spec/controllers/{leads_controller_spec.rb → entities/leads_controller_spec.rb} +7 -9
  134. data/spec/controllers/{opportunities_controller_spec.rb → entities/opportunities_controller_spec.rb} +8 -15
  135. data/spec/controllers/tasks_controller_spec.rb +1 -5
  136. data/spec/controllers/users_controller_spec.rb +5 -9
  137. data/spec/factories/subscription_factories.rb +6 -0
  138. data/spec/lib/mail_processor/base_spec.rb +164 -0
  139. data/spec/lib/mail_processor/comment_replies_spec.rb +63 -0
  140. data/spec/lib/{dropbox_spec.rb → mail_processor/dropbox_spec.rb} +73 -181
  141. data/spec/lib/mail_processor/sample_emails/dropbox.rb +167 -0
  142. data/spec/mailers/subscription_mailer_spec.rb +17 -0
  143. data/spec/models/{base → entities}/account_contact_spec.rb +0 -0
  144. data/spec/models/{base → entities}/account_opportunity_spec.rb +0 -0
  145. data/spec/models/{base → entities}/account_spec.rb +4 -0
  146. data/spec/models/{base → entities}/campaign_spec.rb +4 -0
  147. data/spec/models/{base → entities}/contact_opportunity_spec.rb +0 -0
  148. data/spec/models/{base → entities}/contact_spec.rb +4 -0
  149. data/spec/models/{base → entities}/lead_spec.rb +4 -0
  150. data/spec/models/{base → entities}/opportunity_spec.rb +4 -0
  151. data/spec/models/polymorphic/comment_spec.rb +15 -0
  152. data/spec/models/{base → polymorphic}/task_spec.rb +124 -30
  153. data/spec/models/polymorphic/version_spec.rb +1 -1
  154. data/spec/shared/controllers.rb +5 -7
  155. data/spec/shared/models.rb +46 -0
  156. data/spec/spec_helper.rb +3 -4
  157. data/spec/support/mail_processor_mocks.rb +30 -0
  158. data/spec/support/uploaded_file.rb +3 -0
  159. data/spec/views/{common → application}/auto_complete.haml_spec.rb +1 -1
  160. data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  161. data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  162. data/vendor/assets/images/jquery-ui/ui-bg_flat_10_000000_40x100.png +0 -0
  163. data/vendor/assets/images/jquery-ui/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  164. data/vendor/assets/images/jquery-ui/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  165. data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  166. data/vendor/assets/images/jquery-ui/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  167. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  168. data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  169. data/vendor/assets/images/jquery-ui/ui-icons_222222_256x240.png +0 -0
  170. data/vendor/assets/images/jquery-ui/ui-icons_228ef1_256x240.png +0 -0
  171. data/vendor/assets/images/jquery-ui/ui-icons_ef8c08_256x240.png +0 -0
  172. data/vendor/assets/images/jquery-ui/ui-icons_ffd27a_256x240.png +0 -0
  173. data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
  174. data/vendor/assets/javascripts/textarea_autocomplete.js +605 -0
  175. data/vendor/assets/stylesheets/jquery-ui.custom.css.erb +565 -0
  176. metadata +234 -154
  177. data/config/locales/simple_form.en.yml +0 -24
  178. data/lib/fat_free_crm/dropbox.rb +0 -439
  179. data/spec/lib/dropbox/email_samples.rb +0 -77
@@ -22,10 +22,6 @@ class Admin::SettingsController < Admin::ApplicationController
22
22
  # GET /admin/settings.xml
23
23
  #----------------------------------------------------------------------------
24
24
  def index
25
- respond_to do |format|
26
- format.html # index.html.haml
27
- format.xml { render :xml => nil }
28
- end
29
25
  end
30
26
  end
31
27
 
@@ -18,114 +18,59 @@
18
18
  class Admin::TagsController < Admin::ApplicationController
19
19
  before_filter "set_current_tab('admin/tags')", :only => [ :index, :show ]
20
20
 
21
+ load_resource
22
+
21
23
  # GET /admin/tags
22
24
  # GET /admin/tags.xml HTML
23
25
  #----------------------------------------------------------------------------
24
26
  def index
25
- @tags = Tag.all
26
-
27
- respond_to do |format|
28
- format.html # index.html.haml
29
- format.js # index.js.rjs
30
- format.xml { render :xml => Tag.all }
31
- format.xls { send_data @tags.to_xls, :type => :xls }
32
- format.csv { send_data @tags.to_csv, :type => :csv }
33
- format.rss { render "shared/index.rss.builder" }
34
- format.atom { render "shared/index.atom.builder" }
35
- end
27
+ respond_with(@tags)
36
28
  end
37
29
 
38
30
  # GET /admin/tags/new
39
31
  # GET /admin/tags/new.xml AJAX
40
32
  #----------------------------------------------------------------------------
41
33
  def new
42
- @tag = Tag.new
43
-
44
- respond_to do |format|
45
- format.js # new.js.rjs
46
- format.xml { render :xml => @tag }
47
- end
34
+ respond_with(@tag)
48
35
  end
49
36
 
50
37
  # GET /admin/tags/1/edit AJAX
51
38
  #----------------------------------------------------------------------------
52
39
  def edit
53
- @tag = Tag.find(params[:id])
54
-
55
40
  if params[:previous].to_s =~ /(\d+)\z/
56
- @previous = Tag.find($1)
41
+ @previous = Tag.find_by_id($1) || $1.to_i
57
42
  end
58
-
59
- rescue ActiveRecord::RecordNotFound
60
- @previous ||= $1.to_i
61
- respond_to_not_found(:js) unless @tag
62
43
  end
63
44
 
64
45
  # POST /admin/tags
65
46
  # POST /admin/tags.xml AJAX
66
47
  #----------------------------------------------------------------------------
67
48
  def create
68
- @tag = Tag.new(params[:tag])
49
+ @tag.update_attributes(params[:tag])
69
50
 
70
- respond_to do |format|
71
- if @tag.save
72
- @tags = Tag.all
73
- format.js # create.js.rjs
74
- format.xml { render :xml => @tag, :status => :created, :location => @tag }
75
- else
76
- format.js # create.js.rjs
77
- format.xml { render :xml => @tag.errors, :status => :unprocessable_entity }
78
- end
79
- end
51
+ respond_with(@tag)
80
52
  end
81
53
 
82
54
  # PUT /admin/tags/1
83
55
  # PUT /admin/tags/1.xml AJAX
84
56
  #----------------------------------------------------------------------------
85
57
  def update
86
- @tag = Tag.find(params[:id])
58
+ @tag.update_attributes(params[:tag])
87
59
 
88
- respond_to do |format|
89
- if @tag.update_attributes(params[:tag])
90
- format.js # update.js.rjs
91
- format.xml { head :ok }
92
- else
93
- format.js # update.js.rjs
94
- format.xml { render :xml => @tag.errors, :status => :unprocessable_entity }
95
- end
96
- end
97
-
98
- rescue ActiveRecord::RecordNotFound
99
- respond_to_not_found(:js, :xml)
60
+ respond_with(@tag)
100
61
  end
101
62
 
102
-
103
63
  # DELETE /admin/tags/1
104
64
  # DELETE /admin/tags/1.xml AJAX
105
65
  #----------------------------------------------------------------------------
106
66
  def destroy
107
- @tag = Tag.find(params[:id])
67
+ @tag.destroy
108
68
 
109
- respond_to do |format|
110
- if @tag.destroy
111
- format.js # destroy.js.rjs
112
- format.xml { head :ok }
113
- else
114
- flash[:warning] = t(:msg_cant_delete_tag, @tag.name)
115
- format.js # destroy.js.rjs
116
- format.xml { render :xml => @tag.errors, :status => :unprocessable_entity }
117
- end
118
- end
69
+ respond_with(@tag)
119
70
  end
120
71
 
121
72
  # GET /admin/tags/1/confirm AJAX
122
73
  #----------------------------------------------------------------------------
123
74
  def confirm
124
- @tag = Tag.find(params[:id])
125
-
126
- rescue ActiveRecord::RecordNotFound
127
- respond_to_not_found(:js, :xml)
128
75
  end
129
-
130
76
  end
131
-
@@ -18,59 +18,38 @@
18
18
  class Admin::UsersController < Admin::ApplicationController
19
19
  before_filter "set_current_tab('admin/users')", :only => [ :index, :show ]
20
20
 
21
+ load_resource
22
+
21
23
  # GET /admin/users
22
24
  # GET /admin/users.xml HTML
23
25
  #----------------------------------------------------------------------------
24
26
  def index
25
27
  @users = get_users(:page => params[:page])
26
-
27
- respond_to do |format|
28
- format.html # index.html.haml
29
- format.js # index.js.rjs
30
- format.xml { render :xml => User.all }
31
- format.xls { send_data @users.to_xls, :type => :xls }
32
- format.csv { send_data @users.to_csv, :type => :csv }
33
- format.rss { render "shared/index.rss.builder" }
34
- format.atom { render "shared/index.atom.builder" }
35
- end
28
+ respond_with(@users)
36
29
  end
37
30
 
38
31
  # GET /admin/users/1
39
32
  # GET /admin/users/1.xml
40
33
  #----------------------------------------------------------------------------
41
34
  def show
42
- @user = User.find(params[:id])
43
-
44
- respond_to do |format|
45
- format.html # show.html.haml
46
- format.xml { render :xml => @user }
47
- end
35
+ respond_with(@user)
48
36
  end
49
37
 
50
38
  # GET /admin/users/new
51
39
  # GET /admin/users/new.xml AJAX
52
40
  #----------------------------------------------------------------------------
53
41
  def new
54
- @user = User.new
55
-
56
- respond_to do |format|
57
- format.js # new.js.rjs
58
- format.xml { render :xml => @user }
59
- end
42
+ respond_with(@user)
60
43
  end
61
44
 
62
45
  # GET /admin/users/1/edit AJAX
63
46
  #----------------------------------------------------------------------------
64
47
  def edit
65
- @user = User.find(params[:id])
66
-
67
48
  if params[:previous].to_s =~ /(\d+)\z/
68
- @previous = User.find($1)
49
+ @previous = User.find_by_id($1) || $1.to_i
69
50
  end
70
51
 
71
- rescue ActiveRecord::RecordNotFound
72
- @previous ||= $1.to_i
73
- respond_to_not_found(:js) unless @user
52
+ respond_with(@user)
74
53
  end
75
54
 
76
55
  # POST /admin/users
@@ -80,17 +59,10 @@ class Admin::UsersController < Admin::ApplicationController
80
59
  params[:user][:password_confirmation] = nil if params[:user][:password_confirmation].blank?
81
60
  @user = User.new(params[:user])
82
61
  @user.admin = (params[:user][:admin] == "1")
62
+ @user.save_without_session_maintenance
63
+ @users = get_users
83
64
 
84
- respond_to do |format|
85
- if @user.save_without_session_maintenance
86
- @users = get_users
87
- format.js # create.js.rjs
88
- format.xml { render :xml => @user, :status => :created, :location => @user }
89
- else
90
- format.js # create.js.rjs
91
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
92
- end
93
- end
65
+ respond_with(@user)
94
66
  end
95
67
 
96
68
  # PUT /admin/users/1
@@ -99,47 +71,27 @@ class Admin::UsersController < Admin::ApplicationController
99
71
  def update
100
72
  params[:user][:password_confirmation] = nil if params[:user][:password_confirmation].blank?
101
73
  @user = User.find(params[:id])
74
+ @user.update_attributes(params[:user])
102
75
  @user.admin = (params[:user][:admin] == "1")
103
76
 
104
- respond_to do |format|
105
- if @user.update_attributes(params[:user])
106
- format.js # update.js.rjs
107
- format.xml { head :ok }
108
- else
109
- format.js # update.js.rjs
110
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
111
- end
112
- end
113
-
114
- rescue ActiveRecord::RecordNotFound
115
- respond_to_not_found(:js, :xml)
77
+ respond_with(@user)
116
78
  end
117
79
 
118
80
  # GET /admin/users/1/confirm AJAX
119
81
  #----------------------------------------------------------------------------
120
82
  def confirm
121
- @user = User.find(params[:id])
122
-
123
- rescue ActiveRecord::RecordNotFound
124
- respond_to_not_found(:js, :xml)
83
+ respond_with(@user)
125
84
  end
126
85
 
127
86
  # DELETE /admin/users/1
128
87
  # DELETE /admin/users/1.xml AJAX
129
88
  #----------------------------------------------------------------------------
130
89
  def destroy
131
- @user = User.find(params[:id])
132
-
133
- respond_to do |format|
134
- if @user.destroy
135
- format.js # destroy.js.rjs
136
- format.xml { head :ok }
137
- else
138
- flash[:warning] = t(:msg_cant_delete_user, @user.full_name)
139
- format.js # destroy.js.rjs
140
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
141
- end
90
+ unless @user.destroy
91
+ flash[:warning] = t(:msg_cant_delete_user, @user.full_name)
142
92
  end
93
+
94
+ respond_with(@user)
143
95
  end
144
96
 
145
97
  # POST /users/auto_complete/query AJAX
@@ -150,36 +102,22 @@ class Admin::UsersController < Admin::ApplicationController
150
102
  # PUT /admin/users/1/suspend.xml AJAX
151
103
  #----------------------------------------------------------------------------
152
104
  def suspend
153
- @user = User.find(params[:id])
154
105
  @user.update_attribute(:suspended_at, Time.now) if @user != @current_user
155
106
 
156
- respond_to do |format|
157
- format.js # suspend.js.rjs
158
- format.xml { render :xml => @user }
159
- end
160
-
161
- rescue ActiveRecord::RecordNotFound
162
- respond_to_not_found(:js, :xml)
107
+ respond_with(@user)
163
108
  end
164
109
 
165
110
  # PUT /admin/users/1/reactivate
166
111
  # PUT /admin/users/1/reactivate.xml AJAX
167
112
  #----------------------------------------------------------------------------
168
113
  def reactivate
169
- @user = User.find(params[:id])
170
114
  @user.update_attribute(:suspended_at, nil)
171
115
 
172
- respond_to do |format|
173
- format.js # reactivate.js.rjs
174
- format.xml { render :xml => @user }
175
- end
176
-
177
- rescue ActiveRecord::RecordNotFound
178
- respond_to_not_found(:js, :xml)
116
+ respond_with(@user)
179
117
  end
180
118
 
119
+ private
181
120
 
182
- private
183
121
  #----------------------------------------------------------------------------
184
122
  def get_users(options = {})
185
123
  self.current_page = options[:page] if options[:page]
@@ -192,7 +130,6 @@ class Admin::UsersController < Admin::ApplicationController
192
130
  scope = User.by_id
193
131
  scope = scope.merge(@search.result)
194
132
  scope = scope.text_search(current_query) if current_query.present?
195
- scope = scope.unscoped if wants.csv?
196
133
  scope = scope.paginate(:page => current_page) if wants.html? || wants.js? || wants.xml?
197
134
  scope
198
135
  end
@@ -17,24 +17,47 @@
17
17
 
18
18
  class ApplicationController < ActionController::Base
19
19
 
20
- helper_method :klass
21
- helper_method :current_user_session, :current_user, :can_signup?
22
- helper_method :called_from_index_page?, :called_from_landing_page?
23
-
24
20
  before_filter :set_context
25
21
  before_filter :clear_setting_cache
26
22
  before_filter "hook(:app_before_filter, self)"
27
23
  after_filter "hook(:app_after_filter, self)"
28
24
 
29
- # See ActionController::RequestForgeryProtection for details
30
- # Uncomment the :secret if you're not using the cookie session store
31
- # protect_from_forgery # :secret => '165eb65bfdacf95923dad9aea10cc64a'
25
+ helper_method :current_user_session, :current_user, :can_signup?
26
+ helper_method :called_from_index_page?, :called_from_landing_page?
27
+ helper_method :klass
28
+
29
+ respond_to :html, :only => [ :index, :show, :auto_complete ]
30
+ respond_to :js
31
+ respond_to :json, :xml, :except => :edit
32
+ respond_to :atom, :csv, :rss, :xls, :only => :index
33
+
34
+ rescue_from ActiveRecord::RecordNotFound, :with => :respond_to_not_found
35
+ rescue_from CanCan::AccessDenied, :with => :respond_to_access_denied
36
+
37
+ # Common auto_complete handler for all core controllers.
38
+ #----------------------------------------------------------------------------
39
+ def auto_complete
40
+ @query = params[:auto_complete_query] || ''
41
+ @auto_complete = hook(:auto_complete, self, :query => @query, :user => @current_user)
42
+ if @auto_complete.empty?
43
+ @auto_complete = klass.my.text_search(@query).limit(10)
44
+ else
45
+ @auto_complete = @auto_complete.last
46
+ end
47
+ session[:auto_complete] = controller_name.to_sym
48
+ respond_to do |format|
49
+ format.any(:js, :html) { render :partial => 'auto_complete' }
50
+ format.json { render :json => @auto_complete.inject({}){|h,a| h[a.id] = a.name; h } }
51
+ end
52
+ end
53
+
54
+ private
32
55
 
56
+ #----------------------------------------------------------------------------
33
57
  def klass
34
58
  @klass ||= controller_name.classify.constantize
35
59
  end
36
60
 
37
- private
38
61
  #----------------------------------------------------------------------------
39
62
  def clear_setting_cache
40
63
  Setting.clear_cache!
@@ -94,11 +117,6 @@ private
94
117
  end
95
118
  end
96
119
 
97
- #----------------------------------------------------------------------------
98
- def get_users
99
- @users ||= User.except(current_user)
100
- end
101
-
102
120
  #----------------------------------------------------------------------------
103
121
  def store_location
104
122
  session[:return_to] = request.fullpath
@@ -129,83 +147,79 @@ private
129
147
  request.referer =~ %r(/#{controller}/\w+)
130
148
  end
131
149
 
132
- #----------------------------------------------------------------------------
133
- def respond_to_not_found(*types)
134
- asset = self.controller_name.singularize
135
- flick = case self.action_name
136
- when "destroy" then "delete"
137
- when "promote" then "convert"
138
- else self.action_name
139
- end
140
- if self.action_name == "show"
141
- # If asset does exist, but is not viewable to the current user..
142
- if asset.capitalize.constantize.exists?(params[:id])
143
- flash[:warning] = t(:msg_asset_not_authorized, asset)
144
- else
145
- flash[:warning] = t(:msg_asset_not_available, asset)
146
- end
147
- else
148
- flash[:warning] = t(:msg_cant_do, :action => flick, :asset => asset)
149
- end
150
- respond_to do |format|
151
- format.html { redirect_to :action => :index } if types.include?(:html)
152
- format.js { render(:update) { |page| page.reload } } if types.include?(:js)
153
- format.json { render :text => flash[:warning], :status => :not_found } if types.include?(:json)
154
- format.xml { render :text => flash[:warning], :status => :not_found } if types.include?(:xml)
155
- end
156
- end
157
-
158
- #----------------------------------------------------------------------------
159
- def respond_to_related_not_found(related, *types)
160
- asset = self.controller_name.singularize
161
- asset = "note" if asset == "comment"
162
- flash[:warning] = t(:msg_cant_create_related, :asset => asset, :related => related)
163
- url = send("#{related.pluralize}_path")
164
- respond_to do |format|
165
- format.html { redirect_to url } if types.include?(:html)
166
- format.js { render(:update) { |page| page.redirect_to url } } if types.include?(:js)
167
- format.json { render :text => flash[:warning], :status => :not_found } if types.include?(:json)
168
- format.xml { render :text => flash[:warning], :status => :not_found } if types.include?(:xml)
169
- end
170
- end
171
-
172
150
  # Proxy current page for any of the controllers by storing it in a session.
173
151
  #----------------------------------------------------------------------------
174
152
  def current_page=(page)
175
- @current_page = session["#{controller_name}_current_page".to_sym] = page.to_i
153
+ @current_page = session[:"#{controller_name}_current_page"] = page.to_i
176
154
  end
177
155
 
178
156
  #----------------------------------------------------------------------------
179
157
  def current_page
180
- page = params[:page] || session["#{controller_name}_current_page".to_sym] || 1
158
+ page = params[:page] || session[:"#{controller_name}_current_page"] || 1
181
159
  @current_page = page.to_i
182
160
  end
183
161
 
184
162
  # Proxy current search query for any of the controllers by storing it in a session.
185
163
  #----------------------------------------------------------------------------
186
164
  def current_query=(query)
187
- @current_query = session["#{controller_name}_current_query".to_sym] = query
165
+ @current_query = session[:"#{controller_name}_current_query"] = query
188
166
  end
189
167
 
190
168
  #----------------------------------------------------------------------------
191
169
  def current_query
192
- @current_query = params[:query] || session["#{controller_name}_current_query".to_sym] || ""
170
+ @current_query = params[:query] || session[:"#{controller_name}_current_query"] || ''
171
+ end
172
+
173
+ #----------------------------------------------------------------------------
174
+ def asset
175
+ self.controller_name.singularize
176
+ end
177
+
178
+ #----------------------------------------------------------------------------
179
+ def respond_to_not_found(*types)
180
+ flash[:warning] = t(:msg_asset_not_available, asset)
181
+
182
+ respond_to do |format|
183
+ format.html { redirect_to :action => :index }
184
+ format.js { render(:update) { |page| page.reload } }
185
+ format.json { render :text => flash[:warning], :status => :not_found }
186
+ format.xml { render :text => flash[:warning], :status => :not_found }
187
+ end
193
188
  end
194
189
 
195
- # Somewhat simplistic parser that extracts query and hash-prefixed tags from
196
- # the search string and returns them as two element array, for example:
197
- #
198
- # "#real Billy Bones #pirate" => [ "Billy Bones", "real, pirate" ]
199
190
  #----------------------------------------------------------------------------
200
- def parse_query_and_tags(search_string)
201
- query, tags = [], []
202
- search_string.scan(/[\w@\-\.#]+/).each do |token|
203
- if token.starts_with?("#")
204
- tags << token[1 .. -1]
205
- else
206
- query << token
191
+ def respond_to_related_not_found(related, *types)
192
+ asset = "note" if asset == "comment"
193
+ flash[:warning] = t(:msg_cant_create_related, :asset => asset, :related => related)
194
+
195
+ url = send("#{related.pluralize}_path")
196
+ respond_to do |format|
197
+ format.html { redirect_to url }
198
+ format.js { render(:update) { |page| page.redirect_to url } }
199
+ format.json { render :text => flash[:warning], :status => :not_found }
200
+ format.xml { render :text => flash[:warning], :status => :not_found }
201
+ end
202
+ end
203
+
204
+ #----------------------------------------------------------------------------
205
+ def respond_to_access_denied
206
+ if self.action_name == "show"
207
+ flash[:warning] = t(:msg_asset_not_authorized, asset)
208
+
209
+ else
210
+ flick = case self.action_name
211
+ when "destroy" then "delete"
212
+ when "promote" then "convert"
213
+ else self.action_name
207
214
  end
215
+ flash[:warning] = t(:msg_cant_do, :action => flick, :asset => asset)
216
+ end
217
+
218
+ respond_to do |format|
219
+ format.html { redirect_to :action => :index }
220
+ format.js { render(:update) { |page| page.reload } }
221
+ format.json { render :text => flash[:warning], :status => :unauthorized }
222
+ format.xml { render :text => flash[:warning], :status => :unauthorized }
208
223
  end
209
- [ query.join(" "), tags.join(", ") ]
210
224
  end
211
225
  end