LoginSignup
4
4

More than 5 years have passed since last update.

RedmineのwikiにRestAPI用のIDリストを出力するスクリプト(※要 ViewCustomizePlugin)

Last updated at Posted at 2016-04-21

RedmineのView Customize plugin でwikiページにRestApi用のキー一覧を表示してみました。
Redmineのバージョンは3.1.1です。

RedmineのwikiにIdlistというページを作成して、View Customize pluginで以下を登録
Path pattern: wiki/Idlist
Type:javascript
Code:

$(function () {
  var home = $("a.home").attr("href");
  var getList = 
    ["projects",
     "users", 
     "groups",
     "trackers",
     "issue_statuses",
     "custom_fields",
    ];
  $.each(getList,function (i, target) {
    $.get(home + target + ".json?limit=500")
    .then(function(data) {
      var table = $("<table><tr><th colspan=2>" + target + "</th></tr></table>");
      $.each(data[target], function (j, tObj) {
        var name;
        if (tObj.name) {
          name = tObj.name;
        } else {
          name = tObj.lastname + " " + tObj.firstname
        }
        table.append("<tr><td>" + tObj.id + "</td><td>" + name + "</td></tr>");
      });
      $("div.wiki-page").append(table);
    });
  });
});

ページを開いたときに認証ダイアログが表示されます。
ユーザ一覧、グループ一覧を表示するにはシステム管理者権限のあるユーザで認証する必要があるようです。

一行目に以下を設定すれば認証の手間が省けますが、システム管理者のapikeyが公開されてしまうので、お勧めできません。

$.ajaxSetup({"headers": {"X-Redmine-API-Key" : "※RedmineのApiKey"}});
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4