From fb122fb2ffdf1b25d715a9823cb3ea153c2feed3 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Tue, 12 Nov 2019 16:07:11 -0500 Subject: [PATCH] Now we are at a working base install. Tag this commit. --- Gemfile | 4 +- Gemfile.lock | 10 +++ app/actors/hyrax/actors/generic_work_actor.rb | 8 +++ .../hyrax/generic_works_controller.rb | 14 ++++ app/forms/hyrax/generic_work_form.rb | 9 +++ app/indexers/generic_work_indexer.rb | 18 +++++ app/models/ability.rb | 6 +- app/models/generic_work.rb | 14 ++++ app/models/user.rb | 4 ++ .../hyrax/generic_work_presenter.rb | 6 ++ .../generic_works/_generic_work.html.erb | 2 + config/initializers/hyrax.rb | 2 + config/locales/generic_work.de.yml | 8 +++ config/locales/generic_work.en.yml | 8 +++ config/locales/generic_work.es.yml | 10 +++ config/locales/generic_work.fr.yml | 8 +++ config/locales/generic_work.it.yml | 8 +++ config/locales/generic_work.pt-BR.yml | 8 +++ config/locales/generic_work.zh.yml | 10 +++ config/routes.rb | 2 + db/migrate/20191112184203_user_roles.rb | 19 ++++++ db/schema.rb | 15 +++- .../hyrax/actors/generic_work_actor_spec.rb | 9 +++ .../hyrax/generic_works_controller_spec.rb | 9 +++ spec/features/create_generic_work_spec.rb | 68 +++++++++++++++++++ spec/forms/hyrax/generic_work_form_spec.rb | 9 +++ spec/models/generic_work_spec.rb | 9 +++ .../hyrax/generic_work_presenter_spec.rb | 9 +++ 28 files changed, 303 insertions(+), 3 deletions(-) create mode 100644 app/actors/hyrax/actors/generic_work_actor.rb create mode 100644 app/controllers/hyrax/generic_works_controller.rb create mode 100644 app/forms/hyrax/generic_work_form.rb create mode 100644 app/indexers/generic_work_indexer.rb create mode 100644 app/models/generic_work.rb create mode 100644 app/presenters/hyrax/generic_work_presenter.rb create mode 100644 app/views/hyrax/generic_works/_generic_work.html.erb create mode 100644 config/locales/generic_work.de.yml create mode 100644 config/locales/generic_work.en.yml create mode 100644 config/locales/generic_work.es.yml create mode 100644 config/locales/generic_work.fr.yml create mode 100644 config/locales/generic_work.it.yml create mode 100644 config/locales/generic_work.pt-BR.yml create mode 100644 config/locales/generic_work.zh.yml create mode 100644 db/migrate/20191112184203_user_roles.rb create mode 100644 spec/actors/hyrax/actors/generic_work_actor_spec.rb create mode 100644 spec/controllers/hyrax/generic_works_controller_spec.rb create mode 100644 spec/features/create_generic_work_spec.rb create mode 100644 spec/forms/hyrax/generic_work_form_spec.rb create mode 100644 spec/models/generic_work_spec.rb create mode 100644 spec/presenters/hyrax/generic_work_presenter_spec.rb diff --git a/Gemfile b/Gemfile index befccd8..f2bb698 100644 --- a/Gemfile +++ b/Gemfile @@ -71,4 +71,6 @@ end gem 'riiif', '~> 2.1' -gem 'mysql2' \ No newline at end of file +gem 'mysql2' + +gem 'hydra-role-management' diff --git a/Gemfile.lock b/Gemfile.lock index 9292a80..03ee1e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -116,6 +116,9 @@ GEM bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) + bootstrap_form (4.3.0) + actionpack (>= 5.0) + activemodel (>= 5.0) breadcrumbs_on_rails (3.0.1) browse-everything (1.0.2) addressable (~> 2.5) @@ -324,6 +327,12 @@ GEM hydra-pcdm (1.1.0) active-fedora (>= 10, < 14) mime-types (>= 1) + hydra-role-management (1.0.2) + blacklight + bootstrap_form + bundler (>= 1.5) + cancancan + json (>= 1.8) hydra-works (1.2.0) activesupport (>= 4.2.10, < 6.0) hydra-derivatives (~> 3.0) @@ -801,6 +810,7 @@ DEPENDENCIES devise devise-guests (~> 0.6) fcrepo_wrapper + hydra-role-management hyrax (= 3.0.0.pre.rc1) jbuilder (~> 2.5) jquery-rails diff --git a/app/actors/hyrax/actors/generic_work_actor.rb b/app/actors/hyrax/actors/generic_work_actor.rb new file mode 100644 index 0000000..b4b1877 --- /dev/null +++ b/app/actors/hyrax/actors/generic_work_actor.rb @@ -0,0 +1,8 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +module Hyrax + module Actors + class GenericWorkActor < Hyrax::Actors::BaseActor + end + end +end diff --git a/app/controllers/hyrax/generic_works_controller.rb b/app/controllers/hyrax/generic_works_controller.rb new file mode 100644 index 0000000..00ceab3 --- /dev/null +++ b/app/controllers/hyrax/generic_works_controller.rb @@ -0,0 +1,14 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +module Hyrax + # Generated controller for GenericWork + class GenericWorksController < ApplicationController + # Adds Hyrax behaviors to the controller. + include Hyrax::WorksControllerBehavior + include Hyrax::BreadcrumbsForWorks + self.curation_concern_type = ::GenericWork + + # Use this line if you want to use a custom presenter + self.show_presenter = Hyrax::GenericWorkPresenter + end +end diff --git a/app/forms/hyrax/generic_work_form.rb b/app/forms/hyrax/generic_work_form.rb new file mode 100644 index 0000000..cddaa5f --- /dev/null +++ b/app/forms/hyrax/generic_work_form.rb @@ -0,0 +1,9 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +module Hyrax + # Generated form for GenericWork + class GenericWorkForm < Hyrax::Forms::WorkForm + self.model_class = ::GenericWork + self.terms += [:resource_type] + end +end diff --git a/app/indexers/generic_work_indexer.rb b/app/indexers/generic_work_indexer.rb new file mode 100644 index 0000000..96531c8 --- /dev/null +++ b/app/indexers/generic_work_indexer.rb @@ -0,0 +1,18 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +class GenericWorkIndexer < Hyrax::WorkIndexer + # This indexes the default metadata. You can remove it if you want to + # provide your own metadata and indexing. + include Hyrax::IndexesBasicMetadata + + # Fetch remote labels for based_near. You can remove this if you don't want + # this behavior + include Hyrax::IndexesLinkedMetadata + + # Uncomment this block if you want to add custom indexing behavior: + # def generate_solr_document + # super.tap do |solr_doc| + # solr_doc['my_custom_field_ssim'] = object.my_custom_property + # end + # end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index c5ecb45..848d4f6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -1,6 +1,6 @@ class Ability include Hydra::Ability - + include Hyrax::Ability self.ability_logic += [:everyone_can_create_curation_concerns] @@ -12,6 +12,10 @@ def custom_permissions # can [:destroy], ActiveFedora::Base # end + if current_user.admin? + can [:create, :show, :add_user, :remove_user, :index, :edit, :update, :destroy], Role + end + # Limits creating new objects to a specific group # # if user_groups.include? 'special_group' diff --git a/app/models/generic_work.rb b/app/models/generic_work.rb new file mode 100644 index 0000000..984ade5 --- /dev/null +++ b/app/models/generic_work.rb @@ -0,0 +1,14 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +class GenericWork < ActiveFedora::Base + include ::Hyrax::WorkBehavior + + self.indexer = GenericWorkIndexer + # Change this to restrict which works can be added as a child. + # self.valid_child_concerns = [] + validates :title, presence: { message: 'Your work must have a title.' } + + # This must be included at the end, because it finalizes the metadata + # schema (by adding accepts_nested_attributes) + include ::Hyrax::BasicMetadata +end diff --git a/app/models/user.rb b/app/models/user.rb index 323b5cc..bd9c7c7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,10 @@ class User < ApplicationRecord # Connects this user object to Hydra behaviors. include Hydra::User + # Connects this user object to Role-management behaviors. + include Hydra::RoleManagement::UserRoles + + # Connects this user object to Hyrax behaviors. include Hyrax::User include Hyrax::UserUsageStats diff --git a/app/presenters/hyrax/generic_work_presenter.rb b/app/presenters/hyrax/generic_work_presenter.rb new file mode 100644 index 0000000..ee46be5 --- /dev/null +++ b/app/presenters/hyrax/generic_work_presenter.rb @@ -0,0 +1,6 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +module Hyrax + class GenericWorkPresenter < Hyrax::WorkShowPresenter + end +end diff --git a/app/views/hyrax/generic_works/_generic_work.html.erb b/app/views/hyrax/generic_works/_generic_work.html.erb new file mode 100644 index 0000000..b343e9e --- /dev/null +++ b/app/views/hyrax/generic_works/_generic_work.html.erb @@ -0,0 +1,2 @@ +<%# This is a search result view %> +<%= render 'catalog/document', document: generic_work, document_counter: generic_work_counter %> diff --git a/config/initializers/hyrax.rb b/config/initializers/hyrax.rb index 09609c5..15cc678 100644 --- a/config/initializers/hyrax.rb +++ b/config/initializers/hyrax.rb @@ -1,6 +1,8 @@ Hyrax.config do |config| # Injected via `rails g hyrax:work Work` config.register_curation_concern :work + # Injected via `rails g hyrax:work GenericWork` + config.register_curation_concern :generic_work # Register roles that are expected by your implementation. # @see Hyrax::RoleRegistry for additional details. # @note there are magical roles as defined in Hyrax::RoleRegistry::MAGIC_ROLES diff --git a/config/locales/generic_work.de.yml b/config/locales/generic_work.de.yml new file mode 100644 index 0000000..0ded43b --- /dev/null +++ b/config/locales/generic_work.de.yml @@ -0,0 +1,8 @@ +de: + hyrax: + icons: + generic_work: 'fa fa-file-text-o' + select_type: + generic_work: + description: "Generic work Werke" + name: "Generic Work" diff --git a/config/locales/generic_work.en.yml b/config/locales/generic_work.en.yml new file mode 100644 index 0000000..7723826 --- /dev/null +++ b/config/locales/generic_work.en.yml @@ -0,0 +1,8 @@ +en: + hyrax: + icons: + generic_work: 'fa fa-file-text-o' + select_type: + generic_work: + description: "Generic work works" + name: "Generic Work" diff --git a/config/locales/generic_work.es.yml b/config/locales/generic_work.es.yml new file mode 100644 index 0000000..2b6fb79 --- /dev/null +++ b/config/locales/generic_work.es.yml @@ -0,0 +1,10 @@ +es: + hyrax: + icons: + generic_work: 'fa fa-file-text-o' + select_type: + generic_work: + # TODO: translate `human_name` into Spanish + description: "Generic work trabajos" + name: "Generic Work" + # TODO: translate `human_name` into Spanish diff --git a/config/locales/generic_work.fr.yml b/config/locales/generic_work.fr.yml new file mode 100644 index 0000000..eead8e4 --- /dev/null +++ b/config/locales/generic_work.fr.yml @@ -0,0 +1,8 @@ +fr: + hyrax: + icons: + generic_work: 'fa fa-file-text-o' + select_type: + generic_work: + description: "Generic work œuvres" + name: "Generic Work" diff --git a/config/locales/generic_work.it.yml b/config/locales/generic_work.it.yml new file mode 100644 index 0000000..db84c9a --- /dev/null +++ b/config/locales/generic_work.it.yml @@ -0,0 +1,8 @@ +it: + hyrax: + icons: + generic_work: 'fa fa-file-text-o' + select_type: + generic_work: + description: "Generic work opere" + name: "Generic Work" diff --git a/config/locales/generic_work.pt-BR.yml b/config/locales/generic_work.pt-BR.yml new file mode 100644 index 0000000..1367ba1 --- /dev/null +++ b/config/locales/generic_work.pt-BR.yml @@ -0,0 +1,8 @@ +pt-BR: + hyrax: + icons: + generic_work: 'fa fa-file-text-o' + select_type: + generic_work: + description: "Generic work obras" + name: "Generic Work" diff --git a/config/locales/generic_work.zh.yml b/config/locales/generic_work.zh.yml new file mode 100644 index 0000000..1196152 --- /dev/null +++ b/config/locales/generic_work.zh.yml @@ -0,0 +1,10 @@ +zh: + hyrax: + icons: + generic_work: 'fa fa-file-text-o' + select_type: + generic_work: + # TODO: translate `human_name` into Chinese + description: "Generic work 作品" + name: "Generic Work" + # TODO: translate `human_name` into Chinese diff --git a/config/routes.rb b/config/routes.rb index 0c015e3..fe55184 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,8 @@ end devise_for :users + mount Hydra::RoleManagement::Engine => '/' + mount Qa::Engine => '/authorities' mount Hyrax::Engine, at: '/' resources :welcome, only: 'index' diff --git a/db/migrate/20191112184203_user_roles.rb b/db/migrate/20191112184203_user_roles.rb new file mode 100644 index 0000000..bd757f6 --- /dev/null +++ b/db/migrate/20191112184203_user_roles.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true +class UserRoles < ActiveRecord::Migration[5.0] + def up + create_table :roles do |t| + t.string :name + end + create_table :roles_users, id: false do |t| + t.references :role + t.references :user + end + add_index :roles_users, [:role_id, :user_id] + add_index :roles_users, [:user_id, :role_id] + end + + def down + drop_table :roles_users + drop_table :roles + end +end diff --git a/db/schema.rb b/db/schema.rb index 335873d..3140045 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20191112041953) do +ActiveRecord::Schema.define(version: 20191112184203) do create_table "bookmarks", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.integer "user_id", null: false @@ -283,6 +283,19 @@ t.index ["uri"], name: "index_qa_local_authority_entries_on_uri", unique: true end + create_table "roles", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| + t.string "name" + end + + create_table "roles_users", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| + t.integer "role_id" + t.integer "user_id" + t.index ["role_id", "user_id"], name: "index_roles_users_on_role_id_and_user_id" + t.index ["role_id"], name: "index_roles_users_on_role_id" + t.index ["user_id", "role_id"], name: "index_roles_users_on_user_id_and_role_id" + t.index ["user_id"], name: "index_roles_users_on_user_id" + end + create_table "searches", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.binary "query_params" t.integer "user_id" diff --git a/spec/actors/hyrax/actors/generic_work_actor_spec.rb b/spec/actors/hyrax/actors/generic_work_actor_spec.rb new file mode 100644 index 0000000..22dfa1f --- /dev/null +++ b/spec/actors/hyrax/actors/generic_work_actor_spec.rb @@ -0,0 +1,9 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +require 'rails_helper' + +RSpec.describe Hyrax::Actors::GenericWorkActor do + it "has tests" do + skip "Add your tests here" + end +end diff --git a/spec/controllers/hyrax/generic_works_controller_spec.rb b/spec/controllers/hyrax/generic_works_controller_spec.rb new file mode 100644 index 0000000..c824b81 --- /dev/null +++ b/spec/controllers/hyrax/generic_works_controller_spec.rb @@ -0,0 +1,9 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +require 'rails_helper' + +RSpec.describe Hyrax::GenericWorksController do + it "has tests" do + skip "Add your tests here" + end +end diff --git a/spec/features/create_generic_work_spec.rb b/spec/features/create_generic_work_spec.rb new file mode 100644 index 0000000..6eb869a --- /dev/null +++ b/spec/features/create_generic_work_spec.rb @@ -0,0 +1,68 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +require 'rails_helper' +include Warden::Test::Helpers + +# NOTE: If you generated more than one work, you have to set "js: true" +RSpec.feature 'Create a GenericWork', js: false do + context 'a logged in user' do + let(:user_attributes) do + { email: 'test@example.com' } + end + let(:user) do + User.new(user_attributes) { |u| u.save(validate: false) } + end + let(:admin_set_id) { AdminSet.find_or_create_default_admin_set_id } + let(:permission_template) { Hyrax::PermissionTemplate.find_or_create_by!(source_id: admin_set_id) } + let(:workflow) { Sipity::Workflow.create!(active: true, name: 'test-workflow', permission_template: permission_template) } + + before do + # Create a single action that can be taken + Sipity::WorkflowAction.create!(name: 'submit', workflow: workflow) + + # Grant the user access to deposit into the admin set. + Hyrax::PermissionTemplateAccess.create!( + permission_template_id: permission_template.id, + agent_type: 'user', + agent_id: user.user_key, + access: 'deposit' + ) + login_as user + end + + scenario do + visit '/dashboard' + click_link "Works" + click_link "Add new work" + + # If you generate more than one work uncomment these lines + # choose "payload_concern", option: "GenericWork" + # click_button "Create work" + + expect(page).to have_content "Add New Generic work" + click_link "Files" # switch tab + expect(page).to have_content "Add files" + expect(page).to have_content "Add folder" + within('span#addfiles') do + attach_file("files[]", "#{Hyrax::Engine.root}/spec/fixtures/image.jp2", visible: false) + attach_file("files[]", "#{Hyrax::Engine.root}/spec/fixtures/jp2_fits.xml", visible: false) + end + click_link "Descriptions" # switch tab + fill_in('Title', with: 'My Test Work') + fill_in('Creator', with: 'Doe, Jane') + select('In Copyright', from: 'Rights statement') + + # With selenium and the chrome driver, focus remains on the + # select box. Click outside the box so the next line can't find + # its element + find('body').click + choose('generic_work_visibility_open') + expect(page).to have_content('Please note, making something visible to the world (i.e. marking this as Public) may be viewed as publishing which could impact your ability to') + check('agreement') + + click_on('Save') + expect(page).to have_content('My Test Work') + expect(page).to have_content "Your files are being processed by Hyrax in the background." + end + end +end diff --git a/spec/forms/hyrax/generic_work_form_spec.rb b/spec/forms/hyrax/generic_work_form_spec.rb new file mode 100644 index 0000000..9345da7 --- /dev/null +++ b/spec/forms/hyrax/generic_work_form_spec.rb @@ -0,0 +1,9 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +require 'rails_helper' + +RSpec.describe Hyrax::GenericWorkForm do + it "has tests" do + skip "Add your tests here" + end +end diff --git a/spec/models/generic_work_spec.rb b/spec/models/generic_work_spec.rb new file mode 100644 index 0000000..9e4ed1f --- /dev/null +++ b/spec/models/generic_work_spec.rb @@ -0,0 +1,9 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +require 'rails_helper' + +RSpec.describe GenericWork do + it "has tests" do + skip "Add your tests here" + end +end diff --git a/spec/presenters/hyrax/generic_work_presenter_spec.rb b/spec/presenters/hyrax/generic_work_presenter_spec.rb new file mode 100644 index 0000000..c8f6536 --- /dev/null +++ b/spec/presenters/hyrax/generic_work_presenter_spec.rb @@ -0,0 +1,9 @@ +# Generated via +# `rails generate hyrax:work GenericWork` +require 'rails_helper' + +RSpec.describe Hyrax::GenericWorkPresenter do + it "has tests" do + skip "Add your tests here" + end +end