clear-code / redmine_full_text_search

Full text search for Redmine
MIT License
61 stars 24 forks source link

Conflict Redmine People plugin #57

Closed yassan closed 6 years ago

yassan commented 6 years ago

以下のプラグインを使っている場合、コンフリクトします。 People - Plugins - Redmine

アバターアイコンを変更出来るのですが、変更を確定した際に以下の500エラーが出て、以下のログが出てました。

Started PUT "/redmine/people/157" for 10.5.72.123 at 2018-08-31 12:34:42 +0900
Processing by PeopleController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"tottemo+tottemo+ttotemo+himitu", "person"=>{"information_attributes"=>{"is_system"=>"0", "middlename"=>"", "gender"=>"0", "appearance_date"=>"", "birthday"=>"", "job_title"=>"", "address"=>"", "phone"=>"", "skype"=>"", "facebook"=>"", "twitter"=>"", "linkedin"=>"", "background"=>"", "id"=>"157"}, "firstname"=>"太郎", "lastname"=>"山田", "mail"=>"yamada.taro@hoge.jp"}, "person_avatar"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x00007f788ee4f238 @tempfile=#<Tempfile:/tmp/RackMultipart20180831-13308-1g115zw.png>, @original_filename="taro.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"person_avatar[file]\"; filename=\"nagatomi.png\"\r\nContent-Type: image/png\r\n">}, "pwfmt_select_format"=>"textile", "pwfmt"=>{"formats"=>{"person_information_attributes_background"=>"textile"}}, "commit"=>"保存", "id"=>"157"}
  Current user: taro (id=157)
Saving attachment '/var/lib/redmine/files/2018/08/180831123442_taro.png' (560782 bytes)
Completed 500 Internal Server Error in 93ms (ActiveRecord: 36.2ms)

NoMethodError (undefined method `project_id' for #<User:0x00007f788e730600>
Did you mean?  project_ids
               project_ids=
               project
               projects
               project_ids_by_role
               object_id
               projects=):
  plugins/full_text_search/lib/full_text_search/model.rb:175:in `after_save'
  plugins/redmine_people/lib/acts_as_attachable_global/lib/acts_as_attachable_global.rb:96:in `block in attach_saved_attachments'
  plugins/redmine_people/lib/acts_as_attachable_global/lib/acts_as_attachable_global.rb:95:in `each'
  plugins/redmine_people/lib/acts_as_attachable_global/lib/acts_as_attachable_global.rb:95:in `attach_saved_attachments'
  app/models/attachment.rb:286:in `attach_files'
  plugins/redmine_people/app/controllers/people_controller.rb:277:in `attach_avatar'
  plugins/redmine_people/app/controllers/people_controller.rb:116:in `update'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'
  plugins/full_text_search/lib/full_text_search/model.rb:175:in `after_save'

とあったので確認したのですが、 redmine_full_text_search/model.rb at L175 の辺りに、

return if record.container.try(:project_id).blank?

を入れてみたところ、登録できるようになりました。

実行環境

Redmine 3.4.3 redmine_full_text_search v0.7.3 PGroonga 2.1.1 ruby 2.3.7p456 Rails 4.2.8 PostgreSQL 10.5 CentOS Linux release 7.5.1804 (Core)

PostgreSQLは公式のyumリポジトリを追加してインストール。 PGroongaもyumでインストール。

Redmineの状態

Environment:
  Redmine version                3.4.6.stable.17477
  Ruby version                   2.3.7-p456 (2018-03-28) [x86_64-linux]
  Rails version                  4.2.8
  Environment                    production
  Database adapter               PostgreSQL
SCM:
  Subversion                     1.7.14
  Git                            2.16.4
  Filesystem                     
Redmine plugins:
  clipboard_image_paste          1.12
  full_text_search               0.7.2
  periodictask                   3.2.1
  redmine_banner                 0.1.2
  redmine_checklists             3.1.11
  redmine_default_custom_query   1.3.0
  redmine_favorite_projects      2.0.3
  redmine_issue_badge            0.0.6
  redmine_issue_templates        0.2.0
  redmine_local_avatars          1.0.3
  redmine_logs                   0.1.1
  redmine_niko_cale              1.1.3-dev
  redmine_people                 1.3.2
  redmine_persist_wfmt           1.1.0
  redmine_pivot_table            0.0.6
  redmine_theme_changer          0.3.1
  redmine_wiki_extensions        0.8.1
  redmine_wiki_lists             0.0.9
  redmine_work_days              1.3.0
  redmine_work_time              0.3.4
  sidebar_hide                   0.0.8
  view_customize                 1.1.4
kou commented 6 years ago

ユーザーに紐付いた添付ファイルは検索対象外にしました。

akiko-pusu commented 6 years ago

I also confirmed this defect. Some plugins use Redmine’s attachment feature. Above case, people plugin uses the attachment feature to store user’s profile image as user’s attributes. After save the uploaded attachment, FullText’s after_save callback is fired. But the record object does not have the attribute, such as project_id, so Nomethod error happens.

init.rb:

  [Project, News, Issue, Document, Changeset, Message, Journal, WikiPage, WikiContent, CustomValue, Attachment].each do |klass|
    klass.include(FullTextSearch::Model)
  end

Same error might happen if above models include FullTextSearch::Model are saved without project id. (プロジェクトごとのスコープではなく、グローバルなスコープで、Attachementを使うようなプラグインはエラーになる可能性があるかなと思います)

Hope this comment would be any help.

akiko-pusu commented 6 years ago

Thanks!

kou commented 6 years ago

Same error might happen if above models include FullTextSearch::Model are saved without project id.

Tthat's right. The current search result page assumes that search target belongs to a project. If any useful use case is reported, we may support searching attachments that don't belong to a project. We just ignore attachments that don't belong to a project for now.

akiko-pusu commented 6 years ago

Thanks again. なんどもお手数おかけしてしまい恐れ入ります。とても便利なプラグインなので、本当にありがとうございます!

kou commented 6 years ago

いえいえ!いろいろ調査してもらってこちらも助かっています!