Skip to content

Commit

Permalink
Merge branch '2.x' of github.com:next-l/enju_library into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Aug 29, 2021
2 parents d173ea4 + aee9a41 commit 86d9db5
Show file tree
Hide file tree
Showing 256 changed files with 5,296 additions and 2,087 deletions.
2 changes: 1 addition & 1 deletion app/models/accept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Accept < ApplicationRecord
#
# id :bigint not null, primary key
# basket_id :bigint
# item_id :bigint
# librarian_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# item_id :bigint not null
#
3 changes: 1 addition & 2 deletions app/models/concerns/enju_library/enju_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ module EnjuItem
has_one :accept
scope :accepted_between, lambda{|from, to| includes(:accept).where('items.created_at BETWEEN ? AND ?', Time.zone.parse(from).beginning_of_day, Time.zone.parse(to).end_of_day)}

belongs_to :shelf, counter_cache: true, validate: true
validates_associated :shelf
belongs_to :shelf, counter_cache: true

searchable do
string :library do
Expand Down
1 change: 0 additions & 1 deletion app/models/concerns/export_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module ExportFile

included do
belongs_to :user
validates :user, presence: true
attr_accessor :mode
end

Expand Down
4 changes: 1 addition & 3 deletions app/models/library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Library < ApplicationRecord
default_scope { order('libraries.position') }
scope :real, -> { where('id != 1') }
has_many :shelves
belongs_to :library_group, validate: true
belongs_to :library_group
has_many :profiles
belongs_to :country, optional: true

Expand All @@ -19,9 +19,7 @@ class Library < ApplicationRecord
integer :position
end

validates_associated :library_group
validates :short_display_name, presence: true
validates :library_group, presence: true
validates_uniqueness_of :short_display_name, case_sensitive: false
validates_uniqueness_of :isil, allow_blank: true
validates :display_name, uniqueness: true
Expand Down
4 changes: 2 additions & 2 deletions app/models/library_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LibraryGroup < ApplicationRecord
:erms_url
], coder: JSON

translates :login_banner, :footer_banner, :display_name
translates :display_name, :login_banner, :footer_banner

if ENV['ENJU_STORAGE'] == 's3'
has_attached_file :header_logo, storage: :s3, styles: { medium: 'x80'},
Expand Down Expand Up @@ -88,7 +88,7 @@ def network_access_allowed?(ip_address, options = {})
# display_name :text
# short_name :string not null
# my_networks :text
# old_login_banner :text
# login_banner :text
# note :text
# country_id :integer
# position :integer
Expand Down
1 change: 0 additions & 1 deletion app/models/request_status_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class RequestStatusType < 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 :reserves
translates :display_name

private

Expand Down
1 change: 0 additions & 1 deletion app/models/request_type.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class RequestType < ApplicationRecord
include MasterModel
validates :name, presence: true, format: { with: /\A[0-9A-Za-z][0-9A-Za-z_\-\s,]*[0-9a-z]\Z/ }
translates :display_name

private

Expand Down
1 change: 0 additions & 1 deletion app/models/search_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class SearchEngine < ApplicationRecord
validates :base_url, presence: true, url: true, length: { maximum: 255 }

paginates_per 10
translates :display_name

def search_params(query)
params = {}
Expand Down
6 changes: 2 additions & 4 deletions app/models/shelf.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
class Shelf < ApplicationRecord
include MasterModel
scope :real, -> { where('library_id != 1') }
belongs_to :library, validate: true
belongs_to :library
has_many :items
has_many :picture_files, as: :picture_attachable, dependent: :destroy

validates_associated :library
validates :library, presence: true
validates_uniqueness_of :display_name, scope: :library_id
validates :name, format: { with: /\A[a-z][0-9a-z\-_]{1,253}[0-9a-z]\Z/ }
before_update :reset_position
has_one_attached :image
translates :display_name

acts_as_list scope: :library
translates :display_name

searchable do
string :shelf_name do
Expand Down
7 changes: 3 additions & 4 deletions app/models/subscribe.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
class Subscribe < ApplicationRecord
belongs_to :subscription, counter_cache: true, validate: true
belongs_to :work, class_name: 'Manifestation', validate: true
belongs_to :subscription, counter_cache: true
belongs_to :work, class_name: 'Manifestation'

validates_associated :subscription, :work
validates_presence_of :subscription, :work, :start_at, :end_at
validates_presence_of :start_at, :end_at
validates_uniqueness_of :work_id, scope: :subscription_id
end

Expand Down
7 changes: 3 additions & 4 deletions app/models/subscription.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
class Subscription < ApplicationRecord
has_many :subscribes, dependent: :destroy
has_many :works, through: :subscribes
belongs_to :user, validate: true
belongs_to :user
if defined?(EnjuPurchasRequest)
belongs_to :order_list, validate: true
belongs_to :order_list
end

validates_presence_of :title, :user
validates_associated :user
validates :title, presence: true

searchable do
text :title, :note
Expand Down
18 changes: 8 additions & 10 deletions app/models/user_export_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ def state_machine

# エクスポートの処理を実行します。
def export!
UserExportFile.transaction do
transition_to!(:started)
role_name = user.try(:role).try(:name)
tsv = User.export(role: role_name)
self.user_export = StringIO.new(tsv)
self.user_export.instance_write(:filename, "user_export.txt")
save!
transition_to!(:completed)
end

transition_to!(:started)
tempfile = Tempfile.new(['user_export_file_', '.txt'])
file = User.export(format: :txt)
tempfile.puts(file)
tempfile.close
self.user_export = File.new(tempfile.path, 'r')
save!
transition_to!(:completed)
mailer = UserExportMailer.completed(self)
send_message(mailer)
rescue => e
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class UserGroup < ApplicationRecord
validates_numericality_of :valid_period_for_new_user,
greater_than_or_equal_to: 0,
allow_blank: true
translates :display_name

paginates_per 10
translates :display_name
end

# == Schema Information
Expand Down
41 changes: 20 additions & 21 deletions app/models/user_import_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,34 @@ def import
num[:user_found] += 1
else
new_user = User.new
new_user.role = Role.find_by(name: row['role'])
if new_user.role
unless user.has_role?(new_user.role.name)
num[:failed] += 1
next
end
else
new_user.role = Role.find(2) # User
end
new_user.username = username
new_user.assign_attributes(set_user_params(row))
profile = Profile.new
profile.assign_attributes(set_profile_params(row))
if row['role'].present?
role = Role.find_by(name: row['role'])
else
role = Role.find(2) # User
end

Profile.transaction do
if profile.valid? && role
if new_user.valid? and profile.valid?
new_user.profile = profile
new_user.role = role

if new_user.save
import_result.user = new_user
import_result.save!
num[:user_imported] += 1
next
end
import_result.user = new_user
import_result.save!
num[:user_imported] += 1
else
error_message = "line #{row_num}: "
error_message += new_user.errors.full_messages.join(" ")
error_message += profile.errors.full_messages.join(" ")
import_result.error_message = error_message
import_result.save
num[:error] += 1
end

error_message = "line #{row_num}: "
error_message += new_user.errors.full_messages.join(" ")
error_message += profile.errors.full_messages.join(" ")
import_result.error_message = error_message
import_result.save
num[:error] += 1
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/models/withdraw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ class Withdraw < ApplicationRecord
belongs_to :librarian, class_name: 'User'

validates :item_id,
uniqueness: true, #{ message: I18n.t('withdraw.already_withdrawn', locale: I18n.default_locale) },
presence: true #, { message: I18n.translate('withdraw.item_not_found', locale: I18n.default_locale) }
validates_presence_of :basket_id
uniqueness: true #, { message: I18n.t('withdraw.already_withdrawn', locale: I18n.default_locale) }

attr_accessor :item_identifier

Expand Down
29 changes: 12 additions & 17 deletions app/views/library_groups/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
<%= f.text_field :name, required: true, class: 'form-control' %>
</div>

<% I18n.available_locales.each do |locale| %>
<div class="form-group">
<% display_name = "display_name_#{locale.to_s}" %>
<%= f.label :display_name -%> (<%= locale.to_s %>)<br />
<%= f.text_field display_name, class: 'form-control' -%>
</div>
<% end %>
<div class="form-group">
<%= f.label :display_name -%><br />
<%= f.text_field :display_name, class: 'form-control' -%>
</div>

<div class="form-group">
<%= f.label :header_logo -%><br />
Expand All @@ -32,17 +29,15 @@
<%= f.url_field :url, class: 'form-control' -%>
</div>

<% I18n.available_locales.each do |locale| -%>
<div class="form-group">
<%= f.label :login_banner -%> (<%= locale -%>)
<%= f.text_area :"login_banner_#{locale.to_s}", class: 'form-control' -%>
</div>
<div class="form-group">
<%= f.label :login_banner -%>
<%= f.text_area :login_banner, class: 'form-control' -%>
</div>

<div class="form-group">
<%= f.label :footer_banner -%> (<%= locale -%>)
<%= f.text_area :"footer_banner_#{locale.to_s}", class: 'form-control' -%>
</div>
<% end -%>
<div class="form-group">
<%= f.label :footer_banner -%>
<%= f.text_area :footer_banner, class: 'form-control' -%>
</div>

<div class="form-group">
<%= f.label :max_number_of_results -%><br />
Expand Down
5 changes: 3 additions & 2 deletions db/migrate/20120319173203_create_accepts.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class CreateAccepts < ActiveRecord::Migration[5.2]
def change
create_table :accepts do |t|
t.references :basket, foreign_key: true
t.references :librarian, foreign_key: {to_table: :users}
t.references :basket, index: true
t.references :item, index: true
t.references :librarian, index: true

t.timestamps
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ class CreateUserImportFileTransitions < ActiveRecord::Migration[5.2]
def change
create_table :user_import_file_transitions do |t|
t.string :to_state
t.text :metadata, default: "{}"
if ActiveRecord::Base.configurations[Rails.env]["adapter"].try(:match, /mysql/)
t.text :metadata
else
t.text :metadata, default: "{}"
end
t.integer :sort_key
t.references :user_import_file, index: true
t.timestamps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ class CreateUserExportFileTransitions < ActiveRecord::Migration[5.2]
def change
create_table :user_export_file_transitions do |t|
t.string :to_state
t.text :metadata, default: "{}"
if ActiveRecord::Base.configurations[Rails.env]["adapter"].try(:match, /mysql/)
t.text :metadata
else
t.text :metadata, default: "{}"
end
t.integer :sort_key
t.references :user_export_file, index: true
t.timestamps
Expand Down
22 changes: 22 additions & 0 deletions db/migrate/20151213072705_add_footer_banner_to_library_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This migration comes from enju_library_engine (originally 20151213072705)
class AddFooterBannerToLibraryGroup < ActiveRecord::Migration[5.2]
def up
if defined?(Globalize)
LibraryGroup.add_translation_fields! footer_banner: :text
end

if defined?(AwesomeHstoreTranslate)
add_column :library_groups, :footer_banner, :hstore
end
end

def down
if defined?(Globalize)
remove_column :library_group_translations, :footer_banner
end

if defined?(AwesomeHstoreTranslate)
remove_column :library_groups, :footer_banner
end
end
end

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
user_group_00001:
name: "first_group"
display_name_translations: {"en": "First group", "ja": "最初のグループ"}
note: ""
position: 1
7 changes: 7 additions & 0 deletions spec/controllers/accepts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def mock_user(stubs = {})
post :create, params: { accept: @attrs }
response.should be_forbidden
end

describe 'When basket_id is specified' do
it 'redirects to the created accept' do
post :create, params: { accept: @attrs, basket_id: 9 }
response.should redirect_to(accepts_url(basket_id: assigns(:accept).basket.id))
end
end
end

describe 'with invalid params' do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/budget_types_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def valid_attributes
budget_type = BudgetType.create! valid_attributes
# Assuming there are no other budget_types in the database, this
# specifies that the BudgetType created on the previous line
# receives the :update_attributes message with whatever params are
# receives the :update message with whatever params are
# submitted in the request.
BudgetType.any_instance.should_receive(:update).with('note' => 'test')
put :update, params: { id: budget_type.id, budget_type: { note: 'test' } }
Expand Down
Loading

0 comments on commit 86d9db5

Please sign in to comment.