hyrax 3.1.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +8 -11
- data/.dassie/.env +1 -2
- data/.dassie/Gemfile +8 -4
- data/.dassie/app/controllers/catalog_controller.rb +6 -0
- data/.dassie/app/models/user.rb +0 -2
- data/.dassie/config/analytics.yml +12 -5
- data/.dassie/config/environments/development.rb +2 -0
- data/.dassie/config/initializers/hyrax.rb +13 -1
- data/.dassie/db/migrate/20210921150120_enable_uuid_extension.valkyrie_engine.rb +7 -0
- data/.dassie/db/migrate/20210921150121_create_orm_resources.valkyrie_engine.rb +19 -0
- data/.dassie/db/migrate/20210921150122_add_model_type_to_orm_resources.valkyrie_engine.rb +7 -0
- data/.dassie/db/migrate/20210921150123_change_model_type_to_internal_model.valkyrie_engine.rb +7 -0
- data/.dassie/db/migrate/20210921150124_create_path_gin_index.valkyrie_engine.rb +7 -0
- data/.dassie/db/migrate/20210921150125_create_internal_resource_index.valkyrie_engine.rb +7 -0
- data/.dassie/db/migrate/20210921150126_create_updated_at_index.valkyrie_engine.rb +7 -0
- data/.dassie/db/migrate/20210921150127_add_optimistic_locking_to_orm_resources.valkyrie_engine.rb +7 -0
- data/.dassie/db/migrate/20211130181150_create_default_administrative_set.rb +8 -0
- data/.dassie/db/schema.rb +20 -1
- data/.env +7 -4
- data/.github/workflows/main.yml +17 -0
- data/.github/workflows/release.yml +17 -0
- data/.gitignore +4 -0
- data/.regen +1 -1
- data/.rubocop_fixme.yml +3 -1
- data/CONTAINERS.md +13 -10
- data/Dockerfile +4 -4
- data/README.md +37 -0
- data/app/actors/hyrax/actors/base_actor.rb +1 -1
- data/app/actors/hyrax/actors/collections_membership_actor.rb +3 -3
- data/app/actors/hyrax/actors/file_actor.rb +6 -4
- data/app/actors/hyrax/actors/file_set_actor.rb +2 -0
- data/app/actors/hyrax/actors/transfer_request_actor.rb +3 -7
- data/app/assets/javascripts/hyrax/admin/graphs.es6 +34 -37
- data/app/assets/javascripts/hyrax/analytics_events.js +75 -0
- data/app/assets/javascripts/hyrax/autocomplete/linked_data.es6 +1 -3
- data/app/assets/javascripts/hyrax/collapse.js +24 -0
- data/app/assets/javascripts/hyrax/collections.js +1 -2
- data/app/assets/javascripts/hyrax/ga_events.js +2 -8
- data/app/assets/javascripts/hyrax/reports-buttons.js +33 -0
- data/app/assets/javascripts/hyrax.js +2 -1
- data/app/assets/stylesheets/_bootstrap-default-overrides.scss +9 -0
- data/app/assets/stylesheets/hyrax/_styles.scss +5 -0
- data/app/authorities/qa/authorities/collections.rb +4 -5
- data/app/authorities/qa/authorities/find_works.rb +1 -1
- data/app/controllers/concerns/hyrax/breadcrumbs_for_collection_analytics.rb +26 -0
- data/app/controllers/concerns/hyrax/breadcrumbs_for_works_analytics.rb +26 -0
- data/app/controllers/concerns/hyrax/collections_controller_behavior.rb +13 -5
- data/app/controllers/concerns/hyrax/controller.rb +56 -2
- data/app/controllers/concerns/hyrax/works_controller_behavior.rb +83 -59
- data/app/controllers/hyrax/admin/admin_sets_controller.rb +105 -36
- data/app/controllers/hyrax/admin/analytics/analytics_controller.rb +40 -0
- data/app/controllers/hyrax/admin/analytics/collection_reports_controller.rb +61 -0
- data/app/controllers/hyrax/admin/analytics/work_reports_controller.rb +122 -0
- data/app/controllers/hyrax/admin/permission_template_accesses_controller.rb +17 -21
- data/app/controllers/hyrax/batch_edits_controller.rb +12 -3
- data/app/controllers/hyrax/batch_uploads_controller.rb +4 -0
- data/app/controllers/hyrax/citations_controller.rb +1 -1
- data/app/controllers/hyrax/collections_controller.rb +6 -1
- data/app/controllers/hyrax/dashboard/collection_members_controller.rb +12 -9
- data/app/controllers/hyrax/dashboard/collections_controller.rb +119 -37
- data/app/controllers/hyrax/dashboard/nest_collections_controller.rb +75 -39
- data/app/controllers/hyrax/dashboard_controller.rb +8 -0
- data/app/controllers/hyrax/my_controller.rb +4 -4
- data/app/controllers/hyrax/stats_controller.rb +3 -1
- data/app/controllers/hyrax/workflow_actions_controller.rb +8 -5
- data/app/forms/hyrax/forms/administrative_set_form.rb +80 -0
- data/app/forms/hyrax/forms/batch_edit_form.rb +1 -1
- data/app/forms/hyrax/forms/collection_form.rb +2 -2
- data/app/forms/hyrax/forms/dashboard/nest_collection_form.rb +33 -8
- data/app/forms/hyrax/forms/pcdm_collection_form.rb +68 -0
- data/app/forms/hyrax/forms/permission_template_form.rb +17 -9
- data/app/forms/hyrax/forms/resource_form.rb +24 -15
- data/app/forms/hyrax/forms/workflow_action_form.rb +4 -0
- data/app/helpers/hyrax/collections_helper.rb +14 -0
- data/app/helpers/hyrax/hyrax_helper_behavior.rb +9 -0
- data/app/helpers/hyrax/membership_helper.rb +1 -1
- data/app/helpers/hyrax/trophy_helper.rb +1 -1
- data/app/helpers/hyrax/url_helper.rb +1 -1
- data/app/indexers/hyrax/administrative_set_indexer.rb +12 -6
- data/app/indexers/hyrax/deep_indexing_service.rb +1 -1
- data/app/indexers/hyrax/file_set_indexer.rb +1 -0
- data/app/indexers/hyrax/pcdm_collection_indexer.rb +5 -1
- data/app/indexers/hyrax/thumbnail_indexer.rb +31 -0
- data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +7 -7
- data/app/indexers/hyrax/valkyrie_indexer.rb +4 -2
- data/app/indexers/hyrax/valkyrie_work_indexer.rb +13 -0
- data/app/inputs/controlled_vocabulary_input.rb +2 -0
- data/app/jobs/change_depositor_event_job.rb +47 -0
- data/app/jobs/characterize_job.rb +66 -3
- data/app/jobs/concerns/hyrax/members_permission_job_behavior.rb +1 -1
- data/app/jobs/content_depositor_change_event_job.rb +2 -1
- data/app/jobs/hyrax/propagate_change_depositor_job.rb +32 -0
- data/app/jobs/inherit_permissions_job.rb +1 -1
- data/app/jobs/valkyrie_create_derivatives_job.rb +25 -0
- data/app/jobs/valkyrie_ingest_job.rb +124 -0
- data/app/models/admin_set.rb +18 -7
- data/app/models/collection_branding_info.rb +8 -6
- data/app/models/concerns/hyrax/ability/admin_set_ability.rb +31 -7
- data/app/models/concerns/hyrax/ability/collection_ability.rb +35 -20
- data/app/models/concerns/hyrax/ability/collection_type_ability.rb +1 -1
- data/app/models/concerns/hyrax/ability.rb +28 -7
- data/app/models/concerns/hyrax/collection_behavior.rb +2 -2
- data/app/models/concerns/hyrax/file_set/characterization.rb +7 -1
- data/app/models/concerns/hyrax/solr_document/metadata.rb +2 -0
- data/app/models/concerns/hyrax/solr_document_behavior.rb +11 -5
- data/app/models/file_download_stat.rb +4 -4
- data/app/models/hyrax/administrative_set.rb +43 -2
- data/app/models/hyrax/collection_type.rb +2 -2
- data/app/models/hyrax/default_administrative_set.rb +42 -0
- data/app/models/hyrax/file_metadata.rb +5 -1
- data/app/models/hyrax/file_set.rb +42 -1
- data/app/models/hyrax/pcdm_collection.rb +56 -0
- data/app/models/hyrax/permission.rb +1 -1
- data/app/models/hyrax/permission_template.rb +30 -10
- data/app/models/hyrax/statistic.rb +31 -4
- data/app/models/hyrax/work.rb +92 -0
- data/app/models/hyrax/workflow_action_info.rb +16 -0
- data/app/models/proxy_deposit_request.rb +1 -1
- data/app/models/sipity/comment.rb +17 -0
- data/app/models/sipity.rb +11 -2
- data/app/presenters/hyrax/admin/dashboard_presenter.rb +8 -6
- data/app/presenters/hyrax/admin/repository_growth_presenter.rb +10 -5
- data/app/presenters/hyrax/admin/user_activity_presenter.rb +8 -12
- data/app/presenters/hyrax/admin_set_presenter.rb +10 -5
- data/app/presenters/hyrax/collection_presenter.rb +3 -3
- data/app/presenters/hyrax/file_set_presenter.rb +2 -0
- data/app/presenters/hyrax/menu_presenter.rb +4 -0
- data/app/presenters/hyrax/pcdm_member_presenter_factory.rb +3 -3
- data/app/presenters/hyrax/work_show_presenter.rb +11 -3
- data/app/presenters/hyrax/work_usage.rb +1 -0
- data/app/search_builders/hyrax/README.md +1 -1
- data/app/search_builders/hyrax/abstract_type_relation.rb +4 -2
- data/app/search_builders/hyrax/dashboard/collections_search_builder.rb +2 -2
- data/app/search_builders/hyrax/dashboard/managed_search_filters.rb +44 -4
- data/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb +2 -2
- data/app/search_builders/hyrax/exposed_models_relation.rb +1 -1
- data/app/search_builders/hyrax/filter_by_type.rb +1 -2
- data/app/search_builders/hyrax/my/collections_search_builder.rb +12 -5
- data/app/services/hyrax/access_control_list.rb +13 -0
- data/app/services/hyrax/admin_set_create_service.rb +179 -51
- data/app/services/hyrax/analytics/google/events.rb +37 -0
- data/app/services/hyrax/analytics/google/events_daily.rb +72 -0
- data/app/services/hyrax/analytics/google/visits.rb +44 -0
- data/app/services/hyrax/analytics/google/visits_daily.rb +49 -0
- data/app/services/hyrax/analytics/google.rb +204 -0
- data/app/services/hyrax/analytics/matomo.rb +193 -0
- data/app/services/hyrax/analytics/results.rb +79 -0
- data/app/services/hyrax/analytics.rb +12 -82
- data/app/services/hyrax/change_content_depositor_service.rb +2 -2
- data/app/services/hyrax/change_depositor_service.rb +70 -0
- data/app/services/hyrax/characterization/valkyrie_characterization_service.rb +134 -0
- data/app/services/hyrax/collection_types/permissions_service.rb +1 -1
- data/app/services/hyrax/collections/collection_member_service.rb +12 -2
- data/app/services/hyrax/collections/nested_collection_query_service.rb +31 -14
- data/app/services/hyrax/collections/permissions_create_service.rb +81 -79
- data/app/services/hyrax/collections/permissions_service.rb +1 -1
- data/app/services/hyrax/curation_concern.rb +24 -2
- data/app/services/hyrax/custom_queries/navigators/child_file_sets_navigator.rb +45 -0
- data/app/services/hyrax/custom_queries/navigators/child_filesets_navigator.rb +7 -2
- data/app/services/hyrax/custom_queries/navigators/parent_work_navigator.rb +54 -0
- data/app/services/hyrax/default_middleware_stack.rb +14 -0
- data/app/services/hyrax/ensure_well_formed_admin_set_service.rb +3 -3
- data/app/services/hyrax/file_set_derivatives_service.rb +21 -2
- data/app/services/hyrax/file_set_type_service.rb +2 -5
- data/app/services/hyrax/listeners/acl_index_listener.rb +3 -1
- data/app/services/hyrax/listeners/active_fedora_acl_index_listener.rb +4 -1
- data/app/services/hyrax/listeners/batch_notification_listener.rb +3 -1
- data/app/services/hyrax/listeners/file_metadata_listener.rb +38 -0
- data/app/services/hyrax/listeners/file_set_lifecycle_listener.rb +6 -2
- data/app/services/hyrax/listeners/file_set_lifecycle_notification_listener.rb +6 -2
- data/app/services/hyrax/listeners/member_cleanup_listener.rb +26 -3
- data/app/services/hyrax/listeners/metadata_index_listener.rb +72 -11
- data/app/services/hyrax/listeners/object_lifecycle_listener.rb +9 -3
- data/app/services/hyrax/listeners/proxy_deposit_listener.rb +16 -8
- data/app/services/hyrax/listeners/trophy_cleanup_listener.rb +3 -0
- data/app/services/hyrax/listeners/workflow_listener.rb +3 -1
- data/app/services/hyrax/listeners.rb +8 -0
- data/app/services/hyrax/location_service.rb +33 -0
- data/app/services/hyrax/multiple_membership_checker.rb +44 -1
- data/app/services/hyrax/permission_manager.rb +4 -4
- data/app/services/hyrax/resource_visibility_propagator.rb +1 -1
- data/app/services/hyrax/restriction_service.rb +4 -0
- data/app/services/hyrax/simple_schema_loader.rb +5 -1
- data/app/services/hyrax/solr_query_service.rb +12 -7
- data/app/services/hyrax/solr_service.rb +1 -1
- data/app/services/hyrax/statistics/collections/over_time.rb +2 -1
- data/app/services/hyrax/statistics/users/over_time.rb +8 -5
- data/app/services/hyrax/statistics/works/over_time.rb +10 -0
- data/app/services/hyrax/thumbnail_path_service.rb +1 -1
- data/app/services/hyrax/work_uploads_handler.rb +2 -9
- data/app/services/hyrax/workflow/abstract_notification.rb +2 -2
- data/app/services/hyrax/workflow/action_taken_service.rb +16 -4
- data/app/services/hyrax/workflow/activate_object.rb +5 -4
- data/app/services/hyrax/workflow/changes_required_notification.rb +5 -4
- data/app/services/hyrax/workflow/deactivate_object.rb +7 -5
- data/app/services/hyrax/workflow/deposited_notification.rb +8 -4
- data/app/services/hyrax/workflow/grant_edit_to_depositor.rb +7 -3
- data/app/services/hyrax/workflow/grant_read_to_depositor.rb +10 -3
- data/app/services/hyrax/workflow/revoke_edit_from_depositor.rb +8 -2
- data/app/services/hyrax/workflow/workflow_action_service.rb +4 -1
- data/app/validators/hyrax/collection_membership_validator.rb +38 -0
- data/app/views/catalog/_index_header_list_hyrax_pcdm_collection.html.erb +4 -0
- data/app/views/hyrax/admin/admin_sets/_form.html.erb +1 -1
- data/app/views/hyrax/admin/admin_sets/_form_participant_table.html.erb +2 -2
- data/app/views/hyrax/admin/admin_sets/_form_participants.html.erb +2 -2
- data/app/views/hyrax/admin/admin_sets/_form_visibility.html.erb +2 -2
- data/app/views/hyrax/admin/admin_sets/_form_workflow.erb +1 -1
- data/app/views/hyrax/admin/analytics/_date_range_form.html.erb +11 -0
- data/app/views/hyrax/admin/analytics/collection_reports/_custom_range.html.erb +39 -0
- data/app/views/hyrax/admin/analytics/collection_reports/_monthly_summary.html.erb +48 -0
- data/app/views/hyrax/admin/analytics/collection_reports/_summary.html.erb +55 -0
- data/app/views/hyrax/admin/analytics/collection_reports/_top_collections.html.erb +55 -0
- data/app/views/hyrax/admin/analytics/collection_reports/index.html.erb +70 -0
- data/app/views/hyrax/admin/analytics/collection_reports/show.html.erb +94 -0
- data/app/views/hyrax/admin/analytics/work_reports/_custom_range.html.erb +43 -0
- data/app/views/hyrax/admin/analytics/work_reports/_monthly_summary.html.erb +35 -0
- data/app/views/hyrax/admin/analytics/work_reports/_summary.html.erb +60 -0
- data/app/views/hyrax/admin/analytics/work_reports/_top_file_set_downloads.html.erb +33 -0
- data/app/views/hyrax/admin/analytics/work_reports/_top_works.html.erb +40 -0
- data/app/views/hyrax/admin/analytics/work_reports/_work_counts.html.erb +18 -0
- data/app/views/hyrax/admin/analytics/work_reports/_work_files.html.erb +41 -0
- data/app/views/hyrax/admin/analytics/work_reports/index.html.erb +77 -0
- data/app/views/hyrax/admin/analytics/work_reports/show.html.erb +90 -0
- data/app/views/hyrax/admin/collection_types/index.html.erb +1 -1
- data/app/views/hyrax/admin/stats/show.html.erb +1 -1
- data/app/views/hyrax/base/_form.html.erb +1 -1
- data/app/views/hyrax/base/_form_child_work_relationships.html.erb +1 -1
- data/app/views/hyrax/base/_relationships_parent_row.html.erb +0 -1
- data/app/views/hyrax/base/show.html.erb +6 -0
- data/app/views/hyrax/collections/show.html.erb +4 -0
- data/app/views/hyrax/dashboard/_repository_growth.html.erb +5 -5
- data/app/views/hyrax/dashboard/_resource_type_graph.html.erb +41 -0
- data/app/views/hyrax/dashboard/_sidebar.html.erb +4 -1
- data/app/views/hyrax/dashboard/_tabs.html.erb +11 -0
- data/app/views/hyrax/dashboard/_user_activity.html.erb +17 -23
- data/app/views/hyrax/dashboard/_user_activity_graph.html.erb +55 -0
- data/app/views/hyrax/dashboard/_visibility_graph.html.erb +31 -0
- data/app/views/hyrax/dashboard/_work_type_graph.html.erb +41 -0
- data/app/views/hyrax/dashboard/collections/_collection_title.html.erb +1 -1
- data/app/views/hyrax/dashboard/collections/_default_group.html.erb +2 -2
- data/app/views/hyrax/dashboard/collections/_form.html.erb +24 -17
- data/app/views/hyrax/dashboard/collections/_form_discovery.html.erb +6 -3
- data/app/views/hyrax/dashboard/collections/_form_share.html.erb +2 -2
- data/app/views/hyrax/dashboard/collections/_form_share_table.html.erb +3 -3
- data/app/views/hyrax/dashboard/collections/_list_collections.html.erb +2 -2
- data/app/views/hyrax/dashboard/collections/_sort_and_per_page.html.erb +1 -1
- data/app/views/hyrax/dashboard/show_admin.html.erb +24 -45
- data/app/views/hyrax/dashboard/sidebar/_activity.html.erb +22 -0
- data/app/views/hyrax/dashboard/works/_default_group.html.erb +1 -1
- data/app/views/hyrax/dashboard/works/_list_works.html.erb +1 -1
- data/app/views/hyrax/file_sets/_actions.html.erb +4 -3
- data/app/views/hyrax/file_sets/show.html.erb +6 -0
- data/app/views/hyrax/homepage/index.html.erb +1 -1
- data/app/views/hyrax/my/_work_action_menu.html.erb +8 -9
- data/app/views/hyrax/my/collections/_default_group.html.erb +2 -2
- data/app/views/hyrax/my/collections/_list_collections.html.erb +2 -2
- data/app/views/hyrax/my/collections/_modal_collection_types_to_create.html.erb +1 -1
- data/app/views/hyrax/my/collections/index.html.erb +4 -3
- data/app/views/hyrax/my/works/_default_group.html.erb +1 -1
- data/app/views/hyrax/my/works/_list_works.html.erb +1 -2
- data/app/views/hyrax/my/works/index.html.erb +4 -2
- data/app/views/hyrax/stats/_downloads.html.erb +18 -0
- data/app/views/hyrax/stats/_pageviews.html.erb +18 -0
- data/app/views/hyrax/stats/work.html.erb +17 -9
- data/app/views/layouts/_head_tag_content.html.erb +7 -2
- data/app/views/layouts/hyrax/dashboard.html.erb +1 -0
- data/app/views/layouts/hyrax.html.erb +1 -0
- data/app/views/{_ga.html.erb → shared/_ga.html.erb} +3 -7
- data/app/views/shared/_matomo.html.erb +15 -0
- data/app/views/shared/_read_only.html.erb +5 -0
- data/chart/hyrax/Chart.yaml +2 -2
- data/chart/hyrax/README.md +22 -1
- data/chart/hyrax/templates/deployment.yaml +6 -0
- data/chart/hyrax/values.yaml +1 -1
- data/config/features.rb +3 -0
- data/config/i18n-tasks.yml +2 -2
- data/config/initializers/1_healthz.rb +1 -0
- data/config/initializers/listeners.rb +5 -5
- data/config/locales/hyrax.de.yml +200 -5
- data/config/locales/hyrax.en.yml +202 -21
- data/config/locales/hyrax.es.yml +204 -9
- data/config/locales/hyrax.fr.yml +196 -1
- data/config/locales/hyrax.it.yml +197 -2
- data/config/locales/hyrax.pt-BR.yml +196 -1
- data/config/locales/hyrax.zh.yml +196 -1
- data/config/metadata/basic_metadata.yaml +2 -0
- data/config/metadata/core_metadata.yaml +1 -1
- data/config/routes.rb +4 -0
- data/db/seeds.rb +1 -1
- data/docker-compose.yml +48 -42
- data/documentation/developing-your-hyrax-based-app.md +2 -2
- data/documentation/legacyREADME.md +1 -1
- data/hyrax.gemspec +4 -2
- data/lib/generators/hyrax/templates/catalog_controller.rb +3 -1
- data/lib/generators/hyrax/templates/config/analytics.yml +13 -7
- data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +10 -13
- data/lib/generators/hyrax/templates/db/migrate/20211130181150_create_default_administrative_set.rb.erb +8 -0
- data/lib/generators/hyrax/work/templates/feature_spec.rb.erb +4 -2
- data/lib/generators/hyrax/work_resource/templates/indexer_spec.rb.erb +1 -0
- data/lib/hyrax/administrative_set_name.rb +18 -0
- data/lib/hyrax/collection_name.rb +8 -2
- data/lib/hyrax/configuration.rb +104 -4
- data/lib/hyrax/controlled_vocabularies/location.rb +9 -2
- data/lib/hyrax/controlled_vocabularies/resource_label_caching.rb +42 -0
- data/lib/hyrax/controlled_vocabularies.rb +1 -0
- data/lib/hyrax/engine.rb +7 -6
- data/lib/hyrax/form_fields.rb +1 -0
- data/lib/hyrax/publisher.rb +61 -0
- data/lib/hyrax/resource_sync/change_list_writer.rb +2 -2
- data/lib/hyrax/resource_sync/resource_list_writer.rb +2 -2
- data/lib/hyrax/specs/capybara.rb +1 -1
- data/lib/hyrax/specs/shared_specs/hydra_works.rb +13 -4
- data/lib/hyrax/specs/shared_specs/indexers.rb +120 -0
- data/lib/hyrax/transactions/admin_set_create.rb +23 -0
- data/lib/hyrax/transactions/admin_set_destroy.rb +22 -0
- data/lib/hyrax/transactions/admin_set_update.rb +21 -0
- data/lib/hyrax/transactions/collection_create.rb +25 -0
- data/lib/hyrax/transactions/collection_destroy.rb +22 -0
- data/lib/hyrax/transactions/collection_update.rb +21 -0
- data/lib/hyrax/transactions/container.rb +118 -17
- data/lib/hyrax/transactions/create_work.rb +3 -0
- data/lib/hyrax/transactions/destroy_work.rb +3 -0
- data/lib/hyrax/transactions/steps/add_to_collections.rb +13 -1
- data/lib/hyrax/transactions/steps/apply_collection_permission_template.rb +2 -0
- data/lib/hyrax/transactions/steps/apply_collection_type_permissions.rb +29 -0
- data/lib/hyrax/transactions/steps/apply_permission_template.rb +2 -0
- data/lib/hyrax/transactions/steps/apply_visibility.rb +2 -0
- data/lib/hyrax/transactions/steps/change_depositor.rb +46 -0
- data/lib/hyrax/transactions/steps/check_for_empty_admin_set.rb +36 -0
- data/lib/hyrax/transactions/steps/delete_access_control.rb +32 -0
- data/lib/hyrax/transactions/steps/delete_resource.rb +19 -3
- data/lib/hyrax/transactions/steps/destroy_work.rb +3 -1
- data/lib/hyrax/transactions/steps/ensure_permission_template.rb +2 -0
- data/lib/hyrax/transactions/steps/save.rb +37 -7
- data/lib/hyrax/transactions/steps/save_access_control.rb +2 -2
- data/lib/hyrax/transactions/steps/save_work.rb +3 -0
- data/lib/hyrax/transactions/steps/set_collection_type_gid.rb +35 -0
- data/lib/hyrax/transactions/steps/set_user_as_creator.rb +41 -0
- data/lib/hyrax/transactions/steps/update_work_members.rb +51 -0
- data/lib/hyrax/transactions/update_work.rb +4 -3
- data/lib/hyrax/transactions/work_create.rb +1 -1
- data/lib/hyrax/transactions/work_destroy.rb +2 -1
- data/lib/hyrax/transactions/work_update.rb +19 -0
- data/lib/hyrax/version.rb +1 -1
- data/lib/tasks/default_admin_set.rake +12 -11
- data/lib/tasks/regenerate_derivatives.rake +1 -1
- data/lib/wings/attribute_transformer.rb +5 -1
- data/lib/wings/setup.rb +18 -1
- data/lib/wings/valkyrie/persister.rb +16 -0
- data/lib/wings/valkyrie/query_service.rb +2 -1
- data/lib/wings/valkyrie/storage.rb +7 -1
- data/template.rb +1 -1
- data/vendor/assets/javascripts/morris/morris.min.js +1 -7
- data/vendor/assets/stylesheets/morris.js/0.5.1/morris.css +1 -1
- metadata +121 -17
- data/app/views/hyrax/dashboard/_repository_objects.html.erb +0 -28
@@ -0,0 +1,204 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'oauth2'
|
3
|
+
require 'signet/oauth_2/client'
|
4
|
+
|
5
|
+
# rubocop:disable Metrics/ModuleLength
|
6
|
+
module Hyrax
|
7
|
+
module Analytics
|
8
|
+
module Google
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
# rubocop:disable Metrics/BlockLength
|
11
|
+
class_methods do
|
12
|
+
# Loads configuration options from config/analytics.yml. Expected structure:
|
13
|
+
# `analytics:`
|
14
|
+
# ` google:`
|
15
|
+
# ` app_name: <%= ENV['GOOGLE_OAUTH_APP_NAME']`
|
16
|
+
# ` app_version: <%= ENV['GOOGLE_OAUTH_APP_VERSION']`
|
17
|
+
# ` privkey_path: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_PATH']`
|
18
|
+
# ` privkey_secret: <%= ENV['GOOGLE_OAUTH_PRIVATE_KEY_SECRET']`
|
19
|
+
# ` client_email: <%= ENV['GOOGLE_OAUTH_CLIENT_EMAIL']`
|
20
|
+
# @return [Config]
|
21
|
+
def config
|
22
|
+
@config ||= Config.load_from_yaml
|
23
|
+
end
|
24
|
+
|
25
|
+
class Config
|
26
|
+
def self.load_from_yaml
|
27
|
+
filename = Rails.root.join('config', 'analytics.yml')
|
28
|
+
yaml = YAML.safe_load(ERB.new(File.read(filename)).result)
|
29
|
+
unless yaml
|
30
|
+
Rails.logger.error("Unable to fetch any keys from #{filename}.")
|
31
|
+
return new({})
|
32
|
+
end
|
33
|
+
config = yaml.fetch('analytics')&.fetch('google', nil)
|
34
|
+
unless config
|
35
|
+
Deprecation.warn("Deprecated analytics configuration format found. Please update config/analytics.yml.")
|
36
|
+
config = yaml.fetch('analytics')
|
37
|
+
# this has to exist here with a placeholder so it can be set in the Hyrax initializer
|
38
|
+
# it is only for backward compatibility
|
39
|
+
config['analytics_id'] = '-'
|
40
|
+
end
|
41
|
+
new config
|
42
|
+
end
|
43
|
+
|
44
|
+
REQUIRED_KEYS = %w[analytics_id app_name app_version privkey_path privkey_secret client_email].freeze
|
45
|
+
|
46
|
+
def initialize(config)
|
47
|
+
@config = config
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Boolean] are all the required values present?
|
51
|
+
def valid?
|
52
|
+
config_keys = @config.keys
|
53
|
+
REQUIRED_KEYS.all? { |required| config_keys.include?(required) }
|
54
|
+
end
|
55
|
+
|
56
|
+
REQUIRED_KEYS.each do |key|
|
57
|
+
class_eval %{ def #{key}; @config.fetch('#{key}'); end }
|
58
|
+
end
|
59
|
+
|
60
|
+
# This method allows setting the analytics id in the initializer
|
61
|
+
# @deprecated set the analytics id in either ENV['GOOGLE_ANALYTICS_ID'] or config/analytics.yaml
|
62
|
+
def analytics_id=(value)
|
63
|
+
@config['analytics_id'] = value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Generate an OAuth2 token for Google Analytics
|
68
|
+
# @return [OAuth2::AccessToken] An OAuth2 access token for GA
|
69
|
+
def token(scope = 'https://www.googleapis.com/auth/analytics.readonly')
|
70
|
+
access_token = auth_client(scope).fetch_access_token!
|
71
|
+
OAuth2::AccessToken.new(oauth_client, access_token['access_token'], expires_in: access_token['expires_in'])
|
72
|
+
end
|
73
|
+
|
74
|
+
def oauth_client
|
75
|
+
OAuth2::Client.new('', '', authorize_url: 'https://accounts.google.com/o/oauth2/auth',
|
76
|
+
token_url: 'https://accounts.google.com/o/oauth2/token')
|
77
|
+
end
|
78
|
+
|
79
|
+
def auth_client(scope)
|
80
|
+
raise "Private key file for Google analytics was expected at '#{config.privkey_path}', but no file was found." unless File.exist?(config.privkey_path)
|
81
|
+
private_key = File.read(config.privkey_path)
|
82
|
+
Signet::OAuth2::Client.new token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
|
83
|
+
audience: 'https://accounts.google.com/o/oauth2/token',
|
84
|
+
scope: scope,
|
85
|
+
issuer: config.client_email,
|
86
|
+
signing_key: OpenSSL::PKCS12.new(private_key, config.privkey_secret).key,
|
87
|
+
sub: config.client_email
|
88
|
+
end
|
89
|
+
|
90
|
+
# Return a user object linked to a Google Analytics account
|
91
|
+
# @return [Legato::User] A user account with GA access
|
92
|
+
def user
|
93
|
+
Legato::User.new(token)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Return a Google Analytics profile matching specified ID
|
97
|
+
# @ return [Legato::Management::Profile] A user profile associated with GA
|
98
|
+
def profile
|
99
|
+
return unless config.valid?
|
100
|
+
@profile = user.profiles.detect do |profile|
|
101
|
+
profile.web_property_id == config.analytics_id
|
102
|
+
end
|
103
|
+
raise 'User does not have access to this property' unless @profile
|
104
|
+
@profile
|
105
|
+
end
|
106
|
+
|
107
|
+
# rubocop:disable Metrics/MethodLength
|
108
|
+
def to_date_range(period)
|
109
|
+
case period
|
110
|
+
when "day"
|
111
|
+
start_date = Time.zone.today
|
112
|
+
end_date = Time.zone.today
|
113
|
+
when "week"
|
114
|
+
start_date = Time.zone.today - 7.days
|
115
|
+
end_date = Time.zone.today
|
116
|
+
when "month"
|
117
|
+
start_date = Time.zone.today - 1.month
|
118
|
+
end_date = Time.zone.today
|
119
|
+
when "year"
|
120
|
+
start_date = Time.zone.today - 1.year
|
121
|
+
end_date = Time.zone.today
|
122
|
+
end
|
123
|
+
|
124
|
+
[start_date, end_date]
|
125
|
+
end
|
126
|
+
# rubocop:enabl e Metrics/MethodLength
|
127
|
+
|
128
|
+
def keyword_conversion(date)
|
129
|
+
case date
|
130
|
+
when "last12"
|
131
|
+
start_date = Time.zone.today - 11.months
|
132
|
+
end_date = Time.zone.today
|
133
|
+
|
134
|
+
[start_date, end_date]
|
135
|
+
else
|
136
|
+
date.split(",")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def date_period(period, date)
|
141
|
+
if period == "range"
|
142
|
+
date.split(",")
|
143
|
+
else
|
144
|
+
to_date_range(period)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Configure analytics_start_date in ENV file
|
149
|
+
def default_date_range
|
150
|
+
"#{Hyrax.config.analytics_start_date},#{Time.zone.today + 1.day}"
|
151
|
+
end
|
152
|
+
|
153
|
+
# The number of events by day for an action
|
154
|
+
def daily_events(action, date = default_date_range)
|
155
|
+
date = date.split(",")
|
156
|
+
EventsDaily.summary(profile, date[0], date[1], action)
|
157
|
+
end
|
158
|
+
|
159
|
+
# The number of events by day for an action and ID
|
160
|
+
def daily_events_for_id(id, action, date = default_date_range)
|
161
|
+
date = date.split(",")
|
162
|
+
EventsDaily.by_id(profile, date[0], date[1], id, action)
|
163
|
+
end
|
164
|
+
|
165
|
+
# A list of events sorted by highest event count
|
166
|
+
def top_events(action, date = default_date_range)
|
167
|
+
date = date.split(",")
|
168
|
+
Events.send('list', profile, date[0], date[1], action)
|
169
|
+
end
|
170
|
+
|
171
|
+
def unique_visitors(date = default_date_range); end
|
172
|
+
|
173
|
+
def unique_visitors_for_id(id, date = default_date_range); end
|
174
|
+
|
175
|
+
def new_visitors(period = 'month', date = default_date_range)
|
176
|
+
date = date_period(period, date)
|
177
|
+
Visits.new_visits(profile, date[0], date[1])
|
178
|
+
end
|
179
|
+
|
180
|
+
def new_visits_by_day(date = default_date_range, _period = 'day')
|
181
|
+
date = date.split(",")
|
182
|
+
VisitsDaily.new_visits(profile, date[0], date[1])
|
183
|
+
end
|
184
|
+
|
185
|
+
def returning_visitors(period = 'month', date = default_date_range)
|
186
|
+
date = date_period(period, date)
|
187
|
+
Visits.return_visits(profile, date[0], date[1])
|
188
|
+
end
|
189
|
+
|
190
|
+
def returning_visits_by_day(date = default_date_range, _period = 'day')
|
191
|
+
date = date.split(",")
|
192
|
+
VisitsDaily.return_visits(profile, date[0], date[1])
|
193
|
+
end
|
194
|
+
|
195
|
+
def total_visitors(period = 'month', date = default_date_range)
|
196
|
+
date = date_period(period, date)
|
197
|
+
Visits.total_visits(profile, date[0], date[1])
|
198
|
+
end
|
199
|
+
end
|
200
|
+
# rubocop:enable Metrics/BlockLength
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
# rubocop:enable Metrics/ModuleLength
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/ModuleLength
|
4
|
+
module Hyrax
|
5
|
+
module Analytics
|
6
|
+
module Matomo
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
# rubocop:disable Metrics/BlockLength
|
10
|
+
class_methods do
|
11
|
+
# Loads configuration options from config/analytics.yml. Expected structure:
|
12
|
+
# `analytics:`
|
13
|
+
# ` matomo:`
|
14
|
+
# ` base_url: <%= ENV['MATOMOT_BASE_URL']`
|
15
|
+
# ` site_id: <%= ENV['MATOMOT_SITE_ID']`
|
16
|
+
# ` auth_token: <%= ENV['MATOMOT_AUTH_TOKEN']`
|
17
|
+
# @return [Config]
|
18
|
+
def config
|
19
|
+
@config ||= Config.load_from_yaml
|
20
|
+
end
|
21
|
+
|
22
|
+
class Config
|
23
|
+
def self.load_from_yaml
|
24
|
+
filename = Rails.root.join('config', 'analytics.yml')
|
25
|
+
yaml = YAML.safe_load(ERB.new(File.read(filename)).result)
|
26
|
+
unless yaml
|
27
|
+
Rails.logger.error("Unable to fetch any keys from #{filename}.")
|
28
|
+
return new({})
|
29
|
+
end
|
30
|
+
new yaml.fetch('analytics')&.fetch('matomo')
|
31
|
+
end
|
32
|
+
|
33
|
+
REQUIRED_KEYS = %w[base_url site_id auth_token].freeze
|
34
|
+
|
35
|
+
def initialize(config)
|
36
|
+
@config = config
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Boolean] are all the required values present?
|
40
|
+
def valid?
|
41
|
+
config_keys = @config.keys
|
42
|
+
REQUIRED_KEYS.all? { |required| config_keys.include?(required) }
|
43
|
+
end
|
44
|
+
|
45
|
+
REQUIRED_KEYS.each do |key|
|
46
|
+
class_eval %{ def #{key}; @config.fetch('#{key}'); end }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Period Options = "day, week, month, year, range"
|
51
|
+
# Date Format = "2021-01-01,2021-01-31"
|
52
|
+
|
53
|
+
def default_date_range
|
54
|
+
"#{Hyrax.config.analytics_start_date},#{Time.zone.today}"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns a total count of an event action over a date range
|
58
|
+
def total_events(action, date = default_date_range)
|
59
|
+
additional_params = { label: action }
|
60
|
+
response = api_params('Events.getAction', 'range', date, additional_params)
|
61
|
+
response&.first ? response.first["nb_events"] : 0
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns a total count of an event action for an id over a date range
|
65
|
+
def total_events_for_id(id, action, date = default_date_range)
|
66
|
+
additional_params = {
|
67
|
+
flat: 1,
|
68
|
+
label: "#{id} - #{action}"
|
69
|
+
}
|
70
|
+
response = api_params('Events.getName', 'range', date, additional_params)
|
71
|
+
response&.first ? response.first["nb_events"] : 0
|
72
|
+
end
|
73
|
+
|
74
|
+
def daily_events(action, date = default_date_range)
|
75
|
+
additional_params = { label: action }
|
76
|
+
response = api_params('Events.getAction', 'day', date, additional_params)
|
77
|
+
results_array(response, 'nb_events')
|
78
|
+
end
|
79
|
+
|
80
|
+
# Pass in an action name and an id and get back the daily count of events for that id. [date, event_count]
|
81
|
+
def daily_events_for_id(id, action, date = default_date_range)
|
82
|
+
additional_params = {
|
83
|
+
flat: 1,
|
84
|
+
label: "#{id} - #{action}"
|
85
|
+
}
|
86
|
+
response = api_params('Events.getName', 'day', date, additional_params)
|
87
|
+
results_array(response, 'nb_events')
|
88
|
+
end
|
89
|
+
|
90
|
+
# Returns a list of the total of events by id in the format of [["id", event_count]]
|
91
|
+
def top_events(action, date = default_date_range)
|
92
|
+
additional_params = {
|
93
|
+
flat: '1',
|
94
|
+
filter_column: 'Events_EventAction',
|
95
|
+
filter_pattern: action.to_s,
|
96
|
+
filter_limit: '-1',
|
97
|
+
filter_sort_column: 'nb_events',
|
98
|
+
filter_sort_order: 'desc'
|
99
|
+
}
|
100
|
+
response = api_params('Events.getName', 'range', date, additional_params)
|
101
|
+
response.map { |res| [res['Events_EventName'], res['nb_events']] }
|
102
|
+
end
|
103
|
+
|
104
|
+
# Filter the daily events by a specific action and get back the daily count of number of events.
|
105
|
+
# TODO(geezy): NOT IN USE BUT SAVING FOR POTENTIAL REFACTOR
|
106
|
+
def filter_by_action(action, response)
|
107
|
+
results = []
|
108
|
+
response.each do |result|
|
109
|
+
if result[1].empty?
|
110
|
+
results.push([result[0].to_date, 0])
|
111
|
+
elsif result[1].is_a?(Array)
|
112
|
+
result[1].each do |subtable|
|
113
|
+
results.push([result[0].to_date, subtable["nb_events"].to_i]) if subtable["label"] == action
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
Hyrax::Analytics::Results.new(results)
|
118
|
+
end
|
119
|
+
|
120
|
+
def unique_visitors(date = default_date_range)
|
121
|
+
response = api_params('Actions.get', 'day', date)
|
122
|
+
results_array(response, 'nb_uniq_pageviews')
|
123
|
+
end
|
124
|
+
|
125
|
+
def unique_visitors_for_id(url, date = default_date_range)
|
126
|
+
# additional_params = { pageUrl: url }
|
127
|
+
# response = api_params('Actions.getPageUrl', 'day', date, additional_params)
|
128
|
+
# results_array(response, 'nb_uniq_visitors')
|
129
|
+
end
|
130
|
+
|
131
|
+
def new_visitors(period = 'month', date = 'today')
|
132
|
+
response = api_params('VisitFrequency.get', period, date)
|
133
|
+
response["nb_visits_new"]
|
134
|
+
end
|
135
|
+
|
136
|
+
def new_visits_by_day(date = default_date_range, period = 'day')
|
137
|
+
result = api_params('VisitFrequency.get', period, date)
|
138
|
+
results_array(result, 'nb_visits_new')
|
139
|
+
end
|
140
|
+
|
141
|
+
def returning_visitors(period = 'month', date = 'today')
|
142
|
+
response = api_params('VisitFrequency.get', period, date)
|
143
|
+
response["nb_visits_returning"]
|
144
|
+
end
|
145
|
+
|
146
|
+
def returning_visits_by_day(date = default_date_range, period = 'day')
|
147
|
+
result = api_params('VisitFrequency.get', period, date)
|
148
|
+
results_array(result, 'nb_visits_returning')
|
149
|
+
end
|
150
|
+
|
151
|
+
def total_visitors(period = 'month', date = 'today')
|
152
|
+
response = api_params('VisitFrequency.get', period, date)
|
153
|
+
response["nb_visits_returning"].to_i + response["nb_visits_new"].to_i
|
154
|
+
end
|
155
|
+
|
156
|
+
def results_array(response, metric)
|
157
|
+
results = []
|
158
|
+
response.each do |result|
|
159
|
+
if result[1].empty?
|
160
|
+
results.push([result[0].to_date, 0])
|
161
|
+
elsif result[1].is_a?(Array)
|
162
|
+
results.push([result[0].to_date, result[1].first[metric]])
|
163
|
+
else
|
164
|
+
results.push([result[0].to_date, result[1][metric].presence || 0])
|
165
|
+
end
|
166
|
+
end
|
167
|
+
Hyrax::Analytics::Results.new(results)
|
168
|
+
end
|
169
|
+
|
170
|
+
def get(params)
|
171
|
+
response = Faraday.get(config.base_url, params)
|
172
|
+
return [] if response.status != 200
|
173
|
+
JSON.parse(response.body)
|
174
|
+
end
|
175
|
+
|
176
|
+
def api_params(method, period, date, additional_params = {})
|
177
|
+
params = {
|
178
|
+
module: "API",
|
179
|
+
idSite: config.site_id,
|
180
|
+
method: method,
|
181
|
+
period: period,
|
182
|
+
date: date,
|
183
|
+
format: "JSON",
|
184
|
+
token_auth: config.auth_token
|
185
|
+
}
|
186
|
+
params.merge!(additional_params)
|
187
|
+
get(params)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
# rubocop:enable Metrics/ModuleLength
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Analytics
|
4
|
+
class Results
|
5
|
+
require 'csv'
|
6
|
+
|
7
|
+
attr_accessor :results
|
8
|
+
|
9
|
+
def initialize(results)
|
10
|
+
@results ||= results
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
results.inject(0) { |sum, a| sum + a[1] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def day(date = Time.zone.today)
|
18
|
+
start_date = date.at_beginning_of_day
|
19
|
+
end_date = date.at_end_of_day
|
20
|
+
range_results = []
|
21
|
+
results.each do |result|
|
22
|
+
range_results.push(result) if (start_date..end_date).cover?(result[0])
|
23
|
+
end
|
24
|
+
range_results.inject(0) { |sum, a| sum + a[1] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def week(date = Time.zone.today)
|
28
|
+
start_date = date.at_beginning_of_week
|
29
|
+
end_date = date.at_end_of_week
|
30
|
+
range_results = []
|
31
|
+
results.each do |result|
|
32
|
+
range_results.push(result) if (start_date..end_date).cover?(result[0])
|
33
|
+
end
|
34
|
+
range_results.inject(0) { |sum, a| sum + a[1] }
|
35
|
+
end
|
36
|
+
|
37
|
+
def month(date = Time.zone.today)
|
38
|
+
start_date = date.at_beginning_of_month
|
39
|
+
end_date = date.at_end_of_month
|
40
|
+
range_results = []
|
41
|
+
results.each do |result|
|
42
|
+
range_results.push(result) if (start_date..end_date).cover?(result[0])
|
43
|
+
end
|
44
|
+
range_results.inject(0) { |sum, a| sum + a[1] }
|
45
|
+
end
|
46
|
+
|
47
|
+
def year(date = Time.zone.today)
|
48
|
+
start_date = date.at_beginning_of_year
|
49
|
+
end_date = date.at_end_of_year
|
50
|
+
range_results = []
|
51
|
+
results.each do |result|
|
52
|
+
range_results.push(result) if (start_date..end_date).cover?(result[0])
|
53
|
+
end
|
54
|
+
range_results.inject(0) { |sum, a| sum + a[1] }
|
55
|
+
end
|
56
|
+
|
57
|
+
def range(start_date = Time.zone.today - 1.month, end_date = Time.zone.today)
|
58
|
+
range_results = []
|
59
|
+
results.each do |result|
|
60
|
+
range_results.push(result) if (start_date..end_date).cover?(result[0])
|
61
|
+
end
|
62
|
+
range_results.inject(0) { |sum, a| sum + a[1] }
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_csv
|
66
|
+
results.inject([]) { |csv, row| csv << CSV.generate_line(row) }.join("")
|
67
|
+
end
|
68
|
+
|
69
|
+
def list
|
70
|
+
results.inject([]) { |line, row| line << row }.reverse
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_flot
|
74
|
+
fields = [:date, :pageviews]
|
75
|
+
results.map { |row| fields.zip(row).to_h }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -1,89 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'oauth2'
|
3
|
-
require 'signet/oauth_2/client'
|
4
|
-
|
5
2
|
module Hyrax
|
6
3
|
module Analytics
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
private_class_method :config
|
19
|
-
|
20
|
-
class Config
|
21
|
-
def self.load_from_yaml
|
22
|
-
filename = Rails.root.join('config', 'analytics.yml')
|
23
|
-
yaml = YAML.safe_load(ERB.new(File.read(filename)).result)
|
24
|
-
unless yaml
|
25
|
-
Rails.logger.error("Unable to fetch any keys from #{filename}.")
|
26
|
-
return new({})
|
27
|
-
end
|
28
|
-
new yaml.fetch('analytics')
|
29
|
-
end
|
30
|
-
|
31
|
-
REQUIRED_KEYS = %w[app_name app_version privkey_path privkey_secret client_email].freeze
|
32
|
-
|
33
|
-
def initialize(config)
|
34
|
-
@config = config
|
35
|
-
end
|
36
|
-
|
37
|
-
# @return [Boolean] are all the required values present?
|
38
|
-
def valid?
|
39
|
-
config_keys = @config.keys
|
40
|
-
REQUIRED_KEYS.all? { |required| config_keys.include?(required) }
|
41
|
-
end
|
42
|
-
|
43
|
-
REQUIRED_KEYS.each do |key|
|
44
|
-
class_eval %{ def #{key}; @config.fetch('#{key}'); end }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Generate an OAuth2 token for Google Analytics
|
49
|
-
# @return [OAuth2::AccessToken] An OAuth2 access token for GA
|
50
|
-
def self.token(scope = 'https://www.googleapis.com/auth/analytics.readonly')
|
51
|
-
access_token = auth_client(scope).fetch_access_token!
|
52
|
-
OAuth2::AccessToken.new(oauth_client, access_token['access_token'], expires_in: access_token['expires_in'])
|
4
|
+
##
|
5
|
+
# a completely empty module to include if no parser is configured
|
6
|
+
module NullAnalyticsParser; end
|
7
|
+
|
8
|
+
def self.provider_parser
|
9
|
+
"Hyrax::Analytics::#{Hyrax.config.analytics_provider.to_s.capitalize}".constantize
|
10
|
+
rescue NameError => err
|
11
|
+
Hyrax.logger.warn("Couldn't find an Analytics provider matching "\
|
12
|
+
" #{Hyrax.config.analytics_provider}. Loading " \
|
13
|
+
" NullAnalyticsProvider.\n#{err.message}")
|
14
|
+
NullAnalyticsParser
|
53
15
|
end
|
54
16
|
|
55
|
-
|
56
|
-
OAuth2::Client.new('', '', authorize_url: 'https://accounts.google.com/o/oauth2/auth',
|
57
|
-
token_url: 'https://accounts.google.com/o/oauth2/token')
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.auth_client(scope)
|
61
|
-
raise "Private key file for Google analytics was expected at '#{config.privkey_path}', but no file was found." unless File.exist?(config.privkey_path)
|
62
|
-
private_key = File.read(config.privkey_path)
|
63
|
-
Signet::OAuth2::Client.new token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
|
64
|
-
audience: 'https://accounts.google.com/o/oauth2/token',
|
65
|
-
scope: scope,
|
66
|
-
issuer: config.client_email,
|
67
|
-
signing_key: OpenSSL::PKCS12.new(private_key, config.privkey_secret).key,
|
68
|
-
sub: config.client_email
|
69
|
-
end
|
70
|
-
|
71
|
-
private_class_method :token
|
72
|
-
|
73
|
-
# Return a user object linked to a Google Analytics account
|
74
|
-
# @return [Legato::User] A user account wit GA access
|
75
|
-
def self.user
|
76
|
-
Legato::User.new(token)
|
77
|
-
end
|
78
|
-
private_class_method :user
|
79
|
-
|
80
|
-
# Return a Google Analytics profile matching specified ID
|
81
|
-
# @ return [Legato::Management::Profile] A user profile associated with GA
|
82
|
-
def self.profile
|
83
|
-
return unless config.valid?
|
84
|
-
user.profiles.detect do |profile|
|
85
|
-
profile.web_property_id == Hyrax.config.google_analytics_id
|
86
|
-
end
|
87
|
-
end
|
17
|
+
include provider_parser
|
88
18
|
end
|
89
19
|
end
|
@@ -13,6 +13,7 @@ module Hyrax
|
|
13
13
|
# sets; regardless of true/false make the given user
|
14
14
|
# the depositor of the given work
|
15
15
|
def self.call(work, user, reset)
|
16
|
+
Deprecation.warn("This class will be removed in the next major release. Use Hyrax::ChangeDepositorService.call instead.")
|
16
17
|
case work
|
17
18
|
when ActiveFedora::Base
|
18
19
|
call_af(work, user, reset)
|
@@ -49,7 +50,6 @@ module Hyrax
|
|
49
50
|
apply_valkyrie_changes_to_file_sets(work: work, user: user, reset: reset)
|
50
51
|
|
51
52
|
Hyrax.persister.save(resource: work)
|
52
|
-
work
|
53
53
|
end
|
54
54
|
private_class_method :call_valkyrie
|
55
55
|
|
@@ -61,7 +61,7 @@ module Hyrax
|
|
61
61
|
private_class_method :apply_depositor_metadata
|
62
62
|
|
63
63
|
def self.apply_valkyrie_changes_to_file_sets(work:, user:, reset:)
|
64
|
-
Hyrax.custom_queries.
|
64
|
+
Hyrax.custom_queries.find_child_file_sets(resource: work).each do |f|
|
65
65
|
if reset
|
66
66
|
f.permission_manager.acl.permissions = []
|
67
67
|
f.permission_manager.acl.save
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
class ChangeDepositorService
|
4
|
+
# Set the given `user` as the depositor of the given `work`; If
|
5
|
+
# `reset` is true, first remove all previous permissions.
|
6
|
+
#
|
7
|
+
# Used to transfer a an existing work, and to set
|
8
|
+
# depositor / proxy_depositor on a work newly deposited
|
9
|
+
# on_behalf_of another user
|
10
|
+
#
|
11
|
+
# @param work [ActiveFedora::Base, Valkyrie::Resource] the work
|
12
|
+
# that is receiving a change of depositor
|
13
|
+
# @param user [User] the user that will "become" the depositor of
|
14
|
+
# the given work
|
15
|
+
# @param reset [TrueClass, FalseClass] when true, first clear
|
16
|
+
# permissions for the given work and contained file
|
17
|
+
# sets; regardless of true/false make the given user
|
18
|
+
# the depositor of the given work
|
19
|
+
# @return work, updated if necessary
|
20
|
+
def self.call(work, user, reset)
|
21
|
+
# user_key is nil when there was no `on_behalf_of` in the form
|
22
|
+
return work unless user&.user_key
|
23
|
+
# Don't transfer to self
|
24
|
+
return work if user.user_key == work.depositor
|
25
|
+
|
26
|
+
work = case work
|
27
|
+
when ActiveFedora::Base
|
28
|
+
call_af(work, user, reset)
|
29
|
+
when Valkyrie::Resource
|
30
|
+
call_valkyrie(work, user, reset)
|
31
|
+
end
|
32
|
+
ChangeDepositorEventJob.perform_later(work)
|
33
|
+
work
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.call_af(work, user, reset)
|
37
|
+
work.proxy_depositor = work.depositor
|
38
|
+
work.permissions = [] if reset
|
39
|
+
work.apply_depositor_metadata(user)
|
40
|
+
work.save!
|
41
|
+
Hyrax::PropagateChangeDepositorJob.perform_later(work.id.to_s, user, reset)
|
42
|
+
work
|
43
|
+
end
|
44
|
+
private_class_method :call_af
|
45
|
+
|
46
|
+
# @todo Should this include some dependency injection regarding
|
47
|
+
# the Hyrax.persister and Hyrax.custom_queries?
|
48
|
+
def self.call_valkyrie(work, user, reset)
|
49
|
+
if reset
|
50
|
+
work.permission_manager.acl.permissions = []
|
51
|
+
work.permission_manager.acl.save
|
52
|
+
end
|
53
|
+
|
54
|
+
work.proxy_depositor = work.depositor
|
55
|
+
apply_depositor_metadata(work, user)
|
56
|
+
|
57
|
+
work = Hyrax.persister.save(resource: work)
|
58
|
+
Hyrax::PropagateChangeDepositorJob.perform_later(work.id.to_s, user, reset)
|
59
|
+
work
|
60
|
+
end
|
61
|
+
private_class_method :call_valkyrie
|
62
|
+
|
63
|
+
def self.apply_depositor_metadata(resource, depositor)
|
64
|
+
depositor_id = depositor.respond_to?(:user_key) ? depositor.user_key : depositor
|
65
|
+
resource.depositor = depositor_id if resource.respond_to? :depositor=
|
66
|
+
Hyrax::AccessControlList.new(resource: resource).grant(:edit).to(::User.find_by_user_key(depositor_id)).save
|
67
|
+
end
|
68
|
+
private_class_method :apply_depositor_metadata
|
69
|
+
end
|
70
|
+
end
|