enju_leaf 1.1.0.rc9 → 1.1.0.rc10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/user_import_file.rb +39 -32
  3. data/app/models/user_import_file_state_machine.rb +19 -0
  4. data/app/models/user_import_file_transition.rb +7 -0
  5. data/app/views/page/_menu.html.erb +1 -3
  6. data/app/views/page/configuration.html.erb +13 -7
  7. data/app/views/page/export.html.erb +5 -0
  8. data/app/views/user_groups/index.html.erb +2 -0
  9. data/app/views/user_import_results/index.html.erb +2 -2
  10. data/app/views/users/_form.html.erb +1 -10
  11. data/app/views/users/new.html.erb +1 -1
  12. data/config/initializers/statesman.rb +3 -0
  13. data/config/locales/translation_en.yml +1 -1
  14. data/config/locales/translation_ja.yml +2 -2
  15. data/db/migrate/20140524074813_create_user_import_file_transitions.rb +14 -0
  16. data/db/migrate/20140610123439_drop_email_unique_constraint_enju_leaf_rc10.rb +11 -0
  17. data/lib/enju_leaf.rb +9 -0
  18. data/lib/enju_leaf/bookmark_url.rb +45 -0
  19. data/lib/enju_leaf/calculate_stat.rb +30 -0
  20. data/lib/enju_leaf/engine.rb +1 -0
  21. data/lib/enju_leaf/expire_editable_fragment.rb +30 -0
  22. data/lib/enju_leaf/expire_fragment_cache.rb +17 -0
  23. data/lib/enju_leaf/import_file.rb +13 -0
  24. data/lib/enju_leaf/localized_name.rb +15 -0
  25. data/lib/enju_leaf/master_model.rb +21 -0
  26. data/lib/enju_leaf/url_validator.rb +10 -0
  27. data/lib/enju_leaf/user.rb +1 -1
  28. data/lib/enju_leaf/version.rb +1 -1
  29. data/spec/dummy/config/initializers/statesman.rb +3 -0
  30. data/spec/dummy/db/migrate/20130421093852_add_periodical_to_manifestation.rb +5 -0
  31. data/spec/dummy/db/migrate/20130429020822_add_root_manifestation_id_to_series_statement.rb +6 -0
  32. data/spec/dummy/db/migrate/20130506175303_create_identifier_types.rb +12 -0
  33. data/spec/dummy/db/migrate/20130506175834_create_identifiers.rb +15 -0
  34. data/spec/dummy/db/schema.rb +57 -2
  35. data/spec/dummy/db/test.sqlite3 +0 -0
  36. data/spec/dummy/private/system/user_import_files/user_imports/980/190/963/original/user_import_file_sample.tsv +7 -5
  37. data/spec/dummy/solr/default/data/index/_2h.fdt +0 -0
  38. data/spec/dummy/solr/default/data/index/{_ug.fdx → _2h.fdx} +0 -0
  39. data/spec/dummy/solr/default/data/index/{_ug.fnm → _2h.fnm} +0 -0
  40. data/spec/dummy/solr/default/data/index/{_ug.nvd → _2h.nvd} +0 -0
  41. data/spec/dummy/solr/default/data/index/{_ug.nvm → _2h.nvm} +0 -0
  42. data/spec/dummy/solr/default/data/index/{_ug.si → _2h.si} +0 -0
  43. data/spec/dummy/solr/default/data/index/{_ug_Lucene41_0.doc → _2h_Lucene41_0.doc} +0 -0
  44. data/spec/dummy/solr/default/data/index/{_ug_Lucene41_0.pos → _2h_Lucene41_0.pos} +0 -0
  45. data/spec/dummy/solr/default/data/index/{_ug_Lucene41_0.tim → _2h_Lucene41_0.tim} +0 -0
  46. data/spec/dummy/solr/default/data/index/{_ug_Lucene41_0.tip → _2h_Lucene41_0.tip} +0 -0
  47. data/spec/dummy/solr/default/data/index/segments.gen +0 -0
  48. data/spec/dummy/solr/default/data/index/segments_57 +0 -0
  49. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000176 +0 -0
  50. data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002343 → tlog.0000000000000000177} +0 -0
  51. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000178 +0 -0
  52. data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002345 → tlog.0000000000000000179} +0 -0
  53. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000180 +0 -0
  54. data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002347 → tlog.0000000000000000181} +0 -0
  55. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000182 +0 -0
  56. data/spec/dummy/solr/default/data/tlog/{tlog.0000000000000002349 → tlog.0000000000000000183} +0 -0
  57. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000184 +0 -0
  58. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000000185 +0 -0
  59. data/spec/models/user_import_file_spec.rb +34 -7
  60. data/spec/routing/resource_import_files_routing_spec.rb +35 -0
  61. metadata +107 -55
  62. data/app/assets/stylesheets/scaffold.css +0 -56
  63. data/spec/dummy/solr/default/data/index/_ug.fdt +0 -0
  64. data/spec/dummy/solr/default/data/index/segments_1td +0 -0
  65. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002342 +0 -0
  66. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002344 +0 -0
  67. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002346 +0 -0
  68. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002348 +0 -0
  69. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002350 +0 -0
  70. data/spec/dummy/solr/default/data/tlog/tlog.0000000000000002351 +0 -0
@@ -0,0 +1,30 @@
1
+ module CalculateStat
2
+
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.send :include, InstanceMethods
6
+ base.class_eval do
7
+ validates_presence_of :start_date, :end_date
8
+ validate :check_date
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def calculate_stat
14
+ self.not_calculated.each do |stat|
15
+ stat.calculate_count!
16
+ end
17
+ end
18
+ end
19
+
20
+ module InstanceMethods
21
+ def check_date
22
+ if self.start_date and self.end_date
23
+ if self.start_date >= self.end_date
24
+ errors.add(:start_date)
25
+ errors.add(:end_date)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -9,6 +9,7 @@ require 'sitemap_generator'
9
9
  require 'redis-rails'
10
10
  require 'jquery-rails'
11
11
  require 'jquery-ui-rails'
12
+ require 'statesman'
12
13
  require 'resque/scheduler/server'
13
14
 
14
15
  module EnjuLeaf
@@ -0,0 +1,30 @@
1
+ module ExpireEditableFragment
2
+ def expire_editable_fragment(record, fragments = [])
3
+ fragments.uniq!
4
+ if record.is_a?(Manifestation)
5
+ if fragments.empty?
6
+ fragments = %w[manifestation_html show_detail_user_html show_detail_librarian_html pickup_html title_html title_mobile index_sru list_identifiers_oai list_records_oai]
7
+ end
8
+ expire_manifestation_cache(record, fragments)
9
+ else
10
+ I18n.available_locales.each do |locale|
11
+ Role.all_cache.each do |role|
12
+ fragments.each do |fragment|
13
+ expire_fragment(":#{record.class.to_s.downcase}" => record.id, :fragment => fragment, :role => role.name, :locale => locale)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+ def expire_manifestation_cache(manifestation, fragments = [])
22
+ I18n.available_locales.each do |locale|
23
+ Role.all_cache.each do |role|
24
+ fragments.uniq.each do |fragment|
25
+ expire_fragment(:manifestation => manifestation.id, :fragment => fragment, :role => role.name, :locale => locale)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ class ExpireFragmentCache
2
+ def self.expire_fragment_cache(record, fragments = [])
3
+ if record.is_a?(Manifestation)
4
+ if fragments.empty?
5
+ fragments = %w[manifestation_html show_detail_user_html show_detail_librarian_html pickup_html title_html title_mobile index_sru]
6
+ end
7
+ end
8
+
9
+ I18n.available_locales.each do |locale|
10
+ Role.all_cache.each do |role|
11
+ fragments.each do |fragment|
12
+ Rails.cache.delete(":#{record.class.to_s.downcase}" => record.id, :fragment => fragment, :role => role.name, :locale => locale)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module ImportFile
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ def expire
8
+ self.stucked.find_each do |file|
9
+ file.destroy
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module LocalizedName
2
+ def localize(locale = I18n.locale)
3
+ string = YAML.load(self)
4
+ if string.is_a?(Hash) and string[locale.to_s]
5
+ return string[locale.to_s]
6
+ end
7
+ self
8
+ rescue NoMethodError
9
+ self
10
+ end
11
+ end
12
+
13
+ class String
14
+ include LocalizedName
15
+ end
@@ -0,0 +1,21 @@
1
+ module MasterModel
2
+ def self.included(base)
3
+ #base.extend ClassMethods
4
+ base.send :include, InstanceMethods
5
+ base.class_eval do
6
+ acts_as_list
7
+ validates_uniqueness_of :name, :case_sensitive => false,
8
+ :message => I18n.t('Only lowercase letters and numbers are allowed.')
9
+ validates :name, :presence => true, :format => {:with => /\A[0-9A-Za-z][0-9A-Za-z_\-\s]*[0-9a-z]\Z/}
10
+ validates :display_name, :presence => true
11
+ before_validation :set_display_name, :on => :create
12
+ normalize_attributes :name
13
+ end
14
+ end
15
+
16
+ module InstanceMethods
17
+ def set_display_name
18
+ self.display_name = "#{I18n.locale}: #{self.name}" if self.display_name.blank?
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ class UrlValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ url = ::Addressable::URI.parse(value)
4
+ if url
5
+ unless ['http', 'https'].include?(url.scheme)
6
+ record.errors.add(attribute.to_sym)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -123,7 +123,7 @@ module EnjuLeaf
123
123
 
124
124
  def set_role_and_agent
125
125
  self.required_role = Role.where(:name => 'Librarian').first
126
- self.locale = I18n.default_locale.to_s
126
+ self.locale = I18n.default_locale.to_s unless locale
127
127
  #unless self.agent
128
128
  # self.agent = Agent.create(:full_name => self.username) if self.username
129
129
  #end
@@ -1,3 +1,3 @@
1
1
  module EnjuLeaf
2
- VERSION = "1.1.0.rc9"
2
+ VERSION = "1.1.0.rc10"
3
3
  end
@@ -0,0 +1,3 @@
1
+ Statesman.configure do
2
+ storage_adapter(Statesman::Adapters::ActiveRecord)
3
+ end
@@ -0,0 +1,5 @@
1
+ class AddPeriodicalToManifestation < ActiveRecord::Migration
2
+ def change
3
+ add_column :manifestations, :periodical, :boolean
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddRootManifestationIdToSeriesStatement < ActiveRecord::Migration
2
+ def change
3
+ add_column :series_statements, :root_manifestation_id, :integer
4
+ add_index :series_statements, :root_manifestation_id
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ class CreateIdentifierTypes < ActiveRecord::Migration
2
+ def change
3
+ create_table :identifier_types do |t|
4
+ t.string :name
5
+ t.text :display_name
6
+ t.text :note
7
+ t.integer :position
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ class CreateIdentifiers < ActiveRecord::Migration
2
+ def change
3
+ create_table :identifiers do |t|
4
+ t.string :body, :null => false
5
+ t.integer :identifier_type_id, :null => false
6
+ t.integer :manifestation_id
7
+ t.boolean :primary
8
+ t.integer :position
9
+
10
+ t.timestamps
11
+ end
12
+ add_index :identifiers, [:body, :identifier_type_id]
13
+ add_index :identifiers, :manifestation_id
14
+ end
15
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20140110131010) do
14
+ ActiveRecord::Schema.define(:version => 20140610123439) do
15
15
 
16
16
  create_table "accepts", :force => true do |t|
17
17
  t.integer "basket_id"
@@ -278,6 +278,28 @@ ActiveRecord::Schema.define(:version => 20140110131010) do
278
278
  t.datetime "updated_at", :null => false
279
279
  end
280
280
 
281
+ create_table "identifier_types", :force => true do |t|
282
+ t.string "name"
283
+ t.text "display_name"
284
+ t.text "note"
285
+ t.integer "position"
286
+ t.datetime "created_at", :null => false
287
+ t.datetime "updated_at", :null => false
288
+ end
289
+
290
+ create_table "identifiers", :force => true do |t|
291
+ t.string "body", :null => false
292
+ t.integer "identifier_type_id", :null => false
293
+ t.integer "manifestation_id"
294
+ t.boolean "primary"
295
+ t.integer "position"
296
+ t.datetime "created_at", :null => false
297
+ t.datetime "updated_at", :null => false
298
+ end
299
+
300
+ add_index "identifiers", ["body", "identifier_type_id"], :name => "index_identifiers_on_body_and_identifier_type_id"
301
+ add_index "identifiers", ["manifestation_id"], :name => "index_identifiers_on_manifestation_id"
302
+
281
303
  create_table "import_requests", :force => true do |t|
282
304
  t.string "isbn"
283
305
  t.string "state"
@@ -474,6 +496,7 @@ ActiveRecord::Schema.define(:version => 20140110131010) do
474
496
  t.integer "month_of_publication"
475
497
  t.boolean "fulltext_content"
476
498
  t.string "doi"
499
+ t.boolean "periodical"
477
500
  end
478
501
 
479
502
  add_index "manifestations", ["access_address"], :name => "index_manifestations_on_access_address"
@@ -546,6 +569,24 @@ ActiveRecord::Schema.define(:version => 20140110131010) do
546
569
  add_index "produces", ["agent_id"], :name => "index_produces_on_agent_id"
547
570
  add_index "produces", ["manifestation_id"], :name => "index_produces_on_manifestation_id"
548
571
 
572
+ create_table "profiles", :force => true do |t|
573
+ t.integer "user_id"
574
+ t.integer "user_group_id"
575
+ t.integer "library_id"
576
+ t.string "locale"
577
+ t.string "user_number"
578
+ t.text "full_name"
579
+ t.text "note"
580
+ t.text "keyword_list"
581
+ t.integer "required_role_id"
582
+ t.string "state"
583
+ t.datetime "created_at", :null => false
584
+ t.datetime "updated_at", :null => false
585
+ end
586
+
587
+ add_index "profiles", ["user_id"], :name => "index_profiles_on_user_id"
588
+ add_index "profiles", ["user_number"], :name => "index_profiles_on_user_number"
589
+
549
590
  create_table "realize_types", :force => true do |t|
550
591
  t.string "name"
551
592
  t.text "display_name"
@@ -696,9 +737,11 @@ ActiveRecord::Schema.define(:version => 20140110131010) do
696
737
  t.integer "manifestation_id"
697
738
  t.text "note"
698
739
  t.text "title_subseries_transcription"
740
+ t.integer "root_manifestation_id"
699
741
  end
700
742
 
701
743
  add_index "series_statements", ["manifestation_id"], :name => "index_series_statements_on_manifestation_id"
744
+ add_index "series_statements", ["root_manifestation_id"], :name => "index_series_statements_on_root_manifestation_id"
702
745
  add_index "series_statements", ["series_statement_identifier"], :name => "index_series_statements_on_series_statement_identifier"
703
746
 
704
747
  create_table "shelves", :force => true do |t|
@@ -767,6 +810,18 @@ ActiveRecord::Schema.define(:version => 20140110131010) do
767
810
  add_index "user_has_roles", ["role_id"], :name => "index_user_has_roles_on_role_id"
768
811
  add_index "user_has_roles", ["user_id"], :name => "index_user_has_roles_on_user_id"
769
812
 
813
+ create_table "user_import_file_transitions", :force => true do |t|
814
+ t.string "to_state"
815
+ t.text "metadata", :default => "{}"
816
+ t.integer "sort_key"
817
+ t.integer "user_import_file_id"
818
+ t.datetime "created_at", :null => false
819
+ t.datetime "updated_at", :null => false
820
+ end
821
+
822
+ add_index "user_import_file_transitions", ["sort_key", "user_import_file_id"], :name => "index_user_import_file_transitions_on_sort_key_and_file_id", :unique => true
823
+ add_index "user_import_file_transitions", ["user_import_file_id"], :name => "index_user_import_file_transitions_on_user_import_file_id"
824
+
770
825
  create_table "user_import_files", :force => true do |t|
771
826
  t.integer "user_id"
772
827
  t.text "note"
@@ -821,7 +876,7 @@ ActiveRecord::Schema.define(:version => 20140110131010) do
821
876
  t.datetime "confirmed_at"
822
877
  end
823
878
 
824
- add_index "users", ["email"], :name => "index_users_on_email", :unique => true
879
+ add_index "users", ["email"], :name => "index_users_on_email"
825
880
  add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
826
881
  add_index "users", ["unlock_token"], :name => "index_users_on_unlock_token", :unique => true
827
882
  add_index "users", ["user_group_id"], :name => "index_users_on_user_group_id"
Binary file
@@ -1,5 +1,7 @@
1
- username email user_number role user_group expired_at password note dummy
2
- user001 user001@example.jp 001001 Administrator user test
3
- user002 001002 User faculty 2013-12-01
4
- user003 user003@example.jp 001003 Librarian user 4NsxXPLy テストユーザ
5
- user004 001004 user t
1
+ username email user_number role user_group expired_at password library locale note dummy
2
+ user001 user001@example.jp 001001 Administrator user test
3
+ user002 001002 User faculty 2013-12-01 en
4
+ user003 user003@example.jp 001003 Librarian user 4NsxXPLy kamata ja テストユーザ
5
+ user004 001004 user t
6
+ user005 001005 faculty 2014-12-01 hoge fuga
7
+ user006 usernameのみ
@@ -14,29 +14,56 @@ describe UserImportFile do
14
14
  it "should be imported" do
15
15
  old_users_count = User.count
16
16
  old_import_results_count = UserImportResult.count
17
- @file.state.should eq 'pending'
18
- @file.import_start.should eq({:user_imported => 3, :user_found => 0, :failed => 0})
19
- User.order('id DESC')[1].username.should eq 'user002'
20
- User.order('id DESC')[2].username.should eq 'user001'
21
- User.count.should eq old_users_count + 3
17
+ @file.current_state.should eq 'pending'
18
+ @file.import_start.should eq({:user_imported => 5, :user_found => 0, :failed => 0})
19
+ User.order('id DESC')[1].username.should eq 'user005'
20
+ User.order('id DESC')[2].username.should eq 'user003'
21
+ User.count.should eq old_users_count + 5
22
22
 
23
23
  user002 = User.where(:username => 'user002').first
24
24
  user002.user_number.should eq '001002'
25
25
  user002.user_group.name.should eq 'faculty'
26
26
  user002.expired_at.to_i.should eq Time.zone.parse('2013-12-01').end_of_day.to_i
27
27
  user002.valid_password?('4NsxXPLy')
28
+ user002.user_number.should eq '001002'
29
+ user002.library.name.should eq 'web'
30
+ user002.locale.should eq 'en'
28
31
 
29
32
  user003 = User.where(:username => 'user003').first
30
- user002.user_number.should eq '001002'
31
33
  user003.note.should eq 'テストユーザ'
32
34
  user003.role.name.should eq 'Librarian'
33
35
  user003.user_number.should eq '001003'
36
+ user003.library.name.should eq 'kamata'
37
+ user003.locale.should eq 'ja'
34
38
  User.where(:username => 'user000').first.should be_nil
35
- UserImportResult.count.should eq old_import_results_count + 4
39
+ UserImportResult.count.should eq old_import_results_count + 6
40
+
41
+ user005 = User.where(username: 'user005').first
42
+ user005.role.name.should eq 'User'
43
+ user005.library.name.should eq 'web'
44
+ user005.locale.should eq 'en'
45
+ user005.user_number.should eq '001005'
46
+ user005.user_group.name.should eq 'faculty'
47
+
48
+ user006 = User.where(username: 'user006').first
49
+ user006.role.name.should eq 'User'
50
+ user006.library.name.should eq 'web'
51
+ user006.locale.should eq 'en'
52
+ user006.user_number.should be_nil
53
+ user006.user_group.name.should eq 'not_specified'
36
54
 
37
55
  @file.user_import_fingerprint.should be_true
38
56
  @file.executed_at.should be_true
39
57
  end
58
+
59
+ it "should not import users that have higher roles than current user's role" do
60
+ old_users_count = User.count
61
+ old_import_results_count = UserImportResult.count
62
+ @file.user = User.where(username: 'librarian1').first
63
+ @file.import_start.should eq({:user_imported => 4, :user_found => 0, :failed => 1})
64
+ User.order('id DESC')[1].username.should eq 'user005'
65
+ User.count.should eq old_users_count + 4
66
+ end
40
67
  end
41
68
 
42
69
  describe "when its mode is 'update'" do