Skip to content

Commit

Permalink
Merge branch 'pr-party' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
amclark42 committed Oct 1, 2021
2 parents c0ff403 + ec6a857 commit 51b17ad
Show file tree
Hide file tree
Showing 38 changed files with 237 additions and 157 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ gem 'hydra-head', '~> 10.0'
gem 'hydra-derivatives'
gem 'blacklight-gallery'

gem 'sunspot_rails'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

Expand Down
8 changes: 4 additions & 4 deletions app/actions/content/upsert_thumbnail.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Content
class UpsertThumbnail
class UpsertThumbnail
include Content

attr_reader :core_file, :filepath

def initialize(core_file, filepath)
@core_file = core_file
@filepath = filepath
Expand All @@ -23,9 +23,9 @@ def execute
end

add_unique_file(thumbnail, :filepath => filepath)

# Clear and update the CoreFile's thumbnail list
core_file.thumbnail_list = [thumbnail.download_path('thumbnail_1')]
core_file.thumbnails = [thumbnail.download_path('thumbnail_1')]
core_file.save!
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CatalogController < ApplicationController
config.show.tile_source_field = :content_metadata_image_iiif_info_ssm
config.show.partials.insert(1, :openseadragon)

config.index.thumbnail_field = 'thumbnail_list_tesim'
config.index.thumbnail_field = 'thumbnails_tesim'
## Class for sending and receiving requests from a search index
# config.repository_class = Blacklight::Solr::Repository

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def update
# @core_files = CoreFile.find_by_did(params[:id])
if params[:collection][:remove_thumbnail] == "1"
params[:collection].delete :thumbnail
@collection.thumbnail_list = []
@collection.thumbnails = []
@collection.save!
end
params[:collection].delete :remove_thumbnail
Expand Down
54 changes: 36 additions & 18 deletions app/controllers/communities_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class CommunitiesController < CatalogController
include ApiAccessible
include ControllerHelper

self.copy_blacklight_config_from(CatalogController)

Expand Down Expand Up @@ -49,12 +48,7 @@ def show
# authorize! :show, params[:id]
@community = Community.find(params[:id])
@page_title = @community.title || ""
@rec_count = 0
if @community.children
@community.children.each do |cc|
@rec_count = @rec_count + cc.children.count
end
end
# TODO: Communities can have_many other communities
end

#This method is used to create a new community/project
Expand All @@ -80,16 +74,14 @@ def new

#This method contains the actual logic for creating a new community
def create
@community = Community.new(params[:community])
@community.did = @community.pid
@community.depositor = current_user.id.to_s
if (params[:thumbnail])
params[:thumbnail] = create_temp_file(params[:thumbnail])
@community.add_thumbnail(:filepath => params[:thumbnail])
end
if params[:mass_permissions]
@community.mass_permissions = params[:mass_permissions]
@community = Community.new(community_params)
@community.depositor = current_user

if (thumbnail_params[:thumbnail])
# TODO: (pletcher) Create Thumbnail by uploading (to S3?) and saving URL
# Thumbnail.create!(url: url, owner: @community)
end

@community.save!
redirect_to @community and return
end
Expand All @@ -116,7 +108,7 @@ def update
puts @community
if params[:community][:remove_thumbnail] == "1"
params[:community].delete :thumbnail
@community.thumbnail_list = []
@community.thumbnails = []
@community.save!
end
params[:community].delete :remove_thumbnail
Expand All @@ -137,5 +129,31 @@ def destroy
@community = Community.find(params[:id])
@page_title = "Delete #{@community.title || ''}"
@community.destroy
end
end

protected

def can_read?
current_user && Community.find(params[:id]).can_read?(current_user)
end

private

def community_params
params
.require(:community)
.permit(
:description,
:institutions,
:project_admins,
:project_editors,
:project_members,
:thumbnail,
:title
)
end

def thumbnail_params
params.permit(:thumbnail)
end
end
2 changes: 1 addition & 1 deletion app/controllers/core_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def update
params[:did] = cf.did
if params[:core_file][:remove_thumbnail] == "1"
params[:core_file].delete :thumbnail
cf.thumbnail_list = []
cf.thumbnails = []
cf.save!
end
params[:core_file].delete :remove_thumbnail
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ def my_records_filter(solr_parameters, user_parameters)
end

def check_for_logged_in_user
if current_user
else
render_404("User not signed in") and return
end
redirect_to new_user_session_path if current_user.nil?
end

def verify_admin
Expand Down
2 changes: 1 addition & 1 deletion app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def project
end

def remove_thumbnail
self.thumbnail_list = []
self.thumbnails = []
self.save!
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/communities_institution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class CommunitiesInstitution < ActiveRecord::Base
belongs_to :community
belongs_to :institution
end
22 changes: 15 additions & 7 deletions app/models/community.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ class Community < ActiveRecord::Base
# has_attributes :description, datastream: "DC"

has_many :community_collections
has_many :collections, through: :community_collections, source: :collection
has_many :collections, through: :community_collections
has_many :children, through: :community_collections, source: :collection
has_many :community_members
has_many :members, through: :community_members, source: :user
has_many :users, through: :community_members
has_and_belongs_to_many :communities, join_table: "community_communities", association_foreign_key: "parent_community_id"

has_many :institutions
has_many :communities_institutions
has_many :institutions, through: :communities_institutions
has_many :thumbnails, as: :owner

belongs_to :depositor, class_name: "User"

validates_presence_of :title

# Look up or create the root community of the graph
Expand All @@ -54,15 +58,15 @@ def self.root_community
end

def project_members
members
users
end

def project_editors
members.where(member_type: ["editor", "admin"])
users.where(community_members: { member_type: ["editor", "admin"] })
end

def project_admins
members.where(member_type: "admin")
users.where(community_members: { member_type: "admin" })
end

def as_json
Expand All @@ -78,6 +82,10 @@ def as_json
}
end

def can_read?(user)
community_members.where(user_id: user.id).any?
end

def match_dc_to_mods
# self.DC.title = self.mods.title.first
# self.DC.description = self.mods.abstract.first if !self.mods.abstract.blank?
Expand Down Expand Up @@ -146,7 +154,7 @@ def set_depositor_as_admin
end

def remove_thumbnail
self.thumbnail_list = []
self.thumbnails = []
self.save!
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/inline_thumbnail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add_thumbnail(opts)
self.add_file(content, 'thumbnail_1', filename)
logger.info self.thumbnail_1
self.thumbnail_1.content = content
self.thumbnail_list = [download_path('thumbnail_1')]
self.thumbnails = [download_path('thumbnail_1')]
# self.save!
end
end
2 changes: 1 addition & 1 deletion app/models/core_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def ography_type
end

def remove_thumbnail
self.thumbnail_list = []
self.thumbnails = []
self.save!
end

Expand Down
3 changes: 2 additions & 1 deletion app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class Institution < ActiveRecord::Base
validates_presence_of :name

has_many :users
belongs_to :community
has_many :communities_institutions
has_many :communities, through: :communities_institutions
end
3 changes: 1 addition & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :name, :role, :bio, :account_type
end

attr_accessible :email, :password, :password_confirmation, :name, :role, :bio, :account_type if Rails::VERSION::MAJOR < 4
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
Expand All @@ -24,7 +23,7 @@ class User < ActiveRecord::Base
belongs_to :institution

has_many :community_members
has_many :communities, through: :community_members, source: :community
has_many :communities, through: :community_members

ROLES = %w[admin paid_user unpaid_user]

Expand Down
2 changes: 1 addition & 1 deletion app/views/collections/_data_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
.form-group
= f.label :thumbnail, "Thumbnail", class: "control-label col-md-2"
.col-md-6
- if !@collection.thumbnail_list.blank?
- if !@collection.thumbnails.blank?
=image_tag @collection.download_path('thumbnail_1')
= f.label :remove_thumbnail, "Remove Thumbnail"
= f.check_box "remove_thumbnail", {:checked => false}
Expand Down
6 changes: 3 additions & 3 deletions app/views/collections/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
%dd
= link_to(int.name, institution_path(int))
%br
- if @collection.thumbnail_list.blank?
- if @collection.thumbnails.blank?
=image_tag "tapaslogo-opaque.png"
-else
%img{src:@collection.thumbnail_list.first}
%img{src:@collection.thumbnails.first}
- if [email protected]?
%dt= "Description"
%dd= @collection.description
Expand All @@ -53,7 +53,7 @@
%a{href:edit_core_file_path(record), class: ['btn','btn-xs','btn-default','pull-right']}
%i.fa.fa-pencil
= "Edit"
- if record.thumbnail_list.blank?
- if record.thumbnails.blank?
=image_tag "tapaslogo-opaque.png"
-else
%img{src:record.thumbnail.download_path('thumbnail_1')}
Expand Down
17 changes: 6 additions & 11 deletions app/views/communities/_data_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
.form-group
= f.label :title, "Title", class: "control-label col-md-2"
.col-md-6
= f.text_field :title, required: true, pattern: ".*\\S.*", name: 'community[title][]', class: "form-control", placeholder: "University Libraries"
= f.text_field :title, required: true, pattern: ".*\\S.*", name: 'community[title]', class: "form-control", placeholder: "University Libraries"
.form-group
= f.label :description, "Description", class: "control-label col-md-2"
.col-md-6
= f.text_area :description, required: true, pattern: ".*\\S.*", name: 'community[description][]', class: "form-control", placeholder: "Brief description of the community"
= f.text_area :description, required: true, pattern: ".*\\S.*", name: 'community[description]', class: "form-control", placeholder: "Brief description of the community"
%p.small.help-block="This field accepts plain text"
.form-group
= f.label :is_public, "Visibility", class: "control-label col-md-2"
= f.label :is_public, "Public?", class: "control-label col-md-2"
= f.check_box :is_public, { checked: true }
.form-group
= f.label :thumbnail, "Thumbnail", class: "control-label col-md-2"
= f.label :thumbnail, "Thumbnail", name: 'thumbnail', class: "control-label col-md-2"
.col-md-6
- if [email protected]?
=image_tag @community.download_path('thumbnail_1')
Expand All @@ -32,13 +32,8 @@
%span.institution
= f.select :institutions, options_for_select(@institutions), {}, {name: "community[institutions][]", class: "form-control"}
- else
- @community.institutions.each_with_index do |id, i|
%span.institution{:class=> i != 0 ? "to-remove" : ""}
= f.select :institutions, options_for_select(@institutions, id), {}, {name: "community[institutions][]", class: "form-control"}
-if i != 0
%button.btn.btn-small.btn-danger{"data-delete" => "", "data-target" => ".to-remove", title: "Remove institution", type: "button"}
%i.fa.fa-remove
%br
%span.institution
= f.select :institutions, options_for_select(@institutions), {}, {name: "community[institutions][]", class: "form-control"}
%button#add_another_institution.btn.btn-success{:type => "button"}
%i.fa-plus-sign.fa
Add Institution
Expand Down
8 changes: 4 additions & 4 deletions app/views/communities/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

%div.row
%div.col-md-3
- if @community.thumbnail_list.blank?
- if @community.thumbnails.blank?
=image_tag "tapaslogo-opaque.png"
-else
%img{src:@community.thumbnail_list.first}
%img{src:@community.thumbnails.first}
%dt= "Description"
%dd= @community.description
-# external links TODO
Expand Down Expand Up @@ -50,8 +50,8 @@
%a{href:edit_collection_path(collection), class: ['btn','btn-xs','btn-default','pull-right']}
%i.fa.fa-pencil
= "Edit"
- if collection.thumbnail_list.blank?
- if collection.thumbnails.blank?
=image_tag "tapaslogo-opaque.png"
-else
%img{src:collection.thumbnail_list.first}
%img{src:collection.thumbnails.first}
%h4= link_to collection.title, collection
4 changes: 2 additions & 2 deletions app/views/core_files/_featured.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
%div.carousel-inner{"role"=>"listbox"}
- @featured_core.each_with_index do |c, i|
%div.item{"class"=>("active" if i == 0)}
- if c.thumbnail_list.length > 0
%img{"src"=>c.thumbnail_list[0]}
- if c.thumbnails.length > 0
%img{"src"=>c.thumbnails[0]}
- else
%img{"src"=>"/assets/tapaslogo-opaque.png"}
%div.carousel-caption
Expand Down
5 changes: 3 additions & 2 deletions config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'carrierwave/orm/activerecord'

# Load the Rails application.
require File.expand_path('../application', __FILE__)

Expand All @@ -8,3 +6,6 @@

# Initialize the Rails application.
TapasRails::Application.initialize!

# ActionView complains in tests if we don't copy this config over
TapasRails::Application.default_url_options = TapasRails::Application.config.action_mailer.default_url_options
Loading

0 comments on commit 51b17ad

Please sign in to comment.