-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |