biovision 0.0.200518.1 → 0.12.211124.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +105 -52
- data/app/assets/images/biovision/icons/back.svg +19 -0
- data/app/assets/images/biovision/icons/create.svg +19 -0
- data/app/assets/images/biovision/icons/destroy.svg +12 -0
- data/app/assets/images/biovision/icons/dropdown.svg +3 -0
- data/app/assets/images/biovision/icons/edit.svg +22 -0
- data/app/assets/images/biovision/icons/gear.svg +11 -0
- data/app/assets/images/biovision/icons/return.svg +25 -0
- data/app/assets/images/biovision/icons/world.svg +11 -0
- data/app/assets/stylesheets/biovision/admin/components/users.scss +20 -0
- data/app/assets/stylesheets/biovision/admin/components.scss +13 -1
- data/app/assets/stylesheets/biovision/admin/layout.scss +27 -12
- data/app/assets/stylesheets/biovision/biovision.scss +105 -26
- data/app/assets/stylesheets/biovision/components/breadcrumbs.scss +13 -0
- data/app/assets/stylesheets/biovision/components/buttons.scss +130 -0
- data/app/assets/stylesheets/biovision/components/filters.scss +39 -0
- data/app/assets/stylesheets/biovision/components/forms.scss +208 -1
- data/app/assets/stylesheets/biovision/components/lists.scss +6 -7
- data/app/assets/stylesheets/biovision/{biovision → components}/messages.scss +9 -0
- data/app/assets/stylesheets/biovision/components/pagination.scss +34 -0
- data/app/assets/stylesheets/biovision/components/quick_search.scss +24 -0
- data/app/assets/stylesheets/biovision/components/simple_image.scss +112 -0
- data/app/assets/stylesheets/biovision/components/toggleable.scss +71 -0
- data/app/assets/stylesheets/biovision/components.scss +7 -0
- data/app/assets/stylesheets/biovision/default.scss +4 -4
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/dashboard.scss +4 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/form_tabs.scss +101 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/profile.scss +77 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +3 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +2 -3
- data/app/assets/stylesheets/biovision/themes/default_theme/layout/footer.scss +3 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +12 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +8 -19
- data/app/assets/stylesheets/biovision/themes/default_theme.scss +0 -1
- data/app/assets/stylesheets/biovision/vars.scss +5 -0
- data/app/controllers/admin/biovision_components_controller.rb +10 -0
- data/app/controllers/admin/components_controller.rb +37 -97
- data/app/controllers/admin/dynamic_blocks_controller.rb +15 -0
- data/app/controllers/admin/dynamic_pages_controller.rb +15 -0
- data/app/controllers/admin/index_controller.rb +8 -2
- data/app/controllers/admin/navigation_groups_controller.rb +45 -0
- data/app/controllers/admin/tokens_controller.rb +15 -0
- data/app/controllers/admin/users_controller.rb +101 -0
- data/app/controllers/admin_controller.rb +2 -8
- data/app/controllers/authentication_controller.rb +6 -34
- data/app/controllers/concerns/authentication.rb +12 -12
- data/app/controllers/concerns/component_stories.rb +22 -0
- data/app/controllers/concerns/crud_entities.rb +140 -0
- data/app/controllers/concerns/entity_priority.rb +10 -0
- data/app/controllers/concerns/my_crud_entities.rb +146 -0
- data/app/controllers/concerns/processed_forms.rb +28 -0
- data/app/controllers/concerns/restricted_access.rb +37 -0
- data/app/controllers/concerns/toggleable_entity.rb +31 -0
- data/app/controllers/contact_controller.rb +49 -0
- data/app/controllers/errors_controller.rb +37 -0
- data/app/controllers/fallback_controller.rb +12 -0
- data/app/controllers/index_controller.rb +1 -0
- data/app/controllers/legal_controller.rb +14 -0
- data/app/controllers/my/components_controller.rb +26 -0
- data/app/controllers/my/confirmations_controller.rb +44 -0
- data/app/controllers/my/index_controller.rb +7 -1
- data/app/controllers/my/profiles_controller.rb +33 -16
- data/app/controllers/oembed_controller.rb +12 -0
- data/app/controllers/profile_controller.rb +14 -0
- data/app/controllers/users_controller.rb +63 -0
- data/app/helpers/biovision_components_helper.rb +7 -3
- data/app/helpers/biovision_helper.rb +170 -0
- data/app/helpers/entity_helper.rb +77 -0
- data/app/helpers/my_helper.rb +34 -0
- data/app/helpers/simple_image_helper.rb +125 -0
- data/app/jobs/application_job.rb +7 -0
- data/app/jobs/send_phone_confirmation_job.rb +16 -0
- data/app/lib/biovision/components/base/component_parameters.rb +55 -0
- data/app/lib/biovision/components/base/component_privileges.rb +75 -0
- data/app/lib/biovision/components/base/component_settings.rb +40 -0
- data/app/lib/biovision/components/base/component_stories.rb +30 -0
- data/app/lib/biovision/components/base/entity_links.rb +38 -0
- data/app/lib/biovision/components/base/image_handling.rb +33 -0
- data/app/lib/biovision/components/base_component.rb +63 -95
- data/app/lib/biovision/components/contact_component.rb +26 -0
- data/app/lib/biovision/components/content/oembed/receiver.rb +98 -0
- data/app/lib/biovision/components/content/oembed/twitter_receiver.rb +20 -0
- data/app/lib/biovision/components/content/oembed/vimeo_receiver.rb +20 -0
- data/app/lib/biovision/components/content/oembed/youtube_receiver.rb +20 -0
- data/app/lib/biovision/components/content_component.rb +65 -0
- data/app/lib/biovision/components/track_component.rb +3 -0
- data/app/lib/biovision/components/users/authentication.rb +15 -7
- data/app/lib/biovision/components/users/codes.rb +104 -0
- data/app/lib/biovision/components/users/flag_helpers.rb +72 -0
- data/app/lib/biovision/components/users/profile_handler.rb +111 -1
- data/app/lib/biovision/components/users/registration_handler.rb +40 -52
- data/app/lib/biovision/components/users/validation.rb +83 -0
- data/app/lib/biovision/components/users_component.rb +114 -19
- data/app/lib/biovision/helpers/data_helper.rb +70 -0
- data/app/lib/biovision/helpers/export_helper.rb +97 -0
- data/app/lib/biovision/migrations/component_migration.rb +56 -0
- data/app/lib/biovision/notifiers/base_notifier.rb +2 -2
- data/app/lib/biovision/notifiers/contact_notifier.rb +15 -0
- data/app/lib/biovision/stories/component_story.rb +55 -0
- data/app/lib/canonizer.rb +38 -0
- data/app/lib/carrier_wave/image_optim.rb +32 -0
- data/app/mailers/code_sender.rb +29 -0
- data/app/mailers/feedback_mailer.rb +14 -0
- data/app/models/agent.rb +4 -0
- data/app/models/biovision_component.rb +39 -3
- data/app/models/code.rb +31 -8
- data/app/models/concerns/checkable.rb +2 -1
- data/app/models/concerns/has_simple_image.rb +9 -0
- data/app/models/concerns/has_uploaded_file.rb +26 -0
- data/app/models/concerns/meta_texts.rb +25 -5
- data/app/models/concerns/simple_tag.rb +30 -0
- data/app/models/concerns/toggleable.rb +2 -1
- data/app/models/concerns/tree_structure.rb +75 -0
- data/app/models/contact_method.rb +47 -0
- data/app/models/contact_type.rb +27 -0
- data/app/models/dynamic_block.rb +43 -0
- data/app/models/dynamic_page.rb +73 -0
- data/app/models/feedback_message.rb +65 -0
- data/app/models/feedback_response.rb +50 -0
- data/app/models/group.rb +48 -0
- data/app/models/language.rb +4 -0
- data/app/models/metric.rb +4 -0
- data/app/models/navigation_group.rb +43 -0
- data/app/models/navigation_group_page.rb +23 -0
- data/app/models/oembed_domain.rb +25 -0
- data/app/models/oembed_link.rb +19 -0
- data/app/models/oembed_receiver.rb +15 -0
- data/app/models/role.rb +86 -0
- data/app/models/role_group.rb +13 -0
- data/app/models/simple_image.rb +49 -8
- data/app/models/simple_image_tag.rb +1 -16
- data/app/models/token.rb +6 -2
- data/app/models/uploaded_file.rb +62 -0
- data/app/models/uploaded_file_tag.rb +15 -0
- data/app/models/uploaded_file_tag_file.rb +13 -0
- data/app/models/user.rb +122 -29
- data/app/models/user_group.rb +20 -0
- data/app/models/user_role.rb +18 -0
- data/app/uploaders/simple_file_uploader.rb +23 -0
- data/app/uploaders/simple_image_uploader.rb +29 -20
- data/app/uploaders/uploaders/path_slug.rb +22 -0
- data/app/views/admin/agents/index.html.erb +1 -3
- data/app/views/admin/biovision_components/_nav_item.html.erb +6 -0
- data/app/views/admin/biovision_components/entity/_in_list.html.erb +12 -0
- data/app/views/admin/biovision_components/index.html.erb +11 -0
- data/app/views/admin/components/_image.jbuilder +18 -0
- data/app/views/admin/components/_list.html.erb +1 -1
- data/app/views/admin/components/entity/_links.html.erb +31 -21
- data/app/views/admin/components/image.jbuilder +1 -0
- data/app/views/admin/components/images.jbuilder +4 -0
- data/app/views/admin/components/links/_base.html.erb +1 -0
- data/app/views/admin/components/settings/_new_parameter.html.erb +4 -2
- data/app/views/admin/components/settings/_parameters.html.erb +8 -2
- data/app/views/admin/components/settings/_settings.html.erb +4 -4
- data/app/views/admin/components/settings.html.erb +2 -1
- data/app/views/admin/components/update_privileges.jbuilder +21 -0
- data/app/views/admin/dynamic_blocks/_form.html.erb +16 -0
- data/app/views/admin/dynamic_blocks/_nav_item.html.erb +6 -0
- data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +12 -0
- data/app/views/admin/dynamic_blocks/index.html.erb +17 -0
- data/app/views/admin/dynamic_blocks/show.html.erb +25 -0
- data/app/views/admin/dynamic_pages/_dynamic_page.jbuilder +18 -0
- data/app/views/admin/dynamic_pages/_form.html.erb +21 -0
- data/app/views/admin/dynamic_pages/_nav_item.html.erb +6 -0
- data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +17 -0
- data/app/views/admin/dynamic_pages/entity/_in_search.html.erb +7 -0
- data/app/views/admin/dynamic_pages/index.html.erb +17 -0
- data/app/views/admin/dynamic_pages/search.jbuilder +4 -0
- data/app/views/admin/dynamic_pages/show.html.erb +28 -0
- data/app/views/admin/index/index.html.erb +7 -5
- data/app/views/admin/ip_addresses/index.html.erb +2 -4
- data/app/views/admin/navigation_group_pages/entity/_in_list.html.erb +26 -0
- data/app/views/admin/navigation_groups/_form.html.erb +15 -0
- data/app/views/admin/navigation_groups/_nav_item.html.erb +6 -0
- data/app/views/admin/navigation_groups/entity/_dynamic_pages.html.erb +38 -0
- data/app/views/admin/navigation_groups/entity/_in_list.html.erb +14 -0
- data/app/views/admin/navigation_groups/index.html.erb +17 -0
- data/app/views/admin/navigation_groups/show.html.erb +33 -0
- data/app/views/admin/tokens/_form.html.erb +31 -0
- data/app/views/admin/tokens/_nav_item.html.erb +6 -0
- data/app/views/admin/tokens/entity/_in_list.html.erb +27 -0
- data/app/views/admin/tokens/index.html.erb +11 -0
- data/app/views/admin/tokens/show.html.erb +26 -0
- data/app/views/admin/unauthorized.html.erb +2 -5
- data/app/views/admin/users/_form.html.erb +81 -0
- data/app/views/admin/users/_nav_item.html.erb +6 -0
- data/app/views/admin/users/_user.jbuilder +18 -0
- data/app/views/admin/users/entity/_fields.html.erb +53 -0
- data/app/views/admin/users/entity/_in_list.html.erb +38 -0
- data/app/views/admin/users/entity/_in_search.html.erb +18 -0
- data/app/views/admin/users/entity/_profile.html.erb +26 -0
- data/app/views/admin/users/entity/in_list/_additional_data.html.erb +0 -0
- data/app/views/admin/users/index.html.erb +24 -0
- data/app/views/admin/users/roles/_component.html.erb +22 -0
- data/app/views/admin/users/roles.html.erb +23 -0
- data/app/views/admin/users/search.jbuilder +4 -0
- data/app/views/admin/users/show.html.erb +62 -0
- data/app/views/admin/widgets/_filters.html.erb +20 -0
- data/app/views/admin/widgets/_quick_search.html.erb +13 -0
- data/app/views/admin/widgets/filters/_flag.html.erb +15 -0
- data/app/views/admin/widgets/filters/_text.html.erb +7 -0
- data/app/views/application/forbidden.html.erb +9 -0
- data/app/views/application/forbidden.jbuilder +4 -0
- data/app/views/application/not_found.html.erb +9 -0
- data/app/views/application/not_found.jbuilder +4 -0
- data/app/views/application/unauthorized.html.erb +19 -0
- data/app/views/application/unauthorized.jbuilder +4 -0
- data/app/views/authentication/new.html.erb +2 -8
- data/app/views/components/content/_dynamic_page.html.erb +17 -0
- data/app/views/components/content/_dynamic_page_content.html.erb +14 -0
- data/app/views/components/users/_form_tabs.html.erb +31 -0
- data/app/views/components/users/_join_form.html.erb +192 -0
- data/app/views/components/users/_login_form.html.erb +46 -0
- data/app/views/components/users/form/_image.html.erb +17 -0
- data/app/views/components/users/form/_profile_data.html.erb +54 -0
- data/app/views/contact/_form.html.erb +108 -0
- data/app/views/contact/create_feedback_message.js.erb +1 -0
- data/app/views/contact/feedback.html.erb +13 -0
- data/app/views/contact/index.html.erb +16 -0
- data/app/views/errors/error.html.erb +1 -0
- data/app/views/fallback/show.html.erb +6 -0
- data/app/views/feedback_mailer/new_feedback_request.html.erb +11 -0
- data/app/views/feedback_mailer/new_feedback_request.text.erb +6 -0
- data/app/views/index/index.html.erb +14 -0
- data/app/views/layouts/admin/_footer.html.erb +1 -1
- data/app/views/layouts/admin/_header.html.erb +7 -2
- data/app/views/layouts/admin.html.erb +0 -1
- data/app/views/layouts/application/_footer.html.erb +1 -1
- data/app/views/layouts/application/header/_authentication.html.erb +4 -1
- data/app/views/legal/privacy.html.erb +5 -0
- data/app/views/legal/tos.html.erb +5 -0
- data/app/views/my/components/index.html.erb +25 -0
- data/app/views/my/components/show.html.erb +21 -0
- data/app/views/my/confirmations/show.html.erb +62 -0
- data/app/views/my/index/_cards.html.erb +15 -0
- data/app/views/my/index/_email.html.erb +14 -0
- data/app/views/my/index/_navigation.html.erb +33 -0
- data/app/views/my/index/index.html.erb +12 -0
- data/app/views/my/profiles/_form.html.erb +10 -0
- data/app/views/my/profiles/check.jbuilder +4 -0
- data/app/views/my/profiles/edit.html.erb +14 -0
- data/app/views/my/profiles/form/_basic_parameters.html.erb +9 -0
- data/app/views/my/profiles/form/_sensitive_parameters.html.erb +68 -0
- data/app/views/my/profiles/new.html.erb +6 -8
- data/app/views/my/profiles/show.html.erb +36 -0
- data/app/views/my/recoveries/show.html.erb +0 -0
- data/app/views/shared/_flash_messages.html.erb +1 -1
- data/app/views/shared/_list_of_errors.html.erb +7 -0
- data/app/views/shared/admin/_breadcrumbs.html.erb +8 -0
- data/app/views/shared/admin/_list.html.erb +10 -19
- data/app/views/shared/admin/_list_with_priority.html.erb +10 -19
- data/app/views/shared/admin/_priority.html.erb +6 -0
- data/app/views/shared/admin/_toggle.html.erb +6 -0
- data/app/views/shared/entity/_date_field.html.erb +6 -0
- data/app/views/shared/entity/_formatted_text_field.html.erb +10 -0
- data/app/views/shared/entity/_image.html.erb +31 -0
- data/app/views/shared/entity/_language.html.erb +6 -0
- data/app/views/shared/entity/_linked_entity.html.erb +6 -0
- data/app/views/shared/entity/_list.html.erb +22 -0
- data/app/views/shared/entity/_list_with_priority.html.erb +22 -0
- data/app/views/shared/entity/_meta_texts.html.erb +16 -0
- data/app/views/shared/entity/_metadata.html.erb +18 -0
- data/app/views/shared/entity/_parent.html.erb +6 -0
- data/app/views/shared/entity/_priority.html.erb +4 -0
- data/app/views/shared/entity/_priority_icons.html.erb +8 -0
- data/app/views/shared/entity/_raw_text_field.html.erb +10 -0
- data/app/views/shared/entity/_simple_image.html.erb +10 -0
- data/app/views/shared/entity/_slug.html.erb +6 -0
- data/app/views/shared/entity/_text_field.html.erb +6 -0
- data/app/views/shared/entity/_text_fields.html.erb +9 -0
- data/app/views/shared/entity/_time_field.html.erb +6 -0
- data/app/views/shared/entity/_timestamps.html.erb +13 -0
- data/app/views/shared/entity/_toggle.html.erb +12 -0
- data/app/views/shared/entity/_track.html.erb +12 -0
- data/app/views/shared/entity/_tree_caches.html.erb +19 -0
- data/app/views/shared/entity/_uuid.html.erb +4 -0
- data/app/views/shared/entity/edit.html.erb +23 -0
- data/app/views/shared/entity/new.html.erb +16 -0
- data/app/views/shared/forms/_entity_flags.html.erb +15 -0
- data/app/views/shared/forms/_field.html.erb +50 -0
- data/app/views/shared/forms/_field_with_search.html.erb +17 -0
- data/app/views/shared/forms/_fields.html.erb +3 -0
- data/app/views/shared/forms/_language.html.erb +40 -0
- data/app/views/shared/forms/_meta_texts.html.erb +27 -0
- data/app/views/shared/forms/_priority.html.erb +13 -0
- data/app/views/shared/forms/_simple_entity_link.html.erb +14 -0
- data/app/views/shared/forms/_simple_image.html.erb +47 -0
- data/app/views/shared/forms/_state_container.html.erb +7 -0
- data/app/views/shared/forms/_text_area.html.erb +25 -0
- data/app/views/shared/forms/_text_field.html.erb +24 -0
- data/app/views/shared/forms/_text_fields.html.erb +3 -0
- data/app/views/shared/forms/check.jbuilder +4 -0
- data/app/views/shared/forms/errors.jbuilder +3 -0
- data/app/views/shared/forms/simple_image/_browse.html.erb +14 -0
- data/app/views/shared/forms/simple_image/_load_image.html.erb +38 -0
- data/app/views/shared/my/_list.html.erb +10 -0
- data/app/views/shared/my/_list_with_priority.html.erb +10 -0
- data/app/views/shared/my/entity/edit.html.erb +25 -0
- data/app/views/shared/my/entity/new.html.erb +18 -0
- data/app/views/simple_images/_simple_image.jbuilder +13 -0
- data/app/views/users/_profile.html.erb +30 -0
- data/app/views/users/profile/_data.html.erb +20 -0
- data/app/views/users/show.html.erb +21 -0
- data/config/locales/biovision-ru.yml +76 -1
- data/config/locales/components-ru.yml +55 -4
- data/config/locales/contact-ru.yml +110 -0
- data/config/locales/content-ru.yml +115 -0
- data/config/locales/users-ru.yml +142 -3
- data/config/routes.rb +99 -48
- data/db/migrate/20191228000000_create_biovision_components.rb +6 -5
- data/db/migrate/20200224000000_create_track_component.rb +9 -14
- data/db/migrate/20200224000010_create_users_component.rb +14 -83
- data/db/migrate/20200404000000_create_simple_images.rb +4 -3
- data/db/migrate/20210405000000_create_acl.rb +88 -0
- data/db/migrate/20210421000000_create_content_component.rb +80 -0
- data/db/migrate/20210421000010_create_contact_component.rb +74 -0
- data/db/migrate/20210616000000_create_uploaded_files.rb +52 -0
- data/db/migrate/amends/20210816060606_create_oembed_receivers.rb +21 -0
- data/db/migrate/amends/20210907070707_add_checksum_to_simple_images.rb +13 -0
- data/lib/biovision/base_methods.rb +17 -29
- data/lib/biovision/engine.rb +8 -13
- data/lib/biovision/version.rb +1 -1
- data/lib/tasks/components.rake +51 -0
- metadata +266 -27
- data/app/assets/images/biovision/placeholders/user.svg +0 -15
- data/app/helpers/users_helper.rb +0 -11
- data/app/lib/biovision/components/component_settings.rb +0 -30
- data/app/lib/biovision/components/privilege_handler.rb +0 -77
- data/app/lib/biovision/components/users/code_handler.rb +0 -23
- data/app/models/biovision_component_user.rb +0 -21
- data/app/models/foreign_site.rb +0 -34
- data/app/models/foreign_user.rb +0 -21
- data/app/uploaders/user_image_uploader.rb +0 -58
- data/app/views/admin/components/links/_track.html.erb +0 -2
- data/app/views/admin/components/links/_users.html.erb +0 -11
- data/app/views/admin/components/privileges/_component_user.html.erb +0 -17
- data/app/views/admin/components/privileges/_links.html.erb +0 -35
- data/app/views/admin/components/privileges/_privilege_flag.html.erb +0 -28
- data/app/views/admin/components/privileges/_users.html.erb +0 -23
- data/app/views/admin/components/privileges.html.erb +0 -20
- data/app/views/authentication/_form.html.erb +0 -40
- data/app/views/authentication/failed.js.erb +0 -3
- data/app/views/my/profiles/new/_form.html.erb +0 -147
- data/app/views/shared/admin/_toggleable.html.erb +0 -8
@@ -5,8 +5,118 @@ module Biovision
|
|
5
5
|
module Users
|
6
6
|
# Handling user profiles
|
7
7
|
class ProfileHandler
|
8
|
+
GENDERS = { 0 => 'female', 1 => 'male', 2 => 'other' }.freeze
|
9
|
+
|
8
10
|
attr_accessor :user
|
11
|
+
|
12
|
+
# @param [Biovision::Components::UsersComponent] component
|
13
|
+
def initialize(component)
|
14
|
+
@component = component
|
15
|
+
end
|
16
|
+
|
17
|
+
# List of attributes that can be used in user profile
|
18
|
+
#
|
19
|
+
# Change this method in decorators for other values
|
20
|
+
def self.allowed_parameters
|
21
|
+
%w[gender name patronymic surname about]
|
22
|
+
end
|
23
|
+
|
24
|
+
# List of parameters to be used in controllers for create/update
|
25
|
+
def self.permitted_for_request
|
26
|
+
allowed_parameters.map do |key|
|
27
|
+
key.respond_to?(:to_h) ? [[key.shift, key]].to_h : key
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Normalize profile parameters for storage
|
32
|
+
#
|
33
|
+
# Makes consistent format of profile hash.
|
34
|
+
#
|
35
|
+
# @param [Hash] input
|
36
|
+
def self.clean_parameters(input)
|
37
|
+
return {} unless input.respond_to?(:key?)
|
38
|
+
|
39
|
+
output = normalized_parameters(input)
|
40
|
+
(allowed_parameters - output.keys).each do |parameter|
|
41
|
+
if parameter.respond_to?(:shift)
|
42
|
+
key = parameter.shift
|
43
|
+
output[key] = array_value(input[key].to_h, parameter)
|
44
|
+
else
|
45
|
+
output[parameter] = scalar_value(input, parameter)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
output
|
49
|
+
end
|
50
|
+
|
51
|
+
# @param [Hash] input
|
52
|
+
# @param [String] key
|
53
|
+
def self.scalar_value(input, key)
|
54
|
+
input.key?(key) ? input[key].to_s : nil
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [Hash] input
|
58
|
+
# @param [Array] keys
|
59
|
+
def self.array_value(input, keys)
|
60
|
+
keys.each.map { |key| [key, scalar_value(input, key)] }.to_h
|
61
|
+
end
|
62
|
+
|
63
|
+
# @param [Integer|nil] gender_id
|
64
|
+
def self.gender(gender_id)
|
65
|
+
prefix = 'activerecord.attributes.user_profile.genders'
|
66
|
+
gender_key = gender_id.blank? ? '' : gender_id.to_i
|
67
|
+
postfix = GENDERS[gender_key] || 'not_set'
|
68
|
+
I18n.t("#{prefix}.#{postfix}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.genders_for_select
|
72
|
+
default_key = 'activerecord.attributes.user_profile.genders.not_set'
|
73
|
+
genders = [[I18n.t(default_key), '']]
|
74
|
+
genders + GENDERS.keys.map { |k| [gender(k), k] }
|
75
|
+
end
|
76
|
+
|
77
|
+
# Format parameters that have more restrictions than just "string" type
|
78
|
+
#
|
79
|
+
# Change this method in decorator to add other fields with type
|
80
|
+
# enumerable, integer, etc.
|
81
|
+
#
|
82
|
+
# @param [Hash] input
|
83
|
+
def self.normalized_parameters(input)
|
84
|
+
{ gender: clean_gender(input['gender']) }
|
85
|
+
end
|
86
|
+
|
87
|
+
# Restrict gender to only available values
|
88
|
+
#
|
89
|
+
# Defined gender is stored as integer.
|
90
|
+
#
|
91
|
+
# @param [Integer] input
|
92
|
+
def self.clean_gender(input)
|
93
|
+
gender_key = input.blank? ? nil : input.to_i
|
94
|
+
GENDERS.key?(gender_key) ? gender_key : nil
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param [Hash] profile_data
|
98
|
+
def profile=(profile_data)
|
99
|
+
user.profile = self.class.clean_parameters(profile_data).to_h
|
100
|
+
end
|
101
|
+
|
102
|
+
# @param [Hash] user_data
|
103
|
+
# @param [Hash] profile_data
|
104
|
+
def create(user_data, profile_data)
|
105
|
+
self.user = User.new(user_data)
|
106
|
+
self.profile = profile_data
|
107
|
+
Biovision::Components::UsersComponent.created_user(user) if user.save
|
108
|
+
user
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param [Hash] user_data
|
112
|
+
# @param [Hash] profile_data
|
113
|
+
def update(user_data, profile_data)
|
114
|
+
return if user.nil?
|
115
|
+
|
116
|
+
self.profile = profile_data
|
117
|
+
user.update(user_data)
|
118
|
+
end
|
9
119
|
end
|
10
120
|
end
|
11
121
|
end
|
12
|
-
end
|
122
|
+
end
|
@@ -5,48 +5,44 @@ module Biovision
|
|
5
5
|
module Users
|
6
6
|
# Handling user registration
|
7
7
|
class RegistrationHandler
|
8
|
+
attr_reader :user
|
9
|
+
|
8
10
|
# @param [Biovision::Components::UsersComponent] component
|
9
11
|
def initialize(component)
|
10
12
|
@component = component
|
11
13
|
end
|
12
14
|
|
15
|
+
# @param [Hash] parameters
|
16
|
+
# @param [Code|nil] Code
|
13
17
|
def handle(parameters, code = nil)
|
14
18
|
@user = User.new(parameters)
|
15
|
-
@user.screen_name = @user.email if email_as_login?
|
16
19
|
@user.super_user = 1 if User.count < 1
|
17
|
-
@
|
20
|
+
@user.code = code
|
21
|
+
@code = code
|
18
22
|
|
19
|
-
use_invites? ? use_code : persist_user
|
20
|
-
persist_user if @component.valid?(@user)
|
23
|
+
@component.use_invites? ? use_code : persist_user
|
21
24
|
|
22
25
|
@user
|
23
26
|
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@
|
31
|
-
|
32
|
-
|
33
|
-
def use_invites?
|
34
|
-
@component.settings['use_invites'] || invite_only?
|
35
|
-
end
|
36
|
-
|
37
|
-
def confirm_email?
|
38
|
-
@component.settings['confirm_email']
|
28
|
+
# @param [Hash] parameters
|
29
|
+
# @param [Code|nil] Code
|
30
|
+
def check(parameters, code = nil)
|
31
|
+
@user = User.new(parameters)
|
32
|
+
@user.code = code
|
33
|
+
@user.valid?
|
34
|
+
add_code_error unless acceptable_code?
|
39
35
|
end
|
40
36
|
|
41
|
-
def
|
42
|
-
@component.
|
37
|
+
def open?
|
38
|
+
@component.registration_open?
|
43
39
|
end
|
44
40
|
|
45
|
-
def
|
46
|
-
@
|
41
|
+
def valid?
|
42
|
+
@user.errors.blank?
|
47
43
|
end
|
48
44
|
|
49
|
-
|
45
|
+
private
|
50
46
|
|
51
47
|
def persist_user
|
52
48
|
return unless @user.save
|
@@ -54,44 +50,36 @@ module Biovision
|
|
54
50
|
metric = Biovision::Components::UsersComponent::METRIC_NEW_USER
|
55
51
|
@component.register_metric(metric)
|
56
52
|
|
57
|
-
|
53
|
+
Biovision::Components::UsersComponent.created_user(@user)
|
54
|
+
handle_codes
|
58
55
|
end
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
if @manager.valid? || (@manager.code.nil? && !invite_only?)
|
63
|
-
persist_user
|
64
|
-
else
|
65
|
-
error = I18n.t('biovision.components.users.messages.invalid_code')
|
66
|
-
|
67
|
-
# Add "invalid code" error to other model errors, if any
|
68
|
-
@user.valid?
|
69
|
-
@user.errors.add(:code, error)
|
70
|
-
end
|
57
|
+
def valid_invitation?
|
58
|
+
@component.valid_invitation?(@code)
|
71
59
|
end
|
72
60
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
CodeSender.email(code.id).deliver_later
|
77
|
-
end
|
61
|
+
def acceptable_code?
|
62
|
+
valid_invitation? || (@code.nil? && !@component.invite_only?)
|
63
|
+
end
|
78
64
|
|
79
|
-
|
65
|
+
# Check invitation code and persist user if it's valid
|
66
|
+
def use_code
|
67
|
+
acceptable_code? ? persist_user : add_code_error
|
68
|
+
end
|
80
69
|
|
81
|
-
|
82
|
-
|
70
|
+
def add_code_error
|
71
|
+
@user.valid?
|
72
|
+
@user.errors.add(:code, :invalid)
|
83
73
|
end
|
84
74
|
|
85
|
-
|
86
|
-
|
87
|
-
|
75
|
+
def handle_codes
|
76
|
+
@component.send_email_confirmation(@user) if @component.confirm_email?
|
77
|
+
@component.send_phone_confirmation(@user) if @component.confirm_phone?
|
78
|
+
|
79
|
+
return unless @component.use_invites?
|
88
80
|
|
89
|
-
|
90
|
-
|
91
|
-
user: @user,
|
92
|
-
quantity: quantity
|
93
|
-
}
|
94
|
-
Code.create(parameters)
|
81
|
+
@component.activate_invitation(@code, @user) if valid_invitation?
|
82
|
+
@component.create_invitations_for_user(@user)
|
95
83
|
end
|
96
84
|
end
|
97
85
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Users
|
6
|
+
# Validating instances of User
|
7
|
+
module Validation
|
8
|
+
def validate
|
9
|
+
return if user.nil?
|
10
|
+
|
11
|
+
prepare_screen_name if user.new_record?
|
12
|
+
|
13
|
+
validate_email
|
14
|
+
validate_phone
|
15
|
+
validate_screen_name unless user.data[User::FLAG_SKIP_SCREEN_NAME]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def prepare_screen_name
|
21
|
+
use_uuid = false
|
22
|
+
use_uuid = email_as_login! if email_as_login?
|
23
|
+
use_uuid = phone_as_login! if phone_as_login?
|
24
|
+
|
25
|
+
user.screen_name = user.uuid if use_uuid
|
26
|
+
end
|
27
|
+
|
28
|
+
def email_as_login!
|
29
|
+
key = Biovision::Components::UsersComponent::SETTING_EMAIL_AS_LOGIN
|
30
|
+
user.data[key] = true
|
31
|
+
end
|
32
|
+
|
33
|
+
def phone_as_login!
|
34
|
+
key = Biovision::Components::UsersComponent::SETTING_PHONE_AS_LOGIN
|
35
|
+
user.data[key] = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_phone
|
39
|
+
user.errors.add(:phone, :blank) if require_phone? && user.phone.blank?
|
40
|
+
|
41
|
+
normalize_phone_format unless user.phone.blank?
|
42
|
+
validate_phone_format unless user.phone.blank?
|
43
|
+
end
|
44
|
+
|
45
|
+
def normalize_phone_format
|
46
|
+
has_plus = user.phone.strip[0] == '+'
|
47
|
+
normalized_phone = user.phone.gsub(/\D/, '')
|
48
|
+
normalized_phone[0] = '7' if !has_plus && normalized_phone[0] == '8'
|
49
|
+
|
50
|
+
user.phone = "+#{normalized_phone}" unless normalized_phone.blank?
|
51
|
+
end
|
52
|
+
|
53
|
+
# @see https://ru.wikipedia.org/wiki/MSISDN
|
54
|
+
def validate_phone_format
|
55
|
+
return if user.phone =~ /\+\d{11,15}/
|
56
|
+
|
57
|
+
user.errors.add(:phone, :invalid)
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_email
|
61
|
+
user.errors.add(:email, :blank) if require_email? && user.email.blank?
|
62
|
+
|
63
|
+
validate_email_format unless user.email.blank?
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_email_format
|
67
|
+
too_long = user.email.to_s.length > User::EMAIL_LIMIT
|
68
|
+
pattern_matches = (user.email.to_s =~ User::EMAIL_PATTERN)
|
69
|
+
|
70
|
+
user.errors.add(:email, :invalid) if too_long || !pattern_matches
|
71
|
+
end
|
72
|
+
|
73
|
+
def validate_screen_name
|
74
|
+
pattern = User::SLUG_PATTERN
|
75
|
+
|
76
|
+
return if user.screen_name =~ pattern
|
77
|
+
|
78
|
+
user.errors.add(:screen_name, :invalid)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -5,42 +5,137 @@ module Biovision
|
|
5
5
|
# Handling users
|
6
6
|
class UsersComponent < BaseComponent
|
7
7
|
include Users::Authentication
|
8
|
+
include Users::Validation
|
9
|
+
include Users::Codes
|
10
|
+
include Users::FlagHelpers
|
8
11
|
|
12
|
+
CODE_EMAIL_CONFIRMATION = 'email_confirmation'
|
13
|
+
CODE_INVITATION = 'invitation'
|
14
|
+
CODE_PHONE_CONFIRMATION = 'phone_confirmation'
|
15
|
+
CODE_RECOVERY = 'recovery'
|
16
|
+
METRIC_AUTH_FAILURE = 'users.auth.failure.hit'
|
9
17
|
METRIC_NEW_USER = 'users.new_user.hit'
|
18
|
+
METRIC_REGISTRATION_BOT = 'users.registration.bot.hit'
|
19
|
+
METRIC_USED_INVITATION = 'users.used_invitation.hit'
|
20
|
+
SETTING_BOUNCE_COUNT = 'bounce_count'
|
21
|
+
SETTING_BOUNCE_TIMEOUT = 'bounce_timeout'
|
22
|
+
SETTING_CONFIRM_EMAIL = 'confirm_email'
|
23
|
+
SETTING_CONFIRM_PHONE = 'confirm_phone'
|
24
|
+
SETTING_EMAIL_AS_LOGIN = 'email_as_login'
|
25
|
+
SETTING_INVITE_COUNT = 'invite_count'
|
26
|
+
SETTING_INVITE_ONLY = 'invite_only'
|
27
|
+
SETTING_OPEN = 'registration_open'
|
28
|
+
SETTING_PHONE_AS_LOGIN = 'phone_as_login'
|
29
|
+
SETTING_REQUIRE_EMAIL = 'require_email'
|
30
|
+
SETTING_REQUIRE_PHONE = 'require_phone'
|
31
|
+
SETTING_USE_INVITES = 'use_invites'
|
32
|
+
SETTING_USE_PHONE = 'use_phone'
|
33
|
+
|
34
|
+
def self.dependent_models
|
35
|
+
[
|
36
|
+
User, Token, LoginAttempt, UserLanguage, BiovisionComponentUser, Code,
|
37
|
+
Notification
|
38
|
+
]
|
39
|
+
end
|
10
40
|
|
11
41
|
def self.settings_flags
|
12
|
-
|
13
|
-
|
14
|
-
|
42
|
+
[
|
43
|
+
SETTING_OPEN, SETTING_EMAIL_AS_LOGIN, SETTING_CONFIRM_EMAIL,
|
44
|
+
SETTING_CONFIRM_PHONE, SETTING_PHONE_AS_LOGIN, SETTING_REQUIRE_EMAIL,
|
45
|
+
SETTING_REQUIRE_PHONE, SETTING_INVITE_ONLY, SETTING_USE_INVITES,
|
46
|
+
SETTING_USE_PHONE
|
15
47
|
]
|
16
48
|
end
|
17
49
|
|
18
50
|
def self.settings_numbers
|
19
|
-
|
51
|
+
[SETTING_INVITE_COUNT, SETTING_BOUNCE_COUNT, SETTING_BOUNCE_TIMEOUT]
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.default_settings
|
55
|
+
{
|
56
|
+
SETTING_OPEN => true,
|
57
|
+
SETTING_EMAIL_AS_LOGIN => false,
|
58
|
+
SETTING_PHONE_AS_LOGIN => false,
|
59
|
+
SETTING_CONFIRM_EMAIL => false,
|
60
|
+
SETTING_REQUIRE_EMAIL => false,
|
61
|
+
SETTING_USE_PHONE => false,
|
62
|
+
SETTING_REQUIRE_PHONE => false,
|
63
|
+
SETTING_CONFIRM_PHONE => false,
|
64
|
+
SETTING_INVITE_ONLY => false,
|
65
|
+
SETTING_USE_INVITES => false,
|
66
|
+
SETTING_INVITE_COUNT => 5,
|
67
|
+
SETTING_BOUNCE_COUNT => 10,
|
68
|
+
SETTING_BOUNCE_TIMEOUT => 3,
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param [User] user
|
73
|
+
def self.created_user(user)
|
74
|
+
BiovisionComponent.active.pluck(:slug).each do |slug|
|
75
|
+
handler = Biovision::Components::BaseComponent.handler_class(slug)
|
76
|
+
handler.handle_new_user(user) if handler.respond_to?(:handle_new_user)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param [User] user
|
81
|
+
def self.handle_new_user(user)
|
82
|
+
handler = new(BiovisionComponent[slug], user)
|
83
|
+
|
84
|
+
return unless handler.use_invites?
|
85
|
+
|
86
|
+
parameters = {
|
87
|
+
user: user,
|
88
|
+
quantity: handler.settings[SETTING_INVITE_COUNT].to_i
|
89
|
+
}
|
90
|
+
|
91
|
+
code = handler.component.codes.new(parameters)
|
92
|
+
code.code_type = CODE_INVITATION
|
93
|
+
code.save
|
20
94
|
end
|
21
95
|
|
22
96
|
# @param [Hash] parameters
|
23
|
-
# @param [Code] code
|
24
|
-
def register_user(parameters, code)
|
97
|
+
# @param [Code|nil] code
|
98
|
+
def register_user(parameters, code = nil)
|
25
99
|
handler = Users::RegistrationHandler.new(self)
|
26
100
|
handler.handle(parameters, code)
|
27
101
|
end
|
28
102
|
|
29
|
-
# @param [
|
30
|
-
|
31
|
-
|
103
|
+
# @param [Hash] user_data
|
104
|
+
# @param [Hash] profile_data
|
105
|
+
def create_user(user_data, profile_data)
|
106
|
+
handler = Users::ProfileHandler.new(self)
|
107
|
+
handler.create(user_data, profile_data)
|
108
|
+
handler.user
|
32
109
|
end
|
33
110
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
111
|
+
# @param [User] user
|
112
|
+
# @param [Hash] user_data
|
113
|
+
# @param [Hash] profile_data
|
114
|
+
def update_user(user, user_data, profile_data)
|
115
|
+
handler = Users::ProfileHandler.new(self)
|
116
|
+
handler.user = user
|
117
|
+
handler.update(user_data, profile_data)
|
118
|
+
end
|
119
|
+
|
120
|
+
# @param [String|Symbol] attribute_name
|
121
|
+
def attribute(attribute_name)
|
122
|
+
return nil if user.nil?
|
123
|
+
|
124
|
+
user.attributes[attribute_name.to_s]
|
125
|
+
end
|
126
|
+
|
127
|
+
def role_tree
|
128
|
+
result = super
|
129
|
+
result['users'] << 'log_in'
|
130
|
+
result
|
131
|
+
end
|
132
|
+
|
133
|
+
def crud_table_names
|
134
|
+
super - %w[user_languages biovision_component_users]
|
135
|
+
end
|
136
|
+
|
137
|
+
def administrative_parts
|
138
|
+
%w[users tokens login_attempts codes notifications]
|
44
139
|
end
|
45
140
|
end
|
46
141
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Helpers
|
5
|
+
# Helper for receiving model data in controllers
|
6
|
+
class DataHelper
|
7
|
+
attr_reader :model_class
|
8
|
+
|
9
|
+
# @param [ApplicationRecord] model_class
|
10
|
+
# @param [Hash] filters
|
11
|
+
def initialize(model_class, filters = {})
|
12
|
+
@model_class = model_class
|
13
|
+
@filters = filters
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [Integer] page
|
17
|
+
def administrative_collection(page = 1)
|
18
|
+
paginates = model_class.respond_to?(:page_for_administration)
|
19
|
+
paginates ? administrative_page(page) : administrative_list
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param [User] user
|
23
|
+
# @param [Integer] page
|
24
|
+
def personal_collection(user, page = 1)
|
25
|
+
paginates = model_class.respond_to?(:page_for_owner)
|
26
|
+
paginates ? personal_page(user, page) : personal_list(user)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def administrative_list
|
32
|
+
if model_class.respond_to?(:filtered)
|
33
|
+
model_class.filtered(@filters).list_for_administration
|
34
|
+
else
|
35
|
+
model_class.list_for_administration
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [Integer] page
|
40
|
+
def administrative_page(page)
|
41
|
+
reflection = model_class.singleton_method(:page_for_administration)
|
42
|
+
if reflection.parameters.include?(%i[key filters])
|
43
|
+
model_class.page_for_administration(page, filters: @filters)
|
44
|
+
else
|
45
|
+
model_class.page_for_administration(page)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param [User] user
|
50
|
+
def personal_list(user)
|
51
|
+
if model_class.respond_to?(:filtered)
|
52
|
+
model_class.filtered(@filters).list_for_owner(user)
|
53
|
+
else
|
54
|
+
model_class.list_for_owner(user)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param [User] user
|
59
|
+
# @param [Integer] page
|
60
|
+
def personal_page(user, page)
|
61
|
+
reflection = model_class.singleton_method(:page_for_owner)
|
62
|
+
if reflection.parameters.include?(%i[key filters])
|
63
|
+
model_class.page_for_owner(user, page, filters: @filters)
|
64
|
+
else
|
65
|
+
model_class.page_for_owner(user, page)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Helpers
|
5
|
+
# Helper for exporting model data
|
6
|
+
class ExportHelper
|
7
|
+
EXPORT_DIR = "#{Rails.root}/tmp/export"
|
8
|
+
SPECIAL_FIELDS = %w[id agent_id ip_address_id image attachment].freeze
|
9
|
+
|
10
|
+
# @param [Class] model
|
11
|
+
def export_model(model)
|
12
|
+
puts "Exporting model #{model}..."
|
13
|
+
FileUtils.mkdir_p(EXPORT_DIR) unless Dir.exist?(EXPORT_DIR)
|
14
|
+
file_name = "#{EXPORT_DIR}/#{model.table_name}.yml"
|
15
|
+
File.open(file_name, 'wb') do |file|
|
16
|
+
@file = file
|
17
|
+
model.order(:id).each do |entity|
|
18
|
+
@entity = entity
|
19
|
+
export_entity
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def export_entity
|
27
|
+
print "\r#{@entity.id} "
|
28
|
+
@file.puts "#{@entity.id}:"
|
29
|
+
export_attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
def export_attributes
|
33
|
+
filtered = @entity.attributes.reject { |a, v| ignored?(a) || v.nil? }
|
34
|
+
filtered.each do |attribute, value|
|
35
|
+
export_attribute(attribute, value)
|
36
|
+
end
|
37
|
+
export_track
|
38
|
+
export_media('image') if @entity.attributes.key?('image')
|
39
|
+
export_media('attachment') if @entity.attributes.key?('attachment')
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param [String] attribute
|
43
|
+
# @param value
|
44
|
+
def export_attribute(attribute, value)
|
45
|
+
@file.print " #{attribute}: "
|
46
|
+
if value.is_a?(Hash)
|
47
|
+
if value.blank?
|
48
|
+
@file.puts '{}'
|
49
|
+
else
|
50
|
+
@file.puts value.to_yaml.gsub(/\A---|\n\z/, '').gsub("\n", "\n ")
|
51
|
+
end
|
52
|
+
else
|
53
|
+
@file.puts value.inspect
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def export_track
|
58
|
+
return unless @entity.is_a?(HasTrack)
|
59
|
+
|
60
|
+
unless @entity.ip_address.nil?
|
61
|
+
@file.puts " ip_address: #{@entity.ip_address.ip.to_s.inspect}"
|
62
|
+
end
|
63
|
+
|
64
|
+
return if @entity.agent.blank?
|
65
|
+
|
66
|
+
@file.puts " agent: #{@entity.agent.name.inspect}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def media_dir
|
70
|
+
"#{EXPORT_DIR}/#{@entity.class.table_name}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def export_media(type)
|
74
|
+
media = @entity.send(type.to_sym)
|
75
|
+
|
76
|
+
return if media.blank?
|
77
|
+
|
78
|
+
media_name = File.basename(media.path)
|
79
|
+
dir_name = "#{media_dir}/#{@entity.id}"
|
80
|
+
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
81
|
+
FileUtils.copy(media.path, "#{dir_name}/#{media_name}")
|
82
|
+
@file.puts " #{type}: #{media_name.inspect}"
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param [String] attribute
|
86
|
+
def ignored?(attribute)
|
87
|
+
return true if SPECIAL_FIELDS.include?(attribute)
|
88
|
+
|
89
|
+
%w[count cache].each do |ending|
|
90
|
+
return true if attribute.end_with?("_#{ending}")
|
91
|
+
end
|
92
|
+
|
93
|
+
false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|