agileware-jp / redmine_issue_templates

Redmine Issue Template. Pull requests, reporting issues, stars and sponsoring are always welcome!
https://www.redmine.org/plugins/redmine_issue_templates
GNU General Public License v2.0
65 stars 28 forks source link

Template for note: Sorting doesn't work #20

Closed yui-har closed 2 years ago

yui-har commented 2 years ago

Summary

When you have edit_issue_templates permission, you can sort the templates for note. However, it cannot be sorted at present.

ScreenShot 2022-04-18 16 47 48

Description

When I confirmed the development log, I couldn't update the data and it was rolling back.

Started PUT "/projects/test-proj/note_templates/2" for 127.0.0.1 at 2022-04-18 15:02:10 +0900
Processing by NoteTemplatesController#update as JS
  Parameters: {"note_template"=>{"position"=>"3"}, "project_id"=>"test-proj", "id"=>"2"}
  Token Update All (2.0ms)  UPDATE "tokens" SET "updated_on" = '2022-04-18 15:02:10.634547' WHERE "tokens"."user_id" = ? AND "tokens"."value" = ? AND "tokens"."action" = ?  [["user_id", 1], ["value", "9471cf9282f6618b6a03da3bf64c09274373dd23"], ["action", "session"]]
   (0.4ms)  SELECT MAX("settings"."updated_on") FROM "settings"
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') AND "users"."status" = ? AND "users"."id" = ? LIMIT ?  [["status", 1], ["id", 1], ["LIMIT", 1]]
  Current user: admin (id=1)
  Project Load (0.4ms)  SELECT  "projects".* FROM "projects" WHERE "projects"."identifier" = ? LIMIT ?  [["identifier", "test-proj"], ["LIMIT", 1]]
   (0.5ms)  SELECT "enabled_modules"."name" FROM "enabled_modules" WHERE "enabled_modules"."project_id" = ?  [["project_id", 7]]
  NoteTemplate Load (0.1ms)  SELECT  "note_templates".* FROM "note_templates" WHERE "note_templates"."id" = ? LIMIT ?  [["id", 2], ["LIMIT", 1]]
  Project Load (0.2ms)  SELECT  "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT ?  [["id", 7], ["LIMIT", 1]]
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') AND "users"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
   (0.0ms)  begin transaction
  NoteTemplate Exists (0.2ms)  SELECT  1 AS one FROM "note_templates" WHERE "note_templates"."name" = ? AND "note_templates"."id" != ? AND "note_templates"."project_id" = ? LIMIT ?  [["name", "comment 2:Dev+Repo"], ["id", 2], ["project_id", 7], ["LIMIT", 1]]
  Tracker Load (0.6ms)  SELECT  "trackers".* FROM "trackers" WHERE "trackers"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
   (0.1ms)  rollback transaction
  Rendering plugins/redmine_issue_templates/app/views/note_templates/show.html.erb

Environment

yui-har commented 2 years ago

When I checked it with rails console, it seems that it is not a sorting problem but a validation defect.

[2] pry(main)> note = NoteTemplate.find 1
  NoteTemplate Load (1.1ms)  SELECT  "note_templates".* FROM "note_templates" WHERE "note_templates"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
=> #<NoteTemplate:0x00007fa99b668680
 id: 1,
 name: "comment 1:Repo",
 description: "comment-1\r\ncomment-2\r\ncomment-3\r\n",
 memo: "",
 project_id: 7,
 tracker_id: 1,
 author_id: 1,
 enabled: true,
 position: 1,
 created_at: Tue, 05 Apr 2022 07:30:59 UTC +00:00,
 updated_at: Mon, 18 Apr 2022 05:25:14 UTC +00:00,
 visibility: "roles">
[3] pry(main)> note.position = 2
=> 2
[4] pry(main)> note.valid?
  NoteTemplate Exists (0.1ms)  SELECT  1 AS one FROM "note_templates" WHERE "note_templates"."name" = ? AND "note_templates"."id" != ? AND "note_templates"."project_id" = ? LIMIT ?  [["name", "comment 1:Repo"], ["id", 1], ["project_id", 7], ["LIMIT", 1]]
  Tracker Load (0.5ms)  SELECT  "trackers".* FROM "trackers" WHERE "trackers"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
=> false
[5] pry(main)> note.errors
=> #<ActiveModel::Errors:0x00007fa99b5b39d8
 @base=
  #<NoteTemplate:0x00007fa99b668680
   id: 1,
   name: "comment 1:Repo",
   description: "comment-1\r\ncomment-2\r\ncomment-3\r\n",
   memo: "",
   project_id: 7,
   tracker_id: 1,
   author_id: 1,
   enabled: true,
   position: 2,
   created_at: Tue, 05 Apr 2022 07:30:59 UTC +00:00,
   updated_at: Mon, 18 Apr 2022 05:25:14 UTC +00:00,
   visibility: "roles">,
 @details={:role_ids=>[{:error=>:blank}]},
 @messages={:role_ids=>["cannot be blank"]}>
[6] pry(main)>
yui-har commented 2 years ago

@kyamada23 @nishidayuya Thank you for reviewing and merging #25 and #26. If the problem is resolved, please close this issue.