biovision-base 0.5.170614

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +42 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/config/biovision_base_manifest.js +0 -0
  6. data/app/assets/images/biovision/base/icons/alert.svg +15 -0
  7. data/app/assets/images/biovision/base/icons/back.svg +28 -0
  8. data/app/assets/images/biovision/base/icons/create.svg +1 -0
  9. data/app/assets/images/biovision/base/icons/destroy.svg +3 -0
  10. data/app/assets/images/biovision/base/icons/edit.svg +22 -0
  11. data/app/assets/images/biovision/base/icons/exit.svg +1 -0
  12. data/app/assets/images/biovision/base/icons/foreign/facebook.svg +1 -0
  13. data/app/assets/images/biovision/base/icons/gear.svg +4 -0
  14. data/app/assets/images/biovision/base/icons/lock-closed.svg +1 -0
  15. data/app/assets/images/biovision/base/icons/lock-open.svg +1 -0
  16. data/app/assets/images/biovision/base/icons/notice.svg +1 -0
  17. data/app/assets/images/biovision/base/icons/return.svg +1 -0
  18. data/app/assets/images/biovision/base/icons/warning.svg +43 -0
  19. data/app/assets/images/biovision/base/icons/world.svg +4 -0
  20. data/app/assets/images/biovision/base/placeholders/image.svg +19 -0
  21. data/app/assets/images/biovision/base/placeholders/photo.svg +23 -0
  22. data/app/assets/images/biovision/base/placeholders/user.svg +21 -0
  23. data/app/assets/javascripts/biovision/base/biovision.js +238 -0
  24. data/app/assets/stylesheets/biovision/base/admin.scss +58 -0
  25. data/app/assets/stylesheets/biovision/base/biovision.scss +472 -0
  26. data/app/assets/stylesheets/biovision/base/buttons.scss +90 -0
  27. data/app/assets/stylesheets/biovision/base/default.scss +45 -0
  28. data/app/assets/stylesheets/biovision/base/filters.scss +53 -0
  29. data/app/assets/stylesheets/biovision/base/fonts.scss +9 -0
  30. data/app/assets/stylesheets/biovision/base/message-box.scss +60 -0
  31. data/app/assets/stylesheets/biovision/base/pagination.scss +42 -0
  32. data/app/assets/stylesheets/biovision/base/tootik.scss +385 -0
  33. data/app/assets/stylesheets/biovision/base/track.scss +28 -0
  34. data/app/controllers/admin/agents_controller.rb +30 -0
  35. data/app/controllers/admin/browsers_controller.rb +30 -0
  36. data/app/controllers/admin/codes_controller.rb +25 -0
  37. data/app/controllers/admin/editable_pages_controller.rb +25 -0
  38. data/app/controllers/admin/index_controller.rb +5 -0
  39. data/app/controllers/admin/metrics_controller.rb +29 -0
  40. data/app/controllers/admin/privilege_groups_controller.rb +48 -0
  41. data/app/controllers/admin/privileges_controller.rb +5 -0
  42. data/app/controllers/admin/tokens_controller.rb +28 -0
  43. data/app/controllers/admin/users_controller.rb +87 -0
  44. data/app/controllers/admin_controller.rb +10 -0
  45. data/app/controllers/agents_controller.rb +67 -0
  46. data/app/controllers/authentication_controller.rb +70 -0
  47. data/app/controllers/browsers_controller.rb +63 -0
  48. data/app/controllers/codes_controller.rb +60 -0
  49. data/app/controllers/concerns/authentication.rb +19 -0
  50. data/app/controllers/concerns/biovision/admin/privileges.rb +34 -0
  51. data/app/controllers/concerns/entity_priority.rb +7 -0
  52. data/app/controllers/concerns/lockable_entity.rb +23 -0
  53. data/app/controllers/concerns/toggleable_entity.rb +7 -0
  54. data/app/controllers/editable_pages_controller.rb +60 -0
  55. data/app/controllers/index_controller.rb +5 -0
  56. data/app/controllers/metrics_controller.rb +33 -0
  57. data/app/controllers/my/confirmations_controller.rb +37 -0
  58. data/app/controllers/my/index_controller.rb +7 -0
  59. data/app/controllers/my/profiles_controller.rb +81 -0
  60. data/app/controllers/my/recoveries_controller.rb +68 -0
  61. data/app/controllers/privilege_groups_controller.rb +57 -0
  62. data/app/controllers/privileges_controller.rb +74 -0
  63. data/app/controllers/profiles_controller.rb +22 -0
  64. data/app/controllers/tokens_controller.rb +60 -0
  65. data/app/controllers/users_controller.rb +57 -0
  66. data/app/helpers/biovision_helper.rb +81 -0
  67. data/app/helpers/biovision_users_helper.rb +52 -0
  68. data/app/helpers/codes_helper.rb +10 -0
  69. data/app/helpers/editable_pages_helper.rb +20 -0
  70. data/app/helpers/privileges_helper.rb +11 -0
  71. data/app/helpers/tracking_helper.rb +17 -0
  72. data/app/jobs/application_job.rb +7 -0
  73. data/app/jobs/clean_tokens_job.rb +8 -0
  74. data/app/mailers/code_sender.rb +15 -0
  75. data/app/models/agent.rb +38 -0
  76. data/app/models/application_record.rb +3 -0
  77. data/app/models/browser.rb +22 -0
  78. data/app/models/code.rb +58 -0
  79. data/app/models/code_type.rb +11 -0
  80. data/app/models/concerns/biovision/privilege_base.rb +143 -0
  81. data/app/models/concerns/biovision/user_base.rb +124 -0
  82. data/app/models/concerns/biovision/user_privilege_base.rb +46 -0
  83. data/app/models/concerns/has_owner.rb +19 -0
  84. data/app/models/concerns/required_unique_name.rb +13 -0
  85. data/app/models/concerns/required_unique_slug.rb +12 -0
  86. data/app/models/concerns/toggleable.rb +29 -0
  87. data/app/models/editable_page.rb +30 -0
  88. data/app/models/foreign_site.rb +75 -0
  89. data/app/models/foreign_user.rb +26 -0
  90. data/app/models/metric.rb +67 -0
  91. data/app/models/metric_value.rb +15 -0
  92. data/app/models/privilege.rb +3 -0
  93. data/app/models/privilege_group.rb +50 -0
  94. data/app/models/privilege_group_privilege.rb +6 -0
  95. data/app/models/token.rb +75 -0
  96. data/app/models/user.rb +3 -0
  97. data/app/models/user_privilege.rb +3 -0
  98. data/app/services/canonizer.rb +29 -0
  99. data/app/services/code_manager.rb +16 -0
  100. data/app/services/code_manager/confirmation.rb +26 -0
  101. data/app/services/code_manager/invitation.rb +27 -0
  102. data/app/services/code_manager/recovery.rb +31 -0
  103. data/app/uploaders/avatar_uploader.rb +62 -0
  104. data/app/uploaders/editable_page_image_uploader.rb +38 -0
  105. data/app/views/admin/agents/_filter.html.erb +16 -0
  106. data/app/views/admin/agents/_list.html.erb +17 -0
  107. data/app/views/admin/agents/_nav_item.html.erb +6 -0
  108. data/app/views/admin/agents/_toggleable.html.erb +7 -0
  109. data/app/views/admin/agents/entity/_in_list.html.erb +13 -0
  110. data/app/views/admin/agents/index.html.erb +17 -0
  111. data/app/views/admin/agents/show.html.erb +28 -0
  112. data/app/views/admin/browsers/_list.html.erb +17 -0
  113. data/app/views/admin/browsers/_nav_item.html.erb +6 -0
  114. data/app/views/admin/browsers/_toggleable.html.erb +7 -0
  115. data/app/views/admin/browsers/agents/_add.html.erb +79 -0
  116. data/app/views/admin/browsers/entity/_in_list.html.erb +13 -0
  117. data/app/views/admin/browsers/index.html.erb +17 -0
  118. data/app/views/admin/browsers/show.html.erb +29 -0
  119. data/app/views/admin/codes/_list.html.erb +11 -0
  120. data/app/views/admin/codes/_nav_item.html.erb +6 -0
  121. data/app/views/admin/codes/entity/_in_list.html.erb +24 -0
  122. data/app/views/admin/codes/index.html.erb +16 -0
  123. data/app/views/admin/codes/show.html.erb +51 -0
  124. data/app/views/admin/editable_pages/_list.html.erb +11 -0
  125. data/app/views/admin/editable_pages/_nav_item.html.erb +6 -0
  126. data/app/views/admin/editable_pages/entity/_in_list.html.erb +13 -0
  127. data/app/views/admin/editable_pages/index.html.erb +14 -0
  128. data/app/views/admin/editable_pages/show.html.erb +47 -0
  129. data/app/views/admin/index/index.html.erb +25 -0
  130. data/app/views/admin/metrics/_list.html.erb +26 -0
  131. data/app/views/admin/metrics/_nav_item.html.erb +6 -0
  132. data/app/views/admin/metrics/data.jbuilder +6 -0
  133. data/app/views/admin/metrics/index.html.erb +14 -0
  134. data/app/views/admin/metrics/show.html.erb +52 -0
  135. data/app/views/admin/privilege_groups/_list.html.erb +11 -0
  136. data/app/views/admin/privilege_groups/_nav_item.html.erb +6 -0
  137. data/app/views/admin/privilege_groups/entity/_in_list.html.erb +10 -0
  138. data/app/views/admin/privilege_groups/index.html.erb +14 -0
  139. data/app/views/admin/privilege_groups/show.html.erb +31 -0
  140. data/app/views/admin/privileges/_list.html.erb +15 -0
  141. data/app/views/admin/privileges/_nav_item.html.erb +6 -0
  142. data/app/views/admin/privileges/entity/_groups.html.erb +34 -0
  143. data/app/views/admin/privileges/entity/_in_list.html.erb +25 -0
  144. data/app/views/admin/privileges/index.html.erb +20 -0
  145. data/app/views/admin/privileges/show.html.erb +66 -0
  146. data/app/views/admin/privileges/users.html.erb +24 -0
  147. data/app/views/admin/tokens/_filter.html.erb +17 -0
  148. data/app/views/admin/tokens/_list.html.erb +11 -0
  149. data/app/views/admin/tokens/_nav_item.html.erb +6 -0
  150. data/app/views/admin/tokens/_toggleable.html.erb +7 -0
  151. data/app/views/admin/tokens/entity/_in_list.html.erb +25 -0
  152. data/app/views/admin/tokens/index.html.erb +19 -0
  153. data/app/views/admin/tokens/show.html.erb +43 -0
  154. data/app/views/admin/users/_filter.html.erb +22 -0
  155. data/app/views/admin/users/_list.html.erb +17 -0
  156. data/app/views/admin/users/_nav_item.html.erb +6 -0
  157. data/app/views/admin/users/_search.html.erb +5 -0
  158. data/app/views/admin/users/_toggleable.html.erb +7 -0
  159. data/app/views/admin/users/codes.html.erb +24 -0
  160. data/app/views/admin/users/entity/_in_list.html.erb +24 -0
  161. data/app/views/admin/users/entity/_privilege.html.erb +10 -0
  162. data/app/views/admin/users/entity/_privilege_tree.html.erb +17 -0
  163. data/app/views/admin/users/index.html.erb +19 -0
  164. data/app/views/admin/users/privileges.html.erb +35 -0
  165. data/app/views/admin/users/search.jbuilder +10 -0
  166. data/app/views/admin/users/search/_results.html.erb +11 -0
  167. data/app/views/admin/users/show.html.erb +94 -0
  168. data/app/views/admin/users/tokens.html.erb +24 -0
  169. data/app/views/agents/_agent.jbuilder +20 -0
  170. data/app/views/agents/_filter.html.erb +53 -0
  171. data/app/views/agents/_form.html.erb +33 -0
  172. data/app/views/agents/edit.html.erb +17 -0
  173. data/app/views/agents/index.jbuilder +5 -0
  174. data/app/views/agents/new.html.erb +15 -0
  175. data/app/views/agents/show.jbuilder +3 -0
  176. data/app/views/application/not_found.html.erb +9 -0
  177. data/app/views/application/not_found.jbuilder +3 -0
  178. data/app/views/application/service_unavailable.html.erb +9 -0
  179. data/app/views/application/unauthorized.html.erb +11 -0
  180. data/app/views/application/unauthorized.jbuilder +3 -0
  181. data/app/views/authentication/_form.html.erb +16 -0
  182. data/app/views/authentication/_info.html.erb +8 -0
  183. data/app/views/authentication/new.html.erb +10 -0
  184. data/app/views/browsers/_form.html.erb +28 -0
  185. data/app/views/browsers/edit.html.erb +17 -0
  186. data/app/views/browsers/new.html.erb +15 -0
  187. data/app/views/code_sender/email.text.erb +9 -0
  188. data/app/views/code_sender/password.text.erb +10 -0
  189. data/app/views/codes/_form.html.erb +49 -0
  190. data/app/views/codes/edit.html.erb +17 -0
  191. data/app/views/codes/new.html.erb +15 -0
  192. data/app/views/editable_pages/_form.html.erb +63 -0
  193. data/app/views/editable_pages/edit.html.erb +17 -0
  194. data/app/views/editable_pages/form/_ckeditor.html.erb +11 -0
  195. data/app/views/editable_pages/new.html.erb +15 -0
  196. data/app/views/index/index.html.erb +5 -0
  197. data/app/views/layouts/admin.html.erb +23 -0
  198. data/app/views/layouts/admin/_footer.html.erb +0 -0
  199. data/app/views/layouts/admin/_header.html.erb +11 -0
  200. data/app/views/layouts/admin/header/_logo.html.erb +3 -0
  201. data/app/views/metrics/_form.html.erb +41 -0
  202. data/app/views/metrics/edit.html.erb +17 -0
  203. data/app/views/metrics/index.jbuilder +7 -0
  204. data/app/views/metrics/show.jbuilder +3 -0
  205. data/app/views/my/confirmations/show.html.erb +30 -0
  206. data/app/views/my/index/index.html.erb +17 -0
  207. data/app/views/my/profiles/edit.html.erb +10 -0
  208. data/app/views/my/profiles/edit/_form.html.erb +70 -0
  209. data/app/views/my/profiles/new.html.erb +7 -0
  210. data/app/views/my/profiles/new/_form.html.erb +34 -0
  211. data/app/views/my/profiles/show.html.erb +3 -0
  212. data/app/views/my/recoveries/show.html.erb +39 -0
  213. data/app/views/privilege_groups/_form.html.erb +25 -0
  214. data/app/views/privilege_groups/edit.html.erb +17 -0
  215. data/app/views/privilege_groups/new.html.erb +15 -0
  216. data/app/views/privileges/_form.html.erb +42 -0
  217. data/app/views/privileges/edit.html.erb +21 -0
  218. data/app/views/privileges/new.html.erb +14 -0
  219. data/app/views/profiles/_profile.html.erb +48 -0
  220. data/app/views/profiles/show.html.erb +4 -0
  221. data/app/views/shared/_flash_messages.html.erb +7 -0
  222. data/app/views/shared/_list_of_errors.html.erb +11 -0
  223. data/app/views/shared/_meta_texts.html.erb +17 -0
  224. data/app/views/shared/_nothing_found.html.erb +1 -0
  225. data/app/views/shared/_track.html.erb +10 -0
  226. data/app/views/shared/actions/_locks.html.erb +4 -0
  227. data/app/views/shared/actions/_priority_changer.html.erb +4 -0
  228. data/app/views/shared/admin/_breadcrumbs.html.erb +6 -0
  229. data/app/views/shared/editable_pages/_body.html.erb +12 -0
  230. data/app/views/shared/filter/_flag.html.erb +17 -0
  231. data/app/views/tokens/_form.html.erb +30 -0
  232. data/app/views/tokens/edit.html.erb +17 -0
  233. data/app/views/tokens/new.html.erb +15 -0
  234. data/app/views/users/_form.html.erb +78 -0
  235. data/app/views/users/edit.html.erb +18 -0
  236. data/app/views/users/new.html.erb +15 -0
  237. data/config/initializers/carrierwave.rb +22 -0
  238. data/config/initializers/pluralization.rb +2 -0
  239. data/config/locales/common-ru.yml +96 -0
  240. data/config/locales/editable-pages-ru.yml +43 -0
  241. data/config/locales/plurals.rb +17 -0
  242. data/config/locales/track-ru.yml +102 -0
  243. data/config/locales/users-ru.yml +324 -0
  244. data/config/routes.rb +92 -0
  245. data/db/migrate/20170301000001_create_metrics.rb +23 -0
  246. data/db/migrate/20170301000002_create_metric_values.rb +19 -0
  247. data/db/migrate/20170301000101_create_browsers.rb +22 -0
  248. data/db/migrate/20170301000102_create_agents.rb +22 -0
  249. data/db/migrate/20170302000001_create_users.rb +52 -0
  250. data/db/migrate/20170302000002_create_tokens.rb +23 -0
  251. data/db/migrate/20170302000003_create_code_types.rb +20 -0
  252. data/db/migrate/20170302000004_create_codes.rb +24 -0
  253. data/db/migrate/20170302000101_create_privileges.rb +34 -0
  254. data/db/migrate/20170302000102_create_user_privileges.rb +17 -0
  255. data/db/migrate/20170302000103_create_privilege_groups.rb +23 -0
  256. data/db/migrate/20170302000104_create_privilege_group_privileges.rb +24 -0
  257. data/db/migrate/20170320000000_create_editable_pages.rb +22 -0
  258. data/db/migrate/20170425000001_create_foreign_sites.rb +18 -0
  259. data/db/migrate/20170425000002_create_foreign_users.rb +23 -0
  260. data/lib/biovision/base.rb +9 -0
  261. data/lib/biovision/base/base_methods.rb +96 -0
  262. data/lib/biovision/base/engine.rb +17 -0
  263. data/lib/biovision/base/privilege_methods.rb +35 -0
  264. data/lib/biovision/base/version.rb +5 -0
  265. data/lib/tasks/biovision/agents.rake +38 -0
  266. data/lib/tasks/biovision/base_tasks.rake +4 -0
  267. data/lib/tasks/biovision/browsers.rake +38 -0
  268. data/lib/tasks/biovision/codes.rake +49 -0
  269. data/lib/tasks/biovision/tokens.rake +54 -0
  270. data/lib/tasks/biovision/users.rake +67 -0
  271. metadata +467 -0
@@ -0,0 +1,68 @@
1
+ class My::RecoveriesController < ApplicationController
2
+ include Authentication
3
+
4
+ before_action :redirect_authenticated_user
5
+ before_action :find_user, only: [:create]
6
+
7
+ # get /my/recovery
8
+ def show
9
+ end
10
+
11
+ # post /my/recovery
12
+ def create
13
+ if @user.nil? || @user.email.blank?
14
+ redirect_to my_recovery_path, alert: t('my.recoveries.create.impossible')
15
+ else
16
+ send_code
17
+ redirect_to my_recovery_path, notice: t('my.recoveries.create.completed')
18
+ end
19
+ end
20
+
21
+ # patch /my/recovery
22
+ def update
23
+ set_manager
24
+ if @manager.code_is_valid?
25
+ reset_password
26
+ else
27
+ redirect_to my_recovery_path, alert: t('my.recoveries.update.invalid_code')
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ def find_user
34
+ @user = User.with_email(param_from_request(:email)).first
35
+ end
36
+
37
+ def set_manager
38
+ code = Code.find_by(body: param_from_request(:code))
39
+ @manager = CodeManager::Recovery.new(code)
40
+ end
41
+
42
+ def send_code
43
+ code = CodeManager::Recovery.code_for_user(@user)
44
+ if code.nil?
45
+ logger.warn { "Could not get recovery code for user #{@user.id}" }
46
+ else
47
+ CodeSender.password(code.id).deliver_later
48
+ end
49
+ end
50
+
51
+ def reset_password
52
+ if @manager.activate(new_user_parameters)
53
+ create_token_for_user @manager.code.user
54
+ redirect_to my_path, notice: t('my.recoveries.update.success')
55
+ else
56
+ render :show, status: :bad_request
57
+ end
58
+ end
59
+
60
+ def new_user_parameters
61
+ parameters = params.require(:user).permit(:password, :password_confirmation)
62
+ if parameters[:password].blank?
63
+ parameters[:password] = nil
64
+ parameters[:password_confirmation] = nil
65
+ end
66
+ parameters
67
+ end
68
+ end
@@ -0,0 +1,57 @@
1
+ class PrivilegeGroupsController < AdminController
2
+ before_action :restrict_access
3
+ before_action :set_entity, only: [:edit, :update, :destroy]
4
+
5
+ # get /privilege_groups/new
6
+ def new
7
+ @entity = PrivilegeGroup.new
8
+ end
9
+
10
+ # post /privilege_groups
11
+ def create
12
+ @entity = PrivilegeGroup.new entity_parameters
13
+ if @entity.save
14
+ redirect_to admin_privilege_group_path(@entity)
15
+ else
16
+ render :new, status: :bad_request
17
+ end
18
+ end
19
+
20
+ # get /privilege_groups/:id/edit
21
+ def edit
22
+ end
23
+
24
+ # patch /privilege_groups/:id
25
+ def update
26
+ if @entity.update entity_parameters
27
+ redirect_to admin_privilege_group_path(@entity), notice: t('privilege_groups.update.success')
28
+ else
29
+ render :edit, status: :bad_request
30
+ end
31
+ end
32
+
33
+ # delete /privilege_groups/:id
34
+ def destroy
35
+ if @entity.destroy
36
+ flash[:notice] = t('privilege_groups.destroy.success')
37
+ end
38
+ redirect_to admin_privilege_groups_path
39
+ end
40
+
41
+ private
42
+
43
+ def restrict_access
44
+ require_privilege :administrator
45
+ end
46
+
47
+ def set_entity
48
+ @entity = PrivilegeGroup.find_by(id: params[:id])
49
+ if @entity.nil?
50
+ handle_http_404('PrivilegeGroup is not found')
51
+ end
52
+ end
53
+
54
+ def entity_parameters
55
+ params.require(:privilege_group).permit(PrivilegeGroup.entity_parameters)
56
+ end
57
+ end
@@ -0,0 +1,74 @@
1
+ class PrivilegesController < AdminController
2
+ before_action :restrict_access
3
+ before_action :set_entity, only: [:edit, :update, :destroy]
4
+ before_action :restrict_editing, only: [:edit, :update, :destroy]
5
+
6
+ # post /privileges
7
+ def create
8
+ @entity = Privilege.new(creation_parameters)
9
+ if @entity.save
10
+ cache_relatives
11
+ redirect_to admin_privilege_path(@entity)
12
+ else
13
+ render :new, status: :bad_request
14
+ end
15
+ end
16
+
17
+ # get /privileges/:id/edit
18
+ def edit
19
+ end
20
+
21
+ # patch /privileges/:id
22
+ def update
23
+ if @entity.update(entity_parameters)
24
+ cache_relatives
25
+ redirect_to admin_privilege_path(@entity), notice: t('privileges.update.success')
26
+ else
27
+ render :edit, status: :bad_request
28
+ end
29
+ end
30
+
31
+ # delete /privileges/:id
32
+ def destroy
33
+ if @entity.update deleted: true
34
+ flash[:notice] = t('privileges.destroy.success')
35
+ end
36
+ redirect_to admin_privileges_path
37
+ end
38
+
39
+ private
40
+
41
+ def restrict_access
42
+ require_privilege :administrator
43
+ end
44
+
45
+ def set_entity
46
+ @entity = Privilege.find_by(id: params[:id], deleted: false)
47
+ if @entity.nil?
48
+ handle_http_404("Cannot find non-deleted privilege #{params[:id]}")
49
+ end
50
+ end
51
+
52
+ def restrict_editing
53
+ if @entity.locked?
54
+ redirect_to admin_privilege_path(@entity), alert: t('privileges.edit.forbidden')
55
+ end
56
+ end
57
+
58
+ def entity_parameters
59
+ params.require(:privilege).permit(Privilege.entity_parameters)
60
+ end
61
+
62
+ def creation_parameters
63
+ params.require(:privilege).permit(Privilege.creation_parameters)
64
+ end
65
+
66
+ def cache_relatives
67
+ @entity.cache_parents!
68
+ unless @entity.parent.blank?
69
+ parent = @entity.parent
70
+ parent.cache_children!
71
+ parent.save
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,22 @@
1
+ class ProfilesController < ApplicationController
2
+ before_action :set_entity
3
+
4
+ # get /u/:slug
5
+ def show
6
+ end
7
+
8
+ # get /u/:slug/followees
9
+ def followees
10
+ @filter = params[:filter] || Hash.new
11
+ @collection = UserLink.filtered(:followee, @filter).with_follower(@entity).page_for_user(current_page)
12
+ end
13
+
14
+ private
15
+
16
+ def set_entity
17
+ @entity = User.find_by(slug: params[:slug].downcase, deleted: false)
18
+ if @entity.nil?
19
+ handle_http_404('Cannot find user')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,60 @@
1
+ class TokensController < AdminController
2
+ before_action :set_entity, only: [:edit, :update, :destroy]
3
+
4
+ # get /tokens/new
5
+ def new
6
+ @entity = Token.new
7
+ end
8
+
9
+ # post /tokens
10
+ def create
11
+ @entity = Token.new(creation_parameters)
12
+ if @entity.save
13
+ redirect_to admin_token_path(@entity)
14
+ else
15
+ render :new, status: :bad_request
16
+ end
17
+ end
18
+
19
+ # get /tokens/:id/edit
20
+ def edit
21
+ end
22
+
23
+ # patch /tokens/:id
24
+ def update
25
+ if @entity.update(entity_parameters)
26
+ redirect_to admin_token_path(@entity), notice: t('tokens.update.success')
27
+ else
28
+ render :edit, status: :bad_request
29
+ end
30
+ end
31
+
32
+ # delete /tokens/:id
33
+ def destroy
34
+ if @entity.destroy
35
+ flash[:notice] = t('tokens.destroy.success')
36
+ end
37
+ redirect_to admin_tokens_path
38
+ end
39
+
40
+ protected
41
+
42
+ def restrict_access
43
+ require_privilege :administrator
44
+ end
45
+
46
+ def set_entity
47
+ @entity = Token.find_by(id: params[:id])
48
+ if @entity.nil?
49
+ handle_http_404('Cannot find token')
50
+ end
51
+ end
52
+
53
+ def entity_parameters
54
+ params.require(:token).permit(Token.entity_parameters)
55
+ end
56
+
57
+ def creation_parameters
58
+ params.require(:token).permit(Token.creation_parameters).merge(tracking_for_entity)
59
+ end
60
+ end
@@ -0,0 +1,57 @@
1
+ class UsersController < AdminController
2
+ before_action :set_entity, only: [:edit, :update, :destroy]
3
+
4
+ # get /users/new
5
+ def new
6
+ @entity = User.new
7
+ end
8
+
9
+ # post /users
10
+ def create
11
+ @entity = User.new(creation_parameters)
12
+ if @entity.save
13
+ redirect_to admin_user_path(@entity.id), notice: t('users.create.success')
14
+ else
15
+ render :new, status: :bad_request
16
+ end
17
+ end
18
+
19
+ # get /users/:id/edit
20
+ def edit
21
+ end
22
+
23
+ # patch /users/:id
24
+ def update
25
+ if @entity.update(entity_parameters)
26
+ redirect_to admin_user_path(@entity.id), notice: t('users.update.success')
27
+ else
28
+ render :edit, status: :bad_request
29
+ end
30
+ end
31
+
32
+ # delete /users/:id
33
+ def destroy
34
+ if @entity.update(deleted: true)
35
+ flash[:notice] = t('users.destroy.success')
36
+ end
37
+ redirect_to admin_users_path
38
+ end
39
+
40
+ protected
41
+
42
+ def restrict_access
43
+ require_privilege :administrator
44
+ end
45
+
46
+ def set_entity
47
+ @entity = User.find_by(id: params[:id])
48
+ end
49
+
50
+ def entity_parameters
51
+ params.require(:user).permit(User.entity_parameters)
52
+ end
53
+
54
+ def creation_parameters
55
+ params.require(:user).permit(User.entity_parameters).merge(tracking_for_entity)
56
+ end
57
+ end
@@ -0,0 +1,81 @@
1
+ module BiovisionHelper
2
+ # @param [Integer] year
3
+ # @param [Integer] month
4
+ def title_for_archive(year, month)
5
+ if year && month
6
+ month_name = t('date.nominative_months')[month.to_i]
7
+ t(:archive_month, year: year.to_i, month: month_name)
8
+ elsif year
9
+ t(:archive_year, year: year.to_i)
10
+ else
11
+ ''
12
+ end
13
+ end
14
+
15
+ # @param [String] path
16
+ # @param [String] title
17
+ # @param [Hash] options
18
+ def world_icon(path, title = t(:view_as_visitor), options = {})
19
+ icon_with_link('biovision/base/icons/world.svg', path, title, options)
20
+ end
21
+
22
+ # @param [String] path
23
+ # @param [String] title
24
+ # @param [Hash] options
25
+ def gear_icon(path, title = t(:view_as_administrator), options = {})
26
+ icon_with_link('biovision/base/icons/gear.svg', path, title, options)
27
+ end
28
+
29
+ # @param [String] path
30
+ # @param [String] title
31
+ # @param [Hash] options
32
+ def create_icon(path, title = t(:create), options = {})
33
+ icon_with_link('biovision/base/icons/create.svg', path, title, options)
34
+ end
35
+
36
+ # @param [String] path
37
+ # @param [String] title
38
+ # @param [Hash] options
39
+ def back_icon(path, title = t(:back), options = {})
40
+ icon_with_link('biovision/base/icons/back.svg', path, title, options)
41
+ end
42
+
43
+ # @param [String] path
44
+ # @param [String] title
45
+ # @param [Hash] options
46
+ def return_icon(path, title = t(:back), options = {})
47
+ icon_with_link('biovision/base/icons/return.svg', path, title, options)
48
+ end
49
+
50
+ # @param [String] path
51
+ # @param [String] title
52
+ # @param [Hash] options
53
+ def edit_icon(path, title = t(:edit), options = {})
54
+ icon_with_link('biovision/base/icons/edit.svg', path, title, options)
55
+ end
56
+
57
+ # @param [ApplicationRecord] entity
58
+ # @param [String] title
59
+ # @param [Hash] options
60
+ def destroy_icon(entity, title = t(:delete), options = {})
61
+ default = {
62
+ method: :delete,
63
+ data: { confirm: t(:are_you_sure), tootik: title, tootik_conf: 'danger' }
64
+ }
65
+ icon_with_link('biovision/base/icons/destroy.svg', entity, title, default.merge(options))
66
+ end
67
+
68
+ # @param [String|ApplicationRecord] path
69
+ # @param [String] title
70
+ # @param [Hash] options
71
+ def icon_with_link(source, path, title, options = {})
72
+ default = { data: { tootik: title } }
73
+ link_to(image_tag(source, alt: title), path, default.merge(options))
74
+ end
75
+
76
+ # @param [ApplicationRecord] entity
77
+ # @param [String] path
78
+ def lock_icons(entity, path)
79
+ render partial: 'shared/actions/locks', locals: { path: path, entity: entity }
80
+ end
81
+ end
@@ -0,0 +1,52 @@
1
+ module BiovisionUsersHelper
2
+ def genders_for_select
3
+ genders = [[t(:not_selected), '']]
4
+ prefix = 'activerecord.attributes.user.genders.'
5
+ genders + User.genders.keys.to_a.map { |o| [I18n.t("#{prefix}#{o}"), o] }
6
+ end
7
+
8
+ # @param [User] entity
9
+ def user_link(entity)
10
+ return I18n.t(:anonymous) if entity.nil? || entity.deleted?
11
+
12
+ text = entity.profile_name
13
+ link_to(text, user_profile_path(slug: entity.screen_name), class: 'profile')
14
+ end
15
+
16
+ # @param [User] entity
17
+ def admin_user_link(entity)
18
+ return I18n.t(:anonymous) if entity.nil?
19
+
20
+ text = entity.profile_name
21
+ link_to(text, admin_user_path(entity.id), class: 'profile')
22
+ end
23
+
24
+ # @param [Token] entity
25
+ def admin_token_link(entity)
26
+ link_to entity.name, admin_token_path(entity.id)
27
+ end
28
+
29
+ # @param [User] user
30
+ def profile_avatar(user)
31
+ if user.is_a?(User) && !user.image.blank? && !user.deleted?
32
+ image_tag user.image.profile.url
33
+ else
34
+ image_tag 'biovision/base/placeholders/user.svg'
35
+ end
36
+ end
37
+
38
+ # @param [User] entity
39
+ def user_image_preview(entity)
40
+ return image_tag('biovision/base/placeholders/user.svg') if entity.image.blank?
41
+
42
+ versions = "#{entity.image.preview_2x.url} 2x"
43
+ image_tag(entity.image.preview.url, alt: entity.name, srcset: versions)
44
+ end
45
+
46
+ # @param [ForeignSite] foreign_site
47
+ def foreign_login_link(foreign_site)
48
+ image = "biovision/base/icons/foreign/#{foreign_site.slug}.svg"
49
+ path = "/auth/#{foreign_site.slug}"
50
+ link_to(image_tag(image, alt: foreign_site.name), path)
51
+ end
52
+ end