repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/picture_files_controller.rb | app/controllers/picture_files_controller.rb | class PictureFilesController < ApplicationController
before_action :set_picture_file, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_attachable, only: [ :index, :new ]
skip_before_action :store_current_location, only: :show
# GET /picture_files
# GET /picture_files.json
def index
if @attachable
@picture_files = @attachable.picture_files.attached.page(params[:page])
else
@picture_files = PictureFile.attached.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
end
end
# GET /picture_files/1
# GET /picture_files/1.json
def show
respond_to do |format|
format.html # show.html.erb
format.html.phone
end
end
def download
picture_file = PictureFile.find(params[:picture_file_id])
authorize picture_file, policy_class: PictureFilePolicy
redirect_to rails_storage_proxy_url(picture_file.attachment)
end
# GET /picture_files/new
def new
unless @attachable
redirect_to picture_files_url
return
end
# raise unless @event or @manifestation or @shelf or @agent
@picture_file = PictureFile.new
@picture_file.picture_attachable = @attachable
end
# GET /picture_files/1/edit
def edit
end
# POST /picture_files
# POST /picture_files.json
def create
@picture_file = PictureFile.new(picture_file_params)
respond_to do |format|
if @picture_file.save
format.html { redirect_to @picture_file, notice: t("controller.successfully_created", model: t("activerecord.models.picture_file")) }
format.json { render json: @picture_file, status: :created, location: @picture_file }
else
format.html { render action: "new" }
format.json { render json: @picture_file.errors, status: :unprocessable_entity }
end
end
end
# PUT /picture_files/1
# PUT /picture_files/1.json
def update
# 並べ替え
if params[:move]
move_position(@picture_file, params[:move], false)
case
when @picture_file.picture_attachable.is_a?(Shelf)
redirect_to picture_files_url(shelf_id: @picture_file.picture_attachable_id)
when @picture_file.picture_attachable.is_a?(Manifestation)
redirect_to picture_files_url(manifestation_id: @picture_file.picture_attachable_id)
else
if defined?(EnjuEvent)
if @picture_file.picture_attachable.is_a?(Event)
redirect_to picture_files_url(manifestation_id: @picture_file.picture_attachable_id)
else
redirect_to picture_files_url
end
else
redirect_to picture_files_url
end
end
return
end
respond_to do |format|
if @picture_file.update(picture_file_params)
format.html { redirect_to @picture_file, notice: t("controller.successfully_updated", model: t("activerecord.models.picture_file")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @picture_file.errors, status: :unprocessable_entity }
end
end
end
# DELETE /picture_files/1
# DELETE /picture_files/1.json
def destroy
attachable = @picture_file.picture_attachable
@picture_file.destroy
respond_to do |format|
flash[:notice] = t("controller.successfully_deleted", model: t("activerecord.models.picture_file"))
format.html {
case attachable.class.name
when "Manifestation"
redirect_to picture_files_url(manifestation_id: attachable.id)
when "Agent"
redirect_to picture_files_url(agent_id: attachable.id)
when "Shelf"
redirect_to picture_files_url(shelf_id: attachable.id)
else
if defined?(EnjuEvent)
if attachable.class.name == "Event"
redirect_to picture_files_url(event_id: attachable.id)
else
redirect_to picture_files_url
end
else
redirect_to picture_files_url
end
end
}
format.json { head :no_content }
end
end
private
def set_picture_file
@picture_file = PictureFile.find(params[:id])
authorize @picture_file
end
def check_policy
authorize PictureFile
end
def picture_file_params
params.require(:picture_file).permit(
:attachment, :picture_attachable_id, :picture_attachable_type
)
end
def get_attachable
get_manifestation
if @manifestation
@attachable = @manifestation
return
end
get_agent
if @agent
@attachable = @agent
return
end
get_event
if @event
@attachable = @event
return
end
get_shelf
if @shelf
@attachable = @shelf
nil
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/withdraws_controller.rb | app/controllers/withdraws_controller.rb | class WithdrawsController < ApplicationController
before_action :set_withdraw, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_basket, only: [ :index, :create ]
# GET /withdraws
# GET /withdraws.json
def index
if request.format.text?
@withdraws = Withdraw.order("withdraws.created_at DESC").page(params[:page]).per(65534)
else
if params[:withdraw]
@query = params[:withdraw][:item_identifier].to_s.strip
item = Item.find_by(item_identifier: @query) if @query.present?
end
if item
@withdraws = Withdraw.order("withdraws.created_at DESC").where(item_id: item.id).page(params[:page])
elsif @basket
@withdraws = @basket.withdraws.order("withdraws.created_at DESC").page(params[:page])
else
@withdraws = Withdraw.order("withdraws.created_at DESC").page(params[:page])
end
end
respond_to do |format|
format.html # index.html.erb
format.js { @withdraw = Withdraw.new }
format.text
end
end
# GET /withdraws/1
# GET /withdraws/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /new
def new
@basket = Basket.new
@basket.user = current_user
@basket.save!
@withdraw = Withdraw.new
authorize @withdraw, :new?
@withdraws = []
end
# GET /withdraws/new
# GET /withdraws/1/edit
def edit
end
# POST /withdraws
# POST /withdraws.json
def create
unless @basket
access_denied
return
end
@withdraw = Withdraw.new(withdraw_params)
@withdraw.basket = @basket
@withdraw.librarian = current_user
flash[:message] = ""
if @withdraw.item_identifier.blank?
flash[:message] << t("withdraw.enter_item_identifier") if @withdraw.item_identifier.blank?
else
item = Item.find_by(item_identifier: @withdraw.item_identifier.to_s.strip)
end
@withdraw.item = item
respond_to do |format|
if @withdraw.save
flash[:message] << t("withdraw.successfully_withdrawn", model: t("activerecord.models.withdraw"))
format.html { redirect_to withdraws_url(basket_id: @basket.id) }
format.json { render json: @withdraw, status: :created, location: @withdraw }
format.js { redirect_to withdraws_url(basket_id: @basket.id, format: :js) }
else
@withdraws = @basket.withdraws.page(params[:page])
format.html { render action: "index" }
format.json { render json: @withdraw.errors, status: :unprocessable_entity }
format.js { render action: "index" }
end
end
end
# PUT /withdraws/1
# PUT /withdraws/1.json
def update
respond_to do |format|
if @withdraw.update(withdraw_params)
format.html { redirect_to @withdraw, notice: t("controller.successfully_updated", model: t("activerecord.models.withdraw")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @withdraw.errors, status: :unprocessable_entity }
end
end
end
# DELETE /withdraws/1
# DELETE /withdraws/1.json
def destroy
@withdraw.destroy
respond_to do |format|
format.html { redirect_to withdraws_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.withdraw")) }
format.json { head :no_content }
end
end
private
def set_withdraw
@withdraw = Withdraw.find(params[:id])
authorize @withdraw
end
def check_policy
authorize Withdraw
end
def withdraw_params
params.require(:withdraw).permit(:item_identifier, :librarian_id, :item_id)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/agent_relationships_controller.rb | app/controllers/agent_relationships_controller.rb | class AgentRelationshipsController < ApplicationController
before_action :set_agent_relationship, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_agent
before_action :prepare_options, only: [ :new, :edit ]
# GET /agent_relationships
# GET /agent_relationships.json
def index
case
when @agent
@agent_relationships = @agent.agent_relationships.order("agent_relationships.position").page(params[:page])
else
@agent_relationships = AgentRelationship.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
end
end
# GET /agent_relationships/1
# GET /agent_relationships/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /agent_relationships/new
def new
if @agent.blank?
redirect_to agents_url
nil
else
@agent_relationship = AgentRelationship.new
@agent_relationship.agent = @agent
end
end
# GET /agent_relationships/1/edit
def edit
end
# POST /agent_relationships
# POST /agent_relationships.json
def create
@agent_relationship = AgentRelationship.new(agent_relationship_params)
respond_to do |format|
if @agent_relationship.save
format.html { redirect_to @agent_relationship, notice: t("controller.successfully_created", model: t("activerecord.models.agent_relationship")) }
format.json { render json: @agent_relationship, status: :created, location: @agent_relationship }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @agent_relationship.errors, status: :unprocessable_entity }
end
end
end
# PUT /agent_relationships/1
# PUT /agent_relationships/1.json
def update
# 並べ替え
if @agent && params[:move]
move_position(@agent_relationship, params[:move], false)
redirect_to agent_relationships_url(agent_id: @agent_relationship.parent_id)
return
end
respond_to do |format|
if @agent_relationship.update(agent_relationship_params)
format.html { redirect_to @agent_relationship, notice: t("controller.successfully_updated", model: t("activerecord.models.agent_relationship")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @agent_relationship.errors, status: :unprocessable_entity }
end
end
end
# DELETE /agent_relationships/1
# DELETE /agent_relationships/1.json
def destroy
@agent_relationship.destroy
respond_to do |format|
format.html {
flash[:notice] = t("controller.successfully_deleted", model: t("activerecord.models.agent_relationship"))
if @agent
redirect_to agents_url(agent_id: @agent.id)
else
redirect_to agent_relationships_url
end
}
format.json { head :no_content }
end
end
private
def set_agent_relationship
@agent_relationship = AgentRelationship.find(params[:id])
authorize @agent_relationship
end
def check_policy
authorize AgentRelationship
end
def agent_relationship_params
params.require(:agent_relationship).permit(
:parent_id, :child_id, :agent_relationship_type_id
)
end
def prepare_options
@agent_relationship_types = AgentRelationshipType.all
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/baskets_controller.rb | app/controllers/baskets_controller.rb | class BasketsController < ApplicationController
before_action :set_basket, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /baskets
# GET /baskets.json
def index
if current_user.has_role?("Librarian")
@baskets = Basket.page(params[:page])
else
redirect_to new_basket_url
return
end
respond_to do |format|
format.html # index.html.erb
end
end
# GET /baskets/1
# GET /baskets/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /baskets/new
def new
@basket = Basket.new
@basket.user_number = params[:user_number]
end
# GET /baskets/1/edit
def edit
end
# POST /baskets
# POST /baskets.json
def create
@basket = Basket.new(basket_params)
@user = Profile.where(user_number: @basket.user_number).first.try(:user) if @basket.user_number.present?
if @user
@basket.user = @user
end
respond_to do |format|
if @basket.save
format.html { redirect_to new_checked_item_url(basket_id: @basket.id), notice: t("controller.successfully_created", model: t("activerecord.models.basket")) }
format.json { render json: @basket, status: :created, location: @basket }
else
format.html { render action: "new" }
format.json { render json: @basket.errors, status: :unprocessable_entity }
end
end
end
# PUT /baskets/1
# PUT /baskets/1.json
def update
librarian = current_user
begin
unless @basket.basket_checkout(librarian)
redirect_to new_checked_item_url(basket_id: @basket.id)
return
end
rescue ActiveRecord::RecordInvalid
flash[:message] = t("checked_item.already_checked_out_try_again")
@basket.checked_items.delete_all
redirect_to new_checked_item_url(basket_id: @basket.id)
return
end
respond_to do |format|
# if @basket.update_attributes({})
if @basket.save(validate: false)
# 貸出完了時
format.html { redirect_to checkouts_url(user_id: @basket.user.username), notice: t("basket.checkout_completed") }
format.json { head :no_content }
else
format.html { redirect_to checked_items_url(basket_id: @basket.id) }
format.json { render json: @basket.errors, status: :unprocessable_entity }
end
end
end
# DELETE /baskets/1
# DELETE /baskets/1.json
def destroy
@basket.destroy
respond_to do |format|
format.html { redirect_to checkouts_url(user_id: @basket.user.username) }
format.json { head :no_content }
end
end
private
def set_basket
@basket = Basket.find(params[:id])
authorize @basket
end
def check_policy
authorize Basket
end
def basket_params
params.require(:basket).permit(:note, :user_number)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/bookmarks_controller.rb | app/controllers/bookmarks_controller.rb | class BookmarksController < ApplicationController
before_action :set_bookmark, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_user, only: :index
# GET /bookmarks
# GET /bookmarks.json
def index
search = Bookmark.search(include: [ :manifestation ])
query = params[:query].to_s.strip
if query.present?
@query = query.dup
end
user = @user
unless current_user.has_role?("Librarian")
if user and user != current_user and !user.profile.try(:share_bookmarks)
access_denied; return
end
if current_user == @user
redirect_to bookmarks_url
return
end
end
search.build do
fulltext query
order_by(:created_at, :desc)
if user
with(:user_id).equal_to user.id
else
with(:user_id).equal_to current_user.id
end
end
page = params[:page] || "1"
flash[:page] = page if page.to_i >= 1
search.query.paginate(page.to_i, Bookmark.default_per_page)
@bookmarks = search.execute!.results
respond_to do |format|
format.html # index.html.erb
end
end
# GET /bookmarks/1
# GET /bookmarks/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /bookmarks/new
def new
@bookmark = current_user.bookmarks.new(bookmark_params)
manifestation = @bookmark.get_manifestation
if manifestation
if manifestation.bookmarked?(current_user)
flash[:notice] = t("bookmark.already_bookmarked")
redirect_to manifestation
return
end
@bookmark.title = manifestation.original_title
else
@bookmark.title = Bookmark.get_title_from_url(@bookmark.url) unless @bookmark.title?
end
end
# GET /bookmarks/1/edit
def edit
end
# POST /bookmarks
# POST /bookmarks.json
def create
@bookmark = current_user.bookmarks.new(bookmark_params)
respond_to do |format|
if @bookmark.save
@bookmark.tag_index!
if params[:mode] == "tag_edit"
format.html { redirect_to @bookmark.manifestation, notice: t("controller.successfully_created", model: t("activerecord.models.bookmark")) }
format.json { render json: @bookmark, status: :created, location: @bookmark }
else
format.html { redirect_to @bookmark, notice: t("controller.successfully_created", model: t("activerecord.models.bookmark")) }
format.json { render json: @bookmark, status: :created, location: @bookmark }
end
else
@user = current_user
format.html { render action: "new" }
format.json { render json: @bookmark.errors, status: :unprocessable_entity }
end
end
session[:params][:bookmark] = nil if session[:params]
end
# PUT /bookmarks/1
# PUT /bookmarks/1.json
def update
unless @bookmark.url.try(:bookmarkable?)
access_denied; return
end
@bookmark.title = @bookmark.manifestation.try(:original_title)
@bookmark.taggings.where(tagger_id: @bookmark.user.id).destroy_all
respond_to do |format|
if @bookmark.update(bookmark_params)
@bookmark.tag_index!
case params[:mode]
when "tag_edit"
format.html { redirect_to @bookmark.manifestation, notice: t("controller.successfully_updated", model: t("activerecord.models.bookmark")) }
format.json { head :no_content }
else
format.html { redirect_to @bookmark, notice: t("controller.successfully_updated", model: t("activerecord.models.bookmark")) }
format.json { head :no_content }
end
else
format.html { render action: "edit" }
format.json { render json: @bookmark.errors, status: :unprocessable_entity }
end
end
end
# DELETE /bookmarks/1
# DELETE /bookmarks/1.json
def destroy
@bookmark.destroy
if @user
respond_to do |format|
format.html { redirect_to bookmarks_url(user_id: @user.username), notice: t("controller.successfully_deleted", model: t("activerecord.models.bookmark")) }
format.json { head :no_content }
end
else
respond_to do |format|
format.html { redirect_to bookmarks_url(user_id: @bookmark.user.username), notice: t("controller.successfully_deleted", model: t("activerecord.models.bookmark")) }
format.json { head :no_content }
end
end
end
private
def set_bookmark
@bookmark = Bookmark.find(params[:id])
authorize @bookmark
end
def check_policy
authorize Bookmark
end
def bookmark_params
params.require(:bookmark).permit(:title, :url, :note, :shared, :tag_list)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/orders_controller.rb | app/controllers/orders_controller.rb | class OrdersController < ApplicationController
before_action :set_order, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :set_order_list
before_action :set_purchase_request
# GET /orders
# GET /orders.json
def index
case
when @order_list
@orders = @order_list.orders.page(params[:page])
else
@orders = Order.page(params[:page])
end
@count = {}
@count[:query_result] = @orders.size
respond_to do |format|
format.html # index.html.erb
format.json { render json: @orders }
format.rss
format.atom
format.text
end
end
# GET /orders/1
# GET /orders/1.json
def show
@order = Order.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @order }
end
end
# GET /orders/new
# GET /orders/new.json
def new
@order_lists = OrderList.not_ordered
if @order_lists.blank?
flash[:notice] = t("order.create_order_list")
redirect_to new_order_list_url
return
end
unless @purchase_request
flash[:notice] = t("order.specify_purchase_request")
redirect_to purchase_requests_url
return
end
@order = Order.new(params[:order])
end
# GET /orders/1/edit
def edit
@order = Order.find(params[:id])
@order_lists = OrderList.not_ordered
end
# POST /orders
# POST /orders.json
def create
@order = Order.new(order_params)
respond_to do |format|
if @order.save
flash[:notice] = t("controller.successfully_created", model: t("activerecord.models.order"))
if @purchase_request
format.html { redirect_to purchase_request_order_url(@order.purchase_request, @order) }
format.json { render json: @order, status: :created, location: @order }
else
format.html { redirect_to(@order) }
format.json { render json: @order, status: :created, location: @order }
end
else
@order_lists = OrderList.not_ordered
format.html { render action: "new" }
format.json { render json: @order.errors, status: :unprocessable_entity }
end
end
end
# PUT /orders/1
# PUT /orders/1.json
def update
@order = Order.find(params[:id])
respond_to do |format|
if @order.update(order_params)
flash[:notice] = t("controller.successfully_updated", model: t("activerecord.models.order"))
if @purchase_request
format.html { redirect_to purchase_request_order_url(@order.purchase_request, @order) }
format.json { head :no_content }
else
format.html { redirect_to(@order) }
format.json { head :no_content }
end
else
@order_lists = OrderList.not_ordered
format.html { render action: "edit" }
format.json { render json: @order.errors, status: :unprocessable_entity }
end
end
end
# DELETE /orders/1
# DELETE /orders/1.json
def destroy
@order = Order.find(params[:id])
@order.destroy
respond_to do |format|
if @order_list
format.html { redirect_to purchase_requests_url(order_list: @order_list.id) }
format.json { head :no_content }
else
format.html { redirect_to orders_url }
format.json { head :no_content }
end
end
end
private
def set_order
@order = Order.find(params[:id])
authorize @order
end
def set_order_list
@order_list = OrderList.find_by(id: params[:order_list_id])
authorize @order_list if @order_list
end
def set_purchase_request
@purchase_request = PurchaseRequest.find_by(id: params[:purchase_request_id])
authorize @purchase_request if @purchase_request
end
def check_policy
authorize Order
end
def order_params
params.require(:order).permit(:order_list_id, :purchase_request_id)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/agent_import_results_controller.rb | app/controllers/agent_import_results_controller.rb | class AgentImportResultsController < ApplicationController
before_action :set_agent_import_result, only: [ :show, :destroy ]
before_action :check_policy, only: [ :index ]
# GET /agent_import_results
# GET /agent_import_results.json
def index
@agent_import_file = AgentImportFile.find_by(id: params[:agent_import_file_id])
if @agent_import_file
authorize @agent_import_file, :show?, policy_class: AgentImportFilePolicy
@agent_import_results = @agent_import_file.agent_import_results.page(params[:page])
else
@agent_import_results = AgentImportResult.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
format.text
end
end
# GET /agent_import_results/1
# GET /agent_import_results/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# DELETE /agent_import_results/1
# DELETE /agent_import_results/1.json
def destroy
@agent_import_result.destroy
respond_to do |format|
format.html { redirect_to agent_import_results_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.agent_import_result")) }
format.json { head :no_content }
end
end
private
def set_agent_import_result
@agent_import_result = AgentImportResult.find(params[:id])
authorize @agent_import_result
end
def check_policy
authorize AgentImportResult
end
def agent_import_result_params
params.require(:agent_import_result).permit(
:agent_import_file_id, :agent_id, :body
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/subject_types_controller.rb | app/controllers/subject_types_controller.rb | class SubjectTypesController < ApplicationController
before_action :set_subject_type, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /subject_types
# GET /subject_types.json
def index
@subject_types = SubjectType.order(:position)
respond_to do |format|
format.html # index.html.erb
end
end
# GET /subject_types/1
# GET /subject_types/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /subject_types/new
def new
@subject_type = SubjectType.new
end
# GET /subject_types/1/edit
def edit
end
# POST /subject_types
# POST /subject_types.json
def create
@subject_type = SubjectType.new(subject_type_params)
respond_to do |format|
if @subject_type.save
format.html { redirect_to @subject_type, notice: t("controller.successfully_created", model: t("activerecord.models.subject_type")) }
format.json { render json: @subject_type, status: :created, location: @subject_type }
else
format.html { render action: "new" }
format.json { render json: @subject_type.errors, status: :unprocessable_entity }
end
end
end
# PUT /subject_types/1
# PUT /subject_types/1.json
def update
if params[:move]
move_position(@subject_type, params[:move])
return
end
respond_to do |format|
if @subject_type.update(subject_type_params)
format.html { redirect_to @subject_type, notice: t("controller.successfully_updated", model: t("activerecord.models.subject_type")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @subject_type.errors, status: :unprocessable_entity }
end
end
end
# DELETE /subject_types/1
# DELETE /subject_types/1.json
def destroy
@subject_type.destroy
respond_to do |format|
format.html { redirect_to subject_types_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.subject_type")) }
format.json { head :no_content }
end
end
private
def set_subject_type
@subject_type = SubjectType.find(params[:id])
authorize @subject_type
end
def check_policy
authorize SubjectType
end
def subject_type_params
params.require(:subject_type).permit(:name, :display_name, :note)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/manifestation_checkout_stats_controller.rb | app/controllers/manifestation_checkout_stats_controller.rb | class ManifestationCheckoutStatsController < ApplicationController
before_action :set_manifestation_checkout_stat, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
after_action :convert_charset, only: :show
# GET /manifestation_checkout_stats
# GET /manifestation_checkout_stats.json
def index
@manifestation_checkout_stats = ManifestationCheckoutStat.page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /manifestation_checkout_stats/1
# GET /manifestation_checkout_stats/1.json
def show
if request.format.text?
per_page = 65534
else
per_page = CheckoutStatHasManifestation.default_per_page
end
@carrier_type_results = Checkout.where(
Checkout.arel_table[:created_at].gteq @manifestation_checkout_stat.start_date
).where(
Checkout.arel_table[:created_at].lt @manifestation_checkout_stat.end_date
).joins(item: :manifestation).group(
"checkouts.shelf_id", :carrier_type_id
).merge(
Manifestation.where(carrier_type_id: CarrierType.pluck(:id))
).count(:id)
@checkout_type_results = Checkout.where(
Checkout.arel_table[:created_at].gteq @manifestation_checkout_stat.start_date
).where(
Checkout.arel_table[:created_at].lt @manifestation_checkout_stat.end_date
).joins(item: :manifestation).group(
"checkouts.shelf_id", :checkout_type_id
).count(:id)
@stats = Checkout.where(
Checkout.arel_table[:created_at].gteq @manifestation_checkout_stat.start_date
).where(
Checkout.arel_table[:created_at].lt @manifestation_checkout_stat.end_date
).joins(item: :manifestation).group(:manifestation_id).merge(
Manifestation.where(carrier_type_id: CarrierType.pluck(:id))
).order("count_id DESC").page(params[:page]).per(per_page)
respond_to do |format|
format.html # show.html.erb
format.text
format.js
end
end
# GET /manifestation_checkout_stats/new
def new
@manifestation_checkout_stat = ManifestationCheckoutStat.new
@manifestation_checkout_stat.start_date = Time.zone.now.beginning_of_day
@manifestation_checkout_stat.end_date = Time.zone.now.beginning_of_day
end
# GET /manifestation_checkout_stats/1/edit
def edit
end
# POST /manifestation_checkout_stats
# POST /manifestation_checkout_stats.json
def create
@manifestation_checkout_stat = ManifestationCheckoutStat.new(manifestation_checkout_stat_params)
@manifestation_checkout_stat.user = current_user
respond_to do |format|
if @manifestation_checkout_stat.save
ManifestationCheckoutStatJob.perform_later(@manifestation_checkout_stat)
format.html { redirect_to @manifestation_checkout_stat, notice: t("controller.successfully_created", model: t("activerecord.models.manifestation_checkout_stat")) }
format.json { render json: @manifestation_checkout_stat, status: :created, location: @manifestation_checkout_stat }
else
format.html { render action: "new" }
format.json { render json: @manifestation_checkout_stat.errors, status: :unprocessable_entity }
end
end
end
# PUT /manifestation_checkout_stats/1
# PUT /manifestation_checkout_stats/1.json
def update
respond_to do |format|
if @manifestation_checkout_stat.update(manifestation_checkout_stat_params)
if @manifestation_checkout_stat.mode == "import"
ManifestationCheckoutStatJob.perform_later(@manifestation_checkout_stat)
end
format.html { redirect_to @manifestation_checkout_stat, notice: t("controller.successfully_updated", model: t("activerecord.models.manifestation_checkout_stat")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @manifestation_checkout_stat.errors, status: :unprocessable_entity }
end
end
end
# DELETE /manifestation_checkout_stats/1
# DELETE /manifestation_checkout_stats/1.json
def destroy
@manifestation_checkout_stat.destroy
respond_to do |format|
format.html { redirect_to manifestation_checkout_stats_url }
format.json { head :no_content }
end
end
private
def set_manifestation_checkout_stat
@manifestation_checkout_stat = ManifestationCheckoutStat.find(params[:id])
authorize @manifestation_checkout_stat
end
def check_policy
authorize ManifestationCheckoutStat
end
def manifestation_checkout_stat_params
params.require(:manifestation_checkout_stat).permit(
:start_date, :end_date, :note, :mode
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/news_feeds_controller.rb | app/controllers/news_feeds_controller.rb | class NewsFeedsController < ApplicationController
before_action :set_news_feed, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /news_feeds
# GET /news_feeds.json
def index
@news_feeds = NewsFeed.page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /news_feeds/1
# GET /news_feeds/1.json
def show
if params[:mode] == "force_reload"
@news_feed.force_reload
end
respond_to do |format|
format.html # show.html.erb
end
end
# GET /news_feeds/new
def new
@news_feed = NewsFeed.new
end
# GET /news_feeds/1/edit
def edit
end
# POST /news_feeds
# POST /news_feeds.json
def create
@news_feed = NewsFeed.new(news_feed_params)
respond_to do |format|
if @news_feed.save
flash[:notice] = t("controller.successfully_created", model: t("activerecord.models.news_feed"))
format.html { redirect_to(@news_feed) }
format.json { render json: @news_feed, status: :created, location: @news_feed }
else
format.html { render action: "new" }
format.json { render json: @news_feed.errors, status: :unprocessable_entity }
end
end
end
# PUT /news_feeds/1
# PUT /news_feeds/1.json
def update
if params[:move]
move_position(@news_feed, params[:move])
return
end
if params[:mode] == "force_reload"
expire_cache
end
respond_to do |format|
if @news_feed.update(news_feed_params)
flash[:notice] = t("controller.successfully_updated", model: t("activerecord.models.news_feed"))
format.html { redirect_to(@news_feed) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @news_feed.errors, status: :unprocessable_entity }
end
end
end
# DELETE /news_feeds/1
# DELETE /news_feeds/1.json
def destroy
@news_feed.destroy
respond_to do |format|
format.html { redirect_to news_feeds_url }
format.json { head :no_content }
end
end
private
def set_news_feed
@news_feed = NewsFeed.find(params[:id])
authorize @news_feed
end
def check_policy
authorize NewsFeed
end
def news_feed_params
params.require(:news_feed).permit(:title, :url)
end
def expire_cache
@news_feed.force_reload
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/inventory_files_controller.rb | app/controllers/inventory_files_controller.rb | class InventoryFilesController < ApplicationController
before_action :set_inventory_file, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :prepare_options, only: [ :new, :edit ]
# GET /inventory_files
# GET /inventory_files.json
def index
@inventory_files = InventoryFile.page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /inventory_files/1
# GET /inventory_files/1.json
def show
@inventories = @inventory_file.inventories.page(params[:page])
respond_to do |format|
format.html # show.html.erb
end
end
# GET /inventory_files/new
def new
@inventory_file = InventoryFile.new
end
# GET /inventory_files/1/edit
def edit
end
# POST /inventory_files
# POST /inventory_files.json
def create
@inventory_file = InventoryFile.new(inventory_file_params)
@inventory_file.user = current_user
respond_to do |format|
if @inventory_file.save
flash[:notice] = t("controller.successfully_created", model: t("activerecord.models.inventory_file"))
@inventory_file.import
format.html { redirect_to(@inventory_file) }
format.json { render json: @inventory_file, status: :created, location: @inventory_file }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @inventory_file.errors, status: :unprocessable_entity }
end
end
end
# PUT /inventory_files/1
# PUT /inventory_files/1.json
def update
respond_to do |format|
if @inventory_file.update(inventory_file_params)
flash[:notice] = t("controller.successfully_updated", model: t("activerecord.models.inventory_file"))
format.html { redirect_to(@inventory_file) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @inventory_file.errors, status: :unprocessable_entity }
end
end
end
# DELETE /inventory_files/1
# DELETE /inventory_files/1.json
def destroy
@inventory_file.destroy
respond_to do |format|
format.html { redirect_to inventory_files_url }
format.json { head :no_content }
end
end
private
def set_inventory_file
@inventory_file = InventoryFile.find(params[:id])
authorize @inventory_file
end
def check_policy
authorize InventoryFile
end
def prepare_options
@libraries = Library.order(:position)
@shelves = Shelf.order(:position)
end
def inventory_file_params
params.require(:inventory_file).permit(:attachment, :shelf_id, :note)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/series_statement_merge_lists_controller.rb | app/controllers/series_statement_merge_lists_controller.rb | class SeriesStatementMergeListsController < ApplicationController
before_action :set_series_statement_merge_list, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /series_statement_merge_lists
# GET /series_statement_merge_lists.json
def index
@series_statement_merge_lists = SeriesStatementMergeList.page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /series_statement_merge_lists/1
# GET /series_statement_merge_lists/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /series_statement_merge_lists/new
def new
@series_statement_merge_list = SeriesStatementMergeList.new
end
# GET /series_statement_merge_lists/1/edit
def edit
end
# POST /series_statement_merge_lists
# POST /series_statement_merge_lists.json
def create
@series_statement_merge_list = SeriesStatementMergeList.new(series_statement_merge_list_params)
respond_to do |format|
if @series_statement_merge_list.save
flash[:notice] = t("controller.successfully_created", model: t("activerecord.models.series_statement_merge_list"))
format.html { redirect_to(@series_statement_merge_list) }
format.json { render json: @series_statement_merge_list, status: :created, location: @series_statement_merge_list }
else
format.html { render action: "new" }
format.json { render json: @series_statement_merge_list.errors, status: :unprocessable_entity }
end
end
end
# PUT /series_statement_merge_lists/1
# PUT /series_statement_merge_lists/1.json
def update
respond_to do |format|
if @series_statement_merge_list.update(series_statement_merge_list_params)
if params[:mode] == "merge"
selected_series_statement = SeriesStatement.find(params[:selected_series_statement_id]) rescue nil
if selected_series_statement
flash[:notice] = t("merge_list.successfully_merged", model: t("activerecord.models.series_statement"))
else
flash[:notice] = t("merge_list.specify_id", model: t("activerecord.models.series_statement"))
redirect_to series_statement_merge_list_url(@series_statement_merge_list)
return
end
else
flash[:notice] = t("controller.successfully_updated", model: t("activerecord.models.series_statement_merge_list"))
end
format.html { redirect_to(@series_statement_merge_list) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @series_statement_merge_list.errors, status: :unprocessable_entity }
end
end
end
# DELETE /series_statement_merge_lists/1
# DELETE /series_statement_merge_lists/1.json
def destroy
@series_statement_merge_list.destroy
respond_to do |format|
format.html { redirect_to(series_statement_merge_lists_url) }
format.json { head :no_content }
end
end
private
def set_series_statement_merge_list
@series_statement_merge_list = SeriesStatementMergeList.find(params[:id])
authorize @series_statement_merge_list
end
def check_policy
authorize SeriesStatementMergeList
end
def series_statement_merge_list_params
params.require(:series_statement_merge_list).permit(:title)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/countries_controller.rb | app/controllers/countries_controller.rb | class CountriesController < ApplicationController
before_action :set_country, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /countries
# GET /countries.json
def index
@countries = Country.page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /countries/1
# GET /countries/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /countries/new
def new
@country = Country.new
end
# GET /countries/1/edit
def edit
end
# POST /countries
# POST /countries.json
def create
@country = Country.new(country_params)
respond_to do |format|
if @country.save
format.html { redirect_to @country, notice: t("controller.successfully_created", model: t("activerecord.models.country")) }
format.json { render json: @country, status: :created, location: @country }
else
format.html { render action: "new" }
format.json { render json: @country.errors, status: :unprocessable_entity }
end
end
end
# PUT /countries/1
# PUT /countries/1.json
def update
if params[:move]
move_position(@country, params[:move])
return
end
respond_to do |format|
if @country.update(country_params)
format.html { redirect_to @country, notice: t("controller.successfully_updated", model: t("activerecord.models.country")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @country.errors, status: :unprocessable_entity }
end
end
end
# DELETE /countries/1
# DELETE /countries/1.json
def destroy
@country.destroy
respond_to do |format|
format.html { redirect_to countries_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.country")) }
format.json { head :no_content }
end
end
private
def set_country
@country = Country.find(params[:id])
authorize @country
end
def check_policy
authorize Country
end
def country_params
params.require(:country).permit(
:name, :display_name, :alpha_2, :alpha_3, :numeric_3, :note
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/use_restrictions_controller.rb | app/controllers/use_restrictions_controller.rb | class UseRestrictionsController < ApplicationController
before_action :set_use_restriction, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /use_restrictions
# GET /use_restrictions.json
def index
@use_restrictions = UseRestriction.order(:position)
respond_to do |format|
format.html # index.html.erb
end
end
# GET /use_restrictions/1
# GET /use_restrictions/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /use_restrictions/new
def new
@use_restriction = UseRestriction.new
end
# GET /use_restrictions/1/edit
def edit
end
# POST /use_restrictions
# POST /use_restrictions.json
def create
@use_restriction = UseRestriction.new(use_restriction_params)
respond_to do |format|
if @use_restriction.save
format.html { redirect_to @use_restriction, notice: t("controller.successfully_created", model: t("activerecord.models.use_restriction")) }
format.json { render json: @use_restriction, status: :created, location: @use_restriction }
else
format.html { render action: "new" }
format.json { render json: @use_restriction.errors, status: :unprocessable_entity }
end
end
end
# PUT /use_restrictions/1
# PUT /use_restrictions/1.json
def update
if params[:move]
move_position(@use_restriction, params[:move])
return
end
respond_to do |format|
if @use_restriction.update(use_restriction_params)
format.html { redirect_to @use_restriction, notice: t("controller.successfully_updated", model: t("activerecord.models.use_restriction")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @use_restriction.errors, status: :unprocessable_entity }
end
end
end
# DELETE /use_restrictions/1
# DELETE /use_restrictions/1.json
def destroy
@use_restriction.destroy
respond_to do |format|
format.html { redirect_to use_restrictions_url }
format.json { head :no_content }
end
end
private
def set_use_restriction
@use_restriction = UseRestriction.find(params[:id])
authorize @use_restriction
end
def check_policy
authorize UseRestriction
end
def use_restriction_params
params.require(:use_restriction).permit(:name, :display_name, :note)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/item_custom_properties_controller.rb | app/controllers/item_custom_properties_controller.rb | class ItemCustomPropertiesController < ApplicationController
before_action :set_item_custom_property, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /item_custom_properties
def index
@item_custom_properties = ItemCustomProperty.order(:position)
end
# GET /item_custom_properties/1
def show
end
# GET /item_custom_properties/new
def new
@item_custom_property = ItemCustomProperty.new
end
# GET /item_custom_properties/1/edit
def edit
end
# POST /item_custom_properties
def create
@item_custom_property = ItemCustomProperty.new(item_custom_property_params)
if @item_custom_property.save
redirect_to @item_custom_property, notice: t("controller.successfully_created", model: t("activerecord.models.item_custom_property"))
else
render :new
end
end
# PATCH/PUT /item_custom_properties/1
def update
if params[:move]
move_position(@item_custom_property, params[:move])
return
end
if @item_custom_property.update(item_custom_property_params)
redirect_to @item_custom_property, notice: t("controller.successfully_updated", model: t("activerecord.models.item_custom_property"))
else
render :edit
end
end
# DELETE /item_custom_properties/1
def destroy
@item_custom_property.destroy
redirect_to item_custom_properties_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.item_custom_property"))
end
private
# Use callbacks to share common setup or constraints between actions.
def set_item_custom_property
@item_custom_property = ItemCustomProperty.find(params[:id])
authorize @item_custom_property
end
def check_policy
authorize ItemCustomProperty
end
# Only allow a trusted parameter "white list" through.
def item_custom_property_params
params.require(:item_custom_property).permit(:name, :display_name, :note)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/news_posts_controller.rb | app/controllers/news_posts_controller.rb | class NewsPostsController < ApplicationController
before_action :set_news_post, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :prepare_options, only: [ :new, :edit ]
# GET /news_posts
# GET /news_posts.json
def index
if current_user.try(:has_role?, "Librarian")
@news_posts = NewsPost.page(params[:page])
else
@news_posts = NewsPost.published.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
format.rss
format.atom
end
end
# GET /news_posts/1
# GET /news_posts/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /news_posts/new
def new
@news_post = NewsPost.new
end
# GET /news_posts/1/edit
def edit
end
# POST /news_posts
# POST /news_posts.json
def create
@news_post = NewsPost.new(news_post_params)
@news_post.user = current_user
respond_to do |format|
if @news_post.save
format.html { redirect_to(@news_post, notice: t("controller.successfully_created", model: t("activerecord.models.news_post"))) }
format.json { render json: @news_post, status: :created, location: @news_post }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @news_post.errors, status: :unprocessable_entity }
end
end
end
# PUT /news_posts/1
# PUT /news_posts/1.json
def update
if params[:move]
move_position(@news_post, params[:move])
return
end
respond_to do |format|
if @news_post.update(news_post_params)
format.html { redirect_to(@news_post, notice: t("controller.successfully_updated", model: t("activerecord.models.news_post"))) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @news_post.errors, status: :unprocessable_entity }
end
end
end
# DELETE /news_posts/1
# DELETE /news_posts/1.json
def destroy
@news_post.destroy
respond_to do |format|
format.html { redirect_to(news_posts_url) }
format.json { head :no_content }
end
end
private
def set_news_post
@news_post = NewsPost.find(params[:id])
authorize @news_post
end
def check_policy
authorize NewsPost
end
def news_post_params
params.require(:news_post).permit(:title, :body)
end
def prepare_options
@roles = Role.all
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/user_import_results_controller.rb | app/controllers/user_import_results_controller.rb | class UserImportResultsController < ApplicationController
before_action :set_user_import_result, only: [ :show, :destroy ]
before_action :check_policy, only: [ :index ]
# GET /user_import_results
# GET /user_import_results.json
def index
@user_import_file = UserImportFile.find_by(id: params[:user_import_file_id])
if @user_import_file
@user_import_results = @user_import_file.user_import_results.page(params[:page])
else
@user_import_results = UserImportResult.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
format.text
end
end
# GET /user_import_results/1
# GET /user_import_results/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# DELETE /user_import_results/1
# DELETE /user_import_results/1.json
def destroy
@user_import_result.destroy
respond_to do |format|
format.html { redirect_to user_import_results_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.user_import_result")) }
format.json { head :no_content }
end
end
private
def set_user_import_result
@user_import_result = UserImportResult.find(params[:id])
authorize @user_import_result
end
def check_policy
authorize UserImportResult
end
def user_import_result_params
params.require(:user_import_result).permit(
:user_import_file_id, :user_id, :body
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/resource_import_results_controller.rb | app/controllers/resource_import_results_controller.rb | class ResourceImportResultsController < ApplicationController
before_action :set_resource_import_result, only: [ :show, :destroy ]
before_action :check_policy, only: [ :index ]
# GET /resource_import_results
# GET /resource_import_results.json
def index
@resource_import_file = ResourceImportFile.find_by(id: params[:resource_import_file_id])
if @resource_import_file
if request.format.text?
@resource_import_results = @resource_import_file.resource_import_results
else
@resource_import_results = @resource_import_file.resource_import_results.page(params[:page])
end
else
@resource_import_results = ResourceImportResult.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
format.text
end
end
# GET /resource_import_results/1
# GET /resource_import_results/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# DELETE /resource_import_results/1
# DELETE /resource_import_results/1.json
def destroy
@resource_import_result.destroy
respond_to do |format|
format.html { redirect_to resource_import_results_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.resource_import_result")) }
format.json { head :no_content }
end
end
private
def set_resource_import_result
@resource_import_result = ResourceImportResult.find(params[:id])
authorize @resource_import_result
end
def check_policy
authorize ResourceImportResult
end
def resource_import_result_params
params.require(:resource_import_result).permit(
:resource_import_file_id, :manifestation_id, :item_id, :body
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/produces_controller.rb | app/controllers/produces_controller.rb | class ProducesController < ApplicationController
before_action :set_produce, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_agent, :get_manifestation
before_action :prepare_options, only: [ :new, :edit ]
# GET /produces
# GET /produces.json
def index
case
when @agent
@produces = @agent.produces.order("produces.position").page(params[:page])
when @manifestation
@produces = @manifestation.produces.order("produces.position").page(params[:page])
else
@produces = Produce.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
end
end
# GET /produces/1
# GET /produces/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /produces/new
def new
if @agent && @manifestation.blank?
redirect_to agent_manifestations_url(@agent)
nil
elsif @manifestation && @agent.blank?
redirect_to manifestation_agents_url(@manifestation)
nil
else
@produce = Produce.new
@produce.manifestation = @manifestation
@produce.agent = @agent
end
end
# GET /produces/1/edit
def edit
end
# POST /produces
# POST /produces.json
def create
@produce = Produce.new(produce_params)
respond_to do |format|
if @produce.save
format.html { redirect_to @produce, notice: t("controller.successfully_created", model: t("activerecord.models.produce")) }
format.json { render json: @produce, status: :created, location: @produce }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @produce.errors, status: :unprocessable_entity }
end
end
end
# PUT /produces/1
# PUT /produces/1.json
def update
if @manifestation && params[:move]
move_position(@produce, params[:move], false)
redirect_to produces_url(manifestation_id: @produce.manifestation_id)
return
end
respond_to do |format|
if @produce.update(produce_params)
format.html { redirect_to @produce, notice: t("controller.successfully_updated", model: t("activerecord.models.produce")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @produce.errors, status: :unprocessable_entity }
end
end
end
# DELETE /produces/1
# DELETE /produces/1.json
def destroy
@produce.destroy
respond_to do |format|
format.html {
flash[:notice] = t("controller.successfully_deleted", model: t("activerecord.models.produce"))
case
when @agent
redirect_to agent_manifestations_url(@agent)
when @manifestation
redirect_to manifestation_agents_url(@manifestation)
else
redirect_to produces_url
end
}
format.json { head :no_content }
end
end
private
def set_produce
@produce = Produce.find(params[:id])
authorize @produce
end
def check_policy
authorize Produce
end
def produce_params
params.require(:produce).permit(
:agent_id, :manifestation_id, :produce_type_id, :position
)
end
def prepare_options
@produce_types = ProduceType.all
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/agents_controller.rb | app/controllers/agents_controller.rb | class AgentsController < ApplicationController
before_action :set_agent, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_work, :get_expression, :get_manifestation, :get_item, :get_agent, except: [ :update, :destroy ]
before_action :get_agent_merge_list, except: [ :create, :update, :destroy ]
before_action :prepare_options, only: [ :new, :edit ]
# GET /agents
# GET /agents.json
def index
if params[:mode] == "add"
unless current_user.try(:has_role?, "Librarian")
access_denied
return
end
end
query = params[:query].to_s.strip
if query.size == 1
query = "#{query}*"
end
@query = query.dup
query = query.gsub(" ", " ")
order = nil
@count = {}
search = Agent.search(include: [ :agent_type, :required_role ])
search.data_accessor_for(Agent).select = [
:id,
:full_name,
:full_name_transcription,
:agent_type_id,
:required_role_id,
:created_at,
:updated_at,
:date_of_birth
]
set_role_query(current_user, search)
if params[:mode] == "recent"
query = "#{query} created_at_d:[NOW-1MONTH TO NOW]"
end
if query.present?
search.build do
fulltext query
end
end
unless params[:mode] == "add"
work = @work
expression = @expression
manifestation = @manifestation
agent = @agent
agent_merge_list = @agent_merge_list
search.build do
with(:work_ids).equal_to work.id if work
with(:expression_ids).equal_to expression.id if expression
with(:manifestation_ids).equal_to manifestation.id if manifestation
with(:original_agent_ids).equal_to agent.id if agent
with(:agent_merge_list_ids).equal_to agent_merge_list.id if agent_merge_list
end
end
role = current_user.try(:role) || Role.default
search.build do
with(:required_role_id).less_than_or_equal_to role.id
end
page = params[:page].to_i || 1
page = 1 if page.zero?
search.query.paginate(page, Agent.default_per_page)
@agents = search.execute!.results
flash[:page_info] = { page: page, query: query }
respond_to do |format|
format.html # index.html.erb
format.xml { render xml: @agents }
format.rss { render layout: false }
format.atom
format.json
format.html.phone
end
end
# GET /agents/1
# GET /agents/1.json
def show
case
when @work
@agent = @work.creators.find(params[:id])
when @manifestation
@agent = @manifestation.publishers.find(params[:id])
when @item
@agent = @item.agents.find(params[:id])
end
agent = @agent
role = current_user.try(:role) || Role.default
@works = Manifestation.search do
with(:creator_ids).equal_to agent.id
with(:required_role_id).less_than_or_equal_to role.id
paginate page: params[:work_list_page], per_page: Manifestation.default_per_page
end.results
@expressions = Manifestation.search do
with(:contributor_ids).equal_to agent.id
with(:required_role_id).less_than_or_equal_to role.id
paginate page: params[:expression_list_page], per_page: Manifestation.default_per_page
end.results
@manifestations = Manifestation.search do
with(:publisher_ids).equal_to agent.id
with(:required_role_id).less_than_or_equal_to role.id
paginate page: params[:manifestation_list_page], per_page: Manifestation.default_per_page
end.results
respond_to do |format|
format.html # show.html.erb
format.json
format.js
format.html.phone
end
end
# GET /agents/new
def new
@agent = Agent.new
@agent.required_role = Role.find_by(name: "Guest")
@agent.language = Language.find_by(iso_639_1: I18n.default_locale.to_s) || Language.first
@agent.country = current_user.profile.library.country
prepare_options
end
# GET /agents/1/edit
def edit
prepare_options
end
# POST /agents
# POST /agents.json
def create
@agent = Agent.new(agent_params)
respond_to do |format|
if @agent.save
case
when @work
@agent.works << @work
when @manifestation
@agent.manifestations << @manifestation
when @item
@agent.items << @item
end
format.html { redirect_to @agent, notice: t("controller.successfully_created", model: t("activerecord.models.agent")) }
format.json { render json: @agent, status: :created, location: @agent }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @agent.errors, status: :unprocessable_entity }
end
end
end
# PUT /agents/1
# PUT /agents/1.json
def update
respond_to do |format|
if @agent.update(agent_params)
format.html { redirect_to @agent, notice: t("controller.successfully_updated", model: t("activerecord.models.agent")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @agent.errors, status: :unprocessable_entity }
end
end
end
# DELETE /agents/1
# DELETE /agents/1.json
def destroy
@agent.destroy
respond_to do |format|
format.html { redirect_to agents_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.agent")) }
format.json { head :no_content }
end
end
private
def set_agent
@agent = Agent.find(params[:id])
authorize @agent
end
def check_policy
authorize Agent
end
def agent_params
params.require(:agent).permit(
:last_name, :middle_name, :first_name,
:last_name_transcription, :middle_name_transcription,
:first_name_transcription, :corporate_name, :corporate_name_transcription,
:full_name, :full_name_transcription, :full_name_alternative,
:other_designation, :language_id,
:country_id, :agent_type_id, :note, :required_role_id, :email, :url,
:full_name_alternative_transcription, :title,
:agent_identifier
)
end
def prepare_options
@countries = Country.all_cache
@agent_types = AgentType.all
@roles = Role.all
@languages = Language.all
@agent_type = AgentType.find_by(name: "person")
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/event_export_files_controller.rb | app/controllers/event_export_files_controller.rb | class EventExportFilesController < ApplicationController
before_action :set_event_export_file, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /event_export_files
# GET /event_export_files.json
def index
@event_export_files = EventExportFile.order("id DESC").page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /event_export_files/1
# GET /event_export_files/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /event_export_files/new
def new
@event_export_file = EventExportFile.new
@event_export_file.user = current_user
end
# GET /event_export_files/1/edit
def edit
end
# POST /event_export_files
# POST /event_export_files.json
def create
@event_export_file = EventExportFile.new(event_export_file_params)
@event_export_file.user = current_user
respond_to do |format|
if @event_export_file.save
if @event_export_file.mode == "export"
EventExportFileJob.perform_later(@event_export_file)
end
format.html { redirect_to @event_export_file, notice: t("export.successfully_created", model: t("activerecord.models.event_export_file")) }
format.json { render json: @event_export_file, status: :created, location: @event_export_file }
else
format.html { render action: "new" }
format.json { render json: @event_export_file.errors, status: :unprocessable_entity }
end
end
end
# PUT /event_export_files/1
# PUT /event_export_files/1.json
def update
respond_to do |format|
if @event_export_file.update(event_export_file_params)
if @event_export_file.mode == "export"
EventExportFileJob.perform_later(@event_export_file)
end
format.html { redirect_to @event_export_file, notice: t("controller.successfully_updated", model: t("activerecord.models.event_export_file")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @event_export_file.errors, status: :unprocessable_entity }
end
end
end
# DELETE /event_export_files/1
# DELETE /event_export_files/1.json
def destroy
@event_export_file.destroy
respond_to do |format|
format.html { redirect_to event_export_files_url }
format.json { head :no_content }
end
end
private
def set_event_export_file
@event_export_file = EventExportFile.find(params[:id])
authorize @event_export_file
end
def check_policy
authorize EventExportFile
end
def event_export_file_params
params.require(:event_export_file).permit(:mode)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/item_has_use_restrictions_controller.rb | app/controllers/item_has_use_restrictions_controller.rb | class ItemHasUseRestrictionsController < ApplicationController
before_action :set_item_has_use_restriction, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_item
# GET /item_has_use_restrictions
# GET /item_has_use_restrictions.json
def index
if @item
@item_has_use_restrictions = @item.item_has_use_restrictions.order("item_has_use_restrictions.id DESC").page(params[:page])
else
@item_has_use_restrictions = ItemHasUseRestriction.order("id DESC").page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
end
end
# GET /item_has_use_restrictions/1
# GET /item_has_use_restrictions/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /item_has_use_restrictions/new
def new
@item_has_use_restriction = ItemHasUseRestriction.new
@use_restrictions = UseRestriction.all
end
# GET /item_has_use_restrictions/1/edit
def edit
@use_restrictions = UseRestriction.all
end
# POST /item_has_use_restrictions
# POST /item_has_use_restrictions.json
def create
@item_has_use_restriction = ItemHasUseRestriction.new(item_has_use_restriction_params)
respond_to do |format|
if @item_has_use_restriction.save
format.html { redirect_to @item_has_use_restriction, notice: t("controller.successfully_created", model: t("activerecord.models.item_has_use_restriction")) }
format.json { render json: @item_has_use_restriction, status: :created, location: @item_has_use_restriction }
else
@use_restrictions = UseRestriction.all
format.html { render action: "new" }
format.json { render json: @item_has_use_restriction.errors, status: :unprocessable_entity }
end
end
end
# PUT /item_has_use_restrictions/1
# PUT /item_has_use_restrictions/1.json
def update
@item_has_use_restriction.assign_attributes(item_has_use_restriction_params)
respond_to do |format|
if @item_has_use_restriction.save
format.html { redirect_to @item_has_use_restriction, notice: t("controller.successfully_updated", model: t("activerecord.models.item_has_use_restriction")) }
format.json { head :no_content }
else
@use_restrictions = UseRestriction.all
format.html { render action: "edit" }
format.json { render json: @item_has_use_restriction.errors, status: :unprocessable_entity }
end
end
end
# DELETE /item_has_use_restrictions/1
# DELETE /item_has_use_restrictions/1.json
def destroy
@item_has_use_restriction.destroy
respond_to do |format|
format.html { redirect_to item_has_use_restrictions_url }
format.json { head :no_content }
end
end
private
def set_item_has_use_restriction
@item_has_use_restriction = ItemHasUseRestriction.find(params[:id])
authorize @item_has_use_restriction
end
def check_policy
authorize ItemHasUseRestriction
end
def item_has_use_restriction_params
params.require(:item_has_use_restriction).permit(
:item_id, :use_restriction_id, :use_restriction
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/order_lists_controller.rb | app/controllers/order_lists_controller.rb | class OrderListsController < ApplicationController
before_action :set_order_list, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :prepare_options, only: [ :new, :edit ]
before_action :set_bookstore, only: :index
# GET /order_lists
# GET /order_lists.json
def index
if @bookstore
@order_lists = @bookstore.order_lists.page(params[:page])
else
@order_lists = OrderList.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @order_lists }
format.rss { render layout: false }
format.atom
end
end
# GET /order_lists/1
# GET /order_lists/1.json
def show
respond_to do |format|
format.html # show.html.erb
format.json { render json: @order_list }
end
end
# GET /order_lists/new
# GET /order_lists/new.json
def new
@order_list = OrderList.new
end
# GET /order_lists/1/edit
def edit
if params[:mode] == "order"
@order_list.edit_mode = "order"
end
end
# POST /order_lists
# POST /order_lists.json
def create
@order_list = OrderList.new(order_list_params)
@order_list.user = current_user
respond_to do |format|
if @order_list.save
format.html { redirect_to @order_list, notice: t("controller.successfully_created", model: t("activerecord.models.order_list")) }
format.json { render json: @order_list, status: :created, location: @order_list }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @order_list.errors, status: :unprocessable_entity }
end
end
end
# PUT /order_lists/1
# PUT /order_lists/1.json
def update
respond_to do |format|
if @order_list.update(order_list_params)
if @order_list.edit_mode == "order"
@order_list.transition_to(:ordered)
@order_list.save(validate: false)
format.html { redirect_to purchase_requests_url(order_list_id: @order_list.id), notice: t("controller.successfully_updated", model: t("activerecord.models.order_list")) }
else
format.html { redirect_to @order_list, notice: t("controller.successfully_updated", model: t("activerecord.models.order_list")) }
end
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @order_list.errors, status: :unprocessable_entity }
end
end
end
# DELETE /order_lists/1
# DELETE /order_lists/1.json
def destroy
@order_list.destroy
respond_to do |format|
format.html { redirect_to order_lists_url }
format.json { head :no_content }
end
end
private
def set_order_list
@order_list = OrderList.find(params[:id])
authorize @order_list
end
def set_bookstore
@bookstore = Bookstore.find_by(id: params[:bookstore_id])
authorize @bookstore if @bookstore
end
def check_policy
authorize OrderList
end
def order_list_params
params.require(:order_list).permit(
:user_id, :bookstore_id, :title, :note, :ordered_at, :edit_mode
)
end
def prepare_options
@bookstores = Bookstore.order(:position)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/periodicals_controller.rb | app/controllers/periodicals_controller.rb | class PeriodicalsController < ApplicationController
before_action :set_periodical, only: %i[ show edit update destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /periodicals or /periodicals.json
def index
@periodicals = Periodical.page(params[:page])
end
# GET /periodicals/1 or /periodicals/1.json
def show
end
# GET /periodicals/new
def new
@periodical = Periodical.new
end
# GET /periodicals/1/edit
def edit
end
# POST /periodicals or /periodicals.json
def create
@periodical = Periodical.new(periodical_params)
respond_to do |format|
if @periodical.save
format.html { redirect_to periodical_url(@periodical), notice: "Periodical was successfully created." }
format.json { render :show, status: :created, location: @periodical }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @periodical.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /periodicals/1 or /periodicals/1.json
def update
respond_to do |format|
if @periodical.update(periodical_params)
format.html { redirect_to periodical_url(@periodical), notice: "Periodical was successfully updated." }
format.json { render :show, status: :ok, location: @periodical }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @periodical.errors, status: :unprocessable_entity }
end
end
end
# DELETE /periodicals/1 or /periodicals/1.json
def destroy
@periodical.destroy
respond_to do |format|
format.html { redirect_to periodicals_url, notice: "Periodical was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_periodical
@periodical = Periodical.find(params[:id])
authorize @periodical
end
def check_policy
authorize Periodical
end
# Only allow a list of trusted parameters through.
def periodical_params
params.require(:periodical).permit(:original_title, :manifestation_id, :frequency_id)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/user_groups_controller.rb | app/controllers/user_groups_controller.rb | class UserGroupsController < ApplicationController
before_action :set_user_group, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :prepare_options, only: [ :new, :edit ]
# GET /user_groups
# GET /user_groups.json
def index
@user_groups = UserGroup.order(:position)
respond_to do |format|
format.html # index.html.erb
end
end
# GET /user_groups/1
# GET /user_groups/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /user_groups/new
def new
@user_group = UserGroup.new
end
# GET /user_groups/1/edit
def edit
end
# POST /user_groups
# POST /user_groups.json
def create
@user_group = UserGroup.new(user_group_params)
respond_to do |format|
if @user_group.save
format.html { redirect_to @user_group, notice: t("controller.successfully_created", model: t("activerecord.models.user_group")) }
format.json { render json: @user_group, status: :created, location: @user_group }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @user_group.errors, status: :unprocessable_entity }
end
end
end
# PUT /user_groups/1
# PUT /user_groups/1.json
def update
if params[:move]
move_position(@user_group, params[:move])
return
end
respond_to do |format|
if @user_group.update(user_group_params)
format.html { redirect_to @user_group, notice: t("controller.successfully_updated", model: t("activerecord.models.user_group")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @user_group.errors, status: :unprocessable_entity }
end
end
end
# DELETE /user_groups/1
# DELETE /user_groups/1.json
def destroy
@user_group.destroy
respond_to do |format|
format.html { redirect_to user_groups_url }
format.json { head :no_content }
end
end
private
def set_user_group
@user_group = UserGroup.find(params[:id])
authorize @user_group
end
def check_policy
authorize UserGroup
end
def user_group_params
params.require(:user_group).permit(
:name, :display_name, :note, :valid_period_for_new_user,
:expired_at, :number_of_day_to_notify_overdue,
:number_of_day_to_notify_overdue,
:number_of_day_to_notify_due_date,
:number_of_time_to_notify_overdue,
# EnjuCirculation
{ user_group_has_checkout_types_attributes: [
:id, :checkout_type_id, :checkout_limit, :checkout_period, :checkout_renewal_limit,
:reservation_limit, :reservation_expired_period, :set_due_date_before_closing_day
] }
)
end
def prepare_options
if defined?(EnjuCirculation)
@checkout_types = CheckoutType.select([ :id, :display_name, :position ])
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/ndl_books_controller.rb | app/controllers/ndl_books_controller.rb | class NdlBooksController < ApplicationController
before_action :check_policy, only: %i[index create]
def index
page = if params[:page].to_i.zero?
1
else
params[:page]
end
@query = params[:query].to_s.strip
books = NdlBook.search(params[:query], page)
@books = Kaminari.paginate_array(
books[:items], total_count: books[:total_entries]
).page(page).per(10)
respond_to do |format|
format.html
end
end
def create
if params[:book]
begin
@manifestation = NdlBook.import_from_sru_response(params[:book].try(:[], "iss_itemno"))
rescue EnjuNdl::RecordNotFound
end
respond_to do |format|
if @manifestation.try(:save)
format.html { redirect_to manifestation_url(@manifestation), notice: t("controller.successfully_created", model: t("activerecord.models.manifestation")) }
else
format.html { redirect_to ndl_books_url, notice: t("enju_ndl.record_not_found") }
end
end
end
end
private
def check_policy
authorize NdlBook
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/subscribes_controller.rb | app/controllers/subscribes_controller.rb | class SubscribesController < ApplicationController
before_action :set_subscribe, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_subscription, :get_work
# GET /subscribes
# GET /subscribes.json
def index
@subscribes = Subscribe.page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /subscribes/1
# GET /subscribes/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /subscribes/new
def new
@subscribe = Subscribe.new
@subscribe.subscription = @subscription if @subscription
@subscribe.work = @work if @work
end
# GET /subscribes/1/edit
def edit
end
# POST /subscribes
# POST /subscribes.json
def create
@subscribe = Subscribe.new(subscribe_params)
respond_to do |format|
if @subscribe.save
format.html { redirect_to @subscribe, notice: t("controller.successfully_created", model: t("activerecord.models.subscribe")) }
format.json { render json: @subscribe, status: :created, location: @subscribe }
else
format.html { render action: "new" }
format.json { render json: @subscribe.errors, status: :unprocessable_entity }
end
end
end
# PUT /subscribes/1
# PUT /subscribes/1.json
def update
respond_to do |format|
if @subscribe.update(subscribe_params)
format.html { redirect_to @subscribe, notice: t("controller.successfully_updated", model: t("activerecord.models.subscribe")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @subscribe.errors, status: :unprocessable_entity }
end
end
end
# DELETE /subscribes/1
# DELETE /subscribes/1.json
def destroy
@subscribe.destroy
respond_to do |format|
format.html { redirect_to subscribes_url }
format.json { head :no_content }
end
end
private
def set_subscribe
@subscribe = Subscribe.find(params[:id])
authorize @subscribe
end
def check_policy
authorize Subscribe
end
def subscribe_params
params.require(:subscribe).permit(
:subscription_id, :work_id, :start_at, :end_at
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/circulation_statuses_controller.rb | app/controllers/circulation_statuses_controller.rb | class CirculationStatusesController < ApplicationController
before_action :set_circulation_status, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /circulation_statuses
# GET /circulation_statuses.json
def index
@circulation_statuses = CirculationStatus.order(:position)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @circulation_statuses }
end
end
# GET /circulation_statuses/1
# GET /circulation_statuses/1.json
def show
respond_to do |format|
format.html # show.html.erb
format.json { render json: @circulation_status }
end
end
# GET /circulation_statuses/new
def new
@circulation_status = CirculationStatus.new
end
# GET /circulation_statuses/1/edit
def edit
end
# POST /circulation_statuses
# POST /circulation_statuses.json
def create
@circulation_status = CirculationStatus.new(circulation_status_params)
respond_to do |format|
if @circulation_status.save
format.html { redirect_to @circulation_status, notice: t("controller.successfully_created", model: t("activerecord.models.circulation_status")) }
format.json { render json: @circulation_status, status: :created, location: @circulation_status }
else
format.html { render action: "new" }
format.json { render json: @circulation_status.errors, status: :unprocessable_entity }
end
end
end
# PUT /circulation_statuses/1
# PUT /circulation_statuses/1.json
def update
if params[:move]
move_position(@circulation_status, params[:move])
return
end
respond_to do |format|
if @circulation_status.update(circulation_status_params)
format.html { redirect_to @circulation_status, notice: t("controller.successfully_updated", model: t("activerecord.models.circulation_status")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @circulation_status.errors, status: :unprocessable_entity }
end
end
end
# DELETE /circulation_statuses/1
# DELETE /circulation_statuses/1.json
def destroy
@circulation_status.destroy
respond_to do |format|
format.html { redirect_to circulation_statuses_url }
format.json { head :no_content }
end
end
private
def set_circulation_status
@circulation_status = CirculationStatus.find(params[:id])
authorize @circulation_status
end
def check_policy
authorize CirculationStatus
end
def circulation_status_params
params.require(:circulation_status).permit(:name, :display_name, :note)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/iiif_presentations_controller.rb | app/controllers/iiif_presentations_controller.rb | class IiifPresentationsController < ApplicationController
def show
@manifestation = Manifestation.find(params[:id])
authorize @manifestation
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/messages_controller.rb | app/controllers/messages_controller.rb | class MessagesController < ApplicationController
before_action :set_message, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create, :destroy_selected ]
before_action :get_user, only: :index
# GET /messages
# GET /messages.json
def index
query = @query = params[:query].to_s.strip
search = Sunspot.new_search(Message)
user = current_user
case params[:mode]
when "read"
is_read = true
when "unread"
is_read = false
else
is_read = nil
end
search.build do
fulltext query
order_by :created_at, :desc
with(:receiver_id).equal_to user.id
facet(:is_read)
end
@message_facet = Hash[*search.execute!.facet_response["facet_fields"]["is_read_b"]]
search.build do
with(:is_read).equal_to is_read unless is_read.nil?
end
page = params[:page] || 1
search.query.paginate(page.to_i, Message.default_per_page)
@messages = search.execute!.results
respond_to do |format|
format.html # index.html.erb
format.rss
format.atom
end
end
# GET /messages/1
# GET /messages/1.json
def show
@message.read unless @message.read?
respond_to do |format|
format.html # show.html.erb
end
end
# GET /messages/new
def new
parent = get_parent(params[:parent_id])
@message = current_user.sent_messages.new
if params[:recipient] && current_user.has_role?("Librarian")
@message.recipient = params[:recipient]
elsif parent
@message.recipient = parent.sender.username
end
@message.receiver = User.find_by(username: @message.recipient) if @message.recipient
end
# GET /messages/1/edit
def edit
@message = current_user.received_messages.find(params[:id])
@message.transition_to!(:read)
end
# POST /messages
# POST /messages.json
def create
@message = Message.new(message_params)
@message.sender = current_user
get_parent(@message.parent_id)
@message.receiver = User.find_by(username: @message.recipient)
respond_to do |format|
if @message.save
format.html { redirect_to messages_url, notice: t("controller.successfully_created", model: t("activerecord.models.message")) }
format.json { render json: @message, status: :created, location: @message }
else
format.html { render action: "new" }
format.json { render json: @message.errors, status: :unprocessable_entity }
end
end
end
# PUT /messages/1
# PUT /messages/1.json
def update
@message = current_user.received_messages.find(params[:id])
if @message.update(message_params)
format.html { redirect_to @message, notice: t("controller.successfully_updated", model: t("activerecord.models.message")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @message.errors, status: :unprocessable_entity }
end
end
# DELETE /messages/1
# DELETE /messages/1.json
def destroy
@message = current_user.received_messages.find(params[:id])
@message.destroy
respond_to do |format|
format.html { redirect_to messages_url }
format.json { head :no_content }
end
end
def destroy_selected
unless current_user
redirect_to new_user_session_url
return
end
respond_to do |format|
if params[:delete].present?
messages = params[:delete].map { |m| Message.find_by(id: m) }
end
if messages.present?
messages.each do |message|
message.destroy if message.receiver == current_user
end
flash[:notice] = t("message.messages_were_deleted")
format.html { redirect_to messages_url }
else
flash[:notice] = t("message.select_messages")
format.html { redirect_to messages_url }
end
end
end
private
def set_message
if current_user
@message = current_user.received_messages.find(params[:id])
authorize @message
else
access_denied
nil
end
end
def check_policy
authorize Message
end
def message_params
params.require(:message).permit(
:subject, :body, :sender, :recipient, :parent_id
)
end
def get_parent(id)
parent = Message.find_by(id: id)
if current_user.has_role?("Librarian")
parent
else
unless parent.try(:receiver) == current_user
access_denied
nil
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/form_of_works_controller.rb | app/controllers/form_of_works_controller.rb | class FormOfWorksController < ApplicationController
before_action :set_form_of_work, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /form_of_works
# GET /form_of_works.json
def index
@form_of_works = FormOfWork.order(:position)
respond_to do |format|
format.html # index.html.erb
end
end
# GET /form_of_works/1
# GET /form_of_works/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /form_of_works/new
def new
@form_of_work = FormOfWork.new
end
# GET /form_of_works/1/edit
def edit
end
# POST /form_of_works
# POST /form_of_works.json
def create
@form_of_work = FormOfWork.new(form_of_work_params)
respond_to do |format|
if @form_of_work.save
format.html { redirect_to @form_of_work, notice: t("controller.successfully_created", model: t("activerecord.models.form_of_work")) }
format.json { render json: @form_of_work, status: :created, location: @form_of_work }
else
format.html { render action: "new" }
format.json { render json: @form_of_work.errors, status: :unprocessable_entity }
end
end
end
# PUT /form_of_works/1
# PUT /form_of_works/1.json
def update
if params[:move]
move_position(@form_of_work, params[:move])
return
end
respond_to do |format|
if @form_of_work.update(form_of_work_params)
format.html { redirect_to @form_of_work, notice: t("controller.successfully_updated", model: t("activerecord.models.form_of_work")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @form_of_work.errors, status: :unprocessable_entity }
end
end
end
# DELETE /form_of_works/1
# DELETE /form_of_works/1.json
def destroy
@form_of_work.destroy
respond_to do |format|
format.html { redirect_to form_of_works_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.form_of_work")) }
format.json { head :no_content }
end
end
private
def set_form_of_work
@form_of_work = FormOfWork.find(params[:id])
authorize @form_of_work
end
def check_policy
authorize FormOfWork
end
def form_of_work_params
params.require(:form_of_work).permit(:name, :display_name, :note)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/carrier_type_has_checkout_types_controller.rb | app/controllers/carrier_type_has_checkout_types_controller.rb | class CarrierTypeHasCheckoutTypesController < ApplicationController
include EnjuCirculation::Controller
before_action :set_carrier_type_has_checkout_type, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_checkout_type
before_action :prepare_options, only: [ :new, :edit ]
# GET /carrier_type_has_checkout_types
# GET /carrier_type_has_checkout_types.json
def index
@carrier_type_has_checkout_types = CarrierTypeHasCheckoutType.includes([ :carrier_type, :checkout_type ]).order("carrier_types.position, checkout_types.position").page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /carrier_type_has_checkout_types/1
# GET /carrier_type_has_checkout_types/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /carrier_type_has_checkout_types/new
def new
@carrier_type_has_checkout_type = CarrierTypeHasCheckoutType.new
@carrier_type_has_checkout_type.carrier_type = @carrier_type
@carrier_type_has_checkout_type.checkout_type = @checkout_type
end
# GET /carrier_type_has_checkout_types/1/edit
def edit
end
# POST /carrier_type_has_checkout_types
# POST /carrier_type_has_checkout_types.json
def create
@carrier_type_has_checkout_type = CarrierTypeHasCheckoutType.new(carrier_type_has_checkout_type_params)
respond_to do |format|
if @carrier_type_has_checkout_type.save
flash[:notice] = t("controller.successfully_created", model: t("activerecord.models.carrier_type_has_checkout_type"))
format.html { redirect_to @carrier_type_has_checkout_type }
format.json { render json: @carrier_type_has_checkout_type, status: :created, location: @carrier_type_has_checkout_type }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @carrier_type_has_checkout_type.errors, status: :unprocessable_entity }
end
end
end
# PUT /carrier_type_has_checkout_types/1
# PUT /carrier_type_has_checkout_types/1.json
def update
respond_to do |format|
if @carrier_type_has_checkout_type.update(carrier_type_has_checkout_type_params)
flash[:notice] = t("controller.successfully_updated", model: t("activerecord.models.carrier_type_has_checkout_type"))
format.html { redirect_to @carrier_type_has_checkout_type }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @carrier_type_has_checkout_type.errors, status: :unprocessable_entity }
end
end
end
# DELETE /carrier_type_has_checkout_types/1
# DELETE /carrier_type_has_checkout_types/1.json
def destroy
@carrier_type_has_checkout_type.destroy
respond_to do |format|
format.html { redirect_to carrier_type_has_checkout_types_url }
format.json { head :no_content }
end
end
private
def set_carrier_type_has_checkout_type
@carrier_type_has_checkout_type = CarrierTypeHasCheckoutType.find(params[:id])
authorize @carrier_type_has_checkout_type
end
def check_policy
authorize CarrierTypeHasCheckoutType
end
def carrier_type_has_checkout_type_params
params.require(:carrier_type_has_checkout_type).permit(
:carrier_type_id, :checkout_type_id, :note
)
end
def prepare_options
@checkout_types = CheckoutType.order(:position)
@carrier_types = CarrierType.order(:position)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/manifestation_relationship_types_controller.rb | app/controllers/manifestation_relationship_types_controller.rb | class ManifestationRelationshipTypesController < ApplicationController
before_action :set_manifestation_relationship_type, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
# GET /manifestation_relationship_types
# GET /manifestation_relationship_types.json
def index
@manifestation_relationship_types = ManifestationRelationshipType.all
respond_to do |format|
format.html # index.html.erb
end
end
# GET /manifestation_relationship_types/1
# GET /manifestation_relationship_types/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /manifestation_relationship_types/new
def new
@manifestation_relationship_type = ManifestationRelationshipType.new
end
# GET /manifestation_relationship_types/1/edit
def edit
end
# POST /manifestation_relationship_types
# POST /manifestation_relationship_types.json
def create
@manifestation_relationship_type = ManifestationRelationshipType.new(manifestation_relationship_type_params)
respond_to do |format|
if @manifestation_relationship_type.save
format.html { redirect_to @manifestation_relationship_type, notice: t("controller.successfully_created", model: t("activerecord.models.manifestation_relationship_type")) }
format.json { render json: @manifestation_relationship_type, status: :created, location: @manifestation_relationship_type }
else
format.html { render action: "new" }
format.json { render json: @manifestation_relationship_type.errors, status: :unprocessable_entity }
end
end
end
# PUT /manifestation_relationship_types/1
# PUT /manifestation_relationship_types/1.json
def update
if params[:move]
move_position(@manifestation_relationship_type, params[:move])
return
end
respond_to do |format|
if @manifestation_relationship_type.update(manifestation_relationship_type_params)
format.html { redirect_to @manifestation_relationship_type, notice: t("controller.successfully_updated", model: t("activerecord.models.manifestation_relationship_type")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @manifestation_relationship_type.errors, status: :unprocessable_entity }
end
end
end
# DELETE /manifestation_relationship_types/1
# DELETE /manifestation_relationship_types/1.json
def destroy
@manifestation_relationship_type.destroy
respond_to do |format|
format.html { redirect_to manifestation_relationship_types_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.manifestation_relationship_type")) }
format.json { head :no_content }
end
end
private
def set_manifestation_relationship_type
@manifestation_relationship_type = ManifestationRelationshipType.find(params[:id])
authorize @manifestation_relationship_type
end
def check_policy
authorize ManifestationRelationshipType
end
def manifestation_relationship_type_params
params.require(:manifestation_relationship_type).permit(
:name, :display_name, :note
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/carrier_types_controller.rb | app/controllers/carrier_types_controller.rb | class CarrierTypesController < ApplicationController
before_action :set_carrier_type, only: [ :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :prepare_options, only: [ :new, :edit ]
skip_after_action :verify_authorized
# GET /carrier_types
# GET /carrier_types.json
def index
@carrier_types = CarrierType.order(:position).page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /carrier_types/1
# GET /carrier_types/1.json
def show
@carrier_type = CarrierType.find(params[:id])
authorize @carrier_type
respond_to do |format|
format.html # show.html.erb
end
end
# GET /carrier_types/new
def new
@carrier_type = CarrierType.new
end
# GET /carrier_types/1/edit
def edit
end
# POST /carrier_types
# POST /carrier_types.json
def create
@carrier_type = CarrierType.new(carrier_type_params)
respond_to do |format|
if @carrier_type.save
format.html { redirect_to @carrier_type, notice: t("controller.successfully_created", model: t("activerecord.models.carrier_type")) }
format.json { render json: @carrier_type, status: :created, location: @carrier_type }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @carrier_type.errors, status: :unprocessable_entity }
end
end
end
# PUT /carrier_types/1
# PUT /carrier_types/1.json
def update
if params[:move]
move_position(@carrier_type, params[:move])
return
end
respond_to do |format|
if @carrier_type.update(carrier_type_params)
format.html { redirect_to @carrier_type, notice: t("controller.successfully_updated", model: t("activerecord.models.carrier_type")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @carrier_type.errors, status: :unprocessable_entity }
end
end
end
# DELETE /carrier_types/1
# DELETE /carrier_types/1.json
def destroy
@carrier_type.destroy
respond_to do |format|
format.html { redirect_to carrier_types_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.carrier_type")) }
format.json { head :no_content }
end
end
private
def set_carrier_type
@carrier_type = CarrierType.find(params[:id])
authorize @carrier_type
end
def check_policy
authorize CarrierType
end
def carrier_type_params
params.require(:carrier_type).permit(
:name, :display_name, :note, :position,
:attachment, :delete_attachment,
# EnjuCirculation
{
carrier_type_has_checkout_types_attributes: [
:id, :checkout_type_id, :_destroy
]
}
)
end
def prepare_options
if defined?(EnjuCirculation)
@checkout_types = CheckoutType.select([ :id, :display_name, :position ])
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/manifestations_controller.rb | app/controllers/manifestations_controller.rb | class ManifestationsController < ApplicationController
before_action :set_manifestation, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :authenticate_user!, only: :edit
before_action :get_agent, :get_manifestation, except: [ :create, :update, :destroy ]
before_action :get_expression, only: :new
if defined?(EnjuSubject)
before_action :get_subject, except: [ :create, :update, :destroy ]
end
before_action :get_series_statement, only: [ :index, :new, :edit ]
before_action :get_item, :get_libraries, only: :index
before_action :prepare_options, only: [ :new, :edit ]
after_action :convert_charset, only: :index
# GET /manifestations
# GET /manifestations.json
def index
mode = params[:mode]
if mode == "add"
unless current_user.try(:has_role?, "Librarian")
access_denied
return
end
end
@seconds = Benchmark.realtime do
set_reservable if defined?(EnjuCirculation)
sort, @count = {}, {}
query = ""
if request.format.text?
per_page = 65534
end
if params[:api] == "openurl"
openurl = Openurl.new(params)
@manifestations = openurl.search
query = openurl.query_text
sort = set_search_result_order(params[:sort_by], params[:order])
else
query = make_query(params[:query], params)
sort = set_search_result_order(params[:sort_by], params[:order])
end
# 絞り込みを行わない状態のクエリ
@query = query.dup
query = query.gsub(" ", " ")
includes = [ :series_statements ]
includes << :classifications if defined?(EnjuSubject)
includes << :bookmarks if defined?(EnjuBookmark)
search = Manifestation.search(include: includes)
case @reservable
when "true"
reservable = true
when "false"
reservable = false
else
reservable = nil
end
agent = get_index_agent
@index_agent = agent
manifestation = @manifestation if @manifestation
series_statement = @series_statement if @series_statement
parent = @parent = Manifestation.find_by(id: params[:parent_id]) if params[:parent_id].present?
if defined?(EnjuSubject)
subject = @subject if @subject
end
unless mode == "add"
search.build do
with(:creator_ids).equal_to agent[:creator].id if agent[:creator]
with(:contributor_ids).equal_to agent[:contributor].id if agent[:contributor]
with(:publisher_ids).equal_to agent[:publisher].id if agent[:publisher]
with(:series_statement_ids).equal_to series_statement.id if series_statement
with(:parent_ids).equal_to parent.id if parent
end
end
search.build do
fulltext query if query.present?
order_by sort[:sort_by], sort[:order]
if defined?(EnjuSubject)
with(:subject_ids).equal_to subject.id if subject
end
unless parent
if params[:serial].to_s.downcase == "true"
with(:series_master).equal_to true unless parent
with(:serial).equal_to true
# if series_statement.serial?
# if mode != 'add'
# order_by :volume_number, sort[:order]
# order_by :issue_number, sort[:order]
# order_by :serial_number, sort[:order]
# end
# else
# with(:serial).equal_to false
# end
elsif mode != "add"
with(:resource_master).equal_to true
end
end
facet :reservable if defined?(EnjuCirculation)
end
search = make_internal_query(search)
search.data_accessor_for(Manifestation).select = [
:id,
:original_title,
:title_transcription,
:required_role_id,
:carrier_type_id,
:access_address,
:volume_number_string,
:issue_number_string,
:serial_number_string,
:date_of_publication,
:pub_date,
:language_id,
:created_at,
:updated_at,
:volume_number_string,
:volume_number,
:issue_number_string,
:issue_number,
:serial_number,
:edition_string,
:edition,
:serial,
:statement_of_responsibility
] if params[:format] == "html" || params[:format].nil?
all_result = search.execute
@count[:query_result] = all_result.total
@reservable_facet = all_result.facet(:reservable).rows if defined?(EnjuCirculation)
max_number_of_results = @library_group.max_number_of_results
if max_number_of_results.zero?
@max_number_of_results = @count[:query_result]
else
@max_number_of_results = max_number_of_results
end
if params[:format] == "html" || params[:format].nil?
@search_query = Digest::SHA1.hexdigest(Marshal.dump(search.query.to_params).force_encoding("UTF-8"))
if flash[:search_query] == @search_query
flash.keep(:search_query)
elsif @series_statement
flash.keep(:search_query)
else
flash[:search_query] = @search_query
@manifestation_ids = search.build do
paginate page: 1, per_page: @max_number_of_results
end.execute.raw_results.collect(&:primary_key).map { |id| id.to_i }
end
if defined?(EnjuBookmark)
if params[:view] == "tag_cloud"
unless @manifestation_ids
@manifestation_ids = search.build do
paginate page: 1, per_page: @max_number_of_results
end.execute.raw_results.collect(&:primary_key).map { |id| id.to_i }
end
# bookmark_ids = Bookmark.where(manifestation_id: flash[:manifestation_ids]).limit(1000).pluck(:id)
bookmark_ids = Bookmark.where(manifestation_id: @manifestation_ids).limit(1000).pluck(:id)
@tags = Tag.bookmarked(bookmark_ids)
render partial: "manifestations/tag_cloud"
return
end
end
end
page ||= params[:page] || 1
if params[:per_page].to_i.positive?
per_page = params[:per_page].to_i
else
per_page = Manifestation.default_per_page
end
pub_dates = parse_pub_date(params)
pub_date_range = {}
if pub_dates[:from] == "*"
pub_date_range[:from] = 0
else
pub_date_range[:from] = Time.zone.parse(pub_dates[:from]).year
end
if pub_dates[:until] == "*"
pub_date_range[:until] = 10000
else
pub_date_range[:until] = Time.zone.parse(pub_dates[:until]).year
end
if params[:pub_year_range_interval]
pub_year_range_interval = params[:pub_year_range_interval].to_i
else
pub_year_range_interval = @library_group.pub_year_facet_range_interval || 10
end
search.build do
facet :reservable if defined?(EnjuCirculation)
facet :carrier_type
facet :library
facet :language
facet :pub_year, range: pub_date_range[:from]..pub_date_range[:until], range_interval: pub_year_range_interval
facet :subject_ids if defined?(EnjuSubject)
paginate page: page.to_i, per_page: per_page
end
search_result = search.execute
if @count[:query_result] > @max_number_of_results
max_count = @max_number_of_results
else
max_count = @count[:query_result]
end
@manifestations = Kaminari.paginate_array(
search_result.results, total_count: max_count
).page(page).per(per_page)
if params[:format].blank? || params[:format] == "html"
@carrier_type_facet = search_result.facet(:carrier_type).rows
@language_facet = search_result.facet(:language).rows
@library_facet = search_result.facet(:library).rows
@pub_year_facet = search_result.facet(:pub_year).rows.reverse
end
@search_engines = SearchEngine.order(:position)
if defined?(EnjuSearchLog)
if current_user.try(:save_search_history)
current_user.save_history(query, @manifestations.offset_value + 1, @count[:query_result], params[:format])
end
end
end
respond_to do |format|
format.html
format.html.phone
format.xml
format.rss { render layout: false }
format.text { render layout: false }
format.rdf { render layout: false }
format.atom
format.mods
format.json
format.js
format.xlsx
format.ttl
end
end
# GET /manifestations/1
# GET /manifestations/1.json
def show
case params[:mode]
when "send_email"
if user_signed_in?
Notifier.manifestation_info(current_user.id, @manifestation.id).deliver_later
flash[:notice] = t("page.sent_email")
redirect_to manifestation_url(@manifestation)
return
else
access_denied
return
end
end
return if render_mode(params[:mode])
flash.keep(:search_query)
if @manifestation.series_master?
flash.keep(:notice) if flash[:notice]
flash[:manifestation_id] = @manifestation.id
redirect_to manifestations_url(parent_id: @manifestation.id)
return
end
if defined?(EnjuCirculation)
@reserved_count = Reserve.waiting.where(manifestation_id: @manifestation.id, checked_out_at: nil).count
@reserve = current_user.reserves.where(manifestation_id: @manifestation.id).first if user_signed_in?
end
if defined?(EnjuQuestion)
@questions = @manifestation.questions(user: current_user, page: params[:question_page])
end
respond_to do |format|
format.html # show.html.erb
format.html.phone
format.xml {
case params[:mode]
when "related"
render template: "manifestations/related"
else
render xml: @manifestation
end
}
format.rdf
format.ttl
format.mods
format.json
format.text
format.js
format.xlsx
end
end
# GET /manifestations/new
def new
@manifestation = Manifestation.new
@manifestation.language = Language.find_by(iso_639_1: @locale)
@parent = Manifestation.find_by(id: params[:parent_id]) if params[:parent_id].present?
if @parent
@manifestation.parent_id = @parent.id
[ :original_title, :title_transcription,
:serial, :title_alternative, :statement_of_responsibility, :publication_place,
:height, :width, :depth, :price, :access_address, :language, :frequency, :required_role,
].each do |attribute|
@manifestation.send("#{attribute}=", @parent.send(attribute))
end
[ :creators, :contributors, :publishers, :classifications, :subjects ].each do |attribute|
@manifestation.send(attribute).build(@parent.send(attribute).collect(&:attributes))
end
end
@manifestation.build_doi_record
@manifestation.build_ncid_record
@manifestation.build_jpno_record
end
# GET /manifestations/1/edit
def edit
unless current_user.has_role?("Librarian")
unless params[:mode] == "tag_edit"
access_denied
return
end
end
if defined?(EnjuBookmark)
if params[:mode] == "tag_edit"
@bookmark = current_user.bookmarks.where(manifestation_id: @manifestation.id).first if @manifestation rescue nil
render partial: "manifestations/tag_edit", locals: { manifestation: @manifestation }
end
end
@manifestation.build_doi_record unless @manifestation.doi_record
@manifestation.build_ncid_record unless @manifestation.ncid_record
@manifestation.build_jpno_record unless @manifestation.jpno_record
end
# POST /manifestations
# POST /manifestations.json
def create
@manifestation = Manifestation.new(manifestation_params)
parent = Manifestation.find_by(id: @manifestation.parent_id)
unless @manifestation.original_title?
@manifestation.original_title = @manifestation.attachment.filename
end
respond_to do |format|
if @manifestation.save
Manifestation.transaction do
set_creators
if parent
parent.derived_manifestations << @manifestation
parent.index
@manifestation.index
end
Sunspot.commit
end
format.html { redirect_to @manifestation, notice: t("controller.successfully_created", model: t("activerecord.models.manifestation")) }
format.json { render json: @manifestation, status: :created, location: @manifestation }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @manifestation.errors, status: :unprocessable_entity }
end
end
end
# PUT /manifestations/1
# PUT /manifestations/1.json
def update
@manifestation.assign_attributes(manifestation_params)
respond_to do |format|
if @manifestation.save
set_creators
format.html { redirect_to @manifestation, notice: t("controller.successfully_updated", model: t("activerecord.models.manifestation")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @manifestation.errors, status: :unprocessable_entity }
end
end
end
# DELETE /manifestations/1
# DELETE /manifestations/1.json
def destroy
# workaround
@manifestation.identifiers.destroy_all
@manifestation.creators.destroy_all
@manifestation.contributors.destroy_all
@manifestation.publishers.destroy_all
@manifestation.bookmarks.destroy_all if defined?(EnjuBookmark)
@manifestation.reload
@manifestation.destroy
respond_to do |format|
format.html { redirect_to manifestations_url, notice: t("controller.successfully_deleted", model: t("activerecord.models.manifestation")) }
format.json { head :no_content }
end
end
private
def set_manifestation
@manifestation = Manifestation.find(params[:id])
authorize @manifestation
end
def check_policy
authorize Manifestation
end
def manifestation_params
params.require(:manifestation).permit(
:original_title, :title_alternative, :title_transcription,
:manifestation_identifier, :date_copyrighted,
:access_address, :language_id, :carrier_type_id, :start_page,
:end_page, :height, :width, :depth, :publication_place,
:price, :fulltext, :volume_number_string,
:issue_number_string, :serial_number_string, :edition, :note,
:repository_content, :required_role_id, :frequency_id,
:title_alternative_transcription, :description, :abstract, :available_at,
:valid_until, :date_submitted, :date_accepted, :date_captured,
:ndl_bib_id, :pub_date, :edition_string, :volume_number, :issue_number,
:serial_number, :content_type_id, :attachment, :lock_version,
:dimensions, :fulltext_content, :extent, :memo,
:parent_id, :delete_attachment,
:serial, :statement_of_responsibility,
{ creators_attributes: [
:id, :last_name, :middle_name, :first_name,
:last_name_transcription, :middle_name_transcription,
:first_name_transcription, :corporate_name,
:corporate_name_transcription,
:full_name, :full_name_transcription, :full_name_alternative,
:other_designation, :language_id,
:country_id, :agent_type_id, :note, :required_role_id, :email, :url,
:full_name_alternative_transcription, :title,
:agent_identifier, :agent_id,
:_destroy
] },
{ contributors_attributes: [
:id, :last_name, :middle_name, :first_name,
:last_name_transcription, :middle_name_transcription,
:first_name_transcription, :corporate_name,
:corporate_name_transcription,
:full_name, :full_name_transcription, :full_name_alternative,
:other_designation, :language_id,
:country_id, :agent_type_id, :note, :required_role_id, :email, :url,
:full_name_alternative_transcription, :title,
:agent_identifier,
:_destroy
] },
{ publishers_attributes: [
:id, :last_name, :middle_name, :first_name,
:last_name_transcription, :middle_name_transcription,
:first_name_transcription, :corporate_name,
:corporate_name_transcription,
:full_name, :full_name_transcription, :full_name_alternative,
:other_designation, :language_id,
:country_id, :agent_type_id, :note, :required_role_id, :email, :url,
:full_name_alternative_transcription, :title,
:agent_identifier,
:_destroy
] },
{ series_statements_attributes: [
:id, :original_title, :numbering, :title_subseries,
:numbering_subseries, :title_transcription, :title_alternative,
:title_subseries_transcription, :creator_string, :volume_number_string,
:volume_number_transcription_string, :series_master,
:_destroy
] },
{ subjects_attributes: [
:id, :parent_id, :use_term_id, :term, :term_transcription,
:subject_type_id, :note, :required_role_id, :subject_heading_type_id,
:_destroy
] },
{ classifications_attributes: [
:id, :parent_id, :category, :note, :classification_type_id,
:_destroy
] },
{ identifiers_attributes: [
:id, :body, :identifier_type_id,
:_destroy
] },
{ manifestation_custom_values_attributes: [
:id, :manifestation_custom_property_id, :manifestation_id, :value, :_destroy
] }
)
end
def make_query(query, options = {})
# TODO: integerやstringもqfに含める
query = query.to_s.strip
if query.size == 1
query = "#{query}*"
end
if options[:mode] == "recent"
query = "#{query} created_at_d:[NOW-1MONTH TO NOW]"
end
# unless options[:carrier_type].blank?
# query = "#{query} carrier_type_s:#{options[:carrier_type]}"
# end
if options[:library_adv].present?
library_list = options[:library_adv].split.uniq.join(" OR ")
query = "#{query} library_sm:(#{library_list})"
end
shelf_list = []
options.keys.grep(/_shelf\Z/).each do |library_shelf|
library_name = library_shelf.sub(/_shelf\Z/, "")
options[library_shelf].each do |shelf|
shelf_list << "#{library_name}_#{shelf}"
end
end
if shelf_list.present?
query += " shelf_sm:(#{shelf_list.join(" OR ")})"
end
# unless options[:language].blank?
# query = "#{query} language_sm:#{options[:language]}"
# end
if options[:subject].present?
query = "#{query} subject_sm:#{options[:subject]}"
end
if options[:subject_text].present?
query = "#{query} subject_text:#{options[:subject_text]}"
end
if options[:classification].present? and options[:classification_type].present?
classification_type = ClassificationType.find(options[:classification_type]).name
query = "#{query} classification_sm:#{classification_type}_#{options[:classification]}*"
end
if options[:title].present?
query = "#{query} title_text:#{options[:title]}"
end
if options[:tag].present?
query = "#{query} tag_sm:#{options[:tag]}"
end
if options[:creator].present?
query = "#{query} creator_text:#{options[:creator]}"
end
if options[:contributor].present?
query = "#{query} contributor_text:#{options[:contributor]}"
end
if options[:isbn].present?
query = "#{query} isbn_sm:#{options[:isbn].gsub('-', '')}"
end
if options[:isbn_id].present?
query = "#{query} isbn_sm:#{options[:isbn_id].gsub('-', '')}"
end
if options[:issn].present?
query = "#{query} issn_sm:#{options[:issn].gsub('-', '')}"
end
if options[:lccn].present?
query = "#{query} lccn_s:#{options[:lccn]}"
end
if options[:jpno].present?
query = "#{query} jpno_s:#{options[:jpno]}"
end
if options[:publisher].present?
query = "#{query} publisher_text:#{options[:publisher]}"
end
if options[:call_number].present?
query = "#{query} call_number_sm:#{options[:call_number]}*"
end
if options[:item_identifier].present?
query = "#{query} item_identifier_sm:#{options[:item_identifier]}"
end
unless options[:number_of_pages_at_least].blank? && options[:number_of_pages_at_most].blank?
number_of_pages = {}
number_of_pages[:at_least] = options[:number_of_pages_at_least].to_i
number_of_pages[:at_most] = options[:number_of_pages_at_most].to_i
number_of_pages[:at_least] = "*" if number_of_pages[:at_least] == 0
number_of_pages[:at_most] = "*" if number_of_pages[:at_most] == 0
query = "#{query} number_of_pages_i:[#{number_of_pages[:at_least]} TO #{number_of_pages[:at_most]}]"
end
query = set_pub_date(query, options)
query = set_acquisition_date(query, options)
query = query.strip
if query == "[* TO *]"
# unless params[:advanced_search]
query = ""
# end
end
query
end
def set_search_result_order(sort_by, order)
sort = {}
if sort_by.try(:"include?", ":")
sort_by, order = sort_by.split(/:/)
end
# TODO: ページ数や大きさでの並べ替え
case sort_by
when "title"
sort[:sort_by] = "sort_title"
sort[:order] = "asc"
when "pub_date"
sort[:sort_by] = "date_of_publication"
sort[:order] = "desc"
when "score"
sort[:sort_by] = "score"
sort[:order] = "desc"
else
# デフォルトの並び方
sort[:sort_by] = "created_at"
sort[:order] = "desc"
end
if order == "asc"
sort[:order] = "asc"
elsif order == "desc"
sort[:order] = "desc"
end
sort
end
def render_mode(mode)
case mode
when "holding"
render partial: "manifestations/show_holding", locals: { manifestation: @manifestation }
when "tag_edit"
if defined?(EnjuBookmark)
render partial: "manifestations/tag_edit", locals: { manifestation: @manifestation }
end
when "tag_list"
if defined?(EnjuBookmark)
render partial: "manifestations/tag_list", locals: { manifestation: @manifestation }
end
when "show_index"
render partial: "manifestations/show_index", locals: { manifestation: @manifestation }
when "show_creators"
render partial: "manifestations/show_creators", locals: { manifestation: @manifestation }
when "show_all_creators"
render partial: "manifestations/show_creators", locals: { manifestation: @manifestation }
when "pickup"
render partial: "manifestations/pickup", locals: { manifestation: @manifestation }
when "calil_list"
if defined?(EnjuCalil)
render partial: "manifestations/calil_list", locals: { manifestation: @manifestation }
end
else
false
end
end
def prepare_options
@carrier_types = CarrierType.order(:position).select([ :id, :display_name, :position ])
@content_types = ContentType.order(:position).select([ :id, :display_name, :position ])
@roles = Role.select([ :id, :display_name, :position ])
@languages = Language.order(:position).select([ :id, :display_name, :position ])
@frequencies = Frequency.order(:position).select([ :id, :display_name, :position ])
@identifier_types = IdentifierType.order(:position).select([ :id, :display_name, :position ])
@nii_types = NiiType.select([ :id, :display_name, :position ]) if defined?(EnjuNii)
if defined?(EnjuSubject)
@subject_types = SubjectType.select([ :id, :display_name, :position ])
@subject_heading_types = SubjectHeadingType.select([ :id, :display_name, :position ])
@classification_types = ClassificationType.select([ :id, :display_name, :position ])
end
end
def get_index_agent
agent = {}
case
when params[:agent_id]
agent[:agent] = Agent.find(params[:agent_id])
when params[:creator_id]
agent[:creator] = @creator = Agent.find(params[:creator_id])
when params[:contributor_id]
agent[:contributor] = @contributor = Agent.find(params[:contributor_id])
when params[:publisher_id]
agent[:publisher] = @publisher = Agent.find(params[:publisher_id])
end
agent
end
def set_reservable
case params[:reservable].to_s
when "true"
@reservable = true
when "false"
@reservable = false
else
@reservable = nil
end
end
def parse_pub_date(options)
pub_date = {}
if options[:pub_date_from].blank?
pub_date[:from] = "*"
else
year = options[:pub_date_from].to_s.gsub(/\D/, "").rjust(4, "0")
if year.length == 4
pub_date[:from] = Time.zone.parse(Time.utc(year).to_s).beginning_of_year.utc.iso8601
else
pub_date[:from] = Time.zone.parse(options[:pub_date_from]).beginning_of_day.utc.iso8601 rescue nil
end
unless pub_date[:from]
pub_date[:from] = Time.zone.parse(Time.utc(options[:pub_date_from]).to_s).beginning_of_day.utc.iso8601
end
end
if options[:pub_date_until].blank?
pub_date[:until] = "*"
else
year = options[:pub_date_until].to_s.gsub(/\D/, "").rjust(4, "0")
if year.length == 4
pub_date[:until] = Time.zone.parse(Time.utc(year).to_s).end_of_year.utc.iso8601
else
pub_date[:until] = Time.zone.parse(options[:pub_date_until]).end_of_day.utc.iso8601 rescue nil
end
unless pub_date[:until]
pub_date[:until] = Time.zone.parse(Time.utc(options[:pub_date_until]).to_s).end_of_year.utc.iso8601
end
end
pub_date
end
def set_pub_date(query, options)
unless options[:pub_date_from].blank? && options[:pub_date_until].blank?
pub_date = parse_pub_date(options)
query = "#{query} date_of_publication_d:[#{pub_date[:from]} TO #{pub_date[:until]}]"
end
query
end
def set_acquisition_date(query, options)
unless options[:acquired_from].blank? && options[:acquired_until].blank?
options[:acquired_from].to_s.gsub!(/\D/, "")
options[:acquired_until].to_s.gsub!(/\D/, "")
acquisition_date = {}
if options[:acquired_from].blank?
acquisition_date[:from] = "*"
else
year = options[:acquired_from].rjust(4, "0")
if year.length == 4
acquisition_date[:from] = Time.zone.parse(Time.utc(year).to_s).beginning_of_year.utc.iso8601
else
acquisition_date[:from] = Time.zone.parse(options[:acquired_from]).beginning_of_day.utc.iso8601 rescue nil
end
unless acquisition_date[:from]
acquisition_date[:from] = Time.zone.parse(Time.utc(options[:acquired_from]).to_s).beginning_of_day.utc.iso8601
end
end
if options[:acquired_until].blank?
acquisition_date[:until] = "*"
else
year = options[:acquired_until].rjust(4, "0")
if year.length == 4
acquisition_date[:until] = Time.zone.parse(Time.utc(year).to_s).end_of_year.utc.iso8601
else
acquisition_date[:until] = Time.zone.parse(options[:acquired_until]).end_of_day.utc.iso8601 rescue nil
end
unless acquisition_date[:until]
acquisition_date[:until] = Time.zone.parse(Time.utc(options[:acquired_until]).to_s).end_of_year.utc.iso8601
end
end
query = "#{query} acquired_at_d:[#{acquisition_date[:from]} TO #{acquisition_date[:until]}]"
end
query
end
def set_creators
creators_params = manifestation_params[:creators_attributes]
contributors_params = manifestation_params[:contributors_attributes]
publishers_params = manifestation_params[:publishers_attributes]
Manifestation.transaction do
@manifestation.creates.destroy_all
@manifestation.realizes.destroy_all
@manifestation.produces.destroy_all
@manifestation.reload
@manifestation.creators = Agent.new_agents(creators_params)
@manifestation.contributors = Agent.new_agents(contributors_params)
@manifestation.publishers = Agent.new_agents(publishers_params)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/creates_controller.rb | app/controllers/creates_controller.rb | class CreatesController < ApplicationController
before_action :set_create, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_agent, :get_work
before_action :prepare_options, only: [ :new, :edit ]
# GET /creates
# GET /creates.json
def index
case
when @agent
@creates = @agent.creates.order("creates.position").page(params[:page])
when @work
@creates = @work.creates.order("creates.position").page(params[:page])
else
@creates = Create.page(params[:page])
end
respond_to do |format|
format.html # index.html.erb
end
end
# GET /creates/1
# GET /creates/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /creates/new
def new
if @agent && @work.blank?
redirect_to agent_works_url(@patorn)
elsif @work && @agent.blank?
redirect_to work_agents_url(@work)
else
@create = Create.new
@create.work = @work
@create.agent = @agent
end
end
# GET /creates/1/edit
def edit
end
# POST /creates
# POST /creates.json
def create
@create = Create.new(create_params)
respond_to do |format|
if @create.save
format.html { redirect_to @create, notice: t("controller.successfully_created", model: t("activerecord.models.create")) }
format.json { render json: @create, status: :created, location: @create }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @create.errors, status: :unprocessable_entity }
end
end
end
# PUT /creates/1
# PUT /creates/1.json
def update
# 並べ替え
if @work && params[:move]
move_position(@create, params[:move], false)
redirect_to creates_url(work_id: @create.work_id)
return
end
respond_to do |format|
if @create.update(create_params)
format.html { redirect_to @create, notice: t("controller.successfully_updated", model: t("activerecord.models.create")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @create.errors, status: :unprocessable_entity }
end
end
end
# DELETE /creates/1
# DELETE /creates/1.json
def destroy
@create.destroy
respond_to do |format|
flash[:notice] = t("controller.successfully_deleted", model: t("activerecord.models.create"))
case
when @agent
format.html { redirect_to agent_works_url(@agent) }
format.json { head :no_content }
when @work
format.html { redirect_to work_agents_url(@work) }
format.json { head :no_content }
else
format.html { redirect_to creates_url }
format.json { head :no_content }
end
end
end
private
def set_create
@create = Create.find(params[:id])
authorize @create
end
def check_policy
authorize Create
end
def create_params
params.require(:create).permit(
:agent_id, :work_id, :create_type_id, :position
)
end
def prepare_options
@create_types = CreateType.all
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/shelves_controller.rb | app/controllers/shelves_controller.rb | class ShelvesController < ApplicationController
before_action :set_shelf, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :get_library
before_action :get_libraries, only: [ :new, :edit, :create, :update ]
# GET /shelves
# GET /shelves.json
def index
if params[:mode] == "select"
if @library
@shelves = @library.shelves
else
@shelves = Shelf.real.order(:position)
end
render partial: "select_form"
return
else
sort = { sort_by: "shelf_name", order: "asc" }
# case params[:sort_by]
# when 'name'
# sort[:sort_by] = 'name'
# end
sort[:order] = "desc" if params[:order] == "desc"
query = @query = params[:query].to_s.strip
page = params[:page] || 1
library = @library if @library
search = Shelf.search(include: [ :library ]) do
fulltext query if query.present?
paginate page: page.to_i, per_page: Shelf.default_per_page
if library
with(:library).equal_to library.name
order_by :position, :asc
else
order_by sort[:sort_by], sort[:order]
end
facet :library
end
@shelves = search.results
@library_facet = search.facet(:library).rows
@library_names = Library.pluck(:name)
end
respond_to do |format|
format.html # index.html.erb
end
end
# GET /shelves/1
# GET /shelves/1.json
def show
@shelf = Shelf.includes(:library).find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.html.phone
end
end
# GET /shelves/new
def new
@shelf = Shelf.new
@library ||= current_user.profile.library
@shelf.library = @library
# @shelf.user = current_user
end
# GET /shelves/1/edit
def edit
end
# POST /shelves
# POST /shelves.json
def create
@shelf = Shelf.new(shelf_params)
if @library
@shelf.library = @library
else
@shelf.library = Library.web # unless current_user.has_role?('Librarian')
end
respond_to do |format|
if @shelf.save
format.html { redirect_to @shelf, notice: t("controller.successfully_created", model: t("activerecord.models.shelf")) }
format.json { render json: @shelf, status: :created, location: @shelf }
else
@library = Library.first if @shelf.library.nil?
format.html { render action: "new" }
format.json { render json: @shelf.errors, status: :unprocessable_entity }
end
end
end
# PUT /shelves/1
# PUT /shelves/1.json
def update
@shelf.library = @library if @library
if params[:move]
move_position(@shelf, params[:move], false)
redirect_to shelves_url(library_id: @shelf.library_id)
return
end
respond_to do |format|
if @shelf.update(shelf_params)
format.html { redirect_to @shelf, notice: t("controller.successfully_updated", model: t("activerecord.models.shelf")) }
format.json { head :no_content }
else
@library = Library.first if @library.nil?
format.html { render action: "edit" }
format.json { render json: @shelf.errors, status: :unprocessable_entity }
end
end
end
# DELETE /shelves/1
# DELETE /shelves/1.json
def destroy
@shelf.destroy
respond_to do |format|
format.html { redirect_to shelves_url }
format.json { head :no_content }
end
end
private
def set_shelf
@shelf = Shelf.find(params[:id])
authorize @shelf
end
def check_policy
authorize Shelf
end
def shelf_params
params.require(:shelf).permit(
:name, :display_name, :note, :library_id, :closed
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/request_types_controller.rb | app/controllers/request_types_controller.rb | class RequestTypesController < ApplicationController
before_action :set_request_type, only: [ :show, :edit, :update ]
before_action :check_policy, only: [ :index ]
# GET /request_types
# GET /request_types.json
def index
@request_types = RequestType.order(:position)
respond_to do |format|
format.html # index.html.erb
end
end
# GET /request_types/1
# GET /request_types/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /request_types/1/edit
def edit
end
# PUT /request_types/1
# PUT /request_types/1.json
def update
if params[:move]
move_position(@request_type, params[:move])
return
end
respond_to do |format|
if @request_type.update(request_type_params)
format.html { redirect_to @request_type, notice: t("controller.successfully_updated", model: t("activerecord.models.request_type")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @request_type.errors, status: :unprocessable_entity }
end
end
end
private
def set_request_type
@request_type = RequestType.find(params[:id])
authorize @request_type
end
def check_policy
authorize RequestType
end
def request_type_params
params.require(:request_type).permit(:name, :display_name, :note)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/application_controller.rb | app/controllers/application_controller.rb | class ApplicationController < ActionController::Base
include EnjuLibrary::Controller
include EnjuBiblio::Controller
include EnjuEvent::Controller
include EnjuSubject::Controller
include Pundit::Authorization
after_action :verify_authorized, unless: :devise_controller?
impersonates :user
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/event_import_files_controller.rb | app/controllers/event_import_files_controller.rb | class EventImportFilesController < ApplicationController
before_action :set_event_import_file, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
before_action :prepare_options, only: [ :new, :edit ]
# GET /event_import_files
# GET /event_import_files.json
def index
@event_import_files = EventImportFile.order(created_at: :desc).page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /event_import_files/1
# GET /event_import_files/1.json
def show
@event_import_results = @event_import_file.event_import_results.page(params[:page])
respond_to do |format|
format.html # show.html.erb
end
end
# GET /event_import_files/new
def new
@event_import_file = EventImportFile.new
@event_import_file.default_library = current_user.profile.library
@event_import_file.default_event_category = @event_categories.first
end
# GET /event_import_files/1/edit
def edit
end
# POST /event_import_files
# POST /event_import_files.json
def create
@event_import_file = EventImportFile.new(event_import_file_params)
@event_import_file.user = current_user
respond_to do |format|
if @event_import_file.save
if @event_import_file.mode == "import"
EventImportFileJob.perform_later(@event_import_file)
end
format.html { redirect_to @event_import_file, notice: t("import.successfully_created", model: t("activerecord.models.event_import_file")) }
format.json { render json: @event_import_file, status: :created, location: @event_import_file }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @event_import_file.errors, status: :unprocessable_entity }
end
end
end
# PUT /event_import_files/1
# PUT /event_import_files/1.json
def update
respond_to do |format|
if @event_import_file.update(event_import_file_params)
if @event_import_file.mode == "import"
EventImportFileJob.perform_later(@event_import_file)
end
format.html { redirect_to @event_import_file, notice: t("controller.successfully_updated", model: t("activerecord.models.event_import_file")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @event_import_file.errors, status: :unprocessable_entity }
end
end
end
# DELETE /event_import_files/1
# DELETE /event_import_files/1.json
def destroy
@event_import_file.destroy
respond_to do |format|
format.html { redirect_to event_import_files_url }
format.json { head :no_content }
end
end
private
def set_event_import_file
@event_import_file = EventImportFile.find(params[:id])
authorize @event_import_file
end
def check_policy
authorize EventImportFile
end
def event_import_file_params
params.require(:event_import_file).permit(
:attachment, :edit_mode, :user_encoding, :mode,
:default_library_id, :default_event_category_id
)
end
def prepare_options
@libraries = Library.all
@event_categories = EventCategory.order(:position)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/manifestation_reserve_stats_controller.rb | app/controllers/manifestation_reserve_stats_controller.rb | class ManifestationReserveStatsController < ApplicationController
before_action :set_manifestation_reserve_stat, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
after_action :convert_charset, only: :show
after_action :convert_charset, only: :show
# GET /manifestation_reserve_stats
# GET /manifestation_reserve_stats.json
def index
@manifestation_reserve_stats = ManifestationReserveStat.page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /manifestation_reserve_stats/1
# GET /manifestation_reserve_stats/1.json
def show
if request.format.text?
per_page = 65534
else
per_page = ReserveStatHasManifestation.default_per_page
end
@stats = @manifestation_reserve_stat.reserve_stat_has_manifestations.order("reserves_count DESC, manifestation_id").page(params[:page]).per(per_page)
respond_to do |format|
format.html # show.html.erb
format.text
end
end
# GET /manifestation_reserve_stats/new
def new
@manifestation_reserve_stat = ManifestationReserveStat.new
end
# GET /manifestation_reserve_stats/1/edit
def edit
end
# POST /manifestation_reserve_stats
# POST /manifestation_reserve_stats.json
def create
@manifestation_reserve_stat = ManifestationReserveStat.new(manifestation_reserve_stat_params)
@manifestation_reserve_stat.user = current_user
respond_to do |format|
if @manifestation_reserve_stat.save
ManifestationReserveStatJob.perform_later(@manifestation_reserve_stat)
format.html { redirect_to @manifestation_reserve_stat, notice: t("statistic.successfully_created", model: t("activerecord.models.manifestation_reserve_stat")) }
format.json { render json: @manifestation_reserve_stat, status: :created, location: @manifestation_reserve_stat }
else
format.html { render action: "new" }
format.json { render json: @manifestation_reserve_stat.errors, status: :unprocessable_entity }
end
end
end
# PUT /manifestation_reserve_stats/1
# PUT /manifestation_reserve_stats/1.json
def update
respond_to do |format|
if @manifestation_reserve_stat.update(manifestation_reserve_stat_params)
if @manifestation_reserve_stat.mode == "import"
ManifestationReserveStatJob.perform_later(@manifestation_reserve_stat)
end
format.html { redirect_to @manifestation_reserve_stat, notice: t("controller.successfully_created", model: t("activerecord.models.manifestation_reserve_stat")) }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @manifestation_reserve_stat.errors, status: :unprocessable_entity }
end
end
end
# DELETE /manifestation_reserve_stats/1
# DELETE /manifestation_reserve_stats/1.json
def destroy
@manifestation_reserve_stat.destroy
respond_to do |format|
format.html { redirect_to manifestation_reserve_stats_url }
format.json { head :no_content }
end
end
private
def set_manifestation_reserve_stat
@manifestation_reserve_stat = ManifestationReserveStat.find(params[:id])
authorize @manifestation_reserve_stat
end
def check_policy
authorize ManifestationReserveStat
end
def manifestation_reserve_stat_params
params.require(:manifestation_reserve_stat).permit(
:start_date, :end_date, :note, :mode
)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/user_group_has_checkout_types_controller.rb | app/controllers/user_group_has_checkout_types_controller.rb | class UserGroupHasCheckoutTypesController < ApplicationController
include EnjuCirculation::Controller
before_action :set_user_group_has_checkout_type, only: [ :show, :edit, :update, :destroy ]
before_action :check_policy, only: [ :index, :new, :create ]
helper_method :get_user_group, :get_checkout_type
before_action :prepare_options, only: [ :new, :edit ]
# GET /user_group_has_checkout_types
# GET /user_group_has_checkout_types.json
def index
@user_group_has_checkout_types = UserGroupHasCheckoutType.includes([ :user_group, :checkout_type ]).order("user_groups.position, checkout_types.position").page(params[:page])
respond_to do |format|
format.html # index.html.erb
end
end
# GET /user_group_has_checkout_types/1
# GET /user_group_has_checkout_types/1.json
def show
respond_to do |format|
format.html # show.html.erb
end
end
# GET /user_group_has_checkout_types/new
def new
@user_group_has_checkout_type = UserGroupHasCheckoutType.new(
checkout_type: get_checkout_type,
user_group: get_user_group
)
end
# GET /user_group_has_checkout_types/1/edit
def edit
end
# POST /user_group_has_checkout_types
# POST /user_group_has_checkout_types.json
def create
@user_group_has_checkout_type = UserGroupHasCheckoutType.new(user_group_has_checkout_type_params)
respond_to do |format|
if @user_group_has_checkout_type.save
format.html { redirect_to(@user_group_has_checkout_type, notice: t("controller.successfully_created", model: t("activerecord.models.user_group_has_checkout_type"))) }
format.json { render json: @user_group_has_checkout_type, status: :created, location: @user_group_has_checkout_type }
else
prepare_options
format.html { render action: "new" }
format.json { render json: @user_group_has_checkout_type.errors, status: :unprocessable_entity }
end
end
end
# PUT /user_group_has_checkout_types/1
# PUT /user_group_has_checkout_types/1.json
def update
respond_to do |format|
if @user_group_has_checkout_type.update(user_group_has_checkout_type_params)
format.html { redirect_to @user_group_has_checkout_type, notice: t("controller.successfully_updated", model: t("activerecord.models.user_group_has_checkout_type")) }
format.json { head :no_content }
else
prepare_options
format.html { render action: "edit" }
format.json { render json: @user_group_has_checkout_type.errors, status: :unprocessable_entity }
end
end
end
# DELETE /user_group_has_checkout_types/1
# DELETE /user_group_has_checkout_types/1.json
def destroy
@user_group_has_checkout_type.destroy
respond_to do |format|
format.html { redirect_to user_group_has_checkout_types_url }
format.json { head :no_content }
end
end
private
def set_user_group_has_checkout_type
@user_group_has_checkout_type = UserGroupHasCheckoutType.find(params[:id])
authorize @user_group_has_checkout_type
end
def check_policy
authorize UserGroupHasCheckoutType
end
def user_group_has_checkout_type_params
params.require(:user_group_has_checkout_type).permit(
:user_group_id, :checkout_type_id,
:checkout_limit, :checkout_period, :checkout_renewal_limit,
:reservation_limit, :reservation_expired_period,
:set_due_date_before_closing_day, :fixed_due_date, :note, :position,
:user_group, :checkout_type
)
end
def prepare_options
@checkout_types = CheckoutType.all
@user_groups = UserGroup.all
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/concerns/enju_purchase_request/controller.rb | app/controllers/concerns/enju_purchase_request/controller.rb | module EnjuPurchaseRequest
module Controller
private
def get_order_list
if params[:order_list_id]
@order_list = OrderList.find(params[:order_list_id])
authorize @order_list, :show?
end
end
def get_purchase_request
if params[:purchase_request_id]
@purchase_request = PurchaseRequest.find(params[:purchase_request_id])
authorize @purchase_request, :show?
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/concerns/enju_circulation/controller.rb | app/controllers/concerns/enju_circulation/controller.rb | module EnjuCirculation
module Controller
extend ActiveSupport::Concern
def get_checkout_type
if params[:checkout_type_id]
@checkout_type = CheckoutType.find(params[:checkout_type_id])
authorize @checkout_type, :show?
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/concerns/enju_subject/controller.rb | app/controllers/concerns/enju_subject/controller.rb | module EnjuSubject
module Controller
private
def get_subject_heading_type
if params[:subject_heading_type_id]
@subject_heading_type = SubjectHeadingType.find(params[:subject_heading_type_id])
authorize @subject_heading_type, :show?
end
end
def get_subject
if params[:subject_id]
@subject = Subject.find(params[:subject_id])
authorize @subject, :show?
end
end
def get_classification
if params[:classification_id]
@classification = Classification.find(params[:classification_id])
authorize @classification, :show?
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/concerns/enju_biblio/controller.rb | app/controllers/concerns/enju_biblio/controller.rb | module EnjuBiblio
module Controller
extend ActiveSupport::Concern
private
def get_work
@work = Manifestation.find(params[:work_id]) if params[:work_id]
authorize @work, :show? if @work
end
def get_expression
@expression = Manifestation.find(params[:expression_id]) if params[:expression_id]
authorize @expression, :show? if @expression
end
def get_manifestation
@manifestation = Manifestation.find(params[:manifestation_id]) if params[:manifestation_id]
authorize @manifestation, :show? if @manifestation
end
def get_item
@item = Item.find(params[:item_id]) if params[:item_id]
authorize @item, :show? if @item
end
def get_carrier_type
@carrier_type = CarrierType.find(params[:carrier_type_id]) if params[:carrier_type_id]
end
def get_agent
@agent = Agent.find(params[:agent_id]) if params[:agent_id]
authorize @agent if @agent
end
def get_series_statement
@series_statement = SeriesStatement.find(params[:series_statement_id]) if params[:series_statement_id]
end
def get_basket
@basket = Basket.find(params[:basket_id]) if params[:basket_id]
end
def get_agent_merge_list
@agent_merge_list = AgentMergeList.find(params[:agent_merge_list_id]) if params[:agent_merge_list_id]
end
def get_series_statement_merge_list
@series_statement_merge_list = SeriesStatementMergeList.find(params[:series_statement_merge_list_id]) if params[:series_statement_merge_list_id]
end
def make_internal_query(search)
# 内部的なクエリ
set_role_query(current_user, search)
unless params[:mode] == "add"
expression = @expression
agent = @agent
manifestation = @manifestation
reservable = @reservable
carrier_type = params[:carrier_type]
library = params[:library]
language = params[:language]
if defined?(EnjuSubject)
subject = params[:subject]
subject_by_term = Subject.find_by(term: params[:subject])
@subject_by_term = subject_by_term
end
search.build do
with(:publisher_ids).equal_to agent.id if agent
with(:original_manifestation_ids).equal_to manifestation.id if manifestation
with(:reservable).equal_to reservable unless reservable.nil?
if carrier_type.present?
with(:carrier_type).equal_to carrier_type
end
if library.present?
library_list = library.split.uniq
library_list.each do |lib|
with(:library).equal_to lib
end
end
if language.present?
language_list = language.split.uniq
language_list.each do |language|
with(:language).equal_to language
end
end
if defined?(EnjuSubject)
if subject.present?
with(:subject).equal_to subject_by_term.term
end
end
end
end
search
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/concerns/enju_inventory/controller.rb | app/controllers/concerns/enju_inventory/controller.rb | module EnjuInventory
module Controller
extend ActiveSupport::Concern
def get_inventory_file
@inventory_file = InventoryFile.find(params[:inventory_file_id]) if params[:inventory_file_id]
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/concerns/enju_event/controller.rb | app/controllers/concerns/enju_event/controller.rb | module EnjuEvent
module Controller
private
def get_event
if params[:event_id]
@event = Event.find(params[:event_id])
authorize @event, :show?
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/concerns/enju_event/enju_libraries_controller.rb | app/controllers/concerns/enju_event/enju_libraries_controller.rb | module EnjuEvent
module EnjuLibrariesController
extend ActiveSupport::Concern
def show
search = Sunspot.new_search(Event)
library_id = @library.id
search.build do
with(:library_id).equal_to library_id
order_by(:start_at, :desc)
end
page = params[:event_page] || 1
search.query.paginate(page.to_i, Event.default_per_page)
@events = search.execute!.results
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/concerns/enju_library/controller.rb | app/controllers/concerns/enju_library/controller.rb | module EnjuLibrary
module Controller
extend ActiveSupport::Concern
included do
before_action :get_library_group, :set_locale, :set_available_languages, :set_mobile_request
before_action :store_current_location, unless: :devise_controller?
rescue_from Pundit::NotAuthorizedError, with: :render_403
# rescue_from ActiveRecord::RecordNotFound, with: :render_404
# rescue_from ActionView::MissingTemplate, with: :render_404_invalid_format
end
private
def render_403
return if performed?
if user_signed_in?
respond_to do |format|
format.html { render template: "page/403", status: :forbidden }
# format.html.phone {render template: 'page/403', status: 403}
format.xml { render template: "page/403", status: :forbidden }
format.json { render json: { "error": "forbidden" } }
format.rss { render template: "page/403.xml", status: :forbidden }
end
else
respond_to do |format|
format.html { redirect_to main_app.new_user_session_url }
# format.html.phone { redirect_to new_user_session_url }
format.xml { render template: "page/403", status: :forbidden }
format.json { render json: { "error": "forbidden" } }
format.rss { render template: "page/403.xml", status: :forbidden }
end
end
end
def render_404
return if performed?
respond_to do |format|
format.html { render template: "page/404", status: :not_found }
# format.html.phone { render template: 'page/404', status: 404 }
format.xml { render template: "page/404", status: :not_found }
format.json { render json: { "error": "not_found" } }
format.rss { render template: "page/404.xml", status: :not_found }
end
end
def render_404_invalid_format
return if performed?
render file: Rails.root.join("public/404.html").to_s, formats: [ :html ]
end
def render_500
return if performed?
respond_to do |format|
format.html { render file: Rails.root.join("public/500.html").to_s, layout: false, status: :internal_server_error }
# format.html.phone {render file: "#{Rails.root}/public/500", layout: false, status: 500}
format.xml { render template: "page/500", status: :internal_server_error }
format.json { render json: { "error": "server_error" } }
format.rss { render template: "page/500.xml", status: :internal_server_error }
end
end
def after_sign_in_path_for(resource)
session[:locale] = nil
super
end
def set_locale
if params[:locale]
unless I18n.available_locales.include?(params[:locale].to_s.intern)
raise InvalidLocaleError
end
end
if user_signed_in?
locale = params[:locale] || session[:locale] || current_user.profile.try(:locale).try(:to_sym)
else
locale = params[:locale] || session[:locale]
end
if locale
I18n.locale = @locale = session[:locale] = locale.to_sym
else
I18n.locale = @locale = session[:locale] = I18n.default_locale
end
rescue InvalidLocaleError
reset_session
@locale = I18n.default_locale
end
def default_url_options(options = {})
{ locale: nil }
end
def set_available_languages
if Rails.env.production?
@available_languages = Rails.cache.fetch("available_languages") {
Language.where(iso_639_1: I18n.available_locales.map { |l| l.to_s }).select([ :id, :iso_639_1, :name, :native_name, :display_name, :position ]).all
}
else
@available_languages = Language.where(iso_639_1: I18n.available_locales.map { |l| l.to_s })
end
end
def reset_params_session
session[:params] = nil
end
def not_found
raise ActiveRecord::RecordNotFound
end
def access_denied
raise Pundit::NotAuthorizedError
end
def get_user
@user = User.find_by(username: params[:user_id]) if params[:user_id]
# authorize! :show, @user if @user
end
def get_user_group
@user_group = UserGroup.find(params[:user_group_id]) if params[:user_group_id]
end
def convert_charset
case params[:format]
when "csv"
return unless LibraryGroup.site_config.csv_charset_conversion
# TODO: 他の言語
if @locale.to_sym == :ja
headers["Content-Type"] = "text/csv; charset=Shift_JIS"
response.body = NKF::nkf("-Ws", response.body)
end
when "xml"
if @locale.to_sym == :ja
headers["Content-Type"] = "application/xml; charset=Shift_JIS"
response.body = NKF::nkf("-Ws", response.body)
end
end
end
def store_page
if request.get? && request.format.try(:html?) && !request.xhr?
flash[:page] = params[:page] if params[:page].to_i.positive?
end
end
def set_role_query(user, search)
role = user.try(:role) || Role.default
search.build do
with(:required_role_id).less_than_or_equal_to role.id
end
end
def clear_search_sessions
session[:query] = nil
session[:params] = nil
session[:search_params] = nil
session[:manifestation_ids] = nil
end
def api_request?
true unless params[:format].nil? || (params[:format] == "html")
end
def get_top_page_content
if defined?(EnjuNews)
@news_feeds = Rails.cache.fetch("news_feed_all") { NewsFeed.order(:position) }
@news_posts = NewsPost.limit(LibraryGroup.site_config.news_post_number_top_page || 10)
end
@libraries = Library.real
end
def set_mobile_request
case params[:view]
when "phone"
session[:enju_view] = :phone
when "desktop"
session[:enju_view] = :desktop
when "reset"
session[:enju_view] = nil
end
case session[:enju_view].try(:to_sym)
when :phone
request.variant = :phone
when :desktop
request.variant = nil
else
request.variant = :phone if browser.device.mobile?
end
end
def move_position(resource, direction, redirect = true)
if [ "higher", "lower" ].include?(direction)
resource.send("move_#{direction}")
if redirect
redirect_to url_for(controller: resource.class.to_s.pluralize.underscore)
nil
end
end
end
def store_current_location
store_location_for(:user, request.url) if request.format.html?
end
def get_library_group
@library_group = LibraryGroup.site_config
end
def get_shelf
if params[:shelf_id]
@shelf = Shelf.includes(:library).find(params[:shelf_id])
authorize @shelf, :show?
end
end
def get_library
if params[:library_id]
@library = Library.friendly.find(params[:library_id])
authorize @library, :show?
end
end
def get_libraries
@libraries = Library.order(:position)
end
def get_bookstore
if params[:bookstore_id]
@bookstore = Bookstore.find(params[:bookstore_id])
authorize @bookstore, :show?
end
end
def get_subscription
if params[:subscription_id]
@subscription = Subscription.find(params[:subscription_id])
authorize @subscription, :show?
end
end
class InvalidLocaleError < StandardError
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/active_storage/blobs/proxy_controller.rb | app/controllers/active_storage/blobs/proxy_controller.rb | class ActiveStorage::Blobs::ProxyController < ActiveStorage::BaseController
include ActiveStorage::SetBlob
include ActiveStorage::Streaming
include Pundit::Authorization
def show
@blob.attachments.each do |attachment|
authorize attachment.record
end
if request.headers["Range"].present?
send_blob_byte_range_data @blob, request.headers["Range"]
else
http_cache_forever public: true do
response.headers["Accept-Ranges"] = "bytes"
response.headers["Content-Length"] = @blob.byte_size.to_s
send_blob_stream @blob, disposition: params[:disposition]
end
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/controllers/active_storage/blobs/redirect_controller.rb | app/controllers/active_storage/blobs/redirect_controller.rb | class ActiveStorage::Blobs::RedirectController < ActiveStorage::BaseController
include ActiveStorage::SetBlob
include Pundit::Authorization
def show
@blob.attachments.each do |attachment|
authorize attachment.record
end
expires_in ActiveStorage.service_urls_expire_in
redirect_to @blob.url(disposition: params[:disposition]), allow_other_host: true
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/periodical.rb | app/models/periodical.rb | class Periodical < ApplicationRecord
belongs_to :manifestation
belongs_to :frequency
has_many :periodical_and_manifestations, dependent: :destroy
has_many :manifestations, through: :periodical_and_manifestations
validates :original_title, presence: true
end
# == Schema Information
#
# Table name: periodicals
#
# id :bigint not null, primary key
# original_title :text not null
# created_at :datetime not null
# updated_at :datetime not null
# frequency_id :bigint not null
# manifestation_id :bigint not null
#
# Indexes
#
# index_periodicals_on_frequency_id (frequency_id)
# index_periodicals_on_manifestation_id (manifestation_id)
#
# Foreign Keys
#
# fk_rails_... (frequency_id => frequencies.id)
# fk_rails_... (manifestation_id => manifestations.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/news_feed.rb | app/models/news_feed.rb | class NewsFeed < ApplicationRecord
default_scope { order("news_feeds.position") }
belongs_to :library_group
validates :title, :url, presence: true
validates :url, length: { maximum: 255 }
before_save :fetch
acts_as_list
def self.per_page
10
end
def fetch
begin
feed = Faraday.get(url).body.force_encoding("UTF-8")
if RSS::Parser.parse(feed, false)
self.body = feed
end
rescue StandardError, Timeout::Error
nil
end
end
def content
if body
# tDiary の RSS をパースした際に to_s が空になる
# rss = RSS::Parser.parse(feed)
# rss.to_s
# => ""
# if rss.nil?
begin
rss = RSS::Parser.parse(body)
rescue RSS::InvalidRSSError
rss = RSS::Parser.parse(body, false)
rescue RSS::NotWellFormedError, TypeError
nil
end
# end
end
end
def force_reload
save!
end
def self.fetch_feeds
NewsFeed.find_each do |news_feed|
news_feed.touch
end
end
end
# == Schema Information
#
# Table name: news_feeds
#
# id :bigint not null, primary key
# library_group_id :bigint default(1), not null
# title :string
# url :string
# body :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/tag.rb | app/models/tag.rb | class Tag < ApplicationRecord
has_many :taggings, dependent: :destroy, class_name: "ActsAsTaggableOn::Tagging"
validates :name, presence: true
after_destroy :save_taggings
after_save :save_taggings
extend FriendlyId
friendly_id :name
searchable do
text :name
string :name
time :created_at
time :updated_at
integer :bookmark_ids, multiple: true do
tagged(Bookmark).compact.collect(&:id)
end
integer :taggings_count do
taggings.size
end
end
paginates_per 10
def self.bookmarked(bookmark_ids, options = {})
count = Tag.count
count = Tag.default_per_page if count.zero?
unless bookmark_ids.empty?
Tag.search do
with(:bookmark_ids).any_of bookmark_ids
order_by :taggings_count, :desc
paginate(page: 1, per_page: count)
end.results
end
end
def save_taggings
taggings.map do |t| t.taggable.save end
end
def tagged(taggable_type)
taggings.where(taggable_type: taggable_type.to_s).includes(:taggable).collect(&:taggable)
end
end
# == Schema Information
#
# Table name: tags
#
# id :bigint not null, primary key
# name :string not null
# taggings_count :integer default(0)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_tags_on_name (name) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/agent.rb | app/models/agent.rb | class Agent < ApplicationRecord
include EnjuNdl::EnjuAgent
scope :readable_by, lambda { |user|
if user
where("required_role_id <= ?", user.try(:user_has_role).try(:role_id))
else
where("required_role_id <= 1")
end
}
has_many :creates, dependent: :destroy
has_many :works, through: :creates
has_many :realizes, dependent: :destroy
has_many :expressions, through: :realizes
has_many :produces, dependent: :destroy
has_many :manifestations, through: :produces
has_many :children, foreign_key: "parent_id", class_name: "AgentRelationship", dependent: :destroy, inverse_of: :parent
has_many :parents, foreign_key: "child_id", class_name: "AgentRelationship", dependent: :destroy, inverse_of: :child
has_many :derived_agents, through: :children, source: :child
has_many :original_agents, through: :parents, source: :parent
has_many :picture_files, as: :picture_attachable, dependent: :destroy
has_many :donates, dependent: :destroy
has_many :donated_items, through: :donates, source: :item
has_many :owns, dependent: :destroy
has_many :items, through: :owns
has_many :agent_merges, dependent: :destroy
has_many :agent_merge_lists, through: :agent_merges
belongs_to :agent_type
belongs_to :required_role, class_name: "Role"
belongs_to :language
belongs_to :country
has_one :agent_import_result
belongs_to :profile, optional: true
validates :full_name, presence: true, length: { maximum: 255 }
validates :birth_date, format: { with: /\A\d+(-\d{0,2}){0,2}\z/ }, allow_blank: true
validates :death_date, format: { with: /\A\d+(-\d{0,2}){0,2}\z/ }, allow_blank: true
validates :email, format: { with: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i }, allow_blank: true
validate :check_birth_date
before_validation :set_role_and_name, on: :create
before_save :set_date_of_birth, :set_date_of_death
after_save do |agent|
agent.works.map { |work| work.touch && work.index }
agent.expressions.map { |expression| expression.touch && expression.index }
agent.manifestations.map { |manifestation| manifestation.touch && manifestation.index }
agent.items.map { |item| item.touch && item.index }
Sunspot.commit
end
after_destroy do |agent|
agent.works.map { |work| work.touch && work.index }
agent.expressions.map { |expression| expression.touch && expression.index }
agent.manifestations.map { |manifestation| manifestation.touch && manifestation.index }
agent.items.map { |item| item.touch && item.index }
Sunspot.commit
end
attr_accessor :agent_id
searchable do
text :name, :place, :address_1, :address_2, :other_designation, :note
string :zip_code_1
string :zip_code_2
time :created_at
time :updated_at
time :date_of_birth
time :date_of_death
integer :work_ids, multiple: true
integer :expression_ids, multiple: true
integer :manifestation_ids, multiple: true
integer :agent_merge_list_ids, multiple: true
integer :original_agent_ids, multiple: true
integer :required_role_id
integer :agent_type_id
string :agent_id do
id
end
end
paginates_per 10
def set_role_and_name
self.required_role = Role.find_by(name: "Librarian") if required_role_id.nil?
set_full_name
end
def set_full_name
if full_name.blank?
if LibraryGroup.site_config.family_name_first
self.full_name = [ last_name, middle_name, first_name ].compact.join(" ").to_s.strip
else
self.full_name = [ first_name, last_name, middle_name ].compact.join(" ").to_s.strip
end
end
if full_name_transcription.blank?
self.full_name_transcription = [ last_name_transcription, middle_name_transcription, first_name_transcription ].join(" ").to_s.strip
end
[ full_name, full_name_transcription ]
end
def set_date_of_birth
return if birth_date.blank?
begin
date = Time.zone.parse(birth_date.to_s)
rescue ArgumentError
begin
date = Time.zone.parse("#{birth_date}-01")
rescue ArgumentError
begin
date = Time.zone.parse("#{birth_date}-01-01")
rescue StandardError
nil
end
end
end
self.date_of_birth = date
end
def set_date_of_death
return if death_date.blank?
begin
date = Time.zone.parse(death_date.to_s)
rescue ArgumentError
begin
date = Time.zone.parse("#{death_date}-01")
rescue ArgumentError
begin
date = Time.zone.parse("#{death_date}-01-01")
rescue StandardError
nil
end
end
end
self.date_of_death = date
end
def check_birth_date
if date_of_birth.present? && date_of_death.present?
if date_of_birth > date_of_death
errors.add(:birth_date)
errors.add(:death_date)
end
end
end
# def full_name_generate
# # TODO: 日本人以外は?
# name = []
# name << self.last_name.to_s.strip
# name << self.middle_name.to_s.strip unless self.middle_name.blank?
# name << self.first_name.to_s.strip
# name << self.corporate_name.to_s.strip
# name.join(" ").strip
# end
def full_name_without_space
full_name.gsub(/[\s,]/, "")
# # TODO: 日本人以外は?
# name = []
# name << self.last_name.to_s.strip
# name << self.middle_name.to_s.strip
# name << self.first_name.to_s.strip
# name << self.corporate_name.to_s.strip
# name.join("").strip
end
def full_name_transcription_without_space
full_name_transcription.to_s.gsub(/\s/, "")
end
def full_name_alternative_without_space
full_name_alternative.to_s.gsub(/\s/, "")
end
def name
name = []
name << full_name.to_s.strip
name << full_name_transcription.to_s.strip
name << full_name_alternative.to_s.strip
name << full_name_without_space
# name << full_name_transcription_without_space
# name << full_name_alternative_without_space
# name << full_name.wakati rescue nil
# name << full_name_transcription.wakati rescue nil
# name << full_name_alternative.wakati rescue nil
name
end
def date
if date_of_birth
if date_of_death
"#{date_of_birth} - #{date_of_death}"
else
"#{date_of_birth} -"
end
end
end
def creator?(resource)
resource.creators.include?(self)
end
def publisher?(resource)
resource.publishers.include?(self)
end
def created(work)
creates.find_by(work_id: work.id)
end
def realized(expression)
realizes.find_by(expression_id: expression.id)
end
def produced(manifestation)
produces.find_by(manifestation_id: manifestation.id)
end
def owned(item)
owns.where(item_id: item.id)
end
def self.import_agents(agent_lists)
agents = []
agent_lists.each do |agent_list|
name_and_role = agent_list[:full_name].split("||")
if agent_list[:ndla_identifier].present?
agent = NdlaRecord.find_by(body: agent_list[:ndla_identifier])&.agent
elsif agent_list[:agent_identifier].present?
agent = Agent.find_by(agent_identifier: agent_list[:agent_identifier])
else
agents_matched = Agent.where(full_name: name_and_role[0])
agents_matched = agents_matched.where(place: agent_list[:place]) if agent_list[:place]
agent = agents_matched.first
end
role_type = name_and_role[1].to_s.strip
unless agent
agent = Agent.new(
full_name: name_and_role[0],
full_name_transcription: agent_list[:full_name_transcription],
agent_identifier: agent_list[:agent_identifier],
place: agent_list[:place],
language_id: 1
)
agent.required_role = Role.find_by(name: "Guest")
agent.save
if agent_list[:ndla_identifier].present?
agent.create_ndla_record(body: agent_list[:ndla_identifier])
end
end
agents << agent
end
agents.uniq!
agents
end
def agents
original_agents + derived_agents
end
def self.new_agents(agents_params)
return [] unless agents_params
agents = []
Agent.transaction do
agents_params.each do |k, v|
next if v["_destroy"] == "1"
agent = nil
if v["agent_id"].present?
agent = Agent.find(v["agent_id"])
elsif v["id"].present?
agent = Agent.find(v["id"])
end
if !agent or agent.full_name != v["full_name"]
v.delete("id")
v.delete("agent_id")
v.delete("_destroy")
agent = Agent.create(v)
end
agents << agent
end
end
agents
end
end
# == Schema Information
#
# Table name: agents
#
# id :bigint not null, primary key
# address_1 :text
# address_1_note :text
# address_2 :text
# address_2_note :text
# agent_identifier :string
# birth_date :string
# corporate_name :string
# corporate_name_transcription :string
# date_of_birth :datetime
# date_of_death :datetime
# death_date :string
# email :text
# fax_number_1 :string
# fax_number_2 :string
# first_name :string
# first_name_transcription :string
# full_name :string
# full_name_alternative :text
# full_name_alternative_transcription :text
# full_name_transcription :text
# last_name :string
# last_name_transcription :string
# locality :text
# lock_version :integer default(0), not null
# middle_name :string
# middle_name_transcription :string
# note :text
# other_designation :text
# place :text
# postal_code :string
# region :text
# required_score :integer default(0), not null
# street :text
# telephone_number_1 :string
# telephone_number_2 :string
# url :text
# zip_code_1 :string
# zip_code_2 :string
# created_at :datetime not null
# updated_at :datetime not null
# agent_type_id :bigint default(1), not null
# country_id :bigint default(1), not null
# language_id :bigint default(1), not null
# profile_id :bigint
# required_role_id :bigint default(1), not null
#
# Indexes
#
# index_agents_on_agent_identifier (agent_identifier)
# index_agents_on_country_id (country_id)
# index_agents_on_full_name (full_name)
# index_agents_on_language_id (language_id)
# index_agents_on_profile_id (profile_id)
# index_agents_on_required_role_id (required_role_id)
#
# Foreign Keys
#
# fk_rails_... (required_role_id => roles.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/identifier_type.rb | app/models/identifier_type.rb | class IdentifierType < ApplicationRecord
include MasterModel
has_many :identifiers, dependent: :destroy
validates :name, format: { with: /\A[0-9a-z][0-9a-z_\-]*[0-9a-z]\Z/ }
end
# == Schema Information
#
# Table name: identifier_types
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_identifier_types_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/budget_type.rb | app/models/budget_type.rb | class BudgetType < ApplicationRecord
include MasterModel
validates :name, presence: true, format: { with: /\A[0-9A-Za-z][0-9A-Za-z_\-\s,]*[0-9a-z]\Z/ }
has_many :items, dependent: :restrict_with_exception
private
def valid_name?
true
end
end
# == Schema Information
#
# Table name: budget_types
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_budget_types_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/checkin.rb | app/models/checkin.rb | class Checkin < ApplicationRecord
default_scope { order("checkins.id DESC") }
scope :on, lambda { |date| where("created_at >= ? AND created_at < ?", date.beginning_of_day, date.tomorrow.beginning_of_day) }
has_one :checkout
belongs_to :item, touch: true
belongs_to :librarian, class_name: "User"
belongs_to :basket
validates :item_id, uniqueness: { scope: :basket_id }
validate :available_for_checkin?, on: :create
before_validation :set_item
attr_accessor :item_identifier
paginates_per 10
def available_for_checkin?
unless basket
return nil
end
if item.blank?
errors.add(:base, I18n.t("checkin.item_not_found"))
return
end
if basket.items.find_by("item_id = ?", item.id)
errors[:base] << I18n.t("checkin.already_checked_in")
end
end
def item_checkin(current_user)
message = ""
Checkin.transaction do
item.checkin!
Checkout.not_returned.where(item_id: item_id).find_each do |checkout|
# TODO: ILL時の処理
checkout.checkin = self
checkout.operator = current_user
unless checkout.user.profile.try(:save_checkout_history)
checkout.user = nil
end
checkout.save(validate: false)
unless checkout.item.shelf.library == current_user.profile.library
message << I18n.t("checkin.other_library_item")
end
end
if item.reserved?
# TODO: もっと目立たせるために別画面を表示するべき?
message << I18n.t("item.this_item_is_reserved")
item.retain(current_user)
end
if item.include_supplements?
message << I18n.t("item.this_item_include_supplement")
end
if item.circulation_status.name == "Missing"
message << I18n.t("checkout.missing_item_found")
end
# メールとメッセージの送信
# ReservationNotifier.deliver_reserved(item.manifestation.reserves.first.user, item.manifestation)
# Message.create(sender: current_user, receiver: item.manifestation.next_reservation.user, subject: message_template.title, body: message_template.body, recipient: item.manifestation.next_reservation.user)
end
message.presence
end
def set_item
identifier = item_identifier.to_s.strip
if identifier.present?
item = Item.find_by(item_identifier: identifier)
self.item = item
end
end
end
# == Schema Information
#
# Table name: checkins
#
# id :bigint not null, primary key
# lock_version :integer default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# basket_id :bigint
# item_id :bigint not null
# librarian_id :bigint
#
# Indexes
#
# index_checkins_on_basket_id (basket_id)
# index_checkins_on_item_id_and_basket_id (item_id,basket_id) UNIQUE
# index_checkins_on_librarian_id (librarian_id)
#
# Foreign Keys
#
# fk_rails_... (item_id => items.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/subscription.rb | app/models/subscription.rb | class Subscription < ApplicationRecord
has_many :subscribes, dependent: :destroy
has_many :works, through: :subscribes
belongs_to :user
if defined?(EnjuPurchasRequest)
belongs_to :order_list
end
validates :title, presence: :title
searchable do
text :title, :note
time :created_at
time :updated_at
integer :work_ids, multiple: true
end
paginates_per 10
def subscribed(work)
subscribes.find_by(work_id: work.id)
end
end
# == Schema Information
#
# Table name: subscriptions
#
# id :bigint not null, primary key
# note :text
# subscribes_count :integer default(0), not null
# title :text not null
# created_at :datetime not null
# updated_at :datetime not null
# order_list_id :bigint
# user_id :bigint not null
#
# Indexes
#
# index_subscriptions_on_order_list_id (order_list_id)
# index_subscriptions_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/user_reserve_stat_transition.rb | app/models/user_reserve_stat_transition.rb | class UserReserveStatTransition < ApplicationRecord
belongs_to :user_reserve_stat, inverse_of: :user_reserve_stat_transitions
end
# == Schema Information
#
# Table name: user_reserve_stat_transitions
#
# id :bigint not null, primary key
# metadata :jsonb not null
# most_recent :boolean not null
# sort_key :integer
# to_state :string
# created_at :datetime not null
# updated_at :datetime not null
# user_reserve_stat_id :bigint
#
# Indexes
#
# index_user_reserve_stat_transitions_on_sort_key_and_stat_id (sort_key,user_reserve_stat_id) UNIQUE
# index_user_reserve_stat_transitions_on_user_reserve_stat_id (user_reserve_stat_id)
# index_user_reserve_stat_transitions_parent_most_recent (user_reserve_stat_id,most_recent) UNIQUE WHERE most_recent
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/identifier.rb | app/models/identifier.rb | class Identifier < ApplicationRecord
belongs_to :identifier_type
belongs_to :manifestation, touch: true, optional: true
validates :body, presence: true
validates :body, uniqueness: { scope: [ :identifier_type_id, :manifestation_id ] }
validate :check_identifier
before_validation :normalize
before_save :convert_isbn
scope :id_type, ->(type) {
where(identifier_type: IdentifierType.find_by(name: type))
}
scope :not_migrated, -> {
joins(:identifier_type).where.not(
"identifier_types.name": [
"isbn", "issn", "jpno", "ncid", "lccn", "doi", "iss_itemno"
]
)
}
acts_as_list scope: :manifestation_id
strip_attributes only: :body
after_destroy do
manifestation&.touch
end
def check_identifier
case identifier_type.try(:name)
when "isbn"
unless StdNum::ISBN.valid?(body)
errors.add(:body)
end
when "issn"
unless StdNum::ISSN.valid?(body)
errors.add(:body)
end
when "lccn"
unless StdNum::LCCN.valid?(body)
errors.add(:body)
end
when "doi"
if URI.parse(body).scheme
errors.add(:body)
end
end
end
def convert_isbn
if identifier_type.name == "isbn"
lisbn = Lisbn.new(body)
if lisbn.isbn
if lisbn.isbn.length == 10
self.body = lisbn.isbn13
end
end
end
end
def hyphenated_isbn
if identifier_type.name == "isbn"
lisbn = Lisbn.new(body)
lisbn.parts.join("-")
end
end
def normalize
case identifier_type.try(:name)
when "isbn"
self.body = StdNum::ISBN.normalize(body)
when "issn"
self.body = StdNum::ISSN.normalize(body)
when "lccn"
self.body = StdNum::LCCN.normalize(body)
end
end
end
# == Schema Information
#
# Table name: identifiers
#
# id :bigint not null, primary key
# body :string not null
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
# identifier_type_id :bigint not null
# manifestation_id :bigint
#
# Indexes
#
# index_identifiers_on_body_and_identifier_type_id (body,identifier_type_id)
# index_identifiers_on_manifestation_id (manifestation_id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/manifestation_reserve_stat_state_machine.rb | app/models/manifestation_reserve_stat_state_machine.rb | class ManifestationReserveStatStateMachine
include Statesman::Machine
state :pending, initial: true
state :started
state :completed
transition from: :pending, to: :started
transition from: :started, to: :completed
after_transition(to: :started) do |manifestation_reserve_stat|
manifestation_reserve_stat.update_column(:started_at, Time.zone.now)
manifestation_reserve_stat.calculate_count!
end
after_transition(to: :completed) do |manifestation_reserve_stat|
manifestation_reserve_stat.update_column(:completed_at, Time.zone.now)
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/frequency.rb | app/models/frequency.rb | class Frequency < ApplicationRecord
include MasterModel
has_many :manifestations, dependent: :restrict_with_exception
end
# == Schema Information
#
# Table name: frequencies
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_frequencies_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/event_import_file_state_machine.rb | app/models/event_import_file_state_machine.rb | class EventImportFileStateMachine
include Statesman::Machine
state :pending, initial: true
state :started
state :completed
state :failed
transition from: :pending, to: :started
transition from: :started, to: [ :completed, :failed ]
after_transition(from: :pending, to: :started) do |event_import_file|
event_import_file.update_column(:executed_at, Time.zone.now)
end
before_transition(from: :started, to: :completed) do |event_import_file|
event_import_file.error_message = nil
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/language.rb | app/models/language.rb | class Language < ApplicationRecord
include MasterModel
# If you wish to change the field names for brevity, feel free to enable/modify these.
# alias_attribute :iso1, :iso_639_1
# alias_attribute :iso2, :iso_639_2
# alias_attribute :iso3, :iso_639_3
# Validations
validates :iso_639_1, presence: true # , :iso_639_2, :iso_639_3, presence: true
validates :name, presence: true, format: { with: /\A[0-9A-Za-z][0-9A-Za-z_\-\s,]*[0-9a-z]\Z/ }
def self.available_languages
Language.where(iso_639_1: I18n.available_locales.map { |l| l.to_s }).order(:position)
end
private
def valid_name?
true
end
end
# == Schema Information
#
# Table name: languages
#
# id :bigint not null, primary key
# display_name :text
# iso_639_1 :string
# iso_639_2 :string
# iso_639_3 :string
# name :string not null
# native_name :string
# note :text
# position :integer
#
# Indexes
#
# index_languages_on_iso_639_1 (iso_639_1)
# index_languages_on_iso_639_2 (iso_639_2)
# index_languages_on_iso_639_3 (iso_639_3)
# index_languages_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/agent_merge_list.rb | app/models/agent_merge_list.rb | class AgentMergeList < ApplicationRecord
has_many :agent_merges, dependent: :destroy
has_many :agents, through: :agent_merges
validates :title, presence: true
paginates_per 10
def merge_agents(selected_agent)
agents.each do |agent|
Create.where(agent_id: selected_agent.id).update(agent_id: agent.id)
Produce.where(agent_id: selected_agent.id).update(agent_id: agent.id)
Own.where(agent_id: selected_agent.id).update(agent_id: agent.id)
Donate.where(agent_id: selected_agent.id).update(agent_id: agent.id)
agent.destroy unless agent == selected_agent
end
end
end
# == Schema Information
#
# Table name: agent_merge_lists
#
# id :bigint not null, primary key
# title :string
# created_at :datetime not null
# updated_at :datetime not null
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/place.rb | app/models/place.rb | class Place < ApplicationRecord
has_many :events, dependent: :destroy
validates :term, presence: true
end
# == Schema Information
#
# Table name: places
#
# id :bigint not null, primary key
# city :text
# latitude :float
# longitude :float
# term :string
# created_at :datetime not null
# updated_at :datetime not null
# country_id :bigint
#
# Indexes
#
# index_places_on_country_id (country_id)
# index_places_on_term (term)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/medium_of_performance.rb | app/models/medium_of_performance.rb | class MediumOfPerformance < ApplicationRecord
include MasterModel
has_many :works, class_name: "Manifestation"
end
# == Schema Information
#
# Table name: medium_of_performances
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_medium_of_performances_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/import_request_state_machine.rb | app/models/import_request_state_machine.rb | class ImportRequestStateMachine
include Statesman::Machine
state :pending, initial: true
state :completed
state :failed
transition from: :pending, to: [ :completed, :failed ]
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/url_validator.rb | app/models/url_validator.rb | class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value =~ /\Ahttps?:\/\/[^\n]+\z/i
url = ::Addressable::URI.parse(value)
unless [ "http", "https" ].include?(url.scheme)
record.errors.add(attribute.to_sym)
end
else
record.errors.add(attribute.to_sym)
end
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/reserve_stat_has_manifestation.rb | app/models/reserve_stat_has_manifestation.rb | class ReserveStatHasManifestation < ApplicationRecord
belongs_to :manifestation_reserve_stat
belongs_to :manifestation
validates :manifestation_id, uniqueness: { scope: :manifestation_reserve_stat_id }
paginates_per 10
end
# == Schema Information
#
# Table name: reserve_stat_has_manifestations
#
# id :bigint not null, primary key
# reserves_count :integer
# created_at :datetime not null
# updated_at :datetime not null
# manifestation_id :bigint not null
# manifestation_reserve_stat_id :bigint not null
#
# Indexes
#
# index_reserve_stat_has_manifestations_on_m_reserve_stat_id (manifestation_reserve_stat_id)
# index_reserve_stat_has_manifestations_on_manifestation_id (manifestation_id)
#
# Foreign Keys
#
# fk_rails_... (manifestation_id => manifestations.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/manifestation_reserve_stat_transition.rb | app/models/manifestation_reserve_stat_transition.rb | class ManifestationReserveStatTransition < ApplicationRecord
belongs_to :manifestation_reserve_stat, inverse_of: :manifestation_reserve_stat_transitions
end
# == Schema Information
#
# Table name: manifestation_reserve_stat_transitions
#
# id :bigint not null, primary key
# metadata :jsonb not null
# most_recent :boolean not null
# sort_key :integer
# to_state :string
# created_at :datetime not null
# updated_at :datetime not null
# manifestation_reserve_stat_id :bigint
#
# Indexes
#
# index_manifestation_reserve_stat_transitions_on_stat_id (manifestation_reserve_stat_id)
# index_manifestation_reserve_stat_transitions_on_transition (sort_key,manifestation_reserve_stat_id) UNIQUE
# index_manifestation_reserve_stat_transitions_parent_most_recen (manifestation_reserve_stat_id,most_recent) UNIQUE WHERE most_recent
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/item_custom_property.rb | app/models/item_custom_property.rb | class ItemCustomProperty < ApplicationRecord
include MasterModel
validates :name, presence: true, uniqueness: true
acts_as_list
end
# == Schema Information
#
# Table name: item_custom_properties
#
# id :bigint not null, primary key
# display_name(表示名) :text not null
# name(ラベル名) :string not null
# note(備考) :text
# position :integer default(1), not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_item_custom_properties_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/agent_merge.rb | app/models/agent_merge.rb | class AgentMerge < ApplicationRecord
belongs_to :agent
belongs_to :agent_merge_list
paginates_per 10
end
# == Schema Information
#
# Table name: agent_merges
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :bigint not null
# agent_merge_list_id :bigint not null
#
# Indexes
#
# index_agent_merges_on_agent_id (agent_id)
# index_agent_merges_on_agent_merge_list_id (agent_merge_list_id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/jpno_record.rb | app/models/jpno_record.rb | class JpnoRecord < ApplicationRecord
belongs_to :manifestation
validates :body, presence: true, uniqueness: true
strip_attributes
end
# == Schema Information
#
# Table name: jpno_records
#
# id :bigint not null, primary key
# body :string not null
# created_at :datetime not null
# updated_at :datetime not null
# manifestation_id :bigint not null
#
# Indexes
#
# index_jpno_records_on_body (body) UNIQUE
# index_jpno_records_on_manifestation_id (manifestation_id)
#
# Foreign Keys
#
# fk_rails_... (manifestation_id => manifestations.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/user_checkout_stat_transition.rb | app/models/user_checkout_stat_transition.rb | class UserCheckoutStatTransition < ApplicationRecord
belongs_to :user_checkout_stat, inverse_of: :user_checkout_stat_transitions
end
# == Schema Information
#
# Table name: user_checkout_stat_transitions
#
# id :bigint not null, primary key
# metadata :jsonb not null
# most_recent :boolean not null
# sort_key :integer
# to_state :string
# created_at :datetime not null
# updated_at :datetime not null
# user_checkout_stat_id :bigint
#
# Indexes
#
# index_user_checkout_stat_transitions_on_sort_key_and_stat_id (sort_key,user_checkout_stat_id) UNIQUE
# index_user_checkout_stat_transitions_on_user_checkout_stat_id (user_checkout_stat_id)
# index_user_checkout_stat_transitions_parent_most_recent (user_checkout_stat_id,most_recent) UNIQUE WHERE most_recent
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/cinii_book.rb | app/models/cinii_book.rb | class CiniiBook
def initialize(node)
@node = node
end
def title
@node.at("./xmlns:title").try(:content)
end
def creator
@node.at("./dc:creator").try(:content)
end
def publisher
@node.at("./dc:publisher").try(:content)
end
def link
@node.at("./xmlns:link").try(:content)
end
def ncid
url = @node.attributes["about"].try(:content)
if url
URI.parse(url).path.split("/").reverse.first
end
end
def issued
@node.at("./dc:date").try(:content)
end
def self.per_page
10
end
def self.search(query, page = 1, per_page = self.per_page)
if query
cnt = self.per_page
page = 1 if page.to_i < 1
doc = Nokogiri::XML(Manifestation.search_cinii_book(query, { p: page, count: cnt, raw: true }).to_s)
items = doc.xpath("//xmlns:item").collect { |node| self.new node }
total_entries = doc.at("//opensearch:totalResults").content.to_i
{ items: items, total_entries: total_entries }
else
{ items: [], total_entries: 0 }
end
end
def self.import_ncid(ncid)
ncid_record = NcidRecord.find_by(body: ncid)
return if ncid_record
url = "https://ci.nii.ac.jp/ncid/#{ncid}.rdf"
doc = Nokogiri::XML(Faraday.get(url).body)
Manifestation.import_record_from_cinii_books(doc)
end
attr_accessor :url
class AlreadyImported < StandardError
end
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/library.rb | app/models/library.rb | class Library < ApplicationRecord
include MasterModel
include EnjuEvent::EnjuLibrary
default_scope { order("libraries.position") }
scope :real, -> { where("id != 1") }
has_many :shelves, -> { order("shelves.position") }, dependent: :destroy, inverse_of: :library
belongs_to :library_group
has_many :profiles, dependent: :restrict_with_exception
belongs_to :country, optional: true
extend FriendlyId
friendly_id :name
geocoded_by :address
searchable do
text :name, :display_name, :note, :address
time :created_at
time :updated_at
integer :position
end
validates :short_display_name, presence: true, uniqueness: { case_sensitive: false }
validates :isil, uniqueness: { allow_blank: true }
validates :display_name, uniqueness: true
validates :name, format: { with: /\A[a-z][0-9a-z\-_]{1,253}[0-9a-z]\Z/ }
validates :isil, format: { with: /\A[A-Za-z]{1,4}-[A-Za-z0-9\/:\-]{2,11}\z/ }, allow_blank: true
after_validation :geocode, if: :address_changed?
after_create :create_shelf
def create_shelf
shelf = Shelf.new
shelf.name = "#{name}_default"
shelf.library = self
shelf.save!
end
def web?
return true if id == 1
false
end
def self.web
Library.find(1)
end
def address(locale = I18n.locale)
case locale.to_sym
when :ja
"#{region.to_s.localize(locale)}#{locality.to_s.localize(locale)}#{street.to_s.localize(locale)}"
else
"#{street.to_s.localize(locale)} #{locality.to_s.localize(locale)} #{region.to_s.localize(locale)}"
end
rescue Psych::SyntaxError
nil
end
def address_changed?
return true if saved_change_to_region? || saved_change_to_locality? || saved_change_to_street?
false
end
if defined?(EnjuEvent)
has_many :events, dependent: :restrict_with_exception
def closed?(date)
events.closing_days.map { |c|
c.start_at.beginning_of_day
}.include?(date.beginning_of_day)
end
end
if defined?(EnjuInterLibraryLoan)
has_many :inter_library_loans, foreign_key: "borrowing_library_id", inverse_of: :library, dependent: :restrict_with_exception
end
end
# == Schema Information
#
# Table name: libraries
#
# id :bigint not null, primary key
# call_number_delimiter :string default("|"), not null
# call_number_rows :integer default(1), not null
# display_name :text
# fax_number :string
# isil :string
# latitude :float
# locality :text
# longitude :float
# name :string not null
# note :text
# opening_hour :text
# position :integer
# region :text
# short_display_name :string not null
# street :text
# telephone_number_1 :string
# telephone_number_2 :string
# users_count :integer default(0), not null
# zip_code :string
# created_at :datetime not null
# updated_at :datetime not null
# country_id :bigint
# library_group_id :bigint not null
#
# Indexes
#
# index_libraries_on_isil (isil) UNIQUE WHERE (((isil)::text <> ''::text) AND (isil IS NOT NULL))
# index_libraries_on_library_group_id (library_group_id)
# index_libraries_on_lower_name (lower((name)::text)) UNIQUE
# index_libraries_on_name (name) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (library_group_id => library_groups.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/event.rb | app/models/event.rb | class Event < ApplicationRecord
scope :closing_days, -> { includes(:event_category).where("event_categories.name" => "closed") }
scope :on, lambda { |datetime|
where("start_at >= ? AND start_at < ?", datetime.beginning_of_day, datetime.tomorrow.beginning_of_day + 1)
}
scope :past, lambda { |datetime|
where("end_at <= ?", Time.zone.parse(datetime).beginning_of_day)
}
scope :upcoming, lambda { |datetime|
where("start_at >= ?", Time.zone.parse(datetime).beginning_of_day)
}
scope :at, lambda { |library|
where(library_id: library.id)
}
belongs_to :event_category
belongs_to :library
belongs_to :place, optional: true
has_many :picture_files, as: :picture_attachable, dependent: :destroy
has_many :participates, dependent: :destroy
has_many :agents, through: :participates
has_one :event_import_result
searchable do
text :name, :note
integer :library_id
time :created_at
time :updated_at
time :start_at
time :end_at
end
validates :name, :start_at, :end_at, presence: true
validate :check_date
before_validation :set_date
before_validation :set_display_name, on: :create
paginates_per 10
def set_date
if all_day
set_all_day
end
end
def set_all_day
if start_at && end_at
self.start_at = start_at.beginning_of_day
self.end_at = end_at.end_of_day
end
end
def check_date
if start_at && end_at
if start_at >= end_at
errors.add(:start_at)
errors.add(:end_at)
end
end
end
def set_display_name
self.display_name = name if display_name.blank?
end
# CSVのヘッダ
# @param [String] role 権限
def self.csv_header(role: "Guest")
Event.new.to_hash(role: role).keys
end
# CSV出力用のハッシュ
# @param [String] role 権限
def to_hash(role: "Guest")
record = {
name: name,
display_name: display_name,
event_category: event_category.try(:name),
library: library.try(:name),
start_at: start_at,
end_at: end_at,
all_day: all_day,
note: note,
created_at: created_at,
updated_at: updated_at
}
record
end
# TSVでのエクスポート
# @param [String] role 権限
# @param [String] col_sep 区切り文字
def self.export(role: "Guest", col_sep: "\t")
Tempfile.create("event_export") do |f|
f.write Event.csv_header(role: role).to_csv(col_sep: col_sep)
Event.find_each do |event|
f.write event.to_hash(role: role).values.to_csv(col_sep: col_sep)
end
f.rewind
f.read
end
end
end
# == Schema Information
#
# Table name: events
#
# id :bigint not null, primary key
# all_day :boolean default(FALSE), not null
# display_name :text
# end_at :datetime
# name :string not null
# note :text
# start_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# event_category_id :bigint not null
# library_id :bigint not null
# place_id :bigint
#
# Indexes
#
# index_events_on_event_category_id (event_category_id)
# index_events_on_library_id (library_id)
# index_events_on_place_id (place_id)
#
# Foreign Keys
#
# fk_rails_... (event_category_id => event_categories.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/manifestation_custom_property.rb | app/models/manifestation_custom_property.rb | class ManifestationCustomProperty < ApplicationRecord
include MasterModel
validates :name, presence: true, uniqueness: true
acts_as_list
end
# == Schema Information
#
# Table name: manifestation_custom_properties
#
# id :bigint not null, primary key
# display_name(表示名) :text not null
# name(ラベル名) :string not null
# note(備考) :text
# position :integer default(1), not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_manifestation_custom_properties_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/shelf.rb | app/models/shelf.rb | class Shelf < ApplicationRecord
include MasterModel
scope :real, -> { where("library_id != 1") }
belongs_to :library
has_many :items, dependent: :restrict_with_exception
has_many :picture_files, as: :picture_attachable, dependent: :destroy
validates :display_name, uniqueness: { scope: :library_id }
validates :name, format: { with: /\A[a-z][0-9a-z\-_]{1,253}[0-9a-z]\Z/ }
before_update :reset_position
acts_as_list scope: :library
searchable do
string :shelf_name do
name
end
string :library do
library.name
end
text :name do
[ name, library.name, display_name, library.display_name ]
end
integer :position
end
paginates_per 10
def web_shelf?
return true if id == 1
false
end
def self.web
Shelf.find(1)
end
def localized_display_name
display_name.localize
end
# http://stackoverflow.com/a/12437606
def reset_position
return unless library_id_changed?
self.position = library.shelves.count.positive? ? library.shelves.last.position + 1 : 1
end
end
# == Schema Information
#
# Table name: shelves
#
# id :bigint not null, primary key
# closed :boolean default(FALSE), not null
# display_name :text
# items_count :integer default(0), not null
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
# library_id :bigint not null
#
# Indexes
#
# index_shelves_on_library_id (library_id)
# index_shelves_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/donate.rb | app/models/donate.rb | class Donate < ApplicationRecord
belongs_to :agent
belongs_to :item
end
# == Schema Information
#
# Table name: donates
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# agent_id :bigint not null
# item_id :bigint not null
#
# Indexes
#
# index_donates_on_agent_id (agent_id)
# index_donates_on_item_id (item_id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/content_type.rb | app/models/content_type.rb | class ContentType < ApplicationRecord
include MasterModel
has_many :manifestations, dependent: :restrict_with_exception
end
# == Schema Information
#
# Table name: content_types
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_content_types_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/order.rb | app/models/order.rb | class Order < ApplicationRecord
belongs_to :order_list, validate: true
belongs_to :purchase_request, validate: true
validates_associated :order_list, :purchase_request
validates_presence_of :order_list, :purchase_request
validates_uniqueness_of :purchase_request_id, scope: :order_list_id
after_save :reindex
after_destroy :reindex
acts_as_list scope: :order_list
paginates_per 10
def reindex
purchase_request.try(:index)
end
end
# == Schema Information
#
# Table name: orders
#
# id :bigint not null, primary key
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
# order_list_id :bigint not null
# purchase_request_id :bigint not null
#
# Indexes
#
# index_orders_on_order_list_id (order_list_id)
# index_orders_on_purchase_request_id (purchase_request_id)
#
# Foreign Keys
#
# fk_rails_... (order_list_id => order_lists.id)
# fk_rails_... (purchase_request_id => purchase_requests.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/nii_type.rb | app/models/nii_type.rb | class NiiType < ApplicationRecord
include MasterModel
has_many :manifestations, dependent: :destroy
end
# == Schema Information
#
# Table name: nii_types
#
# id :bigint not null, primary key
# display_name :text
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_nii_types_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/resource_export_file.rb | app/models/resource_export_file.rb | class ResourceExportFile < ApplicationRecord
include Statesman::Adapters::ActiveRecordQueries[
transition_class: ResourceExportFileTransition,
initial_state: ResourceExportFileStateMachine.initial_state
]
include ExportFile
has_one_attached :attachment
has_many :resource_export_file_transitions, autosave: false, dependent: :destroy
def state_machine
ResourceExportFileStateMachine.new(self, transition_class: ResourceExportFileTransition)
end
delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
to: :state_machine
def export!
transition_to!(:started)
role_name = user.try(:role).try(:name)
tsv = Manifestation.export(role: role_name)
file = StringIO.new(tsv)
# file.class.class_eval { attr_accessor :original_filename, :content_type }
attachment.attach(io: file, filename: "resource_export.txt")
save!
transition_to!(:completed)
mailer = ResourceExportMailer.completed(self)
send_message(mailer)
rescue StandardError => e
transition_to!(:failed)
mailer = ResourceExportMailer.failed(self)
send_message(mailer)
raise e
end
end
# == Schema Information
#
# Table name: resource_export_files
#
# id :bigint not null, primary key
# executed_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/ncid_record.rb | app/models/ncid_record.rb | class NcidRecord < ApplicationRecord
belongs_to :manifestation
validates :body, presence: true, uniqueness: true
strip_attributes
end
# == Schema Information
#
# Table name: ncid_records
#
# id :bigint not null, primary key
# body :string not null
# created_at :datetime not null
# updated_at :datetime not null
# manifestation_id :bigint not null
#
# Indexes
#
# index_ncid_records_on_body (body) UNIQUE
# index_ncid_records_on_manifestation_id (manifestation_id)
#
# Foreign Keys
#
# fk_rails_... (manifestation_id => manifestations.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/user_export_file_transition.rb | app/models/user_export_file_transition.rb | class UserExportFileTransition < ApplicationRecord
belongs_to :user_export_file, inverse_of: :user_export_file_transitions
end
# == Schema Information
#
# Table name: user_export_file_transitions
#
# id :bigint not null, primary key
# metadata :jsonb not null
# most_recent :boolean not null
# sort_key :integer
# to_state :string
# created_at :datetime not null
# updated_at :datetime not null
# user_export_file_id :bigint
#
# Indexes
#
# index_user_export_file_transitions_on_file_id (user_export_file_id)
# index_user_export_file_transitions_on_sort_key_and_file_id (sort_key,user_export_file_id) UNIQUE
# index_user_export_file_transitions_on_user_export_file_id (user_export_file_id)
# index_user_export_file_transitions_parent_most_recent (user_export_file_id,most_recent) UNIQUE WHERE most_recent
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/identity.rb | app/models/identity.rb | class Identity < ApplicationRecord
belongs_to :profile
validates :name, presence: true, uniqueness: { scope: :provider }
validates :provider, presence: true
def self.find_for_oauth(auth)
where(name: auth.uid, provider: auth.provider).first_or_create
end
end
# == Schema Information
#
# Table name: identities
#
# id :bigint not null, primary key
# email :string
# name :string not null
# password_digest :string
# provider :string
# created_at :datetime not null
# updated_at :datetime not null
# profile_id :bigint
#
# Indexes
#
# index_identities_on_email (email)
# index_identities_on_name (name)
# index_identities_on_profile_id (profile_id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/license.rb | app/models/license.rb | class License < ApplicationRecord
include MasterModel
end
# == Schema Information
#
# Table name: licenses
#
# id :bigint not null, primary key
# display_name :string
# name :string not null
# note :text
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_licenses_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/reserve_stat_has_user.rb | app/models/reserve_stat_has_user.rb | class ReserveStatHasUser < ApplicationRecord
belongs_to :user_reserve_stat
belongs_to :user
validates :user_id, uniqueness: { scope: :user_reserve_stat_id }
paginates_per 10
end
# == Schema Information
#
# Table name: reserve_stat_has_users
#
# id :bigint not null, primary key
# reserves_count :integer
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
# user_reserve_stat_id :bigint not null
#
# Indexes
#
# index_reserve_stat_has_users_on_user_id (user_id)
# index_reserve_stat_has_users_on_user_reserve_stat_id (user_reserve_stat_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
# fk_rails_... (user_reserve_stat_id => user_reserve_stats.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/purchase_request.rb | app/models/purchase_request.rb | class PurchaseRequest < ApplicationRecord
scope :not_ordered, -> { includes(:order_list).where("order_lists.ordered_at IS NULL") }
scope :ordered, -> { includes(:order_list).where("order_lists.ordered_at IS NOT NULL") }
belongs_to :user, validate: true
has_one :order, dependent: :destroy
has_one :order_list, through: :order
validates_associated :user
validates_presence_of :user, :title
validate :check_price
validates :url, url: true, allow_blank: true, length: { maximum: 255 }
after_destroy :index!
after_save :index!
before_save :set_date_of_publication
strip_attributes only: [ :url, :pub_date ]
searchable do
text :title, :author, :publisher, :url
string :isbn
string :url
integer :price
integer :user_id
integer :order_list_id do
order_list.id if order_list
end
time :pub_date do
date_of_publication
end
time :created_at
time :accepted_at
time :denied_at
boolean :ordered do
if order_list.try(:current_state) == "ordered"
true
else
false
end
end
end
paginates_per 10
def check_price
errors.add(:price) unless price.nil? || price.positive?
end
def set_date_of_publication
return if pub_date.blank?
begin
date = Time.zone.parse("#{pub_date}")
rescue ArgumentError
begin
date = Time.zone.parse("#{pub_date}-01")
rescue ArgumentError
begin
date = Time.zone.parse("#{pub_date}-01-01")
rescue ArgumentError
nil
end
end
end
self.date_of_publication = date
end
end
# == Schema Information
#
# Table name: purchase_requests
#
# id :bigint not null, primary key
# accepted_at :datetime
# author :text
# date_of_publication :datetime
# denied_at :datetime
# isbn :string
# note :text
# price :integer
# pub_date :string
# publisher :text
# state :string
# title :text not null
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_purchase_requests_on_state (state)
# index_purchase_requests_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/user_group.rb | app/models/user_group.rb | class UserGroup < ApplicationRecord
include MasterModel
include EnjuCirculation::EnjuUserGroup
has_many :profiles, dependent: :destroy
validates :valid_period_for_new_user,
numericality: { greater_than_or_equal_to: 0,
allow_blank: true }
paginates_per 10
end
# == Schema Information
#
# Table name: user_groups
#
# id :bigint not null, primary key
# display_name :text
# expired_at :datetime
# name :string not null
# note :text
# number_of_day_to_notify_due_date :integer default(0), not null
# number_of_day_to_notify_overdue :integer default(0), not null
# number_of_time_to_notify_overdue :integer default(0), not null
# position :integer
# valid_period_for_new_user :integer default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_user_groups_on_lower_name (lower((name)::text)) UNIQUE
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/agent_import_file.rb | app/models/agent_import_file.rb | class AgentImportFile < ApplicationRecord
include Statesman::Adapters::ActiveRecordQueries[
transition_class: AgentImportFileTransition,
initial_state: AgentImportFileStateMachine.initial_state
]
include ImportFile
default_scope { order("agent_import_files.id DESC") }
scope :not_imported, -> { in_state(:pending) }
scope :stucked, -> { in_state(:pending).where("agent_import_files.created_at < ?", 1.hour.ago) }
has_one_attached :attachment
belongs_to :user
has_many :agent_import_results, dependent: :destroy
has_many :agent_import_file_transitions, autosave: false, dependent: :destroy
attr_accessor :mode
def state_machine
AgentImportFileStateMachine.new(self, transition_class: AgentImportFileTransition)
end
delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
to: :state_machine
def import_start
case edit_mode
when "create"
import
when "update"
modify
when "destroy"
remove
else
import
end
end
def import
transition_to!(:started)
num = { agent_imported: 0, user_imported: 0, failed: 0 }
rows = open_import_file
field = rows.first
row_num = 1
if [ field["first_name"], field["last_name"], field["full_name"] ].reject { |field| field.to_s.strip == "" }.empty?
raise "You should specify first_name, last_name or full_name in the first line"
end
# rows.shift
AgentImportResult.create!(agent_import_file_id: id, body: rows.headers.join("\t"))
rows.each do |row|
row_num += 1
import_result = AgentImportResult.create!(agent_import_file_id: id, body: row.fields.join("\t"))
next if row["dummy"].to_s.strip.present?
agent = Agent.new
agent = set_agent_value(agent, row)
if agent.save!
import_result.agent = agent
num[:agent_imported] += 1
end
import_result.save!
end
Sunspot.commit
rows.close
transition_to!(:completed)
mailer = AgentImportMailer.completed(self)
send_message(mailer)
num
rescue StandardError => e
self.error_message = "line #{row_num}: #{e.message}"
transition_to!(:failed)
mailer = AgentImportMailer.failed(self)
send_message(mailer)
raise e
end
def self.import
AgentImportFile.not_imported.each do |file|
file.import_start
end
rescue StandardError
Rails.logger.info "#{Time.zone.now} importing agents failed!"
end
def modify
transition_to!(:started)
rows = open_import_file
rows.shift
row_num = 1
rows.each do |row|
row_num += 1
next if row["dummy"].to_s.strip.present?
agent = Agent.find_by(id: row["id"])
next unless agent
agent.full_name = row["full_name"] if row["full_name"].to_s.strip.present?
agent.full_name_transcription = row["full_name_transcription"] if row["full_name_transcription"].to_s.strip.present?
agent.first_name = row["first_name"] if row["first_name"].to_s.strip.present?
agent.first_name_transcription = row["first_name_transcription"] if row["first_name_transcription"].to_s.strip.present?
agent.middle_name = row["middle_name"] if row["middle_name"].to_s.strip.present?
agent.middle_name_transcription = row["middle_name_transcription"] if row["middle_name_transcription"].to_s.strip.present?
agent.last_name = row["last_name"] if row["last_name"].to_s.strip.present?
agent.last_name_transcription = row["last_name_transcription"] if row["last_name_transcription"].to_s.strip.present?
agent.address_1 = row["address_1"] if row["address_1"].to_s.strip.present?
agent.address_2 = row["address_2"] if row["address_2"].to_s.strip.present?
agent.save!
end
transition_to!(:completed)
mailer = AgentImportMailer.completed(self)
send_message(mailer)
rescue StandardError => e
self.error_message = "line #{row_num}: #{e.message}"
transition_to!(:failed)
mailer = AgentImportMailer.failed(self)
send_message(mailer)
raise e
end
def remove
transition_to!(:started)
rows = open_import_file
rows.shift
row_num = 1
rows.each do |row|
row_num += 1
next if row["dummy"].to_s.strip.present?
agent = Agent.find_by(id: row["id"].to_s.strip)
next unless agent
agent.picture_files.destroy_all
agent.reload
agent.destroy
end
transition_to!(:completed)
mailer = AgentImportMailer.completed(self)
send_message(mailer)
rescue StandardError => e
self.error_message = "line #{row_num}: #{e.message}"
transition_to!(:failed)
mailer = AgentImportMailer.failed(self)
send_message(mailer)
raise e
end
private
def open_import_file
tempfile = Tempfile.new(self.class.name.underscore)
tempfile.puts(convert_encoding(attachment.download))
tempfile.close
file = CSV.open(tempfile, col_sep: "\t")
header = file.first
rows = CSV.open(tempfile, headers: header, col_sep: "\t")
tempfile.close(true)
file.close
rows
end
def set_agent_value(agent, row)
agent.first_name = row["first_name"] if row["first_name"]
agent.middle_name = row["middle_name"] if row["middle_name"]
agent.last_name = row["last_name"] if row["last_name"]
agent.first_name_transcription = row["first_name_transcription"] if row["first_name_transcription"]
agent.middle_name_transcription = row["middle_name_transcription"] if row["middle_name_transcription"]
agent.last_name_transcription = row["last_name_transcription"] if row["last_name_transcription"]
agent.full_name = row["full_name"] if row["full_name"]
agent.full_name_transcription = row["full_name_transcription"] if row["full_name_transcription"]
agent.address_1 = row["address_1"] if row["address_1"]
agent.address_2 = row["address_2"] if row["address_2"]
agent.zip_code_1 = row["zip_code_1"] if row["zip_code_1"]
agent.zip_code_2 = row["zip_code_2"] if row["zip_code_2"]
agent.telephone_number_1 = row["telephone_number_1"] if row["telephone_number_1"]
agent.telephone_number_2 = row["telephone_number_2"] if row["telephone_number_2"]
agent.fax_number_1 = row["fax_number_1"] if row["fax_number_1"]
agent.fax_number_2 = row["fax_number_2"] if row["fax_number_2"]
agent.note = row["note"] if row["note"]
agent.birth_date = row["birth_date"] if row["birth_date"]
agent.death_date = row["death_date"] if row["death_date"]
# if row['username'].to_s.strip.blank?
agent.email = row["email"].to_s.strip
agent.required_role = Role.find_by(name: row["required_role"].to_s.strip.camelize) || Role.find_by(name: "Guest")
# else
# agent.required_role = Role.where(name: row['required_role'].to_s.strip.camelize).first || Role.where('Librarian').first
# end
language = Language.find_by(name: row["language"].to_s.strip.camelize) || Language.find_by(iso_639_2: row["language"].to_s.strip.downcase) || Language.find_by(iso_639_1: row["language"].to_s.strip.downcase)
agent.language = language if language
country = Country.find_by(name: row["country"].to_s.strip)
agent.country = country if country
agent
end
end
# == Schema Information
#
# Table name: agent_import_files
#
# id :bigint not null, primary key
# agent_import_fingerprint :string
# edit_mode :string
# error_message :text
# executed_at :datetime
# note :text
# user_encoding :string
# created_at :datetime not null
# updated_at :datetime not null
# parent_id :bigint
# user_id :bigint not null
#
# Indexes
#
# index_agent_import_files_on_parent_id (parent_id)
# index_agent_import_files_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/periodical_and_manifestation.rb | app/models/periodical_and_manifestation.rb | class PeriodicalAndManifestation < ApplicationRecord
belongs_to :periodical
belongs_to :manifestation
end
# == Schema Information
#
# Table name: periodical_and_manifestations
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# manifestation_id :bigint not null
# periodical_id :bigint not null
#
# Indexes
#
# index_periodical_and_manifestations_on_manifestation_id (manifestation_id)
# index_periodical_and_manifestations_on_periodical_id (periodical_id)
#
# Foreign Keys
#
# fk_rails_... (manifestation_id => manifestations.id)
# fk_rails_... (periodical_id => periodicals.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/isbn_record.rb | app/models/isbn_record.rb | class IsbnRecord < ApplicationRecord
has_many :isbn_record_and_manifestations, dependent: :destroy
has_many :manifestations, through: :isbn_record_and_manifestations
before_save :normalize_isbn
validates :body, presence: true
strip_attributes
def self.new_records(isbn_records_params)
return [] unless isbn_records_params
isbn_records = []
IsbnRecord.transaction do
isbn_records_params.each do |k, v|
next if v["_destroy"] == "1"
if v["body"].present?
isbn_record = IsbnRecord.where(body: Lisbn.new(v["body"].gsub(/[^0-9x]/i, "")).isbn13).first_or_create!
elsif v["id"].present?
isbn_record = IsbnRecord.find(v["id"])
else
v.delete("_destroy")
isbn_record = IsbnRecord.create(v)
end
isbn_records << isbn_record
end
end
isbn_records
end
def normalize_isbn
if StdNum::ISBN.valid?(body)
self.body = StdNum::ISBN.normalize(body)
else
errors.add(:body)
end
end
def valid_isbn?
StdNum::ISBN.valid?(body)
end
end
# == Schema Information
#
# Table name: isbn_records(ISBN)
#
# id :bigint not null, primary key
# body(ISBN) :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_isbn_records_on_body (body)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/issn_record_and_manifestation.rb | app/models/issn_record_and_manifestation.rb | class IssnRecordAndManifestation < ApplicationRecord
belongs_to :issn_record
belongs_to :manifestation
validates :issn_record_id, uniqueness: { scope: :manifestation_id }
end
# == Schema Information
#
# Table name: issn_record_and_manifestations(書誌とISSNの関係)
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# issn_record_id :bigint not null
# manifestation_id :bigint not null
#
# Indexes
#
# index_issn_record_and_manifestations_on_issn_record_id (issn_record_id)
# index_issn_record_and_manifestations_on_manifestation_id (manifestation_id,issn_record_id) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (issn_record_id => issn_records.id)
# fk_rails_... (manifestation_id => manifestations.id)
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/event_import_result.rb | app/models/event_import_result.rb | class EventImportResult < ApplicationRecord
scope :file_id, proc { |file_id| where(event_import_file_id: file_id) }
scope :failed, -> { where(event_id: nil) }
belongs_to :event_import_file
belongs_to :event, optional: true
def self.header
%w[
id name display_name library event_category start_at end_at all_day note dummy
]
end
end
# == Schema Information
#
# Table name: event_import_results
#
# id :bigint not null, primary key
# event_import_file_id :bigint
# event_id :bigint
# body :text
# created_at :datetime not null
# updated_at :datetime not null
#
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
next-l/enju_leaf | https://github.com/next-l/enju_leaf/blob/cd3cff6dcc8e67909e1cd0a12c38700b45af6a42/app/models/oai_provider.rb | app/models/oai_provider.rb | class OaiProvider < OAI::Provider::Base
library_group = LibraryGroup.site_config
if library_group
repository_name library_group.display_name
admin_email library_group.email
end
repository_url EnjuOai::OaiModel.repository_url
record_prefix EnjuOai::OaiModel.record_prefix
source_model OAI::Provider::ActiveRecordWrapper.new(
Manifestation.where(required_role: 1)
)
end
| ruby | MIT | cd3cff6dcc8e67909e1cd0a12c38700b45af6a42 | 2026-01-04T17:52:15.550406Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.