1. Yuya Nishihara
  2. redmine_kagemai_import

Commits

Yuya Nishihara  committed aead3d0

simple way to find user

now users are found by login name.
login name is decided based on email@address by default.

  • Participants
  • Parent commits b7e79f3
  • Branches default

Comments (0)

Files changed (1)

File lib/tasks/import_kagemai_reports.rake

View file
  • Ignore whitespace
                   '保留' => '新規', '完了' => '終了'}
     DONE_RATIO_MAP = {'修正済' => 100, '確認待ち' => 100, '完了' => 100}  # default: 0
     PRIORITY_MAP = {'緊急' => '急いで', '高' => '高め', '中' => '通常', '低' => '低め'}
-    USER_EMAIL_MAP = {}
 
-    # assigned user name to email
-    USER_NAME_EMAIL_MAP = {'未定' => nil}
+    # user email or name to login name. '' means anonymous or unassigned.
+    USER_MAP = {
+      '未定' => '',
+    }
 
     def self.initialize()
       # we cannot add LOAD_PATH before loading rails due to unexpected
     end
 
     def self.map_author(kagemai_proj_id, report)  # report or message
-      name = encode(report['email'])
-      User.find_by_mail(USER_EMAIL_MAP[name] || name) or raise "unknown user: #{name}"
+      name = encode(report.respond_to?(:author) ? report.author.value : report.name.value)
+      login = USER_MAP[name] || USER_MAP[name.split('@').first] || name.split('@').first
+      User.find_by_login(login) or raise "unknown user: name=#{name}, login=#{login}"
     end
 
     def self.map_assigned_to(kagemai_proj_id, report)
       name = encode(report['assigned'])
-      email = USER_NAME_EMAIL_MAP.fetch(name, name)
-      return nil unless email  # nil means not assigned
-      User.find_by_mail(email) or raise "unknown user: #{name} (email: #{email})"
+      login = USER_MAP[name] || USER_MAP[name.split('@').first] || name.split('@').first
+      return nil if login.to_s.empty?  # '' means unassigned here
+      User.find_by_login(login) or raise "unknown user: name=#{name}, login=#{login}"
     end
 
     def self.map_done_ratio(kagemai_proj_id, report)