fat_free_crm 0.17.3 → 0.19.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +71 -148
- data/.travis.yml +35 -14
- data/CHANGELOG.md +92 -6
- data/CONTRIBUTORS.md +96 -53
- data/Dockerfile +45 -14
- data/Gemfile +23 -13
- data/Gemfile.lock +256 -248
- data/Procfile +1 -1
- data/README.md +9 -6
- data/Rakefile +1 -1
- data/app/assets/javascripts/crm.js.coffee +3 -3
- data/app/assets/javascripts/crm_select2.js.coffee +15 -14
- data/app/assets/stylesheets/common.scss +1 -1
- data/app/controllers/admin/application_controller.rb +1 -1
- data/app/controllers/admin/field_groups_controller.rb +9 -4
- data/app/controllers/admin/fields_controller.rb +4 -4
- data/app/controllers/admin/groups_controller.rb +1 -1
- data/app/controllers/admin/tags_controller.rb +2 -4
- data/app/controllers/admin/users_controller.rb +5 -8
- data/app/controllers/application_controller.rb +22 -45
- data/app/controllers/comments_controller.rb +16 -11
- data/{config/initializers/authlogic.rb → app/controllers/confirmations_controller.rb} +4 -2
- data/app/controllers/emails_controller.rb +0 -2
- data/app/controllers/entities/accounts_controller.rb +1 -3
- data/app/controllers/entities/campaigns_controller.rb +8 -5
- data/app/controllers/entities/contacts_controller.rb +4 -24
- data/app/controllers/entities/leads_controller.rb +16 -12
- data/app/controllers/entities/opportunities_controller.rb +17 -16
- data/app/controllers/entities_controller.rb +31 -12
- data/app/controllers/home_controller.rb +2 -4
- data/app/controllers/lists_controller.rb +5 -1
- data/app/controllers/passwords_controller.rb +3 -59
- data/{spec/features/support/maintain_sessions.rb → app/controllers/registrations_controller.rb} +12 -5
- data/{lib/development_tasks/gem.rake → app/controllers/sessions_controller.rb} +6 -6
- data/app/controllers/tasks_controller.rb +22 -17
- data/app/controllers/users_controller.rb +8 -29
- data/app/helpers/accounts_helper.rb +1 -1
- data/app/helpers/admin/users_helper.rb +1 -1
- data/app/helpers/application_helper.rb +28 -33
- data/app/helpers/campaigns_helper.rb +1 -1
- data/app/helpers/contacts_helper.rb +1 -3
- data/app/helpers/leads_helper.rb +1 -1
- data/app/helpers/opportunities_helper.rb +48 -3
- data/app/helpers/tasks_helper.rb +1 -1
- data/app/helpers/users_helper.rb +1 -3
- data/{config/initializers/paper_trail.rb → app/mailers/devise_mailer.rb} +5 -1
- data/app/mailers/user_mailer.rb +0 -9
- data/app/models/entities/account.rb +10 -10
- data/app/models/entities/campaign.rb +4 -6
- data/app/models/entities/contact.rb +24 -12
- data/app/models/entities/lead.rb +7 -14
- data/app/models/entities/opportunity.rb +10 -11
- data/app/models/fields/custom_field.rb +1 -0
- data/app/models/fields/custom_field_date_pair.rb +2 -0
- data/app/models/fields/field.rb +1 -3
- data/app/models/list.rb +1 -1
- data/app/models/observers/entity_observer.rb +3 -7
- data/app/models/observers/lead_observer.rb +2 -4
- data/app/models/observers/opportunity_observer.rb +5 -7
- data/app/models/observers/task_observer.rb +1 -1
- data/app/models/polymorphic/email.rb +2 -2
- data/app/models/polymorphic/task.rb +13 -9
- data/app/models/polymorphic/version.rb +3 -2
- data/app/models/setting.rb +2 -0
- data/app/models/users/ability.rb +3 -4
- data/app/models/users/permission.rb +3 -3
- data/app/models/users/preference.rb +2 -1
- data/app/models/users/user.rb +67 -42
- data/app/views/accounts/_top_section.html.haml +1 -1
- data/app/views/accounts/edit.js.haml +1 -1
- data/app/views/accounts/update.js.haml +2 -2
- data/app/views/admin/users/_user.html.haml +4 -4
- data/app/views/campaigns/_metrics.html.haml +3 -3
- data/app/views/contacts/_index_brief.html.haml +1 -1
- data/app/views/contacts/_index_full.html.haml +1 -1
- data/app/views/contacts/_index_long.html.haml +1 -1
- data/app/views/devise/confirmations/new.html.haml +9 -0
- data/app/views/devise/mailer/confirmation_instructions.html.haml +4 -0
- data/app/views/devise/mailer/password_change.html.haml +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.haml +6 -0
- data/app/views/devise/passwords/edit.html.haml +18 -0
- data/app/views/devise/passwords/new.html.haml +10 -0
- data/app/views/devise/registrations/new.html.haml +21 -0
- data/app/views/devise/sessions/new.html.haml +32 -0
- data/app/views/home/_opportunity.html.haml +4 -19
- data/app/views/layouts/_about.html.haml +5 -5
- data/app/views/layouts/_header.html.haml +3 -3
- data/app/views/layouts/admin/_header.html.haml +1 -1
- data/app/views/opportunities/_index_long.html.haml +1 -24
- data/app/views/opportunities/_sidebar_show.html.haml +3 -3
- data/app/views/opportunities/_top_section.html.haml +1 -1
- data/app/views/shared/_address.html.haml +5 -5
- data/app/views/shared/_empty.html.haml +1 -1
- data/app/views/shared/_paginate_with_per_page.html.haml +1 -0
- data/app/views/users/_avatar.html.haml +1 -1
- data/bin/bundle +1 -1
- data/bin/rails +1 -1
- data/bin/setup +38 -0
- data/bin/update +33 -0
- data/bin/yarn +13 -0
- data/config/application.rb +8 -6
- data/config/boot.rb +1 -1
- data/config/brakeman.ignore +2 -2
- data/config/database.postgres.docker.yml +5 -5
- data/config/environment.rb +1 -1
- data/config/environments/development.rb +1 -0
- data/config/environments/test.rb +7 -0
- data/config/initializers/action_mailer.rb +1 -3
- data/config/initializers/application_controller_renderer.rb +9 -0
- data/config/initializers/assets.rb +6 -11
- data/config/initializers/backtrace_silencers.rb +0 -6
- data/config/initializers/content_security_policy.rb +26 -0
- data/config/initializers/cookies_serializer.rb +3 -6
- data/config/initializers/devise.rb +289 -0
- data/config/initializers/filter_parameter_logging.rb +0 -5
- data/config/initializers/gravatar.rb +0 -1
- data/config/initializers/inflections.rb +0 -6
- data/config/initializers/mime_types.rb +1 -9
- data/config/initializers/new_framework_defaults_5_2.rb +40 -0
- data/config/initializers/relative_url_root.rb +1 -3
- data/config/initializers/session_store.rb +1 -3
- data/config/initializers/wrap_parameters.rb +4 -9
- data/config/locales/fat_free_crm.en-GB.yml +5 -5
- data/config/locales/fat_free_crm.en-US.yml +5 -5
- data/config/locales/fat_free_crm.fr.yml +1 -1
- data/config/locales/fat_free_crm.ru.yml +1 -0
- data/config/routes.rb +20 -9
- data/db/demo/users.yml +62 -81
- data/db/migrate/20100928030620_remove_uuid.rb +1 -2
- data/db/migrate/20120316045804_activities_to_versions.rb +1 -0
- data/db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb +1 -0
- data/db/migrate/20180107082701_authlogic_to_devise.rb +58 -0
- data/db/schema.rb +48 -46
- data/docker-compose.yml +10 -0
- data/fat_free_crm.gemspec +12 -14
- data/lib/development_tasks/license.rake +2 -2
- data/lib/fat_free_crm/callback.rb +2 -2
- data/lib/fat_free_crm/comment_extensions.rb +2 -4
- data/lib/fat_free_crm/core_ext/string.rb +1 -1
- data/lib/fat_free_crm/engine.rb +2 -2
- data/lib/fat_free_crm/errors.rb +1 -1
- data/lib/fat_free_crm/export_csv.rb +1 -0
- data/lib/fat_free_crm/exportable.rb +1 -1
- data/lib/fat_free_crm/fields.rb +2 -2
- data/lib/fat_free_crm/gem_dependencies.rb +1 -1
- data/lib/fat_free_crm/gem_ext/simple_form/action_view_extensions/form_helper.rb +1 -3
- data/lib/fat_free_crm/i18n.rb +2 -2
- data/lib/fat_free_crm/mail_processor/base.rb +4 -10
- data/lib/fat_free_crm/mail_processor/dropbox.rb +5 -15
- data/lib/fat_free_crm/permissions.rb +7 -18
- data/lib/fat_free_crm/sortable.rb +1 -1
- data/lib/fat_free_crm/tabs.rb +2 -2
- data/lib/fat_free_crm/version.rb +2 -2
- data/lib/gravatar_image_tag.rb +7 -8
- data/lib/missing_translation_detector.rb +1 -0
- data/lib/tasks/ffcrm/missing_translations.rake +1 -0
- data/lib/tasks/ffcrm/setup.rake +13 -4
- data/lib/tasks/ffcrm/update_data.rake +2 -2
- data/script/rails +2 -2
- data/spec/controllers/admin/users_controller_spec.rb +25 -81
- data/spec/controllers/comments_controller_spec.rb +19 -19
- data/spec/controllers/emails_controller_spec.rb +2 -2
- data/spec/controllers/entities/accounts_controller_spec.rb +56 -56
- data/spec/controllers/entities/campaigns_controller_spec.rb +66 -66
- data/spec/controllers/entities/contacts_controller_spec.rb +69 -68
- data/spec/controllers/entities/leads_controller_spec.rb +126 -126
- data/spec/controllers/entities/opportunities_controller_spec.rb +101 -101
- data/spec/controllers/entities_controller_spec.rb +5 -0
- data/spec/controllers/home_controller_spec.rb +30 -30
- data/spec/controllers/tasks_controller_spec.rb +42 -40
- data/spec/controllers/users_controller_spec.rb +43 -113
- data/spec/factories/account_factories.rb +13 -13
- data/spec/factories/campaign_factories.rb +8 -8
- data/spec/factories/contact_factories.rb +18 -18
- data/spec/factories/field_factories.rb +11 -10
- data/spec/factories/lead_factories.rb +13 -13
- data/spec/factories/list_factories.rb +3 -3
- data/spec/factories/opportunity_factories.rb +9 -9
- data/spec/factories/sequences.rb +1 -1
- data/spec/factories/setting_factories.rb +5 -5
- data/spec/factories/shared_factories.rb +25 -23
- data/spec/factories/subscription_factories.rb +1 -1
- data/spec/factories/tag_factories.rb +1 -1
- data/spec/factories/task_factories.rb +11 -11
- data/spec/factories/user_factories.rb +27 -30
- data/spec/features/accounts_spec.rb +17 -4
- data/spec/features/admin/groups_spec.rb +2 -2
- data/spec/features/admin/users_spec.rb +4 -2
- data/spec/features/campaigns_spec.rb +5 -5
- data/spec/features/contacts_spec.rb +11 -5
- data/spec/features/dashboard_spec.rb +8 -8
- data/spec/features/devise/sign_in_spec.rb +58 -0
- data/spec/features/devise/sign_up_spec.rb +36 -0
- data/spec/features/leads_spec.rb +5 -5
- data/spec/features/opportunities_overview_spec.rb +16 -16
- data/spec/features/opportunities_spec.rb +35 -9
- data/spec/features/support/autocomlete_helper.rb +17 -0
- data/spec/features/support/browser.rb +5 -9
- data/spec/features/tasks_spec.rb +5 -5
- data/spec/helpers/admin/field_groups_helper_spec.rb +1 -1
- data/spec/helpers/application_helper_spec.rb +1 -1
- data/spec/helpers/tasks_helper_spec.rb +1 -1
- data/spec/helpers/users_helper_spec.rb +7 -7
- data/spec/lib/comment_extensions_spec.rb +11 -5
- data/spec/lib/errors_spec.rb +2 -2
- data/spec/lib/mail_processor/base_spec.rb +3 -3
- data/spec/lib/mail_processor/comment_replies_spec.rb +3 -3
- data/spec/lib/mail_processor/dropbox_spec.rb +17 -17
- data/spec/lib/mail_processor/sample_emails/dropbox.rb +8 -8
- data/spec/lib/permissions_spec.rb +15 -28
- data/spec/mailers/devise_mailer_spec.rb +35 -0
- data/spec/mailers/user_mailer_spec.rb +6 -32
- data/spec/models/entities/account_spec.rb +58 -32
- data/spec/models/entities/campaign_spec.rb +18 -25
- data/spec/models/entities/contact_spec.rb +113 -21
- data/spec/models/entities/lead_spec.rb +9 -11
- data/spec/models/entities/opportunity_spec.rb +45 -45
- data/spec/models/fields/custom_field_date_pair_spec.rb +4 -2
- data/spec/models/fields/custom_field_spec.rb +21 -19
- data/spec/models/list_spec.rb +2 -2
- data/spec/models/observers/entity_observer_spec.rb +7 -7
- data/spec/models/polymorphic/address_spec.rb +1 -1
- data/spec/models/polymorphic/avatar_spec.rb +5 -5
- data/spec/models/polymorphic/comment_spec.rb +5 -5
- data/spec/models/polymorphic/task_spec.rb +65 -58
- data/spec/models/polymorphic/version_spec.rb +31 -31
- data/spec/models/setting_spec.rb +2 -2
- data/spec/models/users/preference_spec.rb +6 -6
- data/spec/models/users/user_spec.rb +46 -50
- data/spec/routing/users_routing_spec.rb +30 -8
- data/spec/shared/controllers.rb +3 -9
- data/spec/shared/models.rb +22 -22
- data/spec/spec_helper.rb +12 -4
- data/spec/support/assert_select.rb +1 -0
- data/spec/support/devise_helpers.rb +28 -0
- data/spec/{features/support/helpers.rb → support/feature_helpers.rb} +11 -11
- data/spec/support/macros.rb +7 -4
- data/spec/views/accounts/_edit.haml_spec.rb +1 -1
- data/spec/views/accounts/create.js.haml_spec.rb +3 -3
- data/spec/views/accounts/destroy.js.haml_spec.rb +1 -1
- data/spec/views/accounts/edit.js.haml_spec.rb +2 -2
- data/spec/views/accounts/index.haml_spec.rb +2 -2
- data/spec/views/accounts/index.js.haml_spec.rb +1 -1
- data/spec/views/accounts/show.haml_spec.rb +4 -4
- data/spec/views/accounts/update.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/create.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/edit.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/new.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/update.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/create.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/destroy.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/edit.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/index.haml_spec.rb +1 -1
- data/spec/views/admin/users/index.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/reactivate.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/suspend.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/update.js.haml_spec.rb +1 -1
- data/spec/views/application/auto_complete.haml_spec.rb +3 -3
- data/spec/views/campaigns/_edit.haml_spec.rb +1 -1
- data/spec/views/campaigns/create.js.haml_spec.rb +4 -4
- data/spec/views/campaigns/destroy.js.haml_spec.rb +1 -1
- data/spec/views/campaigns/edit.js.haml_spec.rb +4 -4
- data/spec/views/campaigns/index.haml_spec.rb +1 -1
- data/spec/views/campaigns/index.js.haml_spec.rb +2 -2
- data/spec/views/campaigns/show.haml_spec.rb +4 -4
- data/spec/views/campaigns/update.js.haml_spec.rb +2 -2
- data/spec/views/contacts/_edit.haml_spec.rb +7 -7
- data/spec/views/contacts/_new.haml_spec.rb +1 -1
- data/spec/views/contacts/create.js.haml_spec.rb +5 -5
- data/spec/views/contacts/destroy.js.haml_spec.rb +1 -1
- data/spec/views/contacts/edit.js.haml_spec.rb +4 -4
- data/spec/views/contacts/index.haml_spec.rb +1 -1
- data/spec/views/contacts/index.js.html_spec.rb +2 -2
- data/spec/views/contacts/new.js.haml_spec.rb +1 -1
- data/spec/views/contacts/show.haml_spec.rb +3 -3
- data/spec/views/contacts/update.js.haml_spec.rb +5 -5
- data/spec/views/home/index.haml_spec.rb +1 -1
- data/spec/views/home/index.js.haml_spec.rb +1 -1
- data/spec/views/home/options.js.haml_spec.rb +2 -2
- data/spec/views/leads/_convert.haml_spec.rb +3 -3
- data/spec/views/leads/_edit.haml_spec.rb +2 -2
- data/spec/views/leads/_new.haml_spec.rb +2 -2
- data/spec/views/leads/_sidebar_show.haml_spec.rb +5 -5
- data/spec/views/leads/convert.js.haml_spec.rb +4 -4
- data/spec/views/leads/create.js.haml_spec.rb +5 -5
- data/spec/views/leads/destroy.js.haml_spec.rb +2 -2
- data/spec/views/leads/edit.js.haml_spec.rb +4 -4
- data/spec/views/leads/index.haml_spec.rb +1 -1
- data/spec/views/leads/index.js.haml_spec.rb +1 -1
- data/spec/views/leads/new.js.haml_spec.rb +1 -1
- data/spec/views/leads/promote.js.haml_spec.rb +7 -7
- data/spec/views/leads/reject.js.haml_spec.rb +2 -2
- data/spec/views/leads/show.haml_spec.rb +2 -2
- data/spec/views/leads/update.js.haml_spec.rb +4 -4
- data/spec/views/opportunities/_edit.haml_spec.rb +7 -7
- data/spec/views/opportunities/_new.haml_spec.rb +2 -2
- data/spec/views/opportunities/create.js.haml_spec.rb +6 -6
- data/spec/views/opportunities/destroy.js.haml_spec.rb +3 -3
- data/spec/views/opportunities/edit.js.haml_spec.rb +3 -3
- data/spec/views/opportunities/index.haml_spec.rb +1 -1
- data/spec/views/opportunities/index.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/new.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/show.haml_spec.rb +3 -3
- data/spec/views/opportunities/update.js.haml_spec.rb +5 -5
- data/spec/views/tasks/_edit.haml_spec.rb +1 -1
- data/spec/views/tasks/complete.js.haml_spec.rb +4 -4
- data/spec/views/tasks/create.js.haml_spec.rb +6 -6
- data/spec/views/tasks/destroy.js.haml_spec.rb +2 -2
- data/spec/views/tasks/index.haml_spec.rb +4 -4
- data/spec/views/tasks/new.js.haml_spec.rb +1 -1
- data/spec/views/tasks/uncomplete.js.haml_spec.rb +2 -2
- data/spec/views/tasks/update.js.haml_spec.rb +18 -18
- data/spec/views/users/upload_avatar.js.haml_spec.rb +2 -2
- metadata +49 -71
- data/app/controllers/authentications_controller.rb +0 -53
- data/app/models/users/authentication.rb +0 -56
- data/app/views/authentications/new.html.haml +0 -19
- data/app/views/passwords/edit.html.haml +0 -15
- data/app/views/passwords/new.html.haml +0 -10
- data/app/views/user_mailer/password_reset_instructions.html.haml +0 -6
- data/app/views/users/new.html.haml +0 -19
- data/spec/controllers/authentications_controller_spec.rb +0 -150
- data/spec/controllers/passwords_controller_spec.rb +0 -32
- data/spec/models/users/authentication_spec.rb +0 -19
- data/spec/support/auth_macros.rb +0 -49
- data/spec/views/authentications/new.haml_spec.rb +0 -31
@@ -26,7 +26,7 @@ class TaskObserver < ActiveRecord::Observer
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def log_activity(item, event)
|
29
|
-
item.send(item.class.versions_association_name).create(event: event, whodunnit: PaperTrail.whodunnit)
|
29
|
+
item.send(item.class.versions_association_name).create(event: event, whodunnit: PaperTrail.request.whodunnit)
|
30
30
|
end
|
31
31
|
|
32
32
|
ActiveSupport.run_load_hooks(:fat_free_crm_task_observer, self)
|
@@ -30,8 +30,8 @@
|
|
30
30
|
#
|
31
31
|
|
32
32
|
class Email < ActiveRecord::Base
|
33
|
-
belongs_to :mediator, polymorphic: true
|
34
|
-
belongs_to :user
|
33
|
+
belongs_to :mediator, polymorphic: true, optional: true # TODO: Is this really optional?
|
34
|
+
belongs_to :user, optional: true # TODO: Is this really optional?
|
35
35
|
|
36
36
|
has_paper_trail class_name: 'Version', meta: { related: :mediator },
|
37
37
|
ignore: [:state]
|
@@ -34,15 +34,15 @@ class Task < ActiveRecord::Base
|
|
34
34
|
ALLOWED_VIEWS = %w[pending assigned completed]
|
35
35
|
|
36
36
|
belongs_to :user
|
37
|
-
belongs_to :assignee, class_name: "User", foreign_key: :assigned_to
|
38
|
-
belongs_to :completor, class_name: "User", foreign_key: :completed_by
|
39
|
-
belongs_to :asset, polymorphic: true
|
37
|
+
belongs_to :assignee, class_name: "User", foreign_key: :assigned_to, optional: true # TODO: Is this really optional?
|
38
|
+
belongs_to :completor, class_name: "User", foreign_key: :completed_by, optional: true # TODO: Is this really optional?
|
39
|
+
belongs_to :asset, polymorphic: true, optional: true # TODO: Is this really optional?
|
40
40
|
|
41
41
|
serialize :subscribed_users, Array
|
42
42
|
|
43
43
|
# Tasks created by the user for herself, or assigned to her by others. That's
|
44
44
|
# what gets shown on Tasks/Pending and Tasks/Completed pages.
|
45
|
-
scope :my,
|
45
|
+
scope :my, lambda { |*args|
|
46
46
|
options = args[0] || {}
|
47
47
|
user_option = (options.is_a?(Hash) ? options[:user] : options) || User.current_user
|
48
48
|
includes(:assignee)
|
@@ -55,24 +55,24 @@ class Task < ActiveRecord::Base
|
|
55
55
|
scope :assigned_to, ->(user) { where(assigned_to: user.id) }
|
56
56
|
|
57
57
|
# Tasks assigned by the user to others. That's what we see on Tasks/Assigned.
|
58
|
-
scope :assigned_by,
|
58
|
+
scope :assigned_by, lambda { |user|
|
59
59
|
includes(:assignee)
|
60
60
|
.where('user_id = ? AND assigned_to IS NOT NULL AND assigned_to != ?', user.id, user.id)
|
61
61
|
}
|
62
62
|
|
63
63
|
# Tasks created by the user or assigned to the user, i.e. the union of the two
|
64
64
|
# scopes above. That's the tasks the user is allowed to see and track.
|
65
|
-
scope :tracked_by,
|
65
|
+
scope :tracked_by, lambda { |user|
|
66
66
|
includes(:assignee)
|
67
67
|
.where('user_id = ? OR assigned_to = ?', user.id, user.id)
|
68
68
|
}
|
69
69
|
|
70
70
|
# Show tasks which either belong to the user and are unassigned, or are assigned to the user
|
71
|
-
scope :visible_on_dashboard,
|
71
|
+
scope :visible_on_dashboard, lambda { |user|
|
72
72
|
where('(user_id = :user_id AND assigned_to IS NULL) OR assigned_to = :user_id', user_id: user.id).where('completed_at IS NULL')
|
73
73
|
}
|
74
74
|
|
75
|
-
scope :by_due_at,
|
75
|
+
scope :by_due_at, lambda {
|
76
76
|
order({
|
77
77
|
"MySQL" => "due_at NOT NULL, due_at ASC",
|
78
78
|
"PostgreSQL" => "due_at ASC NULLS FIRST"
|
@@ -101,7 +101,7 @@ class Task < ActiveRecord::Base
|
|
101
101
|
scope :completed_this_month, -> { where('completed_at >= ? AND completed_at < ?', Time.zone.now.beginning_of_month.utc, Time.zone.now.beginning_of_week.utc - 7.days) }
|
102
102
|
scope :completed_last_month, -> { where('completed_at >= ? AND completed_at < ?', (Time.zone.now.beginning_of_month.utc - 1.day).beginning_of_month.utc, Time.zone.now.beginning_of_month.utc) }
|
103
103
|
|
104
|
-
scope :text_search,
|
104
|
+
scope :text_search, lambda { |query|
|
105
105
|
query = query.gsub(/[^\w\s\-\.'\p{L}]/u, '').strip
|
106
106
|
where('upper(name) LIKE upper(?)', "%#{query}%")
|
107
107
|
}
|
@@ -155,6 +155,7 @@ class Task < ActiveRecord::Base
|
|
155
155
|
#----------------------------------------------------------------------------
|
156
156
|
def computed_bucket
|
157
157
|
return bucket if bucket != "specific_time"
|
158
|
+
|
158
159
|
if overdue?
|
159
160
|
"overdue"
|
160
161
|
elsif due_today?
|
@@ -174,6 +175,7 @@ class Task < ActiveRecord::Base
|
|
174
175
|
#----------------------------------------------------------------------------
|
175
176
|
def self.find_all_grouped(user, view)
|
176
177
|
return {} unless ALLOWED_VIEWS.include?(view)
|
178
|
+
|
177
179
|
settings = (view == "completed" ? Setting.task_completed : Setting.task_bucket)
|
178
180
|
Hash[
|
179
181
|
settings.map do |key, _value|
|
@@ -186,6 +188,7 @@ class Task < ActiveRecord::Base
|
|
186
188
|
#----------------------------------------------------------------------------
|
187
189
|
def self.bucket_empty?(bucket, user, view = "pending")
|
188
190
|
return false if bucket.blank? || !ALLOWED_VIEWS.include?(view)
|
191
|
+
|
189
192
|
if view == "assigned"
|
190
193
|
assigned_by(user).send(bucket).pending.count
|
191
194
|
else
|
@@ -197,6 +200,7 @@ class Task < ActiveRecord::Base
|
|
197
200
|
#----------------------------------------------------------------------------
|
198
201
|
def self.totals(user, view = "pending")
|
199
202
|
return {} unless ALLOWED_VIEWS.include?(view)
|
203
|
+
|
200
204
|
settings = (view == "completed" ? Setting.task_completed : Setting.task_bucket)
|
201
205
|
settings.each_with_object(HashWithIndifferentAccess[all: 0]) do |key, hash|
|
202
206
|
hash[key] = (view == "assigned" ? assigned_by(user).send(key).pending.count : my(user).send(key).send(view).count)
|
@@ -12,8 +12,8 @@ class Version < PaperTrail::Version
|
|
12
12
|
EVENTS = %w[all_events create view update destroy]
|
13
13
|
DURATION = %w[one_hour one_day two_days one_week two_weeks one_month]
|
14
14
|
|
15
|
-
belongs_to :related, polymorphic: true
|
16
|
-
belongs_to :user, foreign_key: :whodunnit
|
15
|
+
belongs_to :related, polymorphic: true, optional: true # TODO: Is this really optional?
|
16
|
+
belongs_to :user, foreign_key: :whodunnit, optional: true # TODO: Is this really optional?
|
17
17
|
|
18
18
|
scope :default_order, -> { order('created_at DESC') }
|
19
19
|
scope :include_events, ->(*events) { where(event: events) }
|
@@ -35,6 +35,7 @@ class Version < PaperTrail::Version
|
|
35
35
|
.default_order
|
36
36
|
|
37
37
|
break if query.empty?
|
38
|
+
|
38
39
|
versions += query.select { |v| v.item.present? }
|
39
40
|
versions.uniq! { |v| [v.item_id, v.item_type] }
|
40
41
|
offset += limit * 2
|
data/app/models/setting.rb
CHANGED
@@ -55,6 +55,7 @@ class Setting < ActiveRecord::Base
|
|
55
55
|
def [](name)
|
56
56
|
# Return value if cached
|
57
57
|
return cache[name] if cache.key?(name)
|
58
|
+
|
58
59
|
# Check database
|
59
60
|
if database_and_table_exists?
|
60
61
|
if setting = find_by_name(name.to_s)
|
@@ -69,6 +70,7 @@ class Setting < ActiveRecord::Base
|
|
69
70
|
#-------------------------------------------------------------------
|
70
71
|
def []=(name, value)
|
71
72
|
return nil unless database_and_table_exists?
|
73
|
+
|
72
74
|
setting = find_by_name(name.to_s) || new(name: name)
|
73
75
|
setting.value = value
|
74
76
|
setting.save
|
data/app/models/users/ability.rb
CHANGED
@@ -47,10 +47,9 @@ class Ability
|
|
47
47
|
scope = scope.or(t[:group_id].eq_any(group_ids))
|
48
48
|
end
|
49
49
|
|
50
|
-
entities.
|
51
|
-
|
52
|
-
|
53
|
-
end
|
50
|
+
permissions = Permission.select(:asset_type, :asset_id).where(scope).where(asset_type: entities.map { |k| k.name.to_s })
|
51
|
+
permissions.each do |p|
|
52
|
+
can :manage, p.asset_type.constantize, id: p.asset_id
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
@@ -18,9 +18,9 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
class Permission < ActiveRecord::Base
|
21
|
-
belongs_to :user
|
22
|
-
belongs_to :group
|
23
|
-
belongs_to :asset, polymorphic: true
|
21
|
+
belongs_to :user, optional: true
|
22
|
+
belongs_to :group, optional: true
|
23
|
+
belongs_to :asset, polymorphic: true, optional: true
|
24
24
|
|
25
25
|
validates_presence_of :user_id, unless: :group_id?
|
26
26
|
validates_presence_of :group_id, unless: :user_id?
|
@@ -18,7 +18,7 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
class Preference < ActiveRecord::Base
|
21
|
-
belongs_to :user
|
21
|
+
belongs_to :user, optional: true
|
22
22
|
|
23
23
|
#-------------------------------------------------------------------
|
24
24
|
def [](name)
|
@@ -26,6 +26,7 @@ class Preference < ActiveRecord::Base
|
|
26
26
|
return super(name) if name.to_s == "user_id" # get the value of belongs_to
|
27
27
|
|
28
28
|
return cached_prefs[name.to_s] if cached_prefs.key?(name.to_s)
|
29
|
+
|
29
30
|
cached_prefs[name.to_s] = if user.present? && pref = Preference.find_by_name_and_user_id(name.to_s, user.id)
|
30
31
|
Marshal.load(Base64.decode64(pref.value))
|
31
32
|
end
|
data/app/models/users/user.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# id :integer not null, primary key
|
13
13
|
# username :string(32) default(""), not null
|
14
|
-
# email :string(
|
14
|
+
# email :string(254) default(""), not null
|
15
15
|
# first_name :string(32)
|
16
16
|
# last_name :string(32)
|
17
17
|
# title :string(64)
|
@@ -23,24 +23,34 @@
|
|
23
23
|
# yahoo :string(32)
|
24
24
|
# google :string(32)
|
25
25
|
# skype :string(32)
|
26
|
-
#
|
26
|
+
# encrypted_password :string(255) default(""), not null
|
27
27
|
# password_salt :string(255) default(""), not null
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# current_login_ip :string(255)
|
34
|
-
# login_count :integer default(0), not null
|
28
|
+
# last_sign_in_at :datetime
|
29
|
+
# current_sign_in_at :datetime
|
30
|
+
# last_sign_in_ip :string(255)
|
31
|
+
# current_sign_in_ip :string(255)
|
32
|
+
# sign_in_count :integer default(0), not null
|
35
33
|
# deleted_at :datetime
|
36
34
|
# created_at :datetime
|
37
35
|
# updated_at :datetime
|
38
36
|
# admin :boolean default(FALSE), not null
|
39
37
|
# suspended_at :datetime
|
40
|
-
#
|
38
|
+
# unconfirmed_email :string(254) default(""), not null
|
39
|
+
# reset_password_token :string(255)
|
40
|
+
# reset_password_sent_at :datetime
|
41
|
+
# remember_token :string(255)
|
42
|
+
# remember_created_at :datetime
|
43
|
+
# authentication_token :string(255)
|
44
|
+
# confirmation_token :string(255)
|
45
|
+
# confirmed_at :datetime
|
46
|
+
# confirmation_sent_at :datetime
|
41
47
|
#
|
42
48
|
|
43
49
|
class User < ActiveRecord::Base
|
50
|
+
devise :database_authenticatable, :registerable, :confirmable,
|
51
|
+
:encryptable, :recoverable, :rememberable, :trackable
|
52
|
+
before_create :suspend_if_needs_approval
|
53
|
+
|
44
54
|
has_one :avatar, as: :entity, dependent: :destroy # Personal avatar.
|
45
55
|
has_many :avatars # As owner who uploaded it, ex. Contact avatar.
|
46
56
|
has_many :comments, as: :commentable # As owner who created a comment.
|
@@ -55,40 +65,38 @@ class User < ActiveRecord::Base
|
|
55
65
|
has_many :lists
|
56
66
|
has_and_belongs_to_many :groups
|
57
67
|
|
58
|
-
has_paper_trail class_name: 'Version', ignore: [:
|
68
|
+
has_paper_trail class_name: 'Version', ignore: [:last_sign_in_at]
|
59
69
|
|
60
70
|
scope :by_id, -> { order('id DESC') }
|
61
|
-
scope
|
71
|
+
# TODO: /home/clockwerx/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.3/lib/active_record/scoping/named.rb:175:in `scope': You tried to define a scope named "without" on the model "User", but ActiveRecord::Relation already defined an instance method with the same name. (ArgumentError)
|
72
|
+
scope :without_user, ->(user) { where('id != ?', user.id).by_name }
|
62
73
|
scope :by_name, -> { order('first_name, last_name, email') }
|
63
74
|
|
64
|
-
scope :text_search,
|
75
|
+
scope :text_search, lambda { |query|
|
65
76
|
query = query.gsub(/[^\w\s\-\.'\p{L}]/u, '').strip
|
66
77
|
where('upper(username) LIKE upper(:s) OR upper(email) LIKE upper(:s) OR upper(first_name) LIKE upper(:s) OR upper(last_name) LIKE upper(:s)', s: "%#{query}%")
|
67
78
|
}
|
68
79
|
|
69
80
|
scope :my, ->(current_user) { accessible_by(current_user.ability) }
|
70
81
|
|
71
|
-
scope :have_assigned_opportunities,
|
82
|
+
scope :have_assigned_opportunities, lambda {
|
72
83
|
joins("INNER JOIN opportunities ON users.id = opportunities.assigned_to")
|
73
84
|
.where("opportunities.stage <> 'lost' AND opportunities.stage <> 'won'")
|
74
85
|
.select('DISTINCT(users.id), users.*')
|
75
86
|
}
|
76
87
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
cattr_accessor :current_user
|
90
|
-
|
91
|
-
validates_presence_of :email, message: :missing_email
|
88
|
+
validates :email,
|
89
|
+
presence: { message: :missing_email },
|
90
|
+
length: { minimum: 3, maximum: 254 },
|
91
|
+
uniqueness: { message: :email_in_use, case_sensitive: false },
|
92
|
+
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create }
|
93
|
+
validates :username,
|
94
|
+
uniqueness: { message: :username_taken, case_sensitive: false },
|
95
|
+
presence: { message: :missing_username },
|
96
|
+
format: { with: /[a-z0-9_-]+/i }
|
97
|
+
validates :password,
|
98
|
+
presence: { if: :password_required? },
|
99
|
+
confirmation: true
|
92
100
|
|
93
101
|
#----------------------------------------------------------------------------
|
94
102
|
def name
|
@@ -107,7 +115,23 @@ class User < ActiveRecord::Base
|
|
107
115
|
|
108
116
|
#----------------------------------------------------------------------------
|
109
117
|
def awaits_approval?
|
110
|
-
suspended? &&
|
118
|
+
suspended? && sign_in_count == 0 && Setting.user_signup == :needs_approval
|
119
|
+
end
|
120
|
+
|
121
|
+
def active_for_authentication?
|
122
|
+
super && confirmed? && !awaits_approval? && !suspended?
|
123
|
+
end
|
124
|
+
|
125
|
+
def inactive_message
|
126
|
+
if !confirmed?
|
127
|
+
super
|
128
|
+
elsif awaits_approval?
|
129
|
+
I18n.t(:msg_account_not_approved)
|
130
|
+
elsif suspended?
|
131
|
+
I18n.t(:msg_invalig_login)
|
132
|
+
else
|
133
|
+
super
|
134
|
+
end
|
111
135
|
end
|
112
136
|
|
113
137
|
#----------------------------------------------------------------------------
|
@@ -116,12 +140,6 @@ class User < ActiveRecord::Base
|
|
116
140
|
end
|
117
141
|
alias pref preference
|
118
142
|
|
119
|
-
#----------------------------------------------------------------------------
|
120
|
-
def deliver_password_reset_instructions!
|
121
|
-
reset_perishable_token!
|
122
|
-
UserMailer.password_reset_instructions(self).deliver_now
|
123
|
-
end
|
124
|
-
|
125
143
|
# Override global I18n.locale if the user has individual local preference.
|
126
144
|
#----------------------------------------------------------------------------
|
127
145
|
def set_individual_locale
|
@@ -130,10 +148,6 @@ class User < ActiveRecord::Base
|
|
130
148
|
|
131
149
|
# Generate the value of single access token if it hasn't been set already.
|
132
150
|
#----------------------------------------------------------------------------
|
133
|
-
def set_single_access_token
|
134
|
-
self.single_access_token ||= update_attribute(:single_access_token, Authlogic::Random.friendly_token)
|
135
|
-
end
|
136
|
-
|
137
151
|
def to_json(_options = nil)
|
138
152
|
[name].to_json
|
139
153
|
end
|
@@ -142,6 +156,10 @@ class User < ActiveRecord::Base
|
|
142
156
|
[name].to_xml
|
143
157
|
end
|
144
158
|
|
159
|
+
def password_required?
|
160
|
+
!persisted? || !password.nil? || !password_confirmation.nil?
|
161
|
+
end
|
162
|
+
|
145
163
|
# Returns permissions ability object.
|
146
164
|
#----------------------------------------------------------------------------
|
147
165
|
def ability
|
@@ -171,14 +189,21 @@ class User < ActiveRecord::Base
|
|
171
189
|
!sum.nil?
|
172
190
|
end
|
173
191
|
|
174
|
-
private
|
175
|
-
|
176
192
|
# Define class methods
|
177
193
|
#----------------------------------------------------------------------------
|
178
194
|
class << self
|
179
195
|
def can_signup?
|
180
196
|
%i[allowed needs_approval].include? Setting.user_signup
|
181
197
|
end
|
198
|
+
|
199
|
+
# Overrides Devise sign-in to use either username or email (case-insensitive)
|
200
|
+
#----------------------------------------------------------------------------
|
201
|
+
def find_for_database_authentication(warden_conditions)
|
202
|
+
conditions = warden_conditions.dup
|
203
|
+
if login = conditions.delete(:email)
|
204
|
+
where(conditions.to_h).where(["lower(username) = :value OR lower(email) = :value", { value: login.downcase }]).first
|
205
|
+
end
|
206
|
+
end
|
182
207
|
end
|
183
208
|
|
184
209
|
ActiveSupport.run_load_hooks(:fat_free_crm_user, self)
|
@@ -28,4 +28,4 @@
|
|
28
28
|
- elsif params[:cancel].false? # Called from title of the landing page...
|
29
29
|
$('#edit_#{entity_name}').html('#{ j render(partial: "edit") }');
|
30
30
|
crm.flip_form('edit_#{entity_name}');
|
31
|
-
crm.set_title('edit_#{entity_name}', "#{t :edit} #{
|
31
|
+
crm.set_title('edit_#{entity_name}', "#{t :edit} #{j @entity.name}");
|
@@ -5,7 +5,7 @@
|
|
5
5
|
- if @entity.errors.empty?
|
6
6
|
- if called_from_landing_page?
|
7
7
|
crm.flip_form('edit_#{entity_name}');
|
8
|
-
crm.set_title('edit_#{entity_name}', '#{
|
8
|
+
crm.set_title('edit_#{entity_name}', '#{j @entity.name}');
|
9
9
|
= refresh_sidebar(:show, :summary)
|
10
10
|
- else
|
11
11
|
$('##{id}').replaceWith('#{ j render(partial: entity_name, collection: [ @entity ]) }');
|
@@ -16,4 +16,4 @@
|
|
16
16
|
$('##{id}').effect("shake", { duration:250, distance: 6 });
|
17
17
|
$('##{dom_id(@entity, :edit)} input[type!=hidden]').first().focus();
|
18
18
|
|
19
|
-
= hook(:entity_update, self, {entity: @entity})
|
19
|
+
= hook(:entity_update, self, {entity: @entity})
|
@@ -34,14 +34,14 @@
|
|
34
34
|
= " " + t(:at) + " " + user.company unless user.company.blank?
|
35
35
|
|
36
36
|
%span.black= "|"
|
37
|
-
- if user.
|
38
|
-
= t('pluralize.login', user.
|
37
|
+
- if user.last_sign_in_at && user.sign_in_count > 0
|
38
|
+
= t('pluralize.login', user.sign_in_count)
|
39
39
|
%span.black= "|"
|
40
40
|
|
41
41
|
- if user.awaits_approval?
|
42
42
|
%b.cool= t(:user_awaits_approval)
|
43
|
-
- elsif user.
|
44
|
-
%span.cool= t(:last_logged_in, timeago(user.
|
43
|
+
- elsif user.last_sign_in_at
|
44
|
+
%span.cool= t(:last_logged_in, timeago(user.current_sign_in_at)).html_safe
|
45
45
|
- else
|
46
46
|
%span.warn= t(:user_never_logged_in)
|
47
47
|
%dt{ style: "padding: 2px 0px 0px 0px" }
|
@@ -9,8 +9,8 @@
|
|
9
9
|
%dt
|
10
10
|
- unless objectives.empty?
|
11
11
|
%b #{t :actual}:
|
12
|
-
= t(:revenue_number, number_to_currency(campaign.revenue
|
13
|
-
= t('pluralize.lead', campaign.leads_count
|
14
|
-
= t('pluralize.opportunity', campaign.opportunities_count
|
12
|
+
= t(:revenue_number, number_to_currency(campaign.revenue.to_f, precision: 0)) + " | "
|
13
|
+
= t('pluralize.lead', campaign.leads_count.to_i) + " | "
|
14
|
+
= t('pluralize.opportunity', campaign.opportunities_count.to_i)
|
15
15
|
- if campaign.opportunities_count? && campaign.leads_count? && campaign.leads_count != 0
|
16
16
|
= " | " + t(:conversion_number, number_to_percentage(campaign.opportunities_count * 100 / campaign.leads_count, precision: 1))
|