biovision 0.0.200518.1 → 0.1.210414.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 +60 -18
- 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.scss +3 -1
- data/app/assets/stylesheets/biovision/admin/components/users.scss +16 -0
- data/app/assets/stylesheets/biovision/admin/layout.scss +6 -17
- data/app/assets/stylesheets/biovision/biovision.scss +42 -1
- data/app/assets/stylesheets/biovision/components.scss +6 -0
- 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/forms.scss +162 -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/simple_image.scss +112 -0
- data/app/assets/stylesheets/biovision/components/toggleable.scss +71 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +2 -3
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +2 -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/layout.scss +2 -16
- data/app/controllers/admin/components_controller.rb +9 -19
- data/app/controllers/admin/dynamic_blocks_controller.rb +15 -0
- data/app/controllers/admin/dynamic_pages_controller.rb +15 -0
- data/app/controllers/admin/navigation_groups_controller.rb +14 -0
- data/app/controllers/admin/users_controller.rb +70 -0
- data/app/controllers/admin_controller.rb +3 -2
- data/app/controllers/authentication_controller.rb +6 -34
- data/app/controllers/concerns/authentication.rb +12 -12
- data/app/controllers/concerns/crud_entities.rb +132 -0
- data/app/controllers/concerns/entity_priority.rb +10 -0
- data/app/controllers/concerns/toggleable_entity.rb +31 -0
- data/app/controllers/contact_controller.rb +49 -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 +5 -0
- data/app/controllers/my/confirmations_controller.rb +44 -0
- data/app/controllers/my/index_controller.rb +8 -0
- data/app/controllers/my/profiles_controller.rb +31 -16
- data/app/controllers/profile_controller.rb +12 -0
- data/app/controllers/users_controller.rb +61 -0
- data/app/helpers/biovision_helper.rb +171 -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 +44 -0
- data/app/lib/biovision/components/base/component_privileges.rb +65 -0
- data/app/lib/biovision/components/base/component_settings.rb +32 -0
- data/app/lib/biovision/components/base/privilege_handler.rb +79 -0
- data/app/lib/biovision/components/base_component.rb +51 -54
- data/app/lib/biovision/components/contact_component.rb +22 -0
- data/app/lib/biovision/components/content_component.rb +28 -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 +82 -19
- data/app/lib/biovision/notifiers/base_notifier.rb +2 -2
- data/app/lib/biovision/notifiers/contact_notifier.rb +15 -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/models/agent.rb +4 -0
- data/app/models/biovision_component.rb +22 -2
- data/app/models/browser.rb +1 -1
- data/app/models/code.rb +32 -9
- data/app/models/concerns/has_simple_image.rb +9 -0
- data/app/models/concerns/meta_texts.rb +25 -5
- data/app/models/concerns/tree_structure.rb +72 -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 +71 -0
- data/app/models/feedback_message.rb +59 -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/navigation_group.rb +33 -0
- data/app/models/navigation_group_page.rb +23 -0
- data/app/models/role.rb +56 -0
- data/app/models/role_group.rb +13 -0
- data/app/models/simple_image.rb +22 -8
- data/app/models/simple_image_tag.rb +1 -1
- data/app/models/token.rb +4 -4
- data/app/models/user.rb +94 -26
- data/app/models/user_group.rb +20 -0
- data/app/models/user_role.rb +19 -0
- data/app/uploaders/simple_file_uploader.rb +27 -0
- data/app/uploaders/simple_image_uploader.rb +20 -0
- data/app/views/admin/agents/index.html.erb +0 -2
- 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 +1 -1
- data/app/views/admin/components/image.jbuilder +1 -0
- data/app/views/admin/components/images.jbuilder +4 -0
- data/app/views/admin/components/links/_content.html.erb +9 -0
- data/app/views/admin/components/links/_users.html.erb +1 -8
- data/app/views/admin/components/links/extra/_content.html.erb +0 -0
- data/app/views/admin/components/privileges/_links.html.erb +0 -18
- 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 +1 -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 +10 -0
- data/app/views/admin/dynamic_blocks/index.html.erb +15 -0
- data/app/views/admin/dynamic_blocks/show.html.erb +23 -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 +15 -0
- data/app/views/admin/dynamic_pages/index.html.erb +15 -0
- data/app/views/admin/dynamic_pages/show.html.erb +28 -0
- data/app/views/admin/ip_addresses/index.html.erb +0 -2
- 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/_in_list.html.erb +12 -0
- data/app/views/admin/navigation_groups/index.html.erb +15 -0
- data/app/views/admin/navigation_groups/show.html.erb +20 -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/entity/_fields.html.erb +53 -0
- data/app/views/admin/users/entity/_in_list.html.erb +38 -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 +15 -0
- data/app/views/admin/users/show.html.erb +44 -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 +16 -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 +21 -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 +45 -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/fallback/show.html.erb +6 -0
- data/app/views/layouts/admin.html.erb +1 -1
- data/app/views/layouts/admin/_footer.html.erb +1 -1
- data/app/views/layouts/application/header/_authentication.html.erb +1 -1
- data/app/views/legal/privacy.html.erb +5 -0
- data/app/views/legal/tos.html.erb +5 -0
- data/app/views/my/confirmations/show.html.erb +62 -0
- data/app/views/my/index/index.html.erb +33 -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 +23 -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 +4 -4
- data/app/views/shared/admin/_list_with_priority.html.erb +4 -4
- data/app/views/shared/admin/_priority.html.erb +5 -0
- data/app/views/shared/admin/_toggle.html.erb +11 -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/_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/_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/_timestamps.html.erb +13 -0
- data/app/views/shared/entity/_tree_caches.html.erb +12 -0
- data/app/views/shared/entity/_uuid.html.erb +4 -0
- data/app/views/shared/entity/edit.html.erb +21 -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 +46 -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_image.html.erb +39 -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 +19 -0
- data/app/views/shared/my/_list_with_priority.html.erb +19 -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 +58 -0
- data/config/locales/components-ru.yml +30 -2
- data/config/locales/contact-ru.yml +106 -0
- data/config/locales/content-ru.yml +103 -0
- data/config/locales/users-ru.yml +117 -3
- data/config/routes.rb +70 -50
- data/db/migrate/20191228000000_create_biovision_components.rb +4 -5
- data/db/migrate/20200224000000_create_track_component.rb +7 -8
- data/db/migrate/20200224000010_create_users_component.rb +15 -43
- data/db/migrate/20200404000000_create_simple_images.rb +3 -3
- data/db/migrate/20200529000000_create_content_component.rb +74 -0
- data/db/migrate/20210401000000_create_contact_component.rb +95 -0
- data/db/migrate/20210405000000_create_acl.rb +74 -0
- data/lib/biovision/base_methods.rb +18 -10
- data/lib/biovision/engine.rb +8 -13
- data/lib/biovision/version.rb +1 -1
- metadata +186 -20
- 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/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/privileges/_privilege_flag.html.erb +0 -28
- 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,7 +5,6 @@ class AuthenticationController < ApplicationController
|
|
5
5
|
include Authentication
|
6
6
|
|
7
7
|
before_action :redirect_authenticated_user, except: %i[new destroy]
|
8
|
-
before_action :set_foreign_site, only: :auth_callback
|
9
8
|
|
10
9
|
# get /login
|
11
10
|
def new
|
@@ -13,7 +12,9 @@ class AuthenticationController < ApplicationController
|
|
13
12
|
|
14
13
|
# post /login
|
15
14
|
def create
|
16
|
-
|
15
|
+
user = User[param_from_request(:login).downcase]
|
16
|
+
|
17
|
+
handler = Biovision::Components::UsersComponent[user]
|
17
18
|
if handler.authenticate(params[:password], tracking_for_entity)
|
18
19
|
auth_success(handler.user)
|
19
20
|
else
|
@@ -28,52 +29,23 @@ class AuthenticationController < ApplicationController
|
|
28
29
|
redirect_to root_path
|
29
30
|
end
|
30
31
|
|
31
|
-
# get /auth/:provider/callback
|
32
|
-
def auth_callback
|
33
|
-
data = request.env['omniauth.auth']
|
34
|
-
user = @foreign_site.authenticate(data, tracking_for_entity)
|
35
|
-
create_token_for_user(user) unless user.banned?
|
36
|
-
|
37
|
-
redirect_to my_path
|
38
|
-
end
|
39
|
-
|
40
32
|
private
|
41
33
|
|
42
34
|
def component_class
|
43
35
|
Biovision::Components::UsersComponent
|
44
36
|
end
|
45
37
|
|
46
|
-
def set_foreign_site
|
47
|
-
@foreign_site = ForeignSite[params[:provider]]
|
48
|
-
|
49
|
-
handle_http_503('Cannot set foreign site') if @foreign_site.nil?
|
50
|
-
end
|
51
|
-
|
52
|
-
def find_user
|
53
|
-
login = param_from_request(:login).downcase
|
54
|
-
user = User.find_by(slug: login)
|
55
|
-
|
56
|
-
# Try to authenticate by email, if login does not match anything
|
57
|
-
if user.nil? && login.index('@').to_i.positive?
|
58
|
-
user = User.with_email(login).first
|
59
|
-
end
|
60
|
-
|
61
|
-
user
|
62
|
-
end
|
63
|
-
|
64
38
|
# @param [User] user
|
65
39
|
def auth_success(user)
|
66
40
|
create_token_for_user(user)
|
67
41
|
|
68
42
|
from = param_from_request(:from)
|
69
43
|
next_page = from =~ %r{\A/[^/]} ? from : my_path
|
70
|
-
render
|
44
|
+
render json: { links: { next: next_page } }
|
71
45
|
end
|
72
46
|
|
73
47
|
def auth_failed
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
render 'failed', formats: :js
|
48
|
+
response = { errors: [{ title: t('authentication.create.failed') }] }
|
49
|
+
render json: response, status: :unauthorized
|
78
50
|
end
|
79
51
|
end
|
@@ -15,12 +15,7 @@ module Authentication
|
|
15
15
|
|
16
16
|
token = user.tokens.create!(tracking_for_entity)
|
17
17
|
|
18
|
-
cookies['token'] =
|
19
|
-
value: token.cookie_pair,
|
20
|
-
expires: 1.year.from_now,
|
21
|
-
domain: :all,
|
22
|
-
httponly: true
|
23
|
-
}
|
18
|
+
cookies['token'] = cookie_data(token.cookie_pair)
|
24
19
|
end
|
25
20
|
|
26
21
|
def deactivate_token
|
@@ -31,15 +26,20 @@ module Authentication
|
|
31
26
|
|
32
27
|
def pop_token
|
33
28
|
if cookies['pt']
|
34
|
-
cookies['token'] =
|
35
|
-
value: cookies['pt'],
|
36
|
-
expires: 1.year.from_now,
|
37
|
-
domain: :all,
|
38
|
-
httponly: true
|
39
|
-
}
|
29
|
+
cookies['token'] = cookie_data(cookies['pt'])
|
40
30
|
cookies.delete 'pt', domain: :all
|
41
31
|
else
|
42
32
|
cookies.delete 'token', domain: :all
|
43
33
|
end
|
44
34
|
end
|
35
|
+
|
36
|
+
# @param [String] value
|
37
|
+
def cookie_data(value)
|
38
|
+
{
|
39
|
+
value: value,
|
40
|
+
expires: 1.year.from_now,
|
41
|
+
domain: :all,
|
42
|
+
httponly: true
|
43
|
+
}
|
44
|
+
end
|
45
45
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Adds method for CRUD
|
4
|
+
module CrudEntities
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
# get [scope]/[table_name]
|
8
|
+
def index
|
9
|
+
@collection = if paginate_entities?
|
10
|
+
model_class.page_for_administration(current_page)
|
11
|
+
else
|
12
|
+
model_class.list_for_administration
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# get [scope]/[table_name]/:id
|
17
|
+
def show
|
18
|
+
end
|
19
|
+
|
20
|
+
# post [scope]/[table_name]/check
|
21
|
+
def check
|
22
|
+
@entity = model_class.instance_for_check(params[:entity_id], entity_parameters)
|
23
|
+
|
24
|
+
render 'shared/forms/check'
|
25
|
+
end
|
26
|
+
|
27
|
+
# get [scope]/[table_name]/new
|
28
|
+
def new
|
29
|
+
@entity = model_class.new
|
30
|
+
render view_for_new
|
31
|
+
end
|
32
|
+
|
33
|
+
# post [scope]/[table_name]
|
34
|
+
def create
|
35
|
+
@entity = model_class.new(creation_parameters)
|
36
|
+
apply_meta if @entity.respond_to?(:meta=)
|
37
|
+
if @entity.save
|
38
|
+
form_processed_ok(path_after_save)
|
39
|
+
else
|
40
|
+
form_processed_with_error(view_for_new)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# get [scope]/[table_name]/:id/edit
|
45
|
+
def edit
|
46
|
+
render view_for_edit
|
47
|
+
end
|
48
|
+
|
49
|
+
# patch [scope]/[table_name]/:id
|
50
|
+
def update
|
51
|
+
apply_meta if @entity.respond_to?(:meta=)
|
52
|
+
|
53
|
+
if @entity.update(entity_parameters)
|
54
|
+
form_processed_ok(path_after_save)
|
55
|
+
else
|
56
|
+
form_processed_with_error(view_for_edit)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# delete [scope]/[table_name]/:id
|
61
|
+
def destroy
|
62
|
+
flash[:notice] = t('.success') if @entity.destroy
|
63
|
+
redirect_to path_after_destroy
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def view_for_new
|
69
|
+
default_view = "#{controller_path}/new"
|
70
|
+
lookup_context.exists?(default_view) ? default_view : 'shared/entity/new'
|
71
|
+
end
|
72
|
+
|
73
|
+
def view_for_edit
|
74
|
+
default_view = "#{controller_path}/edit"
|
75
|
+
lookup_context.exists?(default_view) ? default_view : 'shared/entity/edit'
|
76
|
+
end
|
77
|
+
|
78
|
+
def model_class
|
79
|
+
@model_class ||= controller_name.classify.constantize
|
80
|
+
end
|
81
|
+
|
82
|
+
def model_key
|
83
|
+
model_class.model_name.to_s.underscore
|
84
|
+
end
|
85
|
+
|
86
|
+
def path_after_save
|
87
|
+
scope = self.class.module_parent.to_s.downcase
|
88
|
+
prefix = scope.blank? ? '' : "/#{scope}"
|
89
|
+
"#{prefix}/#{model_class.table_name}/#{@entity.id}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def path_after_destroy
|
93
|
+
scope = self.class.module_parent.to_s.downcase
|
94
|
+
prefix = scope.blank? ? '' : "/#{scope}"
|
95
|
+
"#{prefix}/#{model_class.table_name}"
|
96
|
+
end
|
97
|
+
|
98
|
+
def paginate_entities?
|
99
|
+
model_class.respond_to?(:page_for_administration)
|
100
|
+
end
|
101
|
+
|
102
|
+
def set_entity
|
103
|
+
@entity = model_class.find_by(id: params[:id])
|
104
|
+
handle_http_404("Cannot find #{model_class.model_name}") if @entity.nil?
|
105
|
+
end
|
106
|
+
|
107
|
+
def creation_parameters
|
108
|
+
if model_class.respond_to?(:creation_parameters)
|
109
|
+
explicit_creation_parameters
|
110
|
+
else
|
111
|
+
entity_parameters
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def explicit_creation_parameters
|
116
|
+
permitted = model_class.creation_parameters(current_user)
|
117
|
+
parameters = params.require(model_key).permit(permitted)
|
118
|
+
parameters.merge!(tracking_for_entity) if model_class.include?(HasTrack)
|
119
|
+
parameters.merge!(owner_for_entity) if model_class.include?(HasOwner)
|
120
|
+
parameters
|
121
|
+
end
|
122
|
+
|
123
|
+
def entity_parameters
|
124
|
+
permitted = model_class.entity_parameters(current_user)
|
125
|
+
params.require(model_key).permit(permitted)
|
126
|
+
end
|
127
|
+
|
128
|
+
def apply_meta
|
129
|
+
new_data = params[:meta].permit!
|
130
|
+
@entity.meta = new_data
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Adds method for toggling entity flags
|
4
|
+
module ToggleableEntity
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
# Toggle entity flag when allowed
|
8
|
+
def toggle
|
9
|
+
if entity_is_locked?
|
10
|
+
render json: { errors: { locked: true } }, status: :forbidden
|
11
|
+
elsif entity_is_editable?
|
12
|
+
render json: { data: @entity.toggle_parameter(params[:parameter].to_s) }
|
13
|
+
else
|
14
|
+
head :unauthorized
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def entity_is_editable?
|
21
|
+
if @entity.respond_to?(:editable_by?)
|
22
|
+
@entity.editable_by?(current_user)
|
23
|
+
else
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def entity_is_locked?
|
29
|
+
@entity.respond_to?(:locked?) ? @entity.locked? : false
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Contact and feedback
|
4
|
+
class ContactController < ApplicationController
|
5
|
+
# get /contact
|
6
|
+
def index
|
7
|
+
@dynamic_page = DynamicPage['contact']
|
8
|
+
end
|
9
|
+
|
10
|
+
# get /contact/feedback
|
11
|
+
def feedback
|
12
|
+
@dynamic_page = DynamicPage['feedback']
|
13
|
+
end
|
14
|
+
|
15
|
+
# post /contact/feedback_messages
|
16
|
+
def create_feedback_message
|
17
|
+
@entity = FeedbackMessage.new(creation_parameters)
|
18
|
+
if params[:agree]
|
19
|
+
show_result
|
20
|
+
else
|
21
|
+
save_entity
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def save_entity
|
28
|
+
if @entity.save
|
29
|
+
show_result
|
30
|
+
# FeedbackMailer.new_feedback_request(@entity.id).deliver_later
|
31
|
+
else
|
32
|
+
redirect_to root_path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def show_result
|
37
|
+
respond_to do |format|
|
38
|
+
format.html { redirect_to root_path }
|
39
|
+
format.json { head :no_content }
|
40
|
+
format.js
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def creation_parameters
|
45
|
+
permitted = FeedbackMessage.entity_parameters
|
46
|
+
parameters = params.require(:feedback_message).permit(permitted)
|
47
|
+
parameters.merge(owner_for_entity(true))
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Fallback controller for URL outside router
|
4
|
+
class FallbackController < ApplicationController
|
5
|
+
# get (:slug)
|
6
|
+
def show
|
7
|
+
url = params[:slug]
|
8
|
+
|
9
|
+
@dynamic_page = DynamicPage.find_by(url: "/#{url}")
|
10
|
+
handle_http_404 if @dynamic_page.nil?
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Legal information
|
4
|
+
class LegalController < ApplicationController
|
5
|
+
# get /tos
|
6
|
+
def tos
|
7
|
+
@dynamic_page = DynamicPage['tos']
|
8
|
+
end
|
9
|
+
|
10
|
+
# get /privacy
|
11
|
+
def privacy
|
12
|
+
@dynamic_page = DynamicPage['privacy']
|
13
|
+
end
|
14
|
+
end
|
@@ -1,2 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Sending and checking email confirmation codes
|
1
4
|
class My::ConfirmationsController < ApplicationController
|
5
|
+
include Authentication
|
6
|
+
|
7
|
+
before_action :redirect_confirmed_user, only: %i[create update]
|
8
|
+
|
9
|
+
# get /my/confirmation
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# post /my/confirmation
|
14
|
+
def create
|
15
|
+
if current_user.email.blank?
|
16
|
+
redirect_to edit_my_profile_path, notice: t('.set_email')
|
17
|
+
else
|
18
|
+
component_handler.send_email_confirmation(current_user)
|
19
|
+
|
20
|
+
redirect_to my_confirmation_path, notice: t('.success')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# patch /my/confirmation
|
25
|
+
def update
|
26
|
+
code = Code.find_by(body: param_from_request(:code))
|
27
|
+
if component_handler.valid_email_confirmation?(code)
|
28
|
+
component_handler.activate_email_confirmation(code)
|
29
|
+
create_token_for_user(code.user)
|
30
|
+
redirect_to my_path
|
31
|
+
else
|
32
|
+
flash[:error] = t('.invalid_code')
|
33
|
+
redirect_to my_confirmation_path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def component_class
|
40
|
+
Biovision::Components::UsersComponent
|
41
|
+
end
|
42
|
+
|
43
|
+
def redirect_confirmed_user
|
44
|
+
redirect_to(my_path) if current_user&.email_confirmed?
|
45
|
+
end
|
2
46
|
end
|