fat_free_crm 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.

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
@@ -18,9 +18,6 @@
18
18
  class CommentsController < ApplicationController
19
19
  before_filter :require_user
20
20
 
21
- respond_to :js
22
- respond_to :json, :xml, :except => :edit
23
-
24
21
  COMMENTABLE = %w(account_id campaign_id contact_id lead_id opportunity_id task_id).freeze
25
22
 
26
23
  # GET /comments
@@ -56,13 +53,12 @@ class CommentsController < ApplicationController
56
53
 
57
54
  if @commentable
58
55
  update_commentable_session
59
- @commentable.classify.constantize.my.find(params[:"#{@commentable}_id"])
56
+ unless @commentable.classify.constantize.my.find_by_id(params[:"#{@commentable}_id"])
57
+ respond_to_related_not_found(@commentable) and return
58
+ end
60
59
  end
61
60
 
62
61
  respond_with(@comment)
63
-
64
- rescue ActiveRecord::RecordNotFound # Kicks in if commentable asset was not found.
65
- respond_to_related_not_found(@commentable, :js)
66
62
  end
67
63
 
68
64
  # GET /comments/1/edit AJAX
@@ -70,14 +66,10 @@ class CommentsController < ApplicationController
70
66
  def edit
71
67
  @comment = Comment.find(params[:id])
72
68
 
73
- if @comment.commentable
74
- @comment.commentable_type.constantize.my.find(@comment.commentable.id)
75
- else
76
- raise ActiveRecord::RecordNotFound
69
+ model, id = @comment.commentable_type, @comment.commentable_id
70
+ unless model.constantize.my.find_by_id(id)
71
+ respond_to_related_not_found(model.downcase)
77
72
  end
78
-
79
- rescue ActiveRecord::RecordNotFound # Kicks in if commentable asset was not found.
80
- respond_to_related_not_found(params[:comment][:commentable_type].downcase, :js, :xml)
81
73
  end
82
74
 
83
75
  # POST /comments
@@ -88,17 +80,13 @@ class CommentsController < ApplicationController
88
80
  @comment = Comment.new(params[:comment])
89
81
 
90
82
  # Make sure commentable object exists and is accessible to the current user.
91
- if @comment.commentable
92
- @comment.commentable_type.constantize.my.find(@comment.commentable.id)
93
- else
94
- raise ActiveRecord::RecordNotFound
83
+ model, id = @comment.commentable_type, @comment.commentable_id
84
+ unless model.constantize.my.find_by_id(id)
85
+ respond_to_related_not_found(model.downcase)
95
86
  end
96
87
 
97
88
  @comment.save
98
89
  respond_with(@comment)
99
-
100
- rescue ActiveRecord::RecordNotFound # Kicks in if commentable asset was not found.
101
- respond_to_related_not_found(params[:comment][:commentable_type].downcase, :js, :xml)
102
90
  end
103
91
 
104
92
  # PUT /comments/1
@@ -109,9 +97,6 @@ class CommentsController < ApplicationController
109
97
  @comment = Comment.find(params[:id])
110
98
  @comment.update_attributes(params[:comment])
111
99
  respond_with(@comment)
112
-
113
- rescue ActiveRecord::RecordNotFound
114
- respond_to_not_found(:js, :json, :xml)
115
100
  end
116
101
 
117
102
  # DELETE /comments/1
@@ -122,16 +107,14 @@ class CommentsController < ApplicationController
122
107
  @comment = Comment.find(params[:id])
123
108
  @comment.destroy
124
109
  respond_with(@comment)
125
-
126
- rescue ActiveRecord::RecordNotFound
127
- respond_to_not_found(:html, :js, :json, :xml)
128
110
  end
129
111
 
130
- private
112
+ private
113
+
131
114
  #----------------------------------------------------------------------------
132
115
  def extract_commentable_name(params)
133
116
  commentable = (params.keys & COMMENTABLE).first
134
- commentable.sub("_id", "") if commentable
117
+ commentable.sub('_id', '') if commentable
135
118
  end
136
119
 
137
120
  #----------------------------------------------------------------------------
@@ -18,8 +18,6 @@
18
18
  class EmailsController < ApplicationController
19
19
  before_filter :require_user
20
20
 
21
- respond_to :js, :json, :xml
22
-
23
21
  # GET /email
24
22
  # GET /email.xml not implemented
25
23
  #----------------------------------------------------------------------------
@@ -56,9 +54,7 @@ class EmailsController < ApplicationController
56
54
  def destroy
57
55
  @email = Email.find(params[:id])
58
56
  @email.destroy
59
- respond_with(@email)
60
57
 
61
- rescue ActiveRecord::RecordNotFound
62
- respond_to_not_found(:html, :js, :json, :xml)
58
+ respond_with(@email)
63
59
  end
64
60
  end
@@ -28,8 +28,6 @@ class AccountsController < EntitiesController
28
28
  # GET /accounts/1
29
29
  #----------------------------------------------------------------------------
30
30
  def show
31
- @account = Account.my.find(params[:id])
32
-
33
31
  respond_with(@account) do |format|
34
32
  format.html do
35
33
  @stage = Setting.unroll(:opportunity_stage)
@@ -37,18 +35,16 @@ class AccountsController < EntitiesController
37
35
  @timeline = timeline(@account)
38
36
  end
39
37
  end
40
-
41
- rescue ActiveRecord::RecordNotFound
42
- respond_to_not_found(:html, :json, :xml)
43
38
  end
44
39
 
45
40
  # GET /accounts/new
46
41
  #----------------------------------------------------------------------------
47
42
  def new
48
- @account = Account.new(:user => @current_user, :access => Setting.default_access)
43
+ @account.attributes = {:user => @current_user, :access => Setting.default_access}
49
44
  @users = User.except(@current_user)
45
+
50
46
  if params[:related]
51
- model, id = params[:related].split("_")
47
+ model, id = params[:related].split('_')
52
48
  instance_variable_set("@#{model}", model.classify.constantize.find(id))
53
49
  end
54
50
 
@@ -58,22 +54,17 @@ class AccountsController < EntitiesController
58
54
  # GET /accounts/1/edit AJAX
59
55
  #----------------------------------------------------------------------------
60
56
  def edit
61
- @account = Account.my.find(params[:id])
62
57
  @users = User.except(@current_user)
63
58
  if params[:previous].to_s =~ /(\d+)\z/
64
- @previous = Account.my.find($1)
59
+ @previous = Account.my.find_by_id($1) || $1.to_i
65
60
  end
66
- respond_with(@account)
67
61
 
68
- rescue ActiveRecord::RecordNotFound
69
- @previous ||= $1.to_i
70
- respond_to_not_found(:js) unless @account
62
+ respond_with(@account)
71
63
  end
72
64
 
73
65
  # POST /accounts
74
66
  #----------------------------------------------------------------------------
75
67
  def create
76
- @account = Account.new(params[:account])
77
68
  @users = User.except(@current_user)
78
69
 
79
70
  respond_with(@account) do |format|
@@ -89,8 +80,6 @@ class AccountsController < EntitiesController
89
80
  # PUT /accounts/1
90
81
  #----------------------------------------------------------------------------
91
82
  def update
92
- @account = Account.my.find(params[:id])
93
-
94
83
  respond_with(@account) do |format|
95
84
  if @account.update_with_permissions(params[:account], params[:users])
96
85
  get_data_for_sidebar
@@ -98,33 +87,26 @@ class AccountsController < EntitiesController
98
87
  @users = User.except(@current_user) # Need it to redraw [Edit Account] form.
99
88
  end
100
89
  end
101
-
102
- rescue ActiveRecord::RecordNotFound
103
- respond_to_not_found(:js, :json, :xml)
104
90
  end
105
91
 
106
92
  # DELETE /accounts/1
107
93
  #----------------------------------------------------------------------------
108
94
  def destroy
109
- @account = Account.my.find(params[:id])
110
- @account.destroy if @account
95
+ @account.destroy
111
96
 
112
97
  respond_with(@account) do |format|
113
98
  format.html { respond_to_destroy(:html) }
114
99
  format.js { respond_to_destroy(:ajax) }
115
100
  end
116
-
117
- rescue ActiveRecord::RecordNotFound
118
- respond_to_not_found(:html, :js, :json, :xml)
119
101
  end
120
102
 
121
103
  # PUT /accounts/1/attach
122
104
  #----------------------------------------------------------------------------
123
- # Handled by ApplicationController :attach
105
+ # Handled by EntitiesController :attach
124
106
 
125
107
  # PUT /accounts/1/discard
126
108
  #----------------------------------------------------------------------------
127
- # Handled by ApplicationController :discard
109
+ # Handled by EntitiesController :discard
128
110
 
129
111
  # POST /accounts/auto_complete/query AJAX
130
112
  #----------------------------------------------------------------------------
@@ -153,23 +135,22 @@ class AccountsController < EntitiesController
153
135
  # POST /accounts/filter AJAX
154
136
  #----------------------------------------------------------------------------
155
137
  def filter
156
- session[:filter_by_account_category] = params[:category]
138
+ session[:accounts_filter] = params[:category]
157
139
  @accounts = get_accounts(:page => 1)
158
140
  render :index
159
141
  end
160
142
 
161
- private
143
+ private
144
+
162
145
  #----------------------------------------------------------------------------
163
- def get_accounts(options = {})
164
- get_list_of_records(Account, options.merge!(:filter => :filter_by_account_category))
165
- end
146
+ alias :get_accounts :get_list_of_records
166
147
 
167
148
  #----------------------------------------------------------------------------
168
149
  def respond_to_destroy(method)
169
150
  if method == :ajax
170
151
  @accounts = get_accounts
171
152
  get_data_for_sidebar
172
- if @accounts.blank?
153
+ if @accounts.empty?
173
154
  @accounts = get_accounts(:page => current_page - 1) if current_page > 1
174
155
  render :index and return
175
156
  end
@@ -28,8 +28,6 @@ class CampaignsController < EntitiesController
28
28
  # GET /campaigns/1
29
29
  #----------------------------------------------------------------------------
30
30
  def show
31
- @campaign = Campaign.my.find(params[:id])
32
-
33
31
  respond_with(@campaign) do |format|
34
32
  format.html do
35
33
  @stage = Setting.unroll(:opportunity_stage)
@@ -37,9 +35,6 @@ class CampaignsController < EntitiesController
37
35
  @timeline = timeline(@campaign)
38
36
  end
39
37
  end
40
-
41
- rescue ActiveRecord::RecordNotFound
42
- respond_to_not_found(:html, :json, :xml)
43
38
  end
44
39
 
45
40
  # GET /campaigns/new
@@ -47,11 +42,16 @@ class CampaignsController < EntitiesController
47
42
  # GET /campaigns/new.xml AJAX
48
43
  #----------------------------------------------------------------------------
49
44
  def new
50
- @campaign = Campaign.new(:user => @current_user, :access => Setting.default_access)
45
+ @campaign.attributes = {:user => @current_user, :access => Setting.default_access}
51
46
  @users = User.except(@current_user)
47
+
52
48
  if params[:related]
53
- model, id = params[:related].split("_")
54
- instance_variable_set("@#{model}", model.classify.constantize.find(id))
49
+ model, id = params[:related].split('_')
50
+ if related = model.classify.constantize.my.find_by_id(id)
51
+ instance_variable_set("@#{model}", related)
52
+ else
53
+ respond_to_related_not_found(model) and return
54
+ end
55
55
  end
56
56
 
57
57
  respond_with(@campaign)
@@ -60,22 +60,17 @@ class CampaignsController < EntitiesController
60
60
  # GET /campaigns/1/edit AJAX
61
61
  #----------------------------------------------------------------------------
62
62
  def edit
63
- @campaign = Campaign.my.find(params[:id])
64
63
  @users = User.except(@current_user)
65
64
  if params[:previous].to_s =~ /(\d+)\z/
66
- @previous = Campaign.my.find($1)
65
+ @previous = Campaign.my.find_by_id($1) || $1.to_i
67
66
  end
68
- respond_with(@campaign)
69
67
 
70
- rescue ActiveRecord::RecordNotFound
71
- @previous ||= $1.to_i
72
- respond_to_not_found(:js) unless @campaign
68
+ respond_with(@campaign)
73
69
  end
74
70
 
75
71
  # POST /campaigns
76
72
  #----------------------------------------------------------------------------
77
73
  def create
78
- @campaign = Campaign.new(params[:campaign])
79
74
  @users = User.except(@current_user)
80
75
 
81
76
  respond_with(@campaign) do |format|
@@ -89,8 +84,6 @@ class CampaignsController < EntitiesController
89
84
  # PUT /campaigns/1
90
85
  #----------------------------------------------------------------------------
91
86
  def update
92
- @campaign = Campaign.my.find(params[:id])
93
-
94
87
  respond_with(@campaign) do |format|
95
88
  if @campaign.update_with_permissions(params[:campaign], params[:users])
96
89
  get_data_for_sidebar if called_from_index_page?
@@ -98,33 +91,26 @@ class CampaignsController < EntitiesController
98
91
  @users = User.except(@current_user) # Need it to redraw [Edit Campaign] form.
99
92
  end
100
93
  end
101
-
102
- rescue ActiveRecord::RecordNotFound
103
- respond_to_not_found(:js, :json, :xml)
104
94
  end
105
95
 
106
96
  # DELETE /campaigns/1
107
97
  #----------------------------------------------------------------------------
108
98
  def destroy
109
- @campaign = Campaign.my.find(params[:id])
110
- @campaign.destroy if @campaign
99
+ @campaign.destroy
111
100
 
112
101
  respond_with(@campaign) do |format|
113
102
  format.html { respond_to_destroy(:html) }
114
103
  format.js { respond_to_destroy(:ajax) }
115
104
  end
116
-
117
- rescue ActiveRecord::RecordNotFound
118
- respond_to_not_found(:html, :js, :json, :xml)
119
105
  end
120
106
 
121
107
  # PUT /campaigns/1/attach
122
108
  #----------------------------------------------------------------------------
123
- # Handled by ApplicationController :attach
109
+ # Handled by EntitiesController :attach
124
110
 
125
111
  # PUT /campaigns/1/discard
126
112
  #----------------------------------------------------------------------------
127
- # Handled by ApplicationController :discard
113
+ # Handled by EntitiesController :discard
128
114
 
129
115
  # POST /campaigns/auto_complete/query AJAX
130
116
  #----------------------------------------------------------------------------
@@ -153,16 +139,15 @@ class CampaignsController < EntitiesController
153
139
  # POST /campaigns/filter AJAX
154
140
  #----------------------------------------------------------------------------
155
141
  def filter
156
- session[:filter_by_campaign_status] = params[:status]
142
+ session[:campaigns_filter] = params[:status]
157
143
  @campaigns = get_campaigns(:page => 1)
158
144
  render :index
159
145
  end
160
146
 
161
- private
147
+ private
148
+
162
149
  #----------------------------------------------------------------------------
163
- def get_campaigns(options = {})
164
- get_list_of_records(Campaign, options.merge!(:filter => :filter_by_campaign_status))
165
- end
150
+ alias :get_campaigns :get_list_of_records
166
151
 
167
152
  #----------------------------------------------------------------------------
168
153
  def respond_to_destroy(method)
@@ -29,8 +29,6 @@ class ContactsController < EntitiesController
29
29
  # GET /contacts/1
30
30
  #----------------------------------------------------------------------------
31
31
  def show
32
- @contact = Contact.my.find(params[:id])
33
-
34
32
  respond_with(@contact) do |format|
35
33
  format.html do
36
34
  @stage = Setting.unroll(:opportunity_stage)
@@ -38,46 +36,40 @@ class ContactsController < EntitiesController
38
36
  @timeline = timeline(@contact)
39
37
  end
40
38
  end
41
-
42
- rescue ActiveRecord::RecordNotFound
43
- respond_to_not_found(:html, :json, :xml)
44
39
  end
45
40
 
46
41
  # GET /contacts/new
47
42
  #----------------------------------------------------------------------------
48
43
  def new
49
- @contact = Contact.new(:user => current_user, :access => Setting.default_access)
50
- @account = Account.new(:user => current_user)
44
+ @contact.attributes = {:user => current_user, :access => Setting.default_access}
45
+ @account = Account.new(:user => current_user)
46
+
51
47
  if params[:related]
52
- model, id = params[:related].split("_")
53
- instance_variable_set("@#{model}", model.classify.constantize.my.find(id))
48
+ model, id = params[:related].split('_')
49
+ if related = model.classify.constantize.my.find_by_id(id)
50
+ instance_variable_set("@#{model}", related)
51
+ else
52
+ respond_to_related_not_found(model) and return
53
+ end
54
54
  end
55
- respond_with(@contact)
56
55
 
57
- rescue ActiveRecord::RecordNotFound # Kicks in if related asset was not found.
58
- respond_to_related_not_found(model, :js) if model
56
+ respond_with(@contact)
59
57
  end
60
58
 
61
59
  # GET /contacts/1/edit AJAX
62
60
  #----------------------------------------------------------------------------
63
61
  def edit
64
- @contact = Contact.my.find(params[:id])
65
- @account = @contact.account || Account.new(:user => current_user)
62
+ @account = @contact.account || Account.new(:user => current_user)
66
63
  if params[:previous].to_s =~ /(\d+)\z/
67
- @previous = Contact.my.find($1)
64
+ @previous = Contact.my.find_by_id($1) || $1.to_i
68
65
  end
69
- respond_with(@contact)
70
66
 
71
- rescue ActiveRecord::RecordNotFound
72
- @previous ||= $1.to_i
73
- respond_to_not_found(:js) unless @contact
67
+ respond_with(@contact)
74
68
  end
75
69
 
76
70
  # POST /contacts
77
71
  #----------------------------------------------------------------------------
78
72
  def create
79
- @contact = Contact.new(params[:contact])
80
-
81
73
  respond_with(@contact) do |format|
82
74
  if @contact.save_with_account_and_permissions(params)
83
75
  @contacts = get_contacts if called_from_index_page?
@@ -91,7 +83,7 @@ class ContactsController < EntitiesController
91
83
  @account = Account.new(:user => current_user)
92
84
  end
93
85
  end
94
- @opportunity = Opportunity.find(params[:opportunity]) unless params[:opportunity].blank?
86
+ @opportunity = Opportunity.my.find(params[:opportunity]) unless params[:opportunity].blank?
95
87
  end
96
88
  end
97
89
  end
@@ -99,8 +91,6 @@ class ContactsController < EntitiesController
99
91
  # PUT /contacts/1
100
92
  #----------------------------------------------------------------------------
101
93
  def update
102
- @contact = Contact.my.find(params[:id])
103
-
104
94
  respond_with(@contact) do |format|
105
95
  unless @contact.update_with_account_and_permissions(params)
106
96
  @users = User.except(current_user)
@@ -111,33 +101,26 @@ class ContactsController < EntitiesController
111
101
  end
112
102
  end
113
103
  end
114
-
115
- rescue ActiveRecord::RecordNotFound
116
- respond_to_not_found(:js, :json, :xml)
117
104
  end
118
105
 
119
106
  # DELETE /contacts/1
120
107
  #----------------------------------------------------------------------------
121
108
  def destroy
122
- @contact = Contact.my.find(params[:id])
123
- @contact.destroy if @contact
109
+ @contact.destroy
124
110
 
125
111
  respond_with(@contact) do |format|
126
112
  format.html { respond_to_destroy(:html) }
127
113
  format.js { respond_to_destroy(:ajax) }
128
114
  end
129
-
130
- rescue ActiveRecord::RecordNotFound
131
- respond_to_not_found(:html, :js, :json, :xml)
132
115
  end
133
116
 
134
117
  # PUT /contacts/1/attach
135
118
  #----------------------------------------------------------------------------
136
- # Handled by ApplicationController :attach
119
+ # Handled by EntitiesController :attach
137
120
 
138
121
  # POST /contacts/1/discard
139
122
  #----------------------------------------------------------------------------
140
- # Handled by ApplicationController :discard
123
+ # Handled by EntitiesController :discard
141
124
 
142
125
  # POST /contacts/auto_complete/query AJAX
143
126
  #----------------------------------------------------------------------------
@@ -178,12 +161,11 @@ class ContactsController < EntitiesController
178
161
 
179
162
  private
180
163
  #----------------------------------------------------------------------------
181
- def get_contacts(options = {})
182
- get_list_of_records(Contact, options)
183
- end
164
+ alias :get_contacts :get_list_of_records
184
165
 
166
+ #----------------------------------------------------------------------------
185
167
  def get_accounts
186
- @accounts = Account.my.order("name")
168
+ @accounts = Account.my.order('name')
187
169
  end
188
170
 
189
171
  #----------------------------------------------------------------------------