Skip to content

Commit

Permalink
Merge 1e52160 into e727964
Browse files Browse the repository at this point in the history
  • Loading branch information
sephirothkod committed Jan 25, 2019
2 parents e727964 + 1e52160 commit 677c2d2
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 1 deletion.
29 changes: 29 additions & 0 deletions app/controllers/admin/work_types_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Admin
class WorkTypesController < ApplicationController
layout 'hyrax/dashboard'

before_action do
authorize! :manage, Hyrax::Feature
end

def edit
site
end

def update
site.available_works = params[:available_works]
if site.save
flash[:notice] = "Work types have been successfully updated"
else
flash[:error] = "Work types were not updated"
end
render action: "edit"
end

private

def site
@site ||= Site.first
end
end
end
39 changes: 39 additions & 0 deletions app/services/hyrax/quick_classification_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Hyrax
# added for tenant specific works, only the normalized_model_names method has been changed
class QuickClassificationQuery
attr_reader :user

# @param [User] user the current user
# @param [Hash] options
# @option options [#call] :concern_name_normalizer (String#constantize) a proc that translates names to classes
# @option options [Array<String>] :models the options to display, defaults to everything.
def initialize(user, options = {})
@user = user
@concern_name_normalizer = options.fetch(:concern_name_normalizer, ->(str) { str.constantize })
@models = options.fetch(:models, Hyrax.config.registered_curation_concern_types)
end

def each(&block)
authorized_models.each(&block)
end

# @return true if the requested concerns is same as all avaliable concerns
def all?
models == Hyrax.config.registered_curation_concern_types
end

# @return [Array] a list of all the requested concerns that the user can create
def authorized_models
normalized_model_names.select { |klass| user.can?(:create, klass) }
end

private

attr_reader :concern_name_normalizer, :models

# Transform the list of requested model names into a list of class names
def normalized_model_names
models.map { |name| concern_name_normalizer.call(name) if Site.first.available_works.include? name }
end
end
end
15 changes: 15 additions & 0 deletions app/views/admin/work_types/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% provide :page_header do %>
<h1><span class="fa fa-address-book"></span> <%= t('hyku.admin.work_types') %></h1>
<% end %>

<div class="panel panel-default">
<div class="panel-body">
<%= simple_form_for @site, url: '/admin/work_types' do |f| %>
<% Hyrax.config.registered_curation_concern_types.each do |type| %>
<%= check_box_tag 'available_works[]', type, @site.available_works.include?(type) %>
<span><%= type %></span><br />
<% end %>
<%= f.submit class: 'btn btn-primary' %>
<% end %>
</div>
</div>
5 changes: 4 additions & 1 deletion app/views/hyrax/dashboard/sidebar/_configuration.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
<%= menu.nav_link(hyrax.admin_features_path) do %>
<span class="fa fa-wrench" aria-hidden="true"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.technical') %></span>
<% end %>
<%= menu.nav_link('/admin/work_types/edit') do %>
<span class="fa fa-address-book"></span> <span class="sidebar-action-text"><%= t('hyku.admin.work_types') %></span>
<% end %>
<% end %>
<% end %>
</li>
<% end %>
<% if can?(:manage, Sipity::WorkflowResponsibility) %>
Expand All @@ -39,3 +41,4 @@
<% end %>
<% end # end of configuration block %>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ en:
new: New Group
remove: Remove Group
title: Administration
work_types: Available Work Types
footer:
admin_login: Administrator login
proprietor:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

namespace :admin do
resource :account, only: [:edit, :update]
resource :work_types, only: [:edit, :update]
resources :users, only: [:destroy]
resources :groups do
member do
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20181218060922_add_available_works_to_sites.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAvailableWorksToSites < ActiveRecord::Migration[5.1]
def change
add_column :sites, :available_works, :text, array: true, default: []
end
end

0 comments on commit 677c2d2

Please sign in to comment.