Skip to content

Commit

Permalink
Merge pull request #82 from NEU-DSG/pr-party
Browse files Browse the repository at this point in the history
PR party: a new bunch
  • Loading branch information
candyhazlett authored Feb 27, 2023
2 parents ede87c8 + 1ef3409 commit f2759ef
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 214 deletions.
8 changes: 0 additions & 8 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ def create
@collection.depositor = current_user
@collection.save!

# if (params[:thumbnail])
# params[:thumbnail] = create_temp_file(params[:thumbnail])
# @collection.add_thumbnail(:filepath => params[:thumbnail])
# @collection.save!
# end
# can this be used instead of individually spelling out the methods?
# TapasRails::Application::Queue.push TapasObjectUpsertJob.new params

redirect_to @collection and return
end

Expand Down
52 changes: 34 additions & 18 deletions app/controllers/communities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ def upsert
def index
@page_title = "All Projects"

logger.debug repository.inspect
logger.debug repository.connection
(@response, @document_list) = search_results(params)

(@response, @document_list) = search_results(params) #, search_params_logic)
respond_to do |format|
format.html { render :template => 'shared/index' }
format.js { render :template => 'shared/index', :layout => false }
Expand Down Expand Up @@ -59,14 +57,10 @@ def new
# TODO: CoreFiles can belong to many collections (many-to-many), but will always point back to one project

def create
@community = Community.new(community_params)
@community.depositor = current_user
@community.save!
@community = Community.create!(community_params.merge({ depositor_id: current_user.id }))

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

redirect_to @community
end
Expand All @@ -82,12 +76,33 @@ def edit
def update
@community = Community.find(params[:id])
@community.community_members.destroy_all
@community.communities_institutions.destroy_all
@community.institutions.destroy_all
@community.update(community_params)

add_institutions
add_members

if params[:community][:remove_thumbnail].present?
@community.thumbnail.purge_later
end

redirect_to @community
end

def add_institutions
child_params[:institutions].reject(&:empty?).map { |iid| CommunitiesInstitution.create!(community_id: @community.id, institution_id: iid) }
end

def add_members
child_params[:project_members].reject(&:empty?).map { |uid| CommunityMember.create(community_id: @community.id, user_id: uid, member_type: 'member') }
child_params[:project_editors].reject(&:empty?).map { |uid| CommunityMember.create!(community_id: @community.id, user_id: uid, member_type: 'editor') }
child_params[:project_admins].reject(&:empty?).map { |uid| CommunityMember.create!(community_id: @community.id, user_id: uid, member_type: 'admin') }

unless child_params[:project_admins].include?(current_user.id.to_s)
CommunityMember.create!(community_id: @community.id, user_id: current_user.id, member_type: 'admin')
end
end

def destroy
community = Community.find(params[:id])
community.discard
Expand Down Expand Up @@ -115,15 +130,16 @@ def community_params
.permit(
:description,
:thumbnail,
:title,
:institutions => [],
:project_admins => [],
:project_editors => [],
:project_members => []
:title
)
end

def thumbnail_params
params.permit(:thumbnail)
def child_params
params.require(:community).permit(
:institutions => [],
:project_admins => [],
:project_editors => [],
:project_members => []
)
end
end
63 changes: 13 additions & 50 deletions app/controllers/core_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,21 @@ def index

def new
@page_title = "Create New Record"
@collections = Collection
.joins(community: :community_members)
.where(community: { community_members: { user_id: current_user.id } })
@collections = Collection.accessible_by(current_ability)
@core_file = CoreFile.new(is_public: true)
@users = User.order(:name)

# FIXME: (charles) What is this supposed to do?
@file_types = [['TEI Record',""]]
@sel_file_types = []
CoreFile.all_ography_types.each do |o|
@file_types << [o.titleize,o]
end
end

def create
file = CoreFile.new(core_file_params.merge({ depositor_id: current_user.id }))

params[:core_file][:collections].each do |c|
file.collections << Collection.find(c) unless c.blank?
end

file.save!
file = CoreFile.create!(core_file_params.merge({ depositor_id: current_user.id }))

redirect_to file
end

def destroy
file = CoreFile.find(params[:id])
# FIXME: (charles) Should go to the collection where the user is, but the routes aren't set up RESTfully
collection = file.collections.first
collection = file.collections.kept.first

file.destroy!

Expand All @@ -70,40 +55,17 @@ def destroy

def edit
@core_file = CoreFile.find(params[:id])

@collections = @core_file.collections

@file_types = [['TEI Record',""]]
@sel_file_types = []
CoreFile.all_ography_types.each do |o|
@file_types << [o.titleize,o]
end
@core_file.ography_type.each do |o|
@sel_file_types << o
end
if @sel_file_types.blank?
@sel_file_types << ""
end

@collections = Collection.accessible_by(current_ability)
@users = User.order(:name)
@page_title = "Edit #{@core_file.title}"
end

#This method contains the logic for editing/submission of edit form
def update
cf = CoreFile.find(params[:id])
params[:did] = cf.did
if params[:core_file][:remove_thumbnail] == "1"
params[:core_file].delete :thumbnail
cf.thumbnails = []
cf.save!
end
params[:core_file].delete :remove_thumbnail
params[:file_types].reject! { |c| c.blank? }
logger.warn("we are about to edit #{params[:did]}")
logger.warn params
cf.update(core_file_params)

create
redirect_to cf and return
redirect_to cf
end

def view_package_html
Expand Down Expand Up @@ -141,7 +103,7 @@ def rebuild_reading_interfaces
pretty_json(200) and return
end

def show #inherited from catalog controller
def show
@core_file = CoreFile.find(params[:id])
end

Expand Down Expand Up @@ -232,14 +194,15 @@ def can_read?

def core_file_params
params.require(:core_file).permit(
:authors,
:canonical_object,
:collections,
:contributors,
:depositor,
:description,
:thumbnails,
:title
:featured,
:title,
:authors => [],
:contributors => [],
:thumbnails => []
)
end

Expand Down
25 changes: 18 additions & 7 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class UsersController < CatalogController

self.copy_blacklight_config_from(CatalogController)
before_action :check_for_logged_in_user, :only => [:my_tapas, :my_projects]
# before_action :verify_admin, :only => [:index, :show, :create]
before_action :verify_admin, :only => [:index, :show, :create, :delete]

def my_tapas
@page_title = "My TAPAS"
Expand Down Expand Up @@ -78,6 +78,18 @@ def update
redirect_to @user
end

def destroy
user = User.find(params[:id])

if user.discarded?
user.delete
else
user.discard
end

redirect_to users_path
end

def search_action_url(options = {})
# Rails 4.2 deprecated url helpers accepting string keys for 'controller' or 'action'
# catalog_index_path(options.except(:controller, :action))
Expand All @@ -103,22 +115,21 @@ def mail_all_users
private

def five_communities
@user.communities.limit(5).order("RAND()")
@user.communities.kept.limit(5).order("RAND()")
end

def five_collections
Collection
.joins(community: :community_members)
.where(community: { community_members: { user_id: @user.id } })
.kept
.accessible_by(current_ability)
.limit(5)
.order("RAND()")

end

def five_records
CoreFile
.joins(collections: { community: :community_members })
.where(collections: { community: { community_members: { user_id: @user.id } } })
.kept
.accessible_by(current_ability)
.limit(5)
.order("RAND()")
end
Expand Down
49 changes: 3 additions & 46 deletions app/models/community.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,16 @@ class Community < ActiveRecord::Base

belongs_to :depositor, class_name: "User"

has_many_attached :thumbnails
has_one_attached :thumbnail

validates_presence_of :title

# Look up or create the root community of the graph
# FIXME: (charles) I'm not sure why communities are related in a graph here -- is this used anywhere, or can we drop it?
# def self.root_community
# if Community.exists?(Rails.configuration.tap_root)
# Community.find(Rails.configuration.tap_root)
# else
# community = Community.new(:pid => Rails.configuration.tap_root, :title => "Root community")
# community.depositor = "000000000"
# community.mass_permissions = "private"
# community.save!
# return community
# end
# end

def create_members(user_ids = [], member_type = 'member')
# NOTE: (charles) This means that the order in which CommunityMembers are created matters: the last
# (community_id, user_id, member_type) will prevail for that community_id + user_id. In other words,
# selecting the same user in multiple roles is undefined behavior.

user_ids.reject(&:empty?).each do |uid|
CommunityMember.find_or_create_by(community_id: id, user_id: uid, member_type: member_type)
end
end

def institutions=(institution_ids)
puts "creating institutions"
institution_ids.reject(&:empty?).each do |iid|
CommunitiesInstitution.find_or_create_by(community_id: id, institution_id: iid)
end
end

def project_members=(user_ids)
create_members(user_ids)
end

def project_members
users
end

def project_editors=(user_ids)
create_members(user_ids, 'editor')
users.where(community_members: { member_type: "member" })
end

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

def project_admins=(user_ids)
create_members(user_ids, 'admin')
users.where(community_members: { member_type: "editor" })
end

def project_admins
Expand Down
Loading

0 comments on commit f2759ef

Please sign in to comment.